diff --git a/csharp/Svix/Abstractions/IStatistics.cs b/csharp/Svix/Abstractions/IStatistics.cs new file mode 100644 index 000000000..b1b063eb1 --- /dev/null +++ b/csharp/Svix/Abstractions/IStatistics.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Svix.Model; +using Svix.Models; + +namespace Svix.Abstractions +{ + public interface IStatistics + { + AppUsageStatsOut AggregateAppStats(AppUsageStatsIn appUsageStatsIn, string idempotencyKey = default); + + Task AggregateAppStatsAsync(AppUsageStatsIn appUsageStatsIn, string idempotencyKey = default); + + AggregateEventTypesOut AggregateEventTypes(); + + Task AggregateEventTypesAsync(); + + } +} diff --git a/csharp/Svix/Statistics.cs b/csharp/Svix/Statistics.cs new file mode 100644 index 000000000..3e99fee9f --- /dev/null +++ b/csharp/Svix/Statistics.cs @@ -0,0 +1,101 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Svix.Abstractions; +using Svix.Api; +using Svix.Client; +using Svix.Model; + +namespace Svix +{ + public sealed class Statistics : SvixResourceBase, IStatistics + { + private readonly IStatisticsApi _statisticsApi; + + public Statistics(ISvixClient svixClient, IStatisticsApi statisticsApi) + : base(svixClient) + { + _statisticsApi = statisticsApi ?? throw new ArgumentNullException(nameof(statisticsApi)); + } + + public AppUsageStatsOut AggregateAppStats(AppUsageStatsIn appUsageStatsIn, string idempotencyKey = default) + { + try + { + var res = _statisticsApi.AggregateAppStats( + appUsageStatsIn, + idempotencyKey); + + return res; + } + catch (ApiException e) + { + Logger?.LogError(e, $"{nameof(AggregateAppStats)} failed"); + + if (Throw) + throw; + + return null; + } + } + + public async Task AggregateAppStatsAsync(AppUsageStatsIn appUsageStatsIn, string idempotencyKey = default) + { + try + { + var res = await _statisticsApi.AggregateAppStatsAsync( + appUsageStatsIn, + idempotencyKey); + + return res; + } + catch (ApiException e) + { + Logger?.LogError(e, $"{nameof(AggregateAppStatsAsync)} failed"); + + if (Throw) + throw; + + return null; + } + } + + public AggregateEventTypesOut AggregateEventTypes() + { + try + { + var res = _statisticsApi.AggregateEventTypes(); + + return res; + } + catch (ApiException e) + { + Logger?.LogError(e, $"{nameof(AggregateAppStatsAsync)} failed"); + + if (Throw) + throw; + + return null; + } + } + + public async Task AggregateEventTypesAsync() + { + try + { + var res = await _statisticsApi.AggregateEventTypesAsync(); + + return res; + } + catch (ApiException e) + { + Logger?.LogError(e, $"{nameof(AggregateAppStatsAsync)} failed"); + + if (Throw) + throw; + + return null; + } + } + } +} diff --git a/csharp/Svix/SvixClient.cs b/csharp/Svix/SvixClient.cs index 8accde2eb..9d1fb38e3 100644 --- a/csharp/Svix/SvixClient.cs +++ b/csharp/Svix/SvixClient.cs @@ -31,6 +31,8 @@ public sealed class SvixClient : ISvixClient public IMessageAttempt MessageAttempt { get; } + public IStatistics Statistics { get; } + public ILogger Logger { get; } public string ServerUrl => _options?.ServerUrl; @@ -44,7 +46,7 @@ public sealed class SvixClient : ISvixClient public SvixClient(string token, ISvixOptions options, ILogger logger = null , IApplicationApi applicationApi = null, IAuthenticationApi authenticationApi = null, IEndpointApi endpointApi = null , IEventTypeApi eventTypeApi = null, IHealthApi healthApi = null, IIntegrationApi integrationApi = null - , IMessageApi messageApi = null, IMessageAttemptApi messageAttemptApi = null) + , IMessageApi messageApi = null, IMessageAttemptApi messageAttemptApi = null, IStatisticsApi statisticsApi = null) { Logger = logger; _options = options ?? throw new ArgumentNullException(nameof(options)); @@ -58,6 +60,7 @@ public SvixClient(string token, ISvixOptions options, ILogger logger Integration = new Integration(this, integrationApi ?? new IntegrationApi(Config)); Message = new Message(this, messageApi ?? new MessageApi(Config)); MessageAttempt = new MessageAttempt(this, messageAttemptApi ?? new MessageAttemptApi(Config)); + Statistics = new Statistics(this, statisticsApi ?? new StatisticsApi(Config)); } public SvixClient(string token, ISvixOptions options, ILogger logger) diff --git a/go/internal/openapi/api_statistics.go b/go/internal/openapi/api_statistics.go index bdba84f4f..8f496ab2b 100644 --- a/go/internal/openapi/api_statistics.go +++ b/go/internal/openapi/api_statistics.go @@ -28,34 +28,37 @@ var ( // StatisticsApiService StatisticsApi service type StatisticsApiService service -type ApiCalculateAggregateAppStatsRequest struct { +type ApiAggregateAppStatsRequest struct { ctx _context.Context ApiService *StatisticsApiService appUsageStatsIn *AppUsageStatsIn idempotencyKey *string } -func (r ApiCalculateAggregateAppStatsRequest) AppUsageStatsIn(appUsageStatsIn AppUsageStatsIn) ApiCalculateAggregateAppStatsRequest { +func (r ApiAggregateAppStatsRequest) AppUsageStatsIn(appUsageStatsIn AppUsageStatsIn) ApiAggregateAppStatsRequest { r.appUsageStatsIn = &appUsageStatsIn return r } -func (r ApiCalculateAggregateAppStatsRequest) IdempotencyKey(idempotencyKey string) ApiCalculateAggregateAppStatsRequest { +func (r ApiAggregateAppStatsRequest) IdempotencyKey(idempotencyKey string) ApiAggregateAppStatsRequest { r.idempotencyKey = &idempotencyKey return r } -func (r ApiCalculateAggregateAppStatsRequest) Execute() (AppUsageStatsOut, *_nethttp.Response, error) { - return r.ApiService.CalculateAggregateAppStatsExecute(r) +func (r ApiAggregateAppStatsRequest) Execute() (AppUsageStatsOut, *_nethttp.Response, error) { + return r.ApiService.AggregateAppStatsExecute(r) } /* - * CalculateAggregateAppStats Calculate Aggregate App Stats + * AggregateAppStats Aggregate App Stats * Creates a background task to calculate the message destinations for all applications in the environment. + +Note that this endpoint is asynchronous. You will need to poll the `Get Background Task` endpoint to +retrieve the results of the operation. * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). - * @return ApiCalculateAggregateAppStatsRequest + * @return ApiAggregateAppStatsRequest */ -func (a *StatisticsApiService) CalculateAggregateAppStats(ctx _context.Context) ApiCalculateAggregateAppStatsRequest { - return ApiCalculateAggregateAppStatsRequest{ +func (a *StatisticsApiService) AggregateAppStats(ctx _context.Context) ApiAggregateAppStatsRequest { + return ApiAggregateAppStatsRequest{ ApiService: a, ctx: ctx, } @@ -65,7 +68,7 @@ func (a *StatisticsApiService) CalculateAggregateAppStats(ctx _context.Context) * Execute executes the request * @return AppUsageStatsOut */ -func (a *StatisticsApiService) CalculateAggregateAppStatsExecute(r ApiCalculateAggregateAppStatsRequest) (AppUsageStatsOut, *_nethttp.Response, error) { +func (a *StatisticsApiService) AggregateAppStatsExecute(r ApiAggregateAppStatsRequest) (AppUsageStatsOut, *_nethttp.Response, error) { var ( localVarHTTPMethod = _nethttp.MethodPost localVarPostBody interface{} @@ -75,7 +78,7 @@ func (a *StatisticsApiService) CalculateAggregateAppStatsExecute(r ApiCalculateA localVarReturnValue AppUsageStatsOut ) - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "StatisticsApiService.CalculateAggregateAppStats") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "StatisticsApiService.AggregateAppStats") if err != nil { return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} } @@ -217,6 +220,180 @@ func (a *StatisticsApiService) CalculateAggregateAppStatsExecute(r ApiCalculateA return localVarReturnValue, localVarHTTPResponse, nil } +type ApiAggregateEventTypesRequest struct { + ctx _context.Context + ApiService *StatisticsApiService +} + + +func (r ApiAggregateEventTypesRequest) Execute() (AggregateEventTypesOut, *_nethttp.Response, error) { + return r.ApiService.AggregateEventTypesExecute(r) +} + +/* + * AggregateEventTypes Aggregate Event Types + * Creates a background task to calculate the listed event types for all apps in the organization. + +Note that this endpoint is asynchronous. You will need to poll the `Get Background Task` endpoint to +retrieve the results of the operation. + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @return ApiAggregateEventTypesRequest + */ +func (a *StatisticsApiService) AggregateEventTypes(ctx _context.Context) ApiAggregateEventTypesRequest { + return ApiAggregateEventTypesRequest{ + ApiService: a, + ctx: ctx, + } +} + +/* + * Execute executes the request + * @return AggregateEventTypesOut + */ +func (a *StatisticsApiService) AggregateEventTypesExecute(r ApiAggregateEventTypesRequest) (AggregateEventTypesOut, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPut + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + localVarReturnValue AggregateEventTypesOut + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "StatisticsApiService.AggregateEventTypes") + if err != nil { + return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/api/v1/stats/usage/event-types/" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v HttpErrorOut + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v HttpErrorOut + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 403 { + var v HttpErrorOut + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v HttpErrorOut + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 409 { + var v HttpErrorOut + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 422 { + var v HTTPValidationError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHTTPResponse, newErr + } + if localVarHTTPResponse.StatusCode == 429 { + var v HttpErrorOut + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + type ApiV1StatsAppAttemptsRequest struct { ctx _context.Context ApiService *StatisticsApiService diff --git a/go/internal/openapi/model_aggregate_event_types_out.go b/go/internal/openapi/model_aggregate_event_types_out.go new file mode 100644 index 000000000..a059869a3 --- /dev/null +++ b/go/internal/openapi/model_aggregate_event_types_out.go @@ -0,0 +1,166 @@ +/* + * Svix API + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * API version: 1.1.1 + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package openapi + +import ( + "encoding/json" +) + +// AggregateEventTypesOut struct for AggregateEventTypesOut +type AggregateEventTypesOut struct { + Id string `json:"id"` + Status BackgroundTaskStatus `json:"status"` + Task BackgroundTaskType `json:"task"` +} + +// NewAggregateEventTypesOut instantiates a new AggregateEventTypesOut object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewAggregateEventTypesOut(id string, status BackgroundTaskStatus, task BackgroundTaskType) *AggregateEventTypesOut { + this := AggregateEventTypesOut{} + this.Id = id + this.Status = status + this.Task = task + return &this +} + +// NewAggregateEventTypesOutWithDefaults instantiates a new AggregateEventTypesOut object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewAggregateEventTypesOutWithDefaults() *AggregateEventTypesOut { + this := AggregateEventTypesOut{} + return &this +} + +// GetId returns the Id field value +func (o *AggregateEventTypesOut) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *AggregateEventTypesOut) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *AggregateEventTypesOut) SetId(v string) { + o.Id = v +} + +// GetStatus returns the Status field value +func (o *AggregateEventTypesOut) GetStatus() BackgroundTaskStatus { + if o == nil { + var ret BackgroundTaskStatus + return ret + } + + return o.Status +} + +// GetStatusOk returns a tuple with the Status field value +// and a boolean to check if the value has been set. +func (o *AggregateEventTypesOut) GetStatusOk() (*BackgroundTaskStatus, bool) { + if o == nil { + return nil, false + } + return &o.Status, true +} + +// SetStatus sets field value +func (o *AggregateEventTypesOut) SetStatus(v BackgroundTaskStatus) { + o.Status = v +} + +// GetTask returns the Task field value +func (o *AggregateEventTypesOut) GetTask() BackgroundTaskType { + if o == nil { + var ret BackgroundTaskType + return ret + } + + return o.Task +} + +// GetTaskOk returns a tuple with the Task field value +// and a boolean to check if the value has been set. +func (o *AggregateEventTypesOut) GetTaskOk() (*BackgroundTaskType, bool) { + if o == nil { + return nil, false + } + return &o.Task, true +} + +// SetTask sets field value +func (o *AggregateEventTypesOut) SetTask(v BackgroundTaskType) { + o.Task = v +} + +func (o AggregateEventTypesOut) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if true { + toSerialize["id"] = o.Id + } + if true { + toSerialize["status"] = o.Status + } + if true { + toSerialize["task"] = o.Task + } + return json.Marshal(toSerialize) +} + +type NullableAggregateEventTypesOut struct { + value *AggregateEventTypesOut + isSet bool +} + +func (v NullableAggregateEventTypesOut) Get() *AggregateEventTypesOut { + return v.value +} + +func (v *NullableAggregateEventTypesOut) Set(val *AggregateEventTypesOut) { + v.value = val + v.isSet = true +} + +func (v NullableAggregateEventTypesOut) IsSet() bool { + return v.isSet +} + +func (v *NullableAggregateEventTypesOut) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAggregateEventTypesOut(val *AggregateEventTypesOut) *NullableAggregateEventTypesOut { + return &NullableAggregateEventTypesOut{value: val, isSet: true} +} + +func (v NullableAggregateEventTypesOut) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAggregateEventTypesOut) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + diff --git a/go/internal/openapi/model_background_task_type.go b/go/internal/openapi/model_background_task_type.go index 8d0c25a9b..32504c50a 100644 --- a/go/internal/openapi/model_background_task_type.go +++ b/go/internal/openapi/model_background_task_type.go @@ -25,6 +25,7 @@ const ( BACKGROUNDTASKTYPE_APPLICATION_STATS BackgroundTaskType = "application.stats" BACKGROUNDTASKTYPE_MESSAGE_BROADCAST BackgroundTaskType = "message.broadcast" BACKGROUNDTASKTYPE_SDK_GENERATE BackgroundTaskType = "sdk.generate" + BACKGROUNDTASKTYPE_EVENT_TYPE_AGGREGATE BackgroundTaskType = "event-type.aggregate" ) var allowedBackgroundTaskTypeEnumValues = []BackgroundTaskType{ @@ -33,6 +34,7 @@ var allowedBackgroundTaskTypeEnumValues = []BackgroundTaskType{ "application.stats", "message.broadcast", "sdk.generate", + "event-type.aggregate", } func (v *BackgroundTaskType) UnmarshalJSON(src []byte) error { diff --git a/go/internal/openapi/model_message_attempt_headers_out.go b/go/internal/openapi/model_message_attempt_headers_out.go index 6c16622df..25d87e8d8 100644 --- a/go/internal/openapi/model_message_attempt_headers_out.go +++ b/go/internal/openapi/model_message_attempt_headers_out.go @@ -16,6 +16,7 @@ import ( // MessageAttemptHeadersOut struct for MessageAttemptHeadersOut type MessageAttemptHeadersOut struct { + ResponseHeaders [][]string `json:"responseHeaders,omitempty"` Sensitive []string `json:"sensitive"` SentHeaders map[string]string `json:"sentHeaders"` } @@ -39,6 +40,39 @@ func NewMessageAttemptHeadersOutWithDefaults() *MessageAttemptHeadersOut { return &this } +// GetResponseHeaders returns the ResponseHeaders field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *MessageAttemptHeadersOut) GetResponseHeaders() [][]string { + if o == nil { + var ret [][]string + return ret + } + return o.ResponseHeaders +} + +// GetResponseHeadersOk returns a tuple with the ResponseHeaders field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *MessageAttemptHeadersOut) GetResponseHeadersOk() (*[][]string, bool) { + if o == nil || o.ResponseHeaders == nil { + return nil, false + } + return &o.ResponseHeaders, true +} + +// HasResponseHeaders returns a boolean if a field has been set. +func (o *MessageAttemptHeadersOut) HasResponseHeaders() bool { + if o != nil && o.ResponseHeaders != nil { + return true + } + + return false +} + +// SetResponseHeaders gets a reference to the given [][]string and assigns it to the ResponseHeaders field. +func (o *MessageAttemptHeadersOut) SetResponseHeaders(v [][]string) { + o.ResponseHeaders = v +} + // GetSensitive returns the Sensitive field value func (o *MessageAttemptHeadersOut) GetSensitive() []string { if o == nil { @@ -89,6 +123,9 @@ func (o *MessageAttemptHeadersOut) SetSentHeaders(v map[string]string) { func (o MessageAttemptHeadersOut) MarshalJSON() ([]byte, error) { toSerialize := map[string]interface{}{} + if o.ResponseHeaders != nil { + toSerialize["responseHeaders"] = o.ResponseHeaders + } if true { toSerialize["sensitive"] = o.Sensitive } diff --git a/go/statistics.go b/go/statistics.go new file mode 100644 index 000000000..0677fcdbf --- /dev/null +++ b/go/statistics.go @@ -0,0 +1,46 @@ +package svix + +import ( + "context" + + "github.com/svix/svix-webhooks/go/internal/openapi" +) + +type Statistics struct { + api *openapi.APIClient +} + +type ( + AppUsageStatsIn = openapi.AppUsageStatsIn + AppUsageStatsOut = openapi.AppUsageStatsOut + AggregateEventTypesOut = openapi.AggregateEventTypesOut +) + +func (s *Statistics) AggregateAppStats(ctx context.Context, appUsageStatsIn *AppUsageStatsIn, options *PostOptions) (*AppUsageStatsOut, error) { + req := s.api.StatisticsApi.AggregateAppStats(ctx) + if appUsageStatsIn != nil { + req = req.AppUsageStatsIn(*appUsageStatsIn) + } + if options != nil { + if options.IdempotencyKey != nil { + req = req.IdempotencyKey(*options.IdempotencyKey) + } + } + out, res, err := req.Execute() + if err != nil { + return nil, wrapError(err, res) + } + ret := AppUsageStatsOut(out) + return &ret, nil +} + +func (s *Statistics) AggregateEventTypes(ctx context.Context) (*AggregateEventTypesOut, error) { + req := s.api.StatisticsApi.AggregateEventTypes(ctx) + + out, res, err := req.Execute() + if err != nil { + return nil, wrapError(err, res) + } + ret := AggregateEventTypesOut(out) + return &ret, nil +} diff --git a/go/svix.go b/go/svix.go index ecff13c0f..950e6e5b5 100644 --- a/go/svix.go +++ b/go/svix.go @@ -27,6 +27,7 @@ type ( Integration *Integration Message *Message MessageAttempt *MessageAttempt + Statistics *Statistics } ) @@ -98,5 +99,8 @@ func New(token string, options *SvixOptions) *Svix { MessageAttempt: &MessageAttempt{ api: apiClient, }, + Statistics: &Statistics{ + api: apiClient, + }, } } diff --git a/java/lib/src/main/java/com/svix/Statistics.java b/java/lib/src/main/java/com/svix/Statistics.java new file mode 100644 index 000000000..e99b60a8a --- /dev/null +++ b/java/lib/src/main/java/com/svix/Statistics.java @@ -0,0 +1,32 @@ +package com.svix; + +import com.svix.exceptions.ApiException; +import com.svix.internal.api.StatisticsApi; +import com.svix.models.AggregateEventTypesOut; +import com.svix.models.AppUsageStatsIn; +import com.svix.models.AppUsageStatsOut; + +public class Statistics { + private final StatisticsApi api; + + Statistics() { + api = new StatisticsApi(); + } + + public AppUsageStatsOut aggregateAppStats(final AppUsageStatsIn appUsageStatsIn, final PostOptions options) throws ApiException { + try { + return api.aggregateAppStats(appUsageStatsIn, options.getIdempotencyKey()); + } catch (com.svix.internal.ApiException e) { + throw Utils.wrapInternalApiException(e); + } + } + + public AggregateEventTypesOut aggregateEventTypes() throws com.svix.internal.ApiException { + try { + return api.aggregateEventTypes(); + } catch (com.svix.internal.ApiException e) { + throw Utils.wrapInternalApiException(e); + } + } + +} diff --git a/java/lib/src/main/java/com/svix/Svix.java b/java/lib/src/main/java/com/svix/Svix.java index 5eb4fc8ed..0430f0ef4 100644 --- a/java/lib/src/main/java/com/svix/Svix.java +++ b/java/lib/src/main/java/com/svix/Svix.java @@ -13,6 +13,7 @@ public final class Svix { private final Integration integration; private final Message message; private final MessageAttempt messageAttempt; + private final Statistics statistics; public Svix(final String token) { this(token, new SvixOptions()); @@ -47,6 +48,7 @@ public Svix(final String token, final SvixOptions options) { integration = new Integration(); message = new Message(); messageAttempt = new MessageAttempt(); + statistics = new Statistics(); } public Application getApplication() { @@ -76,4 +78,8 @@ public Message getMessage() { public MessageAttempt getMessageAttempt() { return messageAttempt; } + + public Statistics getStatistics() { + return statistics; + } } diff --git a/javascript/src/index.ts b/javascript/src/index.ts index d54fd9f8b..9dc447a6d 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -64,6 +64,10 @@ import { EventTypePatch, EventTypeImportOpenApiIn, EventTypeImportOpenApiOut, + StatisticsApi, + AppUsageStatsIn, + AppUsageStatsOut, + AggregateEventTypesOut, } from "./openapi/index"; export * from "./openapi/models/all"; export * from "./openapi/apis/exception"; @@ -106,6 +110,7 @@ export class Svix { public readonly message: Message; public readonly messageAttempt: MessageAttempt; public readonly backgroundTask: BackgroundTask; + public readonly statistics: Statistics; public constructor(token: string, options: SvixOptions = {}) { const regionalUrl = REGIONS.find((x) => x.region === token.split(".")[1])?.url; @@ -135,6 +140,7 @@ export class Svix { this.message = new Message(config); this.messageAttempt = new MessageAttempt(config); this.backgroundTask = new BackgroundTask(config); + this.statistics = new Statistics(config); } } export interface PostOptions { @@ -875,3 +881,25 @@ export class Webhook { return new Date(timestamp * 1000); } } + +class Statistics { + private readonly api: StatisticsApi; + + public constructor(config: Configuration) { + this.api = new StatisticsApi(config); + } + + public aggregateEventTypes(): Promise { + return this.api.aggregateEventTypes({}); + } + + public aggregateAppStats( + appUsageStatsIn: AppUsageStatsIn, + options?: PostOptions + ): Promise { + return this.api.aggregateAppStats({ + appUsageStatsIn, + ...options, + }); + } +} \ No newline at end of file diff --git a/kotlin/lib/src/main/kotlin/Statistics.kt b/kotlin/lib/src/main/kotlin/Statistics.kt new file mode 100644 index 000000000..945ceb186 --- /dev/null +++ b/kotlin/lib/src/main/kotlin/Statistics.kt @@ -0,0 +1,34 @@ +package com.svix.kotlin + +import com.svix.kotlin.exceptions.ApiException +import com.svix.kotlin.internal.apis.StatisticsApi +import com.svix.kotlin.models.AggregateEventTypesOut +import com.svix.kotlin.models.AppUsageStatsIn +import com.svix.kotlin.models.AppUsageStatsOut + +class Statistics internal constructor(token: String, options: SvixOptions) { + private val api = StatisticsApi(options.serverUrl) + + init { + api.accessToken = token + api.userAgent = options.getUA() + options.initialRetryDelayMillis?.let { api.initialRetryDelayMillis = it } + options.numRetries?.let { api.numRetries = it } + } + + suspend fun aggregateAppStats(appUsageStatsIn: AppUsageStatsIn, options: PostOptions = PostOptions()): AppUsageStatsOut { + try { + return api.aggregateAppStats(appUsageStatsIn, options.idempotencyKey) + } catch (e: Exception) { + throw ApiException.wrap(e) + } + } + + suspend fun aggregateEventTypes(): AggregateEventTypesOut { + try { + return api.aggregateEventTypes() + } catch (e: Exception) { + throw ApiException.wrap(e) + } + } +} diff --git a/kotlin/lib/src/main/kotlin/Svix.kt b/kotlin/lib/src/main/kotlin/Svix.kt index e6a871dc6..d7c7b1a63 100644 --- a/kotlin/lib/src/main/kotlin/Svix.kt +++ b/kotlin/lib/src/main/kotlin/Svix.kt @@ -23,4 +23,5 @@ class Svix(token: String, options: SvixOptions = SvixOptions()) { val integration = Integration(token, options) val message = Message(token, options) val messageAttempt = MessageAttempt(token, options) + val statistics = Statistics(token, options) } diff --git a/openapi.json b/openapi.json index a45c46abb..c3ecd95b3 100644 --- a/openapi.json +++ b/openapi.json @@ -1,6 +1,25 @@ { "components": { "schemas": { + "AggregateEventTypesOut": { + "properties": { + "id": { + "type": "string" + }, + "status": { + "$ref": "#/components/schemas/BackgroundTaskStatus" + }, + "task": { + "$ref": "#/components/schemas/BackgroundTaskType" + } + }, + "required": [ + "id", + "status", + "task" + ], + "type": "object" + }, "AppPortalAccessIn": { "properties": { "featureFlags": { @@ -328,7 +347,8 @@ "endpoint.recover", "application.stats", "message.broadcast", - "sdk.generate" + "sdk.generate", + "event-type.aggregate" ], "type": "string" }, @@ -1457,28 +1477,6 @@ }, "description": "A pre-parsed JSON spec.", "example": { - "components": { - "schemas": { - "Pet": { - "properties": { - "id": { - "format": "int64", - "type": "integer" - }, - "name": { - "type": "string" - }, - "tag": { - "type": "string" - } - }, - "required": [ - "id", - "name" - ] - } - } - }, "info": { "title": "Webhook Example", "version": "1.0.0" @@ -1491,7 +1489,22 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Pet" + "properties": { + "id": { + "format": "int64", + "type": "integer" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + }, + "required": [ + "id", + "name" + ] } } }, @@ -1512,28 +1525,6 @@ "specRaw": { "description": "A string, parsed by the server as YAML or JSON.", "example": { - "components": { - "schemas": { - "Pet": { - "properties": { - "id": { - "format": "int64", - "type": "integer" - }, - "name": { - "type": "string" - }, - "tag": { - "type": "string" - } - }, - "required": [ - "id", - "name" - ] - } - } - }, "info": { "title": "Webhook Example", "version": "1.0.0" @@ -1546,7 +1537,22 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Pet" + "properties": { + "id": { + "format": "int64", + "type": "integer" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + }, + "required": [ + "id", + "name" + ] } } }, @@ -2535,6 +2541,18 @@ }, "MessageAttemptHeadersOut": { "properties": { + "responseHeaders": { + "items": { + "items": { + "type": "string" + }, + "maxItems": 2, + "minItems": 2, + "type": "array" + }, + "nullable": true, + "type": "array" + }, "sensitive": { "items": { "type": "string" @@ -16333,62 +16351,62 @@ { "label": "JavaScript", "lang": "JavaScript", - "source": "const eventTypeImportOpenApiOut = await svix.eventType.importOpenapi({\n spec: {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n specRaw: {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n});" + "source": "const eventTypeImportOpenApiOut = await svix.eventType.importOpenapi({\n spec: {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n specRaw: {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n});" }, { "label": "TypeScript", "lang": "JavaScript", - "source": "const eventTypeImportOpenApiOut = await svix.eventType.importOpenapi({\n spec: {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n specRaw: {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n});" + "source": "const eventTypeImportOpenApiOut = await svix.eventType.importOpenapi({\n spec: {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n specRaw: {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n});" }, { "label": "Python", "lang": "Python", - "source": "event_type_import_open_api_out = svix.event_type.import_openapi(EventTypeImportOpenApiIn(\n spec={\"components\": {\"schemas\": {\"Pet\": {\"properties\": {\"id\": {\"format\": \"int64\", \"type\": \"integer\"}, \"name\": {\"type\": \"string\"}, \"tag\": {\"type\": \"string\"}}, \"required\": [\"id\", \"name\"]}}}, \"info\": {\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": {\"pet.new\": {\"post\": {\"requestBody\": {\"content\": {\"application/json\": {\"schema\": {\"$ref\": \"#/components/schemas/Pet\"}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": {\"200\": {\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n spec_raw={\"components\": {\"schemas\": {\"Pet\": {\"properties\": {\"id\": {\"format\": \"int64\", \"type\": \"integer\"}, \"name\": {\"type\": \"string\"}, \"tag\": {\"type\": \"string\"}}, \"required\": [\"id\", \"name\"]}}}, \"info\": {\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": {\"pet.new\": {\"post\": {\"requestBody\": {\"content\": {\"application/json\": {\"schema\": {\"$ref\": \"#/components/schemas/Pet\"}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": {\"200\": {\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n), None)" + "source": "event_type_import_open_api_out = svix.event_type.import_openapi(EventTypeImportOpenApiIn(\n spec={\"info\": {\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": {\"pet.new\": {\"post\": {\"requestBody\": {\"content\": {\"application/json\": {\"schema\": {\"properties\": {\"id\": {\"format\": \"int64\", \"type\": \"integer\"}, \"name\": {\"type\": \"string\"}, \"tag\": {\"type\": \"string\"}}, \"required\": [\"id\", \"name\"]}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": {\"200\": {\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n spec_raw={\"info\": {\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": {\"pet.new\": {\"post\": {\"requestBody\": {\"content\": {\"application/json\": {\"schema\": {\"properties\": {\"id\": {\"format\": \"int64\", \"type\": \"integer\"}, \"name\": {\"type\": \"string\"}, \"tag\": {\"type\": \"string\"}}, \"required\": [\"id\", \"name\"]}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": {\"200\": {\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n), None)" }, { "label": "Python (Async)", "lang": "Python", - "source": "event_type_import_open_api_out = await svix.event_type.import_openapi(EventTypeImportOpenApiIn(\n spec={\"components\": {\"schemas\": {\"Pet\": {\"properties\": {\"id\": {\"format\": \"int64\", \"type\": \"integer\"}, \"name\": {\"type\": \"string\"}, \"tag\": {\"type\": \"string\"}}, \"required\": [\"id\", \"name\"]}}}, \"info\": {\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": {\"pet.new\": {\"post\": {\"requestBody\": {\"content\": {\"application/json\": {\"schema\": {\"$ref\": \"#/components/schemas/Pet\"}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": {\"200\": {\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n spec_raw={\"components\": {\"schemas\": {\"Pet\": {\"properties\": {\"id\": {\"format\": \"int64\", \"type\": \"integer\"}, \"name\": {\"type\": \"string\"}, \"tag\": {\"type\": \"string\"}}, \"required\": [\"id\", \"name\"]}}}, \"info\": {\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": {\"pet.new\": {\"post\": {\"requestBody\": {\"content\": {\"application/json\": {\"schema\": {\"$ref\": \"#/components/schemas/Pet\"}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": {\"200\": {\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n), None)" + "source": "event_type_import_open_api_out = await svix.event_type.import_openapi(EventTypeImportOpenApiIn(\n spec={\"info\": {\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": {\"pet.new\": {\"post\": {\"requestBody\": {\"content\": {\"application/json\": {\"schema\": {\"properties\": {\"id\": {\"format\": \"int64\", \"type\": \"integer\"}, \"name\": {\"type\": \"string\"}, \"tag\": {\"type\": \"string\"}}, \"required\": [\"id\", \"name\"]}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": {\"200\": {\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n spec_raw={\"info\": {\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": {\"pet.new\": {\"post\": {\"requestBody\": {\"content\": {\"application/json\": {\"schema\": {\"properties\": {\"id\": {\"format\": \"int64\", \"type\": \"integer\"}, \"name\": {\"type\": \"string\"}, \"tag\": {\"type\": \"string\"}}, \"required\": [\"id\", \"name\"]}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": {\"200\": {\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n), None)" }, { "label": "Go", "lang": "Go", - "source": "eventTypeImportOpenApiOut, err := svixClient.EventType.ImportOpenapi(ctx, &EventTypeImportOpenApiIn{\n Spec: map[interface{}]interface{}{\"components\": map[interface{}]interface{}{\"schemas\": map[interface{}]interface{}{\"Pet\": map[interface{}]interface{}{\"properties\": map[interface{}]interface{}{\"id\": map[string]interface{}{\"format\": \"int64\", \"type\": \"integer\"}, \"name\": map[string]interface{}{\"type\": \"string\"}, \"tag\": map[string]interface{}{\"type\": \"string\"}}, \"required\": []string{\"id\", \"name\"}}}}, \"info\": map[string]interface{}{\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": map[interface{}]interface{}{\"pet.new\": map[interface{}]interface{}{\"post\": map[interface{}]interface{}{\"requestBody\": map[interface{}]interface{}{\"content\": map[interface{}]interface{}{\"application/json\": map[interface{}]interface{}{\"schema\": map[string]interface{}{\"$ref\": \"#/components/schemas/Pet\"}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": map[interface{}]interface{}{\"200\": map[string]interface{}{\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n SpecRaw: map[interface{}]interface{}{\"components\": map[interface{}]interface{}{\"schemas\": map[interface{}]interface{}{\"Pet\": map[interface{}]interface{}{\"properties\": map[interface{}]interface{}{\"id\": map[string]interface{}{\"format\": \"int64\", \"type\": \"integer\"}, \"name\": map[string]interface{}{\"type\": \"string\"}, \"tag\": map[string]interface{}{\"type\": \"string\"}}, \"required\": []string{\"id\", \"name\"}}}}, \"info\": map[string]interface{}{\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": map[interface{}]interface{}{\"pet.new\": map[interface{}]interface{}{\"post\": map[interface{}]interface{}{\"requestBody\": map[interface{}]interface{}{\"content\": map[interface{}]interface{}{\"application/json\": map[interface{}]interface{}{\"schema\": map[string]interface{}{\"$ref\": \"#/components/schemas/Pet\"}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": map[interface{}]interface{}{\"200\": map[string]interface{}{\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n})" + "source": "eventTypeImportOpenApiOut, err := svixClient.EventType.ImportOpenapi(ctx, &EventTypeImportOpenApiIn{\n Spec: map[interface{}]interface{}{\"info\": map[string]interface{}{\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": map[interface{}]interface{}{\"pet.new\": map[interface{}]interface{}{\"post\": map[interface{}]interface{}{\"requestBody\": map[interface{}]interface{}{\"content\": map[interface{}]interface{}{\"application/json\": map[interface{}]interface{}{\"schema\": map[interface{}]interface{}{\"properties\": map[interface{}]interface{}{\"id\": map[string]interface{}{\"format\": \"int64\", \"type\": \"integer\"}, \"name\": map[string]interface{}{\"type\": \"string\"}, \"tag\": map[string]interface{}{\"type\": \"string\"}}, \"required\": []string{\"id\", \"name\"}}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": map[interface{}]interface{}{\"200\": map[string]interface{}{\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n SpecRaw: map[interface{}]interface{}{\"info\": map[string]interface{}{\"title\": \"Webhook Example\", \"version\": \"1.0.0\"}, \"openapi\": \"3.1.0\", \"webhooks\": map[interface{}]interface{}{\"pet.new\": map[interface{}]interface{}{\"post\": map[interface{}]interface{}{\"requestBody\": map[interface{}]interface{}{\"content\": map[interface{}]interface{}{\"application/json\": map[interface{}]interface{}{\"schema\": map[interface{}]interface{}{\"properties\": map[interface{}]interface{}{\"id\": map[string]interface{}{\"format\": \"int64\", \"type\": \"integer\"}, \"name\": map[string]interface{}{\"type\": \"string\"}, \"tag\": map[string]interface{}{\"type\": \"string\"}}, \"required\": []string{\"id\", \"name\"}}}}, \"description\": \"Information about a new pet in the system\"}, \"responses\": map[interface{}]interface{}{\"200\": map[string]interface{}{\"description\": \"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n})" }, { "label": "Kotlin", "lang": "Kotlin", - "source": "val eventTypeImportOpenApiOut = svix.eventType.importOpenapi(EventTypeImportOpenApiIn()\n .spec(\"\"\"{\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\"\"\")\n .specRaw(\"\"\"{\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\"\"\")\n)" + "source": "val eventTypeImportOpenApiOut = svix.eventType.importOpenapi(EventTypeImportOpenApiIn()\n .spec(\"\"\"{\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\"\"\")\n .specRaw(\"\"\"{\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\"\"\")\n)" }, { "label": "Java", "lang": "Java", - "source": "EventTypeImportOpenApiOut eventTypeImportOpenApiOut = svix.getEventType().importOpenapi(new EventTypeImportOpenApiIn()\n .spec(\"{\\\"components\\\":{\\\"schemas\\\":{\\\"Pet\\\":{\\\"properties\\\":{\\\"id\\\":{\\\"format\\\":\\\"int64\\\",\\\"type\\\":\\\"integer\\\"},\\\"name\\\":{\\\"type\\\":\\\"string\\\"},\\\"tag\\\":{\\\"type\\\":\\\"string\\\"}},\\\"required\\\":[\\\"id\\\",\\\"name\\\"]}}},\\\"info\\\":{\\\"title\\\":\\\"Webhook Example\\\",\\\"version\\\":\\\"1.0.0\\\"},\\\"openapi\\\":\\\"3.1.0\\\",\\\"webhooks\\\":{\\\"pet.new\\\":{\\\"post\\\":{\\\"requestBody\\\":{\\\"content\\\":{\\\"application/json\\\":{\\\"schema\\\":{\\\"$ref\\\":\\\"#/components/schemas/Pet\\\"}}},\\\"description\\\":\\\"Information about a new pet in the system\\\"},\\\"responses\\\":{\\\"200\\\":{\\\"description\\\":\\\"Return a 200 status to indicate that the data was received successfully\\\"}}}}}}\")\n .specRaw(\"{\\\"components\\\":{\\\"schemas\\\":{\\\"Pet\\\":{\\\"properties\\\":{\\\"id\\\":{\\\"format\\\":\\\"int64\\\",\\\"type\\\":\\\"integer\\\"},\\\"name\\\":{\\\"type\\\":\\\"string\\\"},\\\"tag\\\":{\\\"type\\\":\\\"string\\\"}},\\\"required\\\":[\\\"id\\\",\\\"name\\\"]}}},\\\"info\\\":{\\\"title\\\":\\\"Webhook Example\\\",\\\"version\\\":\\\"1.0.0\\\"},\\\"openapi\\\":\\\"3.1.0\\\",\\\"webhooks\\\":{\\\"pet.new\\\":{\\\"post\\\":{\\\"requestBody\\\":{\\\"content\\\":{\\\"application/json\\\":{\\\"schema\\\":{\\\"$ref\\\":\\\"#/components/schemas/Pet\\\"}}},\\\"description\\\":\\\"Information about a new pet in the system\\\"},\\\"responses\\\":{\\\"200\\\":{\\\"description\\\":\\\"Return a 200 status to indicate that the data was received successfully\\\"}}}}}}\")\n)" + "source": "EventTypeImportOpenApiOut eventTypeImportOpenApiOut = svix.getEventType().importOpenapi(new EventTypeImportOpenApiIn()\n .spec(\"{\\\"info\\\":{\\\"title\\\":\\\"Webhook Example\\\",\\\"version\\\":\\\"1.0.0\\\"},\\\"openapi\\\":\\\"3.1.0\\\",\\\"webhooks\\\":{\\\"pet.new\\\":{\\\"post\\\":{\\\"requestBody\\\":{\\\"content\\\":{\\\"application/json\\\":{\\\"schema\\\":{\\\"properties\\\":{\\\"id\\\":{\\\"format\\\":\\\"int64\\\",\\\"type\\\":\\\"integer\\\"},\\\"name\\\":{\\\"type\\\":\\\"string\\\"},\\\"tag\\\":{\\\"type\\\":\\\"string\\\"}},\\\"required\\\":[\\\"id\\\",\\\"name\\\"]}}},\\\"description\\\":\\\"Information about a new pet in the system\\\"},\\\"responses\\\":{\\\"200\\\":{\\\"description\\\":\\\"Return a 200 status to indicate that the data was received successfully\\\"}}}}}}\")\n .specRaw(\"{\\\"info\\\":{\\\"title\\\":\\\"Webhook Example\\\",\\\"version\\\":\\\"1.0.0\\\"},\\\"openapi\\\":\\\"3.1.0\\\",\\\"webhooks\\\":{\\\"pet.new\\\":{\\\"post\\\":{\\\"requestBody\\\":{\\\"content\\\":{\\\"application/json\\\":{\\\"schema\\\":{\\\"properties\\\":{\\\"id\\\":{\\\"format\\\":\\\"int64\\\",\\\"type\\\":\\\"integer\\\"},\\\"name\\\":{\\\"type\\\":\\\"string\\\"},\\\"tag\\\":{\\\"type\\\":\\\"string\\\"}},\\\"required\\\":[\\\"id\\\",\\\"name\\\"]}}},\\\"description\\\":\\\"Information about a new pet in the system\\\"},\\\"responses\\\":{\\\"200\\\":{\\\"description\\\":\\\"Return a 200 status to indicate that the data was received successfully\\\"}}}}}}\")\n)" }, { "label": "Ruby", "lang": "Ruby", - "source": "event_type_import_open_api_out = svix.event_type.import_openapi(Svix::EventTypeImportOpenApiIn.new({\n \"spec\": {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n \"spec_raw\": {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n}))" + "source": "event_type_import_open_api_out = svix.event_type.import_openapi(Svix::EventTypeImportOpenApiIn.new({\n \"spec\": {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n \"spec_raw\": {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n}))" }, { "label": "Rust", "lang": "Rust", - "source": "let event_type_import_open_api_out = svix.event_type().import_openapi(EventTypeImportOpenApiIn {\n spec: Some(json!({\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}})),\n spec_raw: Some(json!({\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}})),\n}, None).await?;" + "source": "let event_type_import_open_api_out = svix.event_type().import_openapi(EventTypeImportOpenApiIn {\n spec: Some(json!({\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}})),\n spec_raw: Some(json!({\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}})),\n}, None).await?;" }, { "label": "C#", "lang": "C#", - "source": "var eventTypeImportOpenApiOut = await svix.EventType.ImportOpenapiAsync(new EventTypeImportOpenApiIn{\n spec: new {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n specRaw: new {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n})" + "source": "var eventTypeImportOpenApiOut = await svix.EventType.ImportOpenapiAsync(new EventTypeImportOpenApiIn{\n spec: new {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n specRaw: new {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n})" }, { "label": "CLI", "lang": "Shell", - "source": "svix event-type import-openapi '{\n \"spec\": {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n \"specRaw\": {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n}'" + "source": "svix event-type import-openapi '{\n \"spec\": {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n \"specRaw\": {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n}'" }, { "label": "cURL", "lang": "Shell", - "source": "curl -X 'POST' \\\n 'https://api.eu.svix.com/api/v1/event-type/import/openapi/' \\\n -H 'Authorization: Bearer AUTH_TOKEN' \\\n -H 'Accept: application/json' \\\n -H 'Content-Type: application/json' \\\n -d '{\n \"spec\": {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n \"specRaw\": {\"components\":{\"schemas\":{\"Pet\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pet\"}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n }'" + "source": "curl -X 'POST' \\\n 'https://api.eu.svix.com/api/v1/event-type/import/openapi/' \\\n -H 'Authorization: Bearer AUTH_TOKEN' \\\n -H 'Accept: application/json' \\\n -H 'Content-Type: application/json' \\\n -d '{\n \"spec\": {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}},\n \"specRaw\": {\"info\":{\"title\":\"Webhook Example\",\"version\":\"1.0.0\"},\"openapi\":\"3.1.0\",\"webhooks\":{\"pet.new\":{\"post\":{\"requestBody\":{\"content\":{\"application/json\":{\"schema\":{\"properties\":{\"id\":{\"format\":\"int64\",\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"tag\":{\"type\":\"string\"}},\"required\":[\"id\",\"name\"]}}},\"description\":\"Information about a new pet in the system\"},\"responses\":{\"200\":{\"description\":\"Return a 200 status to indicate that the data was received successfully\"}}}}}}\n }'" } ] } @@ -17983,8 +18001,8 @@ }, "/api/v1/stats/usage/app/": { "post": { - "description": "Creates a background task to calculate the message destinations for all applications in the environment.", - "operationId": "calculate_aggregate_app_stats", + "description": "Creates a background task to calculate the message destinations for all applications in the environment.\n\nNote that this endpoint is asynchronous. You will need to poll the `Get Background Task` endpoint to\nretrieve the results of the operation.", + "operationId": "aggregate_app_stats", "parameters": [ { "description": "The request's idempotency key", @@ -18093,7 +18111,104 @@ "HTTPBearer": [] } ], - "summary": "Calculate Aggregate App Stats", + "summary": "Aggregate App Stats", + "tags": [ + "Statistics" + ] + } + }, + "/api/v1/stats/usage/event-types/": { + "put": { + "description": "Creates a background task to calculate the listed event types for all apps in the organization.\n\nNote that this endpoint is asynchronous. You will need to poll the `Get Background Task` endpoint to\nretrieve the results of the operation.", + "operationId": "aggregate_event_types", + "responses": { + "202": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AggregateEventTypesOut" + } + } + }, + "description": "" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HttpErrorOut" + } + } + }, + "description": "Bad request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HttpErrorOut" + } + } + }, + "description": "Unauthorized" + }, + "403": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HttpErrorOut" + } + } + }, + "description": "Forbidden" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HttpErrorOut" + } + } + }, + "description": "Not Found" + }, + "409": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HttpErrorOut" + } + } + }, + "description": "Conflict" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + }, + "429": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HttpErrorOut" + } + } + }, + "description": "Too Many Requests" + } + }, + "security": [ + { + "HTTPBearer": [] + } + ], + "summary": "Aggregate Event Types", "tags": [ "Statistics" ] @@ -19761,6 +19876,10 @@ { "description": "The background tasks that have been executed for your environment.", "name": "Background Tasks" + }, + { + "description": "Generate statistics about your Svix utilization", + "name": "Statistics" } ], "x-tagGroups": [ @@ -19793,6 +19912,12 @@ "tags": [ "Webhooks" ] + }, + { + "name": "Statistics", + "tags": [ + "Statistics" + ] } ], "x-webhooks": { @@ -19803,6 +19928,15 @@ "requestBody": { "content": { "application/json": { + "example": { + "data": { + "appId": "app_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "appUid": "unique-app-identifier", + "endpointId": "ep_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "endpointUid": "unique-endpoint-identifier" + }, + "type": "endpoint.created" + }, "schema": { "$ref": "#/components/schemas/EndpointCreatedEvent" } @@ -19827,6 +19961,15 @@ "requestBody": { "content": { "application/json": { + "example": { + "data": { + "appId": "app_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "appUid": "unique-app-identifier", + "endpointId": "ep_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "endpointUid": "unique-endpoint-identifier" + }, + "type": "endpoint.deleted" + }, "schema": { "$ref": "#/components/schemas/EndpointDeletedEvent" } @@ -19851,6 +19994,16 @@ "requestBody": { "content": { "application/json": { + "example": { + "data": { + "appId": "app_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "appUid": "unique-app-identifier", + "endpointId": "ep_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "endpointUid": "unique-endpoint-identifier", + "failSince": "2022-11-06T15:04:05Z" + }, + "type": "endpoint.disabled" + }, "schema": { "$ref": "#/components/schemas/EndpointDisabledEvent" } @@ -19875,6 +20028,15 @@ "requestBody": { "content": { "application/json": { + "example": { + "data": { + "appId": "app_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "appUid": "unique-app-identifier", + "endpointId": "ep_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "endpointUid": "unique-endpoint-identifier" + }, + "type": "endpoint.updated" + }, "schema": { "$ref": "#/components/schemas/EndpointUpdatedEvent" } @@ -19899,6 +20061,21 @@ "requestBody": { "content": { "application/json": { + "example": { + "data": { + "appId": "app_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "appUid": "unique-app-identifier", + "endpointId": "ep_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "lastAttempt": { + "id": "atmpt_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "responseStatusCode": 500, + "timestamp": "2022-11-06T15:04:05Z" + }, + "msgEventId": "unique-msg-identifier", + "msgId": "msg_1srOrx2ZWZBpBUvZwXKQmoEYga2" + }, + "type": "message.attempt.exhausted" + }, "schema": { "$ref": "#/components/schemas/MessageAttemptExhaustedEvent" } @@ -19923,6 +20100,21 @@ "requestBody": { "content": { "application/json": { + "example": { + "data": { + "appId": "app_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "appUid": "unique-app-identifier", + "endpointId": "ep_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "lastAttempt": { + "id": "atmpt_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "responseStatusCode": 500, + "timestamp": "2022-11-06T15:04:05Z" + }, + "msgEventId": "unique-msg-identifier", + "msgId": "msg_1srOrx2ZWZBpBUvZwXKQmoEYga2" + }, + "type": "message.attempt.failing" + }, "schema": { "$ref": "#/components/schemas/MessageAttemptFailingEvent" } @@ -19947,6 +20139,21 @@ "requestBody": { "content": { "application/json": { + "example": { + "data": { + "appId": "app_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "appUid": "unique-app-identifier", + "endpointId": "ep_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "lastAttempt": { + "id": "atmpt_1srOrx2ZWZBpBUvZwXKQmoEYga2", + "responseStatusCode": 200, + "timestamp": "2022-11-06T15:04:05Z" + }, + "msgEventId": "unique-msg-identifier", + "msgId": "msg_1srOrx2ZWZBpBUvZwXKQmoEYga2" + }, + "type": "message.attempt.recovered" + }, "schema": { "$ref": "#/components/schemas/MessageAttemptRecoveredEvent" } diff --git a/python/svix/api.py b/python/svix/api.py index aff8d2c5b..586b241e2 100644 --- a/python/svix/api.py +++ b/python/svix/api.py @@ -4,6 +4,10 @@ from deprecated import deprecated +from svix.internal.openapi_client.models.aggregate_event_types_out import AggregateEventTypesOut +from svix.internal.openapi_client.models.app_usage_stats_in import AppUsageStatsIn +from svix.internal.openapi_client.models.app_usage_stats_out import AppUsageStatsOut + from .internal.openapi_client.api.application import ( v1_application_create, v1_application_delete, @@ -71,6 +75,7 @@ v1_message_attempt_list_by_msg, v1_message_attempt_resend, ) +from .internal.openapi_client.api.statistics import aggregate_app_stats, aggregate_event_types from .internal.openapi_client.client import AuthenticatedClient from .internal.openapi_client.models.app_portal_access_in import AppPortalAccessIn from .internal.openapi_client.models.app_portal_access_out import AppPortalAccessOut @@ -1034,6 +1039,34 @@ def get(self, task_id: str) -> BackgroundTaskOut: return get_background_task.sync(client=self._client, task_id=task_id) +class StatisticsAsync(ApiBase): + async def aggregate_app_stats( + self, app_usage_stats_in: AppUsageStatsIn, options: PostOptions = PostOptions() + ) -> AppUsageStatsOut: + return await aggregate_app_stats.asyncio( + client=self._client, + json_body=app_usage_stats_in, + **options.to_dict(), + ) + + async def aggregate_event_types(self, task_id: str) -> AggregateEventTypesOut: + return await aggregate_event_types.asyncio(client=self._client) + + +class Statistics(ApiBase): + def aggregate_app_stats( + self, app_usage_stats_in: AppUsageStatsIn, options: PostOptions = PostOptions() + ) -> AppUsageStatsOut: + return aggregate_app_stats.sync( + client=self._client, + json_body=app_usage_stats_in, + **options.to_dict(), + ) + + def aggregate_event_types(self, task_id: str) -> AggregateEventTypesOut: + return aggregate_event_types.sync(client=self._client) + + class ClientBase: _client: AuthenticatedClient @@ -1091,6 +1124,10 @@ def message(self) -> MessageAsync: def message_attempt(self) -> MessageAttemptAsync: return MessageAttemptAsync(self._client) + @property + def statistics(self) -> StatisticsAsync: + return StatisticsAsync(self._client) + class Svix(ClientBase): @property @@ -1121,6 +1158,10 @@ def message(self) -> Message: def message_attempt(self) -> MessageAttempt: return MessageAttempt(self._client) + @property + def statistics(self) -> Statistics: + return Statistics(self._client) + __all__ = [ "ApplicationIn", diff --git a/ruby/lib/svix/statistics_api.rb b/ruby/lib/svix/statistics_api.rb new file mode 100644 index 000000000..d875e6b0b --- /dev/null +++ b/ruby/lib/svix/statistics_api.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Svix + class StatisticsAPI + def initialize(api_client) + @api = StatisticsApi.new(api_client) + end + + def aggregate_app_stats(options = {}) + return @api.aggregate_app_stats(options) + end + + def aggregate_event_types(options = {}) + return @api.aggregate_event_types(options) + end + end +end diff --git a/rust/src/api.rs b/rust/src/api.rs index 2e07a6436..d9132cd0a 100644 --- a/rust/src/api.rs +++ b/rust/src/api.rs @@ -1,7 +1,7 @@ use crate::apis::configuration::Configuration; use crate::apis::{ application_api, authentication_api, background_tasks_api, endpoint_api, event_type_api, - integration_api, message_api, message_attempt_api, + integration_api, message_api, message_attempt_api, statistics_api, }; use crate::error::Result; pub use crate::models::*; @@ -1177,3 +1177,44 @@ impl<'a> BackgroundTask<'a> { .await?) } } + +pub struct Statistics<'a> { + cfg: &'a Configuration, +} + +pub struct AggregateAppStatsOptions { + pub app_ids: Option>, + pub since: String, + pub until: String, +} + +impl<'a> Statistics<'a> { + pub fn new(cfg: &'a Configuration) -> Self { + Self { cfg } + } + + pub async fn aggregate_app_stats( + &self, + AggregateAppStatsOptions { + app_ids, + since, + until, + }: AggregateAppStatsOptions, + options: Option, + ) -> Result { + let options = options.unwrap_or_default(); + let params = statistics_api::AggregateAppStatsParams { + app_usage_stats_in: AppUsageStatsIn { + app_ids, + since, + until, + }, + idempotency_key: options.idempotency_key, + }; + Ok(statistics_api::aggregate_app_stats(self.cfg, params).await?) + } + + pub async fn aggregate_event_types(&self) -> Result { + Ok(statistics_api::aggregate_event_types(self.cfg).await?) + } +}