diff --git a/platform/.speakeasy/gen.lock b/platform/.speakeasy/gen.lock index 61c2a58f0..13ca20f22 100755 --- a/platform/.speakeasy/gen.lock +++ b/platform/.speakeasy/gen.lock @@ -1,19 +1,19 @@ lockVersion: 2.0.0 id: 803b84ac-e26a-4a5c-9224-dbc3d0c7712a management: - docChecksum: 91b86a7707fc536ccbdc7b7345d775a0 + docChecksum: 45c9274f0e3c7dac25b46ab3b4007b5f docVersion: 3.0.0 - speakeasyVersion: 1.274.1 - generationVersion: 2.314.0 - releaseVersion: 3.6.0 - configChecksum: da622ef0f54bd9e9d3a34c5694447ea5 + speakeasyVersion: 1.277.6 + generationVersion: 2.319.7 + releaseVersion: 3.6.1 + configChecksum: e1137e6a45616de97875384f08e19dd5 repoURL: https://github.com/codatio/client-sdk-csharp.git repoSubDirectory: platform published: true features: csharp: constsAndDefaults: 0.0.1 - core: 3.8.0 + core: 3.8.2 deprecations: 2.81.2 examples: 2.81.3 globalSecurity: 2.83.4 @@ -22,7 +22,7 @@ features: ignores: 2.81.1 inputOutputModels: 2.83.0 nameOverrides: 2.81.2 - responseFormat: 0.0.1 + responseFormat: 0.0.2 webhooks: 1.0.0 generatedFiles: - Codat/Platform/Settings.cs @@ -49,7 +49,7 @@ generatedFiles: - Codat/Platform/Utils/IsoDateTimeSerializer.cs - Codat/Platform/Utils/RequestBodySerializer.cs - Codat/Platform/Utils/ResponseBodyDeserializer.cs - - Codat/Platform/Utils/SecuritySerializer.cs + - Codat/Platform/Utils/SecurityMetadata.cs - Codat/Platform/Utils/SpeakeasyHttpClient.cs - Codat/Platform/Utils/SpeakeasyMetadata.cs - Codat/Platform/Utils/URLBuilder.cs @@ -449,3 +449,5 @@ generatedFiles: - docs/sdks/webhooks/README.md - USAGE.md - .gitattributes + - Codat/Platform/Hooks/SDKHooks.cs + - Codat/Platform/Hooks/HookTypes.cs diff --git a/platform/Codat/Platform/Codat.Platform.csproj b/platform/Codat/Platform/Codat.Platform.csproj index 599df99b2..076455482 100644 --- a/platform/Codat/Platform/Codat.Platform.csproj +++ b/platform/Codat/Platform/Codat.Platform.csproj @@ -2,7 +2,7 @@ true Codat.Platform - 3.6.0 + 3.6.1 Codat net6.0 enable diff --git a/platform/Codat/Platform/CodatPlatform.cs b/platform/Codat/Platform/CodatPlatform.cs index e9616af6b..59b5a6815 100644 --- a/platform/Codat/Platform/CodatPlatform.cs +++ b/platform/Codat/Platform/CodatPlatform.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Shared; using Codat.Platform.Utils; @@ -117,16 +118,28 @@ public class SDKConfig "https://api.codat.io", }; - public string serverUrl = ""; - public int serverIndex = 0; + public string ServerUrl = ""; + public int ServerIndex = 0; + public SDKHooks hooks = new SDKHooks(); - public string GetTemplatedServerDetails() + public string GetTemplatedServerUrl() { - if (!String.IsNullOrEmpty(this.serverUrl)) + if (!String.IsNullOrEmpty(this.ServerUrl)) { - return Utilities.TemplateUrl(Utilities.RemoveSuffix(this.serverUrl, "/"), new Dictionary()); + return Utilities.TemplateUrl(Utilities.RemoveSuffix(this.ServerUrl, "/"), new Dictionary()); } - return Utilities.TemplateUrl(SDKConfig.ServerList[this.serverIndex], new Dictionary()); + return Utilities.TemplateUrl(SDKConfig.ServerList[this.ServerIndex], new Dictionary()); + } + + public ISpeakeasyHttpClient InitHooks(ISpeakeasyHttpClient client) + { + string preHooksUrl = GetTemplatedServerUrl(); + var (postHooksUrl, postHooksClient) = this.hooks.SDKInit(preHooksUrl, client); + if (preHooksUrl != postHooksUrl) + { + this.ServerUrl = postHooksUrl; + } + return postHooksClient; } } @@ -165,10 +178,10 @@ public class CodatPlatform: ICodatPlatform public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private int _serverIndex = 0; private ISpeakeasyHttpClient _defaultClient; @@ -222,21 +235,44 @@ public CodatPlatform(Security? security = null, Func? securitySource = SDKConfiguration = new SDKConfig() { - serverIndex = _serverIndex, - serverUrl = _serverUrl + ServerIndex = _serverIndex, + ServerUrl = _serverUrl }; + _defaultClient = SDKConfiguration.InitHooks(_defaultClient); + + Settings = new Settings(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + Companies = new Companies(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + ConnectionManagement = new ConnectionManagement(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + Connections = new Connections(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + CustomDataType = new CustomDataType(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + PushData = new PushData(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + RefreshData = new RefreshData(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + Groups = new Groups(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + Integrations = new Integrations(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + SupplementalData = new SupplementalData(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); + + Webhooks = new Webhooks(_defaultClient, _securitySource, _serverUrl, SDKConfiguration); } } -} +} \ No newline at end of file diff --git a/platform/Codat/Platform/Companies.cs b/platform/Codat/Platform/Companies.cs index 8ee4e1640..4876a60e5 100644 --- a/platform/Codat/Platform/Companies.cs +++ b/platform/Codat/Platform/Companies.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -100,10 +101,10 @@ public class Companies: ICompanies { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -118,7 +119,7 @@ public Companies(ISpeakeasyHttpClient defaultClient, Func? securitySou public async Task CreateAsync(CompanyRequestBody? request = null) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/companies"; @@ -131,13 +132,43 @@ public async Task CreateAsync(CompanyRequestBody? request httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("create-company", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -184,19 +215,49 @@ public async Task CreateAsync(CompanyRequestBody? request public async Task DeleteAsync(DeleteCompanyRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("delete-company", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -233,19 +294,49 @@ public async Task DeleteAsync(DeleteCompanyRequest reques public async Task GetAsync(GetCompanyRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-company", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -292,19 +383,49 @@ public async Task GetAsync(GetCompanyRequest request) public async Task ListAsync(ListCompaniesRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("list-companies", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -351,7 +472,7 @@ public async Task ListAsync(ListCompaniesRequest request) public async Task UpdateAsync(UpdateCompanyRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Put, urlString); @@ -363,13 +484,43 @@ public async Task UpdateAsync(UpdateCompanyRequest reques httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("update-company", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/ConnectionManagement.cs b/platform/Codat/Platform/ConnectionManagement.cs index d062589d6..1fd2a1527 100644 --- a/platform/Codat/Platform/ConnectionManagement.cs +++ b/platform/Codat/Platform/ConnectionManagement.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -32,7 +33,7 @@ public interface IConnectionManagement /// Get access token /// /// - /// Use the *Get access token* endpoint to retrieve a new access token for use by the connection management UI.
+ /// Use the *Get access token* endpoint to retrieve a new access token for use by the connection management UI. The token is only valid for one hour and applies to a single company.
///
/// The embedded connection management UI lets your customers control access to their data by allowing them to manage their existing connections. ///
@@ -47,10 +48,10 @@ public class ConnectionManagement: IConnectionManagement { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -67,19 +68,49 @@ public ConnectionManagement(ISpeakeasyHttpClient defaultClient, Func? public async Task GetAccessTokenAsync(GetConnectionManagementAccessTokenRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connectionManagement/accessToken", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-connection-management-access-token", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/Connections.cs b/platform/Codat/Platform/Connections.cs index 703aa2de5..37c0e461c 100644 --- a/platform/Codat/Platform/Connections.cs +++ b/platform/Codat/Platform/Connections.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -92,10 +93,10 @@ public class Connections: IConnections { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -110,7 +111,7 @@ public Connections(ISpeakeasyHttpClient defaultClient, Func? securityS public async Task CreateAsync(CreateConnectionRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections", request); var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); @@ -122,13 +123,43 @@ public async Task CreateAsync(CreateConnectionRequest httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("create-connection", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -175,19 +206,49 @@ public async Task CreateAsync(CreateConnectionRequest public async Task DeleteAsync(DeleteConnectionRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections/{connectionId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("delete-connection", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -224,19 +285,49 @@ public async Task DeleteAsync(DeleteConnectionRequest public async Task GetAsync(GetConnectionRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections/{connectionId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("get-connection", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -283,19 +374,49 @@ public async Task GetAsync(GetConnectionRequest request) public async Task ListAsync(ListConnectionsRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("list-connections", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -342,7 +463,7 @@ public async Task ListAsync(ListConnectionsRequest requ public async Task UnlinkAsync(UnlinkConnectionRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections/{connectionId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Patch, urlString); @@ -354,13 +475,43 @@ public async Task UnlinkAsync(UnlinkConnectionRequest httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("unlink-connection", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -407,7 +558,7 @@ public async Task UnlinkAsync(UnlinkConnectionRequest public async Task UpdateAuthorizationAsync(UpdateConnectionAuthorizationRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections/{connectionId}/authorization", request); var httpRequest = new HttpRequestMessage(HttpMethod.Put, urlString); @@ -419,13 +570,43 @@ public async Task UpdateAuthorizationAsyn httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("update-connection-authorization", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/CorsSettings.cs b/platform/Codat/Platform/CorsSettings.cs index e0a4927f0..6a1e70471 100644 --- a/platform/Codat/Platform/CorsSettings.cs +++ b/platform/Codat/Platform/CorsSettings.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -55,10 +56,10 @@ public class CorsSettings: ICorsSettings { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -73,20 +74,50 @@ public CorsSettings(ISpeakeasyHttpClient defaultClient, Func? security public async Task GetAsync() { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/connectionManagement/corsSettings"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-connection-management-cors-settings", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -133,7 +164,7 @@ public async Task GetAsync() public async Task SetAsync(ConnectionManagementAllowedOrigins? request = null) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/connectionManagement/corsSettings"; @@ -146,13 +177,43 @@ public async Task SetAsync(Connecti httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("set-connection-management-cors-settings", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/CustomDataType.cs b/platform/Codat/Platform/CustomDataType.cs index c6fa01b49..1ec87a334 100644 --- a/platform/Codat/Platform/CustomDataType.cs +++ b/platform/Codat/Platform/CustomDataType.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -85,10 +86,10 @@ public class CustomDataType: ICustomDataType { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -103,7 +104,7 @@ public CustomDataType(ISpeakeasyHttpClient defaultClient, Func? securi public async Task ConfigureAsync(ConfigureCustomDataTypeRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/integrations/{platformKey}/dataTypes/custom/{customDataIdentifier}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Put, urlString); @@ -115,13 +116,43 @@ public async Task ConfigureAsync(ConfigureCusto httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("configure-custom-data-type", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -168,19 +199,49 @@ public async Task ConfigureAsync(ConfigureCusto public async Task GetConfigurationAsync(GetCustomDataTypeConfigurationRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/integrations/{platformKey}/dataTypes/custom/{customDataIdentifier}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("get-custom-data-type-configuration", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -227,19 +288,49 @@ public async Task GetConfigurationAsync( public async Task ListAsync(ListCustomDataTypeRecordsRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections/{connectionId}/data/custom/{customDataIdentifier}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("list-custom-data-type-records", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode == 451 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -286,19 +377,49 @@ public async Task ListAsync(ListCustomDataTyp public async Task RefreshAsync(RefreshCustomDataTypeRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections/{connectionId}/data/queue/custom/{customDataIdentifier}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("refresh-custom-data-type", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode == 451 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/Groups.cs b/platform/Codat/Platform/Groups.cs index 0b26172d9..1672c5b90 100644 --- a/platform/Codat/Platform/Groups.cs +++ b/platform/Codat/Platform/Groups.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -84,10 +85,10 @@ public class Groups: IGroups { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -102,7 +103,7 @@ public Groups(ISpeakeasyHttpClient defaultClient, Func? securitySource public async Task AddCompanyAsync(AddCompanyToGroupRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/groups", request); var httpRequest = new HttpRequestMessage(HttpMethod.Patch, urlString); @@ -114,13 +115,43 @@ public async Task AddCompanyAsync(AddCompanyToGroupRe httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("add-company-to-group", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -167,7 +198,7 @@ public async Task AddCompanyAsync(AddCompanyToGroupRe public async Task CreateAsync(GroupPrototype? request = null) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/groups"; @@ -180,13 +211,43 @@ public async Task CreateAsync(GroupPrototype? request = nul httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("create-group", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 409 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -233,20 +294,50 @@ public async Task CreateAsync(GroupPrototype? request = nul public async Task ListAsync() { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/groups"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("list-groups", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -293,19 +384,49 @@ public async Task ListAsync() public async Task RemoveCompanyAsync(RemoveCompanyFromGroupRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/groups/{groupId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("remove-company-from-group", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/Hooks/HookRegistration.cs b/platform/Codat/Platform/Hooks/HookRegistration.cs new file mode 100644 index 000000000..377b98976 --- /dev/null +++ b/platform/Codat/Platform/Hooks/HookRegistration.cs @@ -0,0 +1,36 @@ + +namespace Codat.Platform.Hooks +{ + /// + /// Hook Registration File. + /// + /// + /// This file is only ever generated once on the first generation and then is free to be modified. + /// Any hooks you wish to add should be registered in the InitHooks function. Feel free to define them + /// in this file or in separate files in the Hooks folder. + /// + public static class HookRegistration + { + /// + /// Initializes hooks. + /// + /// + /// Add hooks by calling `Codat.Platform.Hooks.Register<HookInterface>(myHook);` + /// where `I<HookInterface>` is one of the following interfaces defined in HookTypes.cs: + /// - ISDKInitHook + /// - IBeforeRequestHook + /// - IAfterSuccess + /// - IAfterError + /// and `myHook` an instance that implements that specific interface. + /// + public static void InitHooks(IHooks hooks) + { + // var myHook = new MyHook(); + + // hooks.RegisterSDKInitHook(myHook); + // hooks.RegisterBeforeRequestHook(myHook); + // hooks.RegisterAfterSuccessHook(myHook); + // hooks.RegisterAfterErrorHook(myHook; + } + } +} \ No newline at end of file diff --git a/platform/Codat/Platform/Hooks/HookTypes.cs b/platform/Codat/Platform/Hooks/HookTypes.cs new file mode 100644 index 000000000..3e0d02c8d --- /dev/null +++ b/platform/Codat/Platform/Hooks/HookTypes.cs @@ -0,0 +1,99 @@ + +//------------------------------------------------------------------------------ +// +// This code was generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// +// Changes to this file may cause incorrect behavior and will be lost when +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +namespace Codat.Platform.Hooks +{ + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + using Codat.Platform.Utils; + + public class HookContext + { + public string OperationID { get; set; } + public List? Oauth2Scopes { get; set; } + public Func? SecuritySource { get; set; } + + public HookContext(string operationID, List? oauth2Scopes, Func? securitySource) + { + OperationID = operationID; + Oauth2Scopes = oauth2Scopes; + SecuritySource = securitySource; + } + } + + public class BeforeRequestContext : HookContext + { + public BeforeRequestContext(HookContext hookCtx) + : base(hookCtx.OperationID, hookCtx.Oauth2Scopes, hookCtx.SecuritySource) { } + } + + public class AfterSuccessContext : HookContext + { + public AfterSuccessContext(HookContext hookCtx) + : base(hookCtx.OperationID, hookCtx.Oauth2Scopes, hookCtx.SecuritySource) { } + } + + public class AfterErrorContext : HookContext + { + public AfterErrorContext(HookContext hookCtx) + : base(hookCtx.OperationID, hookCtx.Oauth2Scopes, hookCtx.SecuritySource) { } + } + + /// + /// SDKInit hook is called when the SDK is initializing. + /// The hook can modify and return a new baseUrl and HTTP client to be used by the SDK. + /// + public interface ISDKInitHook + { + (string, ISpeakeasyHttpClient) SDKInit(string baseUrl, ISpeakeasyHttpClient client); + } + + /// + /// BeforeRequestAsync hook is called before the SDK sends a request. + /// The hook can modify the request before it is sent or throw an exception to stop the request from being sent. + /// + public interface IBeforeRequestHook + { + Task BeforeRequestAsync(BeforeRequestContext hookCtx, HttpRequestMessage request); + } + + /// + /// AfterSuccessAsync is called after the SDK receives a response. + /// The hook can modify the response before it is handled or throw an exception to stop the response from being handled. + /// + public interface IAfterSuccessHook + { + Task AfterSuccessAsync(AfterSuccessContext hookCtx, HttpResponseMessage response); + } + + /// + /// AfterErrorAsync is called after the SDK encounters an error, or a non-successful response. + /// The hook can modify the response, if available, otherwise modify the error. + /// All hooks are called sequentially. If an error is returned, it will be passed to the subsequent hook implementing IAfterErrorHook. + /// If you want to prevent other AfterError hooks from being run, you can throw an FailEarlyException instead. + /// + public interface IAfterErrorHook + { + Task<(HttpResponseMessage?, Exception?)> AfterErrorAsync(AfterErrorContext hookCtx, HttpResponseMessage? response, Exception? error); + } + + public interface IHooks + { + void RegisterSDKInitHook(ISDKInitHook hook); + + void RegisterBeforeRequestHook(IBeforeRequestHook hook); + + void RegisterAfterSuccessHook(IAfterSuccessHook hook); + + void RegisterAfterErrorHook(IAfterErrorHook hook); + } +} diff --git a/platform/Codat/Platform/Hooks/SDKHooks.cs b/platform/Codat/Platform/Hooks/SDKHooks.cs new file mode 100644 index 000000000..300efe494 --- /dev/null +++ b/platform/Codat/Platform/Hooks/SDKHooks.cs @@ -0,0 +1,130 @@ + +//------------------------------------------------------------------------------ +// +// This code was generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. +// +// Changes to this file may cause incorrect behavior and will be lost when +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +namespace Codat.Platform.Hooks +{ + using Codat.Platform.Utils; + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + + public sealed class FailEarlyException : Exception {} + + public class SDKHooks: IHooks + { + public List sdkInitHooks; + public List beforeRequestHooks; + public List afterSuccessHooks; + public List afterErrorHooks; + + public SDKHooks() + { + this.sdkInitHooks = new List(); + this.beforeRequestHooks = new List(); + this.afterSuccessHooks = new List(); + this.afterErrorHooks = new List(); + HookRegistration.InitHooks(this); + } + + public void RegisterSDKInitHook(ISDKInitHook hook) + { + this.sdkInitHooks.Add(hook); + } + + public void RegisterBeforeRequestHook(IBeforeRequestHook hook) + { + this.beforeRequestHooks.Add(hook); + } + + public void RegisterAfterSuccessHook(IAfterSuccessHook hook) + { + this.afterSuccessHooks.Add(hook); + } + + public void RegisterAfterErrorHook(IAfterErrorHook hook) + { + this.afterErrorHooks.Add(hook); + } + + public (string, ISpeakeasyHttpClient) SDKInit(string baseUrl, ISpeakeasyHttpClient client) + { + var urlAndClient = (baseUrl, client); + foreach (var hook in this.sdkInitHooks) + { + try + { + urlAndClient = hook.SDKInit(urlAndClient.Item1, urlAndClient.Item2); + } catch (Exception ex) + { + throw new Exception("An error occurred while calling SDKInit hook.", ex); + } + } + return urlAndClient; + } + + public async Task BeforeRequestAsync(BeforeRequestContext hookCtx, HttpRequestMessage request) + { + foreach (var hook in this.beforeRequestHooks) + { + try + { + request = await hook.BeforeRequestAsync(hookCtx, request); + } catch (Exception ex) + { + throw new Exception("An error occurred while calling BeforeRequestAsync hook", ex); + } + } + return request; + } + + public async Task AfterSuccessAsync(AfterSuccessContext hookCtx, HttpResponseMessage response) + { + foreach (var hook in this.afterSuccessHooks) + { + try + { + response = await hook.AfterSuccessAsync(hookCtx, response); + } + catch (Exception ex) + { + throw new Exception("An error occurred while calling AfterSuccessAsync hook.", ex); + } + } + return response; + } + + public async Task AfterErrorAsync(AfterErrorContext hookCtx, HttpResponseMessage? response, Exception? error) + { + + (HttpResponseMessage?, Exception?) responseAndError = (response, error); + foreach (var hook in this.afterErrorHooks) + { + try + { + responseAndError = await hook.AfterErrorAsync(hookCtx, responseAndError.Item1, responseAndError.Item2); + } catch (FailEarlyException) + { + throw; + } catch (Exception ex) + { + throw new Exception("An error occurred while calling AfterErrorAsync hook", ex); + } + } + + if (responseAndError.Item2 != null) + { + throw responseAndError.Item2; + } + + return responseAndError.Item1; + } + } +} \ No newline at end of file diff --git a/platform/Codat/Platform/Integrations.cs b/platform/Codat/Platform/Integrations.cs index 24562e00b..e6626f867 100644 --- a/platform/Codat/Platform/Integrations.cs +++ b/platform/Codat/Platform/Integrations.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -62,10 +63,10 @@ public class Integrations: IIntegrations { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -80,19 +81,49 @@ public Integrations(ISpeakeasyHttpClient defaultClient, Func? security public async Task GetAsync(GetIntegrationRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/integrations/{platformKey}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-integration", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -139,19 +170,49 @@ public async Task GetAsync(GetIntegrationRequest request public async Task GetBrandingAsync(GetIntegrationsBrandingRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/integrations/{platformKey}/branding", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-integrations-branding", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -198,19 +259,49 @@ public async Task GetBrandingAsync(GetIntegrati public async Task ListAsync(ListIntegrationsRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/integrations", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("list-integrations", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/PushData.cs b/platform/Codat/Platform/PushData.cs index 81e1e9dee..f9a9101ed 100644 --- a/platform/Codat/Platform/PushData.cs +++ b/platform/Codat/Platform/PushData.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -71,10 +72,10 @@ public class PushData: IPushData { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -89,19 +90,49 @@ public PushData(ISpeakeasyHttpClient defaultClient, Func? securitySour public async Task GetModelOptionsAsync(GetCreateUpdateModelOptionsByDataTypeRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/connections/{connectionId}/options/{dataType}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-create-update-model-options-by-data-type", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -148,19 +179,49 @@ public async Task GetModelOptions public async Task GetOperationAsync(GetPushOperationRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/push/{pushOperationKey}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-push-operation", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -207,19 +268,49 @@ public async Task GetOperationAsync(GetPushOperationRe public async Task ListOperationsAsync(GetCompanyPushHistoryRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/push", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("get-company-push-history", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/RefreshData.cs b/platform/Codat/Platform/RefreshData.cs index e514298ce..fe4513bb9 100644 --- a/platform/Codat/Platform/RefreshData.cs +++ b/platform/Codat/Platform/RefreshData.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -86,10 +87,10 @@ public class RefreshData: IRefreshData { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -104,19 +105,49 @@ public RefreshData(ISpeakeasyHttpClient defaultClient, Func? securityS public async Task AllAsync(RefreshCompanyDataRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/data/all", request); var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("refresh-company-data", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -153,19 +184,49 @@ public async Task AllAsync(RefreshCompanyDataRequest public async Task ByDataTypeAsync(RefreshDataTypeRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/data/queue/{dataType}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("refresh-data-type", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -212,19 +273,49 @@ public async Task ByDataTypeAsync(RefreshDataTypeReques public async Task GetAsync(GetCompanyDataStatusRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/dataStatus", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-company-data-status", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -271,19 +362,49 @@ public async Task GetAsync(GetCompanyDataStatusReq public async Task GetPullOperationAsync(GetPullOperationRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/data/history/{datasetId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-pull-operation", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -330,19 +451,49 @@ public async Task GetPullOperationAsync(GetPullOperati public async Task ListPullOperationsAsync(ListPullOperationsRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/companies/{companyId}/data/history", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("list-pull-operations", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/Settings.cs b/platform/Codat/Platform/Settings.cs index d67cd97d0..5e8b3fd24 100644 --- a/platform/Codat/Platform/Settings.cs +++ b/platform/Codat/Platform/Settings.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -121,10 +122,10 @@ public class Settings: ISettings { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -139,7 +140,7 @@ public Settings(ISpeakeasyHttpClient defaultClient, Func? securitySour public async Task CreateApiKeyAsync(CreateApiKey? request = null) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/apiKeys"; @@ -152,13 +153,43 @@ public async Task CreateApiKeyAsync(CreateApiKey? request httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("create-api-key", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 409 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -205,19 +236,49 @@ public async Task CreateApiKeyAsync(CreateApiKey? request public async Task DeleteApiKeyAsync(DeleteApiKeyRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/apiKeys/{apiKeyId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("delete-api-key", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -264,20 +325,50 @@ public async Task DeleteApiKeyAsync(DeleteApiKeyRequest re public async Task GetProfileAsync() { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/profile"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("get-profile", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -324,20 +415,50 @@ public async Task GetProfileAsync() public async Task GetSyncSettingsAsync() { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/profile/syncSettings"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-profile-syncSettings", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -384,20 +505,50 @@ public async Task GetSyncSettingsAsync() public async Task ListApiKeysAsync() { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/apiKeys"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("list-api-keys", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -444,7 +595,7 @@ public async Task ListApiKeysAsync() public async Task UpdateProfileAsync(Profile? request = null) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/profile"; @@ -457,13 +608,43 @@ public async Task UpdateProfileAsync(Profile? request = n httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("update-profile", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -510,7 +691,7 @@ public async Task UpdateProfileAsync(Profile? request = n public async Task UpdateSyncSettingsAsync(UpdateProfileSyncSettingsRequestBody? request = null) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/profile/syncSettings"; @@ -523,13 +704,43 @@ public async Task UpdateSyncSettingsAsync(Upd httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("update-profile-syncSettings", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/SupplementalData.cs b/platform/Codat/Platform/SupplementalData.cs index 6f5e63676..8101741c7 100644 --- a/platform/Codat/Platform/SupplementalData.cs +++ b/platform/Codat/Platform/SupplementalData.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -60,10 +61,10 @@ public class SupplementalData: ISupplementalData { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -78,7 +79,7 @@ public SupplementalData(ISpeakeasyHttpClient defaultClient, Func? secu public async Task ConfigureAsync(ConfigureSupplementalDataRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/integrations/{platformKey}/dataTypes/{dataType}/supplementalDataConfig", request); var httpRequest = new HttpRequestMessage(HttpMethod.Put, urlString); @@ -90,13 +91,43 @@ public async Task ConfigureAsync(ConfigureSup httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("configure-supplemental-data", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -133,19 +164,49 @@ public async Task ConfigureAsync(ConfigureSup public async Task GetConfigurationAsync(GetSupplementalDataConfigurationRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/integrations/{platformKey}/dataTypes/{dataType}/supplementalDataConfig", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("get-supplemental-data-configuration", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/Codat/Platform/Utils/AnyDeserializer.cs b/platform/Codat/Platform/Utils/AnyDeserializer.cs index 2958cfb90..119a240f1 100644 --- a/platform/Codat/Platform/Utils/AnyDeserializer.cs +++ b/platform/Codat/Platform/Utils/AnyDeserializer.cs @@ -36,7 +36,10 @@ public override object ReadJson( JsonSerializer serializer ) { - return ParseTokenIntoDictionary(JToken.Load(reader)); + if (reader.TokenType == JsonToken.StartObject) { + return ParseTokenIntoDictionary(JToken.Load(reader)); + } + throw new JsonSerializationException($"Could not deserialize token into dictionary"); } private Dictionary ParseTokenIntoDictionary(JToken token) diff --git a/platform/Codat/Platform/Utils/SecuritySerializer.cs b/platform/Codat/Platform/Utils/SecurityMetadata.cs similarity index 50% rename from platform/Codat/Platform/Utils/SecuritySerializer.cs rename to platform/Codat/Platform/Utils/SecurityMetadata.cs index f921006c1..cf279bc3d 100644 --- a/platform/Codat/Platform/Utils/SecuritySerializer.cs +++ b/platform/Codat/Platform/Utils/SecurityMetadata.cs @@ -11,179 +11,189 @@ namespace Codat.Platform.Utils { using System; + using System.Collections.Generic; + using System.Net.Http; using System.Reflection; using System.Text; + using System.Web; - internal static class SecuritySerializer + + internal class SecurityMetadata { - public static ISpeakeasyHttpClient Apply(ISpeakeasyHttpClient client, Func securitySource) + private Dictionary headerParams { get; } = new Dictionary(); + private Dictionary queryParams { get; } = new Dictionary(); + + public SecurityMetadata(Func securitySource) + { + ParseSecuritySource(securitySource); + } + + public HttpRequestMessage Apply(HttpRequestMessage request) + { + foreach (var kvp in headerParams) + { + request.Headers.Add(kvp.Key, kvp.Value); + } + + if(request.RequestUri != null) + { + var uriBuilder = new UriBuilder(request.RequestUri); + var query = HttpUtility.ParseQueryString(uriBuilder.Query); + foreach (var kvp in queryParams) + { + query.Add(kvp.Key, kvp.Value); + } + uriBuilder.Query = query.ToString(); + request.RequestUri = uriBuilder.Uri; + } + + return request; + } + + private void ParseSecuritySource(Func securitySource) { if (securitySource == null) { - return client; + return; } var security = securitySource(); if (security == null) { - return client; + return; } - client = new SpeakeasyHttpClient(client); - - var props = security.GetType().GetProperties(); - - foreach (var prop in props) + foreach (var prop in security.GetType().GetProperties()) { var value = prop.GetValue(security, null); - if (value == null) { continue; } - var metadata = prop.GetCustomAttribute()?.GetSecurityMetadata(); - if (metadata == null) + var secMetadata = prop.GetCustomAttribute()?.GetSecurityMetadata(); + if (secMetadata == null) { continue; } - if (metadata.Option) + if (secMetadata.Option) { - ApplyOption(ref client, value); + ParseOption(value); } - else if (metadata.Scheme) + else if (secMetadata.Scheme) { - if (metadata.SubType == "basic" && !Utilities.IsClass(value)) + if (secMetadata.SubType == "basic" && !Utilities.IsClass(value)) { - ApplyScheme(ref client, metadata, security); - return client; + ParseScheme(secMetadata, security); + return; } else { - ApplyScheme(ref client, metadata, value); + ParseScheme(secMetadata, value); } } } - return client; + return; } - private static void ApplyOption(ref ISpeakeasyHttpClient client, object option) + private void ParseOption(object option) { - var props = option.GetType().GetProperties(); - - foreach (var prop in props) + foreach (var prop in option.GetType().GetProperties()) { var value = prop.GetValue(option, null); - if (value == null) { continue; } - var metadata = prop.GetCustomAttribute()?.GetSecurityMetadata(); - if (metadata == null || !metadata.Scheme) + var secMetadata = prop.GetCustomAttribute()?.GetSecurityMetadata(); + if (secMetadata == null || !secMetadata.Scheme) { continue; } - ApplyScheme(ref client, metadata, value); + ParseScheme(secMetadata, value); } } - private static void ApplyScheme( - ref ISpeakeasyHttpClient client, - SpeakeasyMetadata.SecurityMetadata schemeMetadata, - object scheme - ) + private void ParseScheme(SpeakeasyMetadata.SecurityMetadata schemeMetadata, object scheme) { if (Utilities.IsClass(scheme)) { if (schemeMetadata.Type == "http" && schemeMetadata.SubType == "basic") { - ApplyBasicAuthScheme(ref client, scheme); + ParseBasicAuthScheme(scheme); return; } - var props = scheme.GetType().GetProperties(); - - foreach (var prop in props) + foreach (var prop in scheme.GetType().GetProperties()) { var value = prop.GetValue(scheme, null); - if (value == null) { continue; } - var metadata = prop.GetCustomAttribute()?.GetSecurityMetadata(); - if (metadata == null || metadata.Name == "") + var secMetadata = prop.GetCustomAttribute()?.GetSecurityMetadata(); + if (secMetadata == null || secMetadata.Name == "") { continue; } - ApplySchemeValue(ref client, schemeMetadata, metadata, value); + ParseSchemeValue(schemeMetadata, secMetadata, value); } } else { - ApplySchemeValue(ref client, schemeMetadata, schemeMetadata, scheme); + ParseSchemeValue(schemeMetadata, schemeMetadata, scheme); } } - private static void ApplySchemeValue( - ref ISpeakeasyHttpClient client, + private void ParseSchemeValue( SpeakeasyMetadata.SecurityMetadata schemeMetadata, SpeakeasyMetadata.SecurityMetadata valueMetadata, object value ) { - if (valueMetadata.Name == "") + var key = valueMetadata.Name; + if (key == "") { return; } + var valStr = Utilities.ValueToString(value); + switch (schemeMetadata.Type) { case "apiKey": switch (schemeMetadata.SubType) { case "header": - client.AddHeader(valueMetadata.Name, Utilities.ValueToString(value)); + headerParams.Add(key, valStr); break; case "query": - client.AddQueryParam( - valueMetadata.Name, - Utilities.ValueToString(value) - ); + queryParams.Add(key, valStr); break; case "cookie": - client.AddHeader( - "cookie", - $"{valueMetadata.Name}={Utilities.ValueToString(value)}" - ); + headerParams.Add("cookie", $"{key}={valStr}"); break; default: - throw new Exception( - $"Unknown apiKey subType: {schemeMetadata.SubType}" - ); + throw new Exception($"Unknown apiKey subType: {schemeMetadata.SubType}"); } break; case "openIdConnect": - client.AddHeader(valueMetadata.Name, Utilities.PrefixBearer(Utilities.ValueToString(value))); + headerParams.Add(key, Utilities.PrefixBearer(valStr)); break; case "oauth2": - client.AddHeader(valueMetadata.Name, Utilities.PrefixBearer(Utilities.ValueToString(value))); + headerParams.Add(key, Utilities.PrefixBearer(valStr)); break; case "http": switch (schemeMetadata.SubType) { case "bearer": - client.AddHeader( - valueMetadata.Name, - Utilities.PrefixBearer(Utilities.ValueToString(value)) - ); + headerParams.Add(key, Utilities.PrefixBearer(valStr)); break; default: throw new Exception($"Unknown http subType: {schemeMetadata.SubType}"); @@ -194,40 +204,38 @@ object value } } - private static void ApplyBasicAuthScheme(ref ISpeakeasyHttpClient client, object scheme) + private void ParseBasicAuthScheme(object scheme) { - var props = scheme.GetType().GetProperties(); string username = ""; string password = ""; - foreach (var prop in props) + foreach (var prop in scheme.GetType().GetProperties()) { var value = prop.GetValue(scheme, null); - if (value == null) { continue; } - var metadata = prop.GetCustomAttribute()?.GetSecurityMetadata(); - if (metadata == null || metadata.Name == "") + var secMetadata = prop.GetCustomAttribute()?.GetSecurityMetadata(); + if (secMetadata == null || secMetadata.Name == "") { continue; } - if (metadata.Name == "username") + if (secMetadata.Name == "username") { username = Utilities.ValueToString(value); } - else if (metadata.Name == "password") + else if (secMetadata.Name == "password") { password = Utilities.ValueToString(value); } } var auth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}")); - client.AddHeader("Authorization", $"Basic {auth}"); + headerParams.Add("Authorization", $"Basic {auth}"); } } } diff --git a/platform/Codat/Platform/Utils/SpeakeasyHttpClient.cs b/platform/Codat/Platform/Utils/SpeakeasyHttpClient.cs index 5578249de..c380af86a 100644 --- a/platform/Codat/Platform/Utils/SpeakeasyHttpClient.cs +++ b/platform/Codat/Platform/Utils/SpeakeasyHttpClient.cs @@ -17,80 +17,41 @@ namespace Codat.Platform.Utils public interface ISpeakeasyHttpClient { - void AddHeader(string key, string value); - void AddQueryParam(string key, string value); - Task SendAsync(HttpRequestMessage message); + Task SendAsync(HttpRequestMessage request); } public class SpeakeasyHttpClient : ISpeakeasyHttpClient { - private ISpeakeasyHttpClient? client; - - private Dictionary> headers { get; } = - new Dictionary>(); - - private Dictionary> queryParams { get; } = - new Dictionary>(); - - internal SpeakeasyHttpClient(ISpeakeasyHttpClient? client = null) + private class HttpClient : ISpeakeasyHttpClient { - this.client = client; - } + private System.Net.Http.HttpClient client; - public void AddHeader(string key, string value) - { - if (headers.ContainsKey(key)) - { - headers[key].Add(value); - } - else + public HttpClient() { - headers.Add(key, new List { value }); + client = new System.Net.Http.HttpClient(); } - } - public void AddQueryParam(string key, string value) - { - if (queryParams.ContainsKey(key)) + public async Task SendAsync(HttpRequestMessage request) { - queryParams[key].Add(value); - } - else - { - queryParams.Add(key, new List { value }); + return await client.SendAsync(request); } } - public async Task SendAsync(HttpRequestMessage message) + private ISpeakeasyHttpClient? client; + + internal SpeakeasyHttpClient(ISpeakeasyHttpClient? client = null) { - foreach(var hh in headers) + if (client == null) { - foreach(var hv in hh.Value) - { - message.Headers.Add(hh.Key, hv); - } + client = new HttpClient(); } - /*var qp = URLBuilder.SerializeQueryParams(queryParams); - - if (qp != "") - { - if (message.uri.Query == "") - { - message.url += "?" + qp; - } - else - { - message.url += "&" + qp; - } - }*/ - - if (client != null) - { - return await client.SendAsync(message); - } + this.client = client; + } - return await new HttpClient().SendAsync(message); + public async Task SendAsync(HttpRequestMessage request) + { + return await client?.SendAsync(request); } } } \ No newline at end of file diff --git a/platform/Codat/Platform/Webhooks.cs b/platform/Codat/Platform/Webhooks.cs index 85d91ce33..06ec57519 100644 --- a/platform/Codat/Platform/Webhooks.cs +++ b/platform/Codat/Platform/Webhooks.cs @@ -10,6 +10,7 @@ #nullable enable namespace Codat.Platform { + using Codat.Platform.Hooks; using Codat.Platform.Models.Errors; using Codat.Platform.Models.Operations; using Codat.Platform.Models.Shared; @@ -95,10 +96,10 @@ public class Webhooks: IWebhooks { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "3.6.0"; - private const string _sdkGenVersion = "2.314.0"; + private const string _sdkVersion = "3.6.1"; + private const string _sdkGenVersion = "2.319.7"; private const string _openapiDocVersion = "3.0.0"; - private const string _userAgent = "speakeasy-sdk/csharp 3.6.0 2.314.0 3.0.0 Codat.Platform"; + private const string _userAgent = "speakeasy-sdk/csharp 3.6.1 2.319.7 3.0.0 Codat.Platform"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; @@ -114,7 +115,7 @@ public Webhooks(ISpeakeasyHttpClient defaultClient, Func? securitySour [Obsolete("This method will be removed in a future release, please migrate away from it as soon as possible")] public async Task CreateAsync(CreateRule? request = null) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/rules"; @@ -127,13 +128,43 @@ public async Task CreateAsync(CreateRule? request = null) httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("create-rule", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -180,7 +211,7 @@ public async Task CreateAsync(CreateRule? request = null) public async Task CreateConsumerAsync(WebhookConsumerPrototype? request = null) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/webhooks"; @@ -193,13 +224,43 @@ public async Task CreateConsumerAsync(WebhookCons httpRequest.Content = serializedBody; } - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("create-webhook-consumer", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -246,19 +307,49 @@ public async Task CreateConsumerAsync(WebhookCons public async Task DeleteConsumerAsync(DeleteWebhookConsumerRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/webhooks/{webhookId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("delete-webhook-consumer", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -296,19 +387,49 @@ public async Task DeleteConsumerAsync(DeleteWebho [Obsolete("This method will be removed in a future release, please migrate away from it as soon as possible")] public async Task GetAsync(GetWebhookRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/rules/{ruleId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("get-webhook", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -356,19 +477,49 @@ public async Task GetAsync(GetWebhookRequest request) [Obsolete("This method will be removed in a future release, please migrate away from it as soon as possible")] public async Task ListAsync(ListRulesRequest request) { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/rules", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } - var httpResponse = await client.SendAsync(httpRequest); + var hookCtx = new HookContext("list-rules", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 404 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } + } + + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; @@ -415,20 +566,50 @@ public async Task ListAsync(ListRulesRequest request) public async Task ListConsumersAsync() { - string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); + string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/webhooks"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); - var client = _defaultClient; if (_securitySource != null) { - client = SecuritySerializer.Apply(_defaultClient, _securitySource); + httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); + } + + var hookCtx = new HookContext("list-webhook-consumers", null, _securitySource); + + httpRequest = await this.SDKConfiguration.hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); + HttpResponseMessage httpResponse; + try + { + httpResponse = await _defaultClient.SendAsync(httpRequest); + int _statusCode = (int)httpResponse.StatusCode; + + if (_statusCode == 400 || _statusCode == 401 || _statusCode == 402 || _statusCode == 403 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 503 || _statusCode >= 500 && _statusCode < 600) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + } + } + catch (Exception error) + { + var _httpResponse = await this.SDKConfiguration.hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); + if (_httpResponse != null) + { + httpResponse = _httpResponse; + } + else + { + throw; + } } - var httpResponse = await client.SendAsync(httpRequest); + httpResponse = await this.SDKConfiguration.hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; diff --git a/platform/RELEASES.md b/platform/RELEASES.md index 2f47d6d36..59cec8f83 100644 --- a/platform/RELEASES.md +++ b/platform/RELEASES.md @@ -146,4 +146,14 @@ Based on: ### Generated - [csharp v3.6.0] platform ### Releases -- [NuGet v3.6.0] https://www.nuget.org/packages/Codat.Platform/3.6.0 - platform \ No newline at end of file +- [NuGet v3.6.0] https://www.nuget.org/packages/Codat.Platform/3.6.0 - platform + +## 2024-05-02 09:21:39 +### Changes +Based on: +- OpenAPI Doc 3.0.0 https://raw.githubusercontent.com/codatio/oas/main/yaml/Codat-Platform.yaml +- Speakeasy CLI 1.277.6 (2.319.7) https://github.com/speakeasy-api/speakeasy +### Generated +- [csharp v3.6.1] platform +### Releases +- [NuGet v3.6.1] https://www.nuget.org/packages/Codat.Platform/3.6.1 - platform \ No newline at end of file diff --git a/platform/docs/sdks/companies/README.md b/platform/docs/sdks/companies/README.md index f829b211f..332563351 100644 --- a/platform/docs/sdks/companies/README.md +++ b/platform/docs/sdks/companies/README.md @@ -35,6 +35,11 @@ var sdk = new CodatPlatform(security: new Security() { CompanyRequestBody req = new CompanyRequestBody() { Description = "Requested early access to the new financing scheme.", + Groups = new List() { + new GroupRef() { + Id = "60d2fa12-8a04-11ee-b9d1-0242ac120002", + }, + }, Name = "Bank of Dave", }; @@ -217,6 +222,15 @@ var sdk = new CodatPlatform(security: new Security() { }); UpdateCompanyRequest req = new UpdateCompanyRequest() { + CompanyRequestBody = new CompanyRequestBody() { + Description = "Requested early access to the new financing scheme.", + Groups = new List() { + new GroupRef() { + Id = "60d2fa12-8a04-11ee-b9d1-0242ac120002", + }, + }, + Name = "Bank of Dave", + }, CompanyId = "8a210b68-6988-11ed-a1eb-0242ac120002", }; diff --git a/platform/docs/sdks/connectionmanagement/README.md b/platform/docs/sdks/connectionmanagement/README.md index 59816bd67..bf3498c3c 100644 --- a/platform/docs/sdks/connectionmanagement/README.md +++ b/platform/docs/sdks/connectionmanagement/README.md @@ -11,7 +11,7 @@ Configure connection management UI and retrieve access tokens for authentication ## GetAccessToken -Use the *Get access token* endpoint to retrieve a new access token for use by the [connection management UI](https://docs.codat.io/auth-flow/optimize/connection-management). +Use the *Get access token* endpoint to retrieve a new access token for use by the [connection management UI](https://docs.codat.io/auth-flow/optimize/connection-management). The token is only valid for one hour and applies to a single company. The embedded [connection management UI](https://docs.codat.io/auth-flow/optimize/connection-management) lets your customers control access to their data by allowing them to manage their existing connections. diff --git a/platform/docs/sdks/connections/README.md b/platform/docs/sdks/connections/README.md index fbbc8faaa..c83d5b4e9 100644 --- a/platform/docs/sdks/connections/README.md +++ b/platform/docs/sdks/connections/README.md @@ -32,6 +32,9 @@ var sdk = new CodatPlatform(security: new Security() { }); CreateConnectionRequest req = new CreateConnectionRequest() { + RequestBody = new CreateConnectionRequestBody() { + PlatformKey = "gbol", + }, CompanyId = "8a210b68-6988-11ed-a1eb-0242ac120002", }; diff --git a/platform/docs/sdks/groups/README.md b/platform/docs/sdks/groups/README.md index d2e22daca..081914ac2 100644 --- a/platform/docs/sdks/groups/README.md +++ b/platform/docs/sdks/groups/README.md @@ -30,6 +30,9 @@ var sdk = new CodatPlatform(security: new Security() { }); AddCompanyToGroupRequest req = new AddCompanyToGroupRequest() { + CompanyGroupAssignment = new CompanyGroupAssignment() { + GroupId = "60d2fa12-8a04-11ee-b9d1-0242ac120002", + }, CompanyId = "8a210b68-6988-11ed-a1eb-0242ac120002", }; diff --git a/platform/gen.yaml b/platform/gen.yaml index 4f0eb97c1..63728fc5c 100644 --- a/platform/gen.yaml +++ b/platform/gen.yaml @@ -11,7 +11,7 @@ generation: oAuth2ClientCredentialsEnabled: false telemetryEnabled: true csharp: - version: 3.6.0 + version: 3.6.1 additionalDependencies: [] author: Codat clientServerStatusCodesAsErrors: true