From cfa4a36c6d7ceef523e69d8f29814671041cc65d Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Mon, 20 Jul 2026 18:59:35 +0000 Subject: [PATCH 1/2] [fern-generated] Update SDK Generated by Fern CLI Version: unknown Generators: - fernapi/fern-csharp-sdk: 2.71.1 --- .fern/metadata.json | 6 +- WASM_VERSION | 1 - reference.md | 763 +++++- .../Catalogs/CatalogsClient.cs | 2241 +++++++++++++++++ .../Catalogs/ICatalogsClient.cs | 94 + .../Requests/CreateCatalogRequestBody.cs | 23 + .../Catalogs/Requests/ListCatalogsRequest.cs | 35 + .../UpdateCatalogConfigurationRequestBody.cs | 41 + .../Requests/UpdateCatalogRequestBody.cs | 23 + .../Catalogs/Types/CreateCatalogResponse.cs | 34 + .../Catalogs/Types/DeleteCatalogResponse.cs | 34 + .../Catalogs/Types/GetCatalogResponse.cs | 34 + .../Types/GetConfigurationResponse.cs | 34 + .../GetCreditBundlesInCatalogResponse.cs | 34 + .../Types/GetDerivedFeaturesResponse.cs | 34 + .../Types/GetPlansInCatalogResponse.cs | 34 + .../Catalogs/Types/ListCatalogsParams.cs | 49 + .../Catalogs/Types/ListCatalogsResponse.cs | 34 + .../Catalogs/Types/UpdateCatalogResponse.cs | 34 + .../Types/UpdateConfigurationResponse.cs | 34 + .../Components/ComponentsClient.cs | 172 ++ .../Components/IComponentsClient.cs | 7 + .../Requests/BindCatalogRequestBody.cs | 17 + .../Components/Types/BindCatalogResponse.cs | 34 + src/SchematicHQ.Client/Core/Public/Version.cs | 2 +- .../Dataexports/DataexportsClient.cs | 338 ++- .../Dataexports/IDataexportsClient.cs | 12 + .../Requests/CreateDataExportRequestBody.cs | 6 +- .../Requests/ListDataExportsRequest.cs | 32 + .../Types/GetDataExportResponse.cs | 34 + .../Types/ListDataExportsParams.cs | 46 + .../Types/ListDataExportsResponse.cs | 35 + src/SchematicHQ.Client/ISchematicApi.cs | 1 + .../CreateCustomPlanBundleRequestBody.cs | 3 + src/SchematicHQ.Client/SchematicApi.cs | 5 +- .../SchematicHQ.Client.csproj | 2 +- .../Types/AuditLogExportMetadata.cs | 55 + .../Types/CatalogConfigOrderedBundle.cs | 28 + .../CatalogConfigOrderedBundleResponseData.cs | 28 + .../Types/CatalogConfigOrderedEntitlement.cs | 31 + ...logConfigOrderedEntitlementResponseData.cs | 31 + .../Types/CatalogConfigOrderedPlan.cs | 31 + .../CatalogConfigOrderedPlanResponseData.cs | 32 + .../Types/CatalogConfigurationResponseData.cs | 63 + .../CatalogCreditBundleIDsResponseData.cs | 28 + .../CatalogDerivedFeatureResponseData.cs | 34 + .../CatalogDerivedFeaturesResponseData.cs | 29 + .../Types/CatalogPlanIDsResponseData.cs | 28 + .../Types/CatalogResponseData.cs | 67 + .../CompanyFeatureUsageExportMetadata.cs | 127 + .../Types/CompanyPlanDetailResponseData.cs | 3 + .../Types/ComponentResponseData.cs | 3 + .../Types/DataExportMetadata.cs | 293 +++ .../Types/DataExportOutputFileType.cs | 115 + .../Types/DataExportResponseData.cs | 6 +- .../Types/DataExportType.cs | 115 + .../Types/FeatureEntitlement.cs | 6 + .../PlanCatalogMembershipResponseData.cs | 31 + .../Types/PlanDetailResponseData.cs | 3 + .../Types/PlanGroupPlanDetailResponseData.cs | 3 + .../Types/PlanViewPublicResponseData.cs | 3 + ...PreviewSubscriptionDiscountResponseData.cs | 58 + .../PreviewSubscriptionFinanceResponseData.cs | 7 + .../Types/RulesengineFeatureEntitlement.cs | 6 + .../Types/RulesengineWarningTier.cs | 37 + .../Types/UpsertCompanyRequestBody.cs | 12 + src/SchematicHQ.Client/Types/WarningTier.cs | 37 + 67 files changed, 5693 insertions(+), 19 deletions(-) delete mode 100644 WASM_VERSION create mode 100644 src/SchematicHQ.Client/Catalogs/CatalogsClient.cs create mode 100644 src/SchematicHQ.Client/Catalogs/ICatalogsClient.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Requests/CreateCatalogRequestBody.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Requests/ListCatalogsRequest.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Requests/UpdateCatalogConfigurationRequestBody.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Requests/UpdateCatalogRequestBody.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/CreateCatalogResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/DeleteCatalogResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/GetCatalogResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/GetConfigurationResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/GetCreditBundlesInCatalogResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/GetDerivedFeaturesResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/GetPlansInCatalogResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/ListCatalogsParams.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/ListCatalogsResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/UpdateCatalogResponse.cs create mode 100644 src/SchematicHQ.Client/Catalogs/Types/UpdateConfigurationResponse.cs create mode 100644 src/SchematicHQ.Client/Components/Requests/BindCatalogRequestBody.cs create mode 100644 src/SchematicHQ.Client/Components/Types/BindCatalogResponse.cs create mode 100644 src/SchematicHQ.Client/Dataexports/Requests/ListDataExportsRequest.cs create mode 100644 src/SchematicHQ.Client/Dataexports/Types/GetDataExportResponse.cs create mode 100644 src/SchematicHQ.Client/Dataexports/Types/ListDataExportsParams.cs create mode 100644 src/SchematicHQ.Client/Dataexports/Types/ListDataExportsResponse.cs create mode 100644 src/SchematicHQ.Client/Types/AuditLogExportMetadata.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogConfigOrderedBundle.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogConfigOrderedBundleResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogConfigOrderedEntitlement.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogConfigOrderedEntitlementResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogConfigOrderedPlan.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogConfigOrderedPlanResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogConfigurationResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogCreditBundleIDsResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogDerivedFeatureResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogDerivedFeaturesResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogPlanIDsResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CatalogResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/CompanyFeatureUsageExportMetadata.cs create mode 100644 src/SchematicHQ.Client/Types/DataExportMetadata.cs create mode 100644 src/SchematicHQ.Client/Types/DataExportOutputFileType.cs create mode 100644 src/SchematicHQ.Client/Types/DataExportType.cs create mode 100644 src/SchematicHQ.Client/Types/PlanCatalogMembershipResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/PreviewSubscriptionDiscountResponseData.cs create mode 100644 src/SchematicHQ.Client/Types/RulesengineWarningTier.cs create mode 100644 src/SchematicHQ.Client/Types/WarningTier.cs diff --git a/.fern/metadata.json b/.fern/metadata.json index fd816940..367f19f5 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -8,10 +8,10 @@ "exported-client-class-name": "Schematic", "generate-mock-server-tests": false }, - "originGitCommit": "19cafdf92ab056ef6ba803bf1e352b0422a8ec45", + "originGitCommit": "86a4c45d14847babf70751d87de4da7764ecd894", "originGitCommitIsDirty": false, "invokedBy": "ci", - "requestedVersion": "1.5.1", + "requestedVersion": "1.5.2", "ciProvider": "github", - "sdkVersion": "1.5.1" + "sdkVersion": "1.5.2" } \ No newline at end of file diff --git a/WASM_VERSION b/WASM_VERSION deleted file mode 100644 index 1d0ba9ea..00000000 --- a/WASM_VERSION +++ /dev/null @@ -1 +0,0 @@ -0.4.0 diff --git a/reference.md b/reference.md index 1aac3f10..830c18e5 100644 --- a/reference.md +++ b/reference.md @@ -3459,6 +3459,628 @@ await client.Credits.CountCreditEventLedgerAsync( + + + + +## catalogs +
client.Catalogs.ListCatalogsAsync(ListCatalogsRequest { ... }) -> WithRawResponseTask<ListCatalogsResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.ListCatalogsAsync( + new ListCatalogsRequest + { + IsDefault = true, + Q = "q", + Limit = 1000000, + Offset = 1000000, + } +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**request:** `ListCatalogsRequest` + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.CreateCatalogAsync(CreateCatalogRequestBody { ... }) -> WithRawResponseTask<CreateCatalogResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.CreateCatalogAsync( + new CreateCatalogRequestBody { IsDefault = true, Name = "name" } +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**request:** `CreateCatalogRequestBody` + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.GetCatalogAsync(catalogId) -> WithRawResponseTask<GetCatalogResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.GetCatalogAsync("catalog_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.UpdateCatalogAsync(catalogId, UpdateCatalogRequestBody { ... }) -> WithRawResponseTask<UpdateCatalogResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.UpdateCatalogAsync("catalog_id", new UpdateCatalogRequestBody()); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+ +
+
+ +**request:** `UpdateCatalogRequestBody` + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.DeleteCatalogAsync(catalogId) -> WithRawResponseTask<DeleteCatalogResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.DeleteCatalogAsync("catalog_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.GetConfigurationAsync(catalogId) -> WithRawResponseTask<GetConfigurationResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.GetConfigurationAsync("catalog_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.UpdateConfigurationAsync(catalogId, UpdateCatalogConfigurationRequestBody { ... }) -> WithRawResponseTask<UpdateConfigurationResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.UpdateConfigurationAsync( + "catalog_id", + new UpdateCatalogConfigurationRequestBody() +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+ +
+
+ +**request:** `UpdateCatalogConfigurationRequestBody` + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.GetCreditBundlesInCatalogAsync(catalogId) -> WithRawResponseTask<GetCreditBundlesInCatalogResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.GetCreditBundlesInCatalogAsync("catalog_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.AddCreditBundleAsync(catalogId, creditBundleId) -> WithRawResponseTask +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.AddCreditBundleAsync("catalog_id", "credit_bundle_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+ +
+
+ +**creditBundleId:** `string` — credit_bundle_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.RemoveCreditBundleAsync(catalogId, creditBundleId) -> WithRawResponseTask +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.RemoveCreditBundleAsync("catalog_id", "credit_bundle_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+ +
+
+ +**creditBundleId:** `string` — credit_bundle_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.GetDerivedFeaturesAsync(catalogId) -> WithRawResponseTask<GetDerivedFeaturesResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.GetDerivedFeaturesAsync("catalog_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.GetPlansInCatalogAsync(catalogId) -> WithRawResponseTask<GetPlansInCatalogResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.GetPlansInCatalogAsync("catalog_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.AddPlanAsync(catalogId, planId) -> WithRawResponseTask +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.AddPlanAsync("catalog_id", "plan_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+ +
+
+ +**planId:** `string` — plan_id + +
+
+
+
+ + +
+
+
+ +
client.Catalogs.RemovePlanAsync(catalogId, planId) -> WithRawResponseTask +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Catalogs.RemovePlanAsync("catalog_id", "plan_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**catalogId:** `string` — catalog_id + +
+
+ +
+
+ +**planId:** `string` — plan_id + +
+
+
+
+ +
@@ -7805,6 +8427,54 @@ await client.Components.DeleteComponentAsync("component_id"); + + + + +
client.Components.BindCatalogAsync(componentId, BindCatalogRequestBody { ... }) -> WithRawResponseTask<BindCatalogResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Components.BindCatalogAsync("component_id", new BindCatalogRequestBody()); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**componentId:** `string` — component_id + +
+
+ +
+
+ +**request:** `BindCatalogRequestBody` + +
+
+
+
+ +
@@ -8053,6 +8723,54 @@ await client.Planbundle.UpdatePlanBundleAsync( ## dataexports +
client.Dataexports.ListDataExportsAsync(ListDataExportsRequest { ... }) -> WithRawResponseTask<ListDataExportsResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Dataexports.ListDataExportsAsync( + new ListDataExportsRequest + { + ExportType = DataExportType.AuditLog, + Status = DataExportStatus.Failure, + Limit = 1000000, + Offset = 1000000, + } +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**request:** `ListDataExportsRequest` + +
+
+
+
+ + +
+
+
+
client.Dataexports.CreateDataExportAsync(CreateDataExportRequestBody { ... }) -> WithRawResponseTask<CreateDataExportResponse>
@@ -8069,9 +8787,8 @@ await client.Planbundle.UpdatePlanBundleAsync( await client.Dataexports.CreateDataExportAsync( new CreateDataExportRequestBody { - ExportType = "company-feature-usage", - Metadata = "metadata", - OutputFileType = "csv", + ExportType = DataExportType.AuditLog, + OutputFileType = DataExportOutputFileType.Csv, } ); ``` @@ -8096,6 +8813,46 @@ await client.Dataexports.CreateDataExportAsync(
+ + +
+ +
client.Dataexports.GetDataExportAsync(dataExportId) -> WithRawResponseTask<GetDataExportResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Dataexports.GetDataExportAsync("data_export_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**dataExportId:** `string` — data_export_id + +
+
+
+
+ +
diff --git a/src/SchematicHQ.Client/Catalogs/CatalogsClient.cs b/src/SchematicHQ.Client/Catalogs/CatalogsClient.cs new file mode 100644 index 00000000..1f0c35f4 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/CatalogsClient.cs @@ -0,0 +1,2241 @@ +using global::System.Text.Json; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +public partial class CatalogsClient : ICatalogsClient +{ + private readonly RawClient _client; + + internal CatalogsClient(RawClient client) + { + _client = client; + } + + private async Task> ListCatalogsAsyncCore( + ListCatalogsRequest request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 4) + .Add("is_default", request.IsDefault) + .Add("q", request.Q) + .Add("limit", request.Limit) + .Add("offset", request.Offset) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Get, + Path = "catalogs", + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task> CreateCatalogAsyncCore( + CreateCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Post, + Path = "catalogs", + Body = request, + QueryString = _queryString, + Headers = _headers, + ContentType = "application/json", + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task> GetCatalogAsyncCore( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Get, + Path = string.Format( + "catalogs/{0}", + ValueConvert.ToPathParameterString(catalogId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task> UpdateCatalogAsyncCore( + string catalogId, + UpdateCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Put, + Path = string.Format( + "catalogs/{0}", + ValueConvert.ToPathParameterString(catalogId) + ), + Body = request, + QueryString = _queryString, + Headers = _headers, + ContentType = "application/json", + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task> DeleteCatalogAsyncCore( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Delete, + Path = string.Format( + "catalogs/{0}", + ValueConvert.ToPathParameterString(catalogId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task> GetConfigurationAsyncCore( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Get, + Path = string.Format( + "catalogs/{0}/configuration", + ValueConvert.ToPathParameterString(catalogId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task> UpdateConfigurationAsyncCore( + string catalogId, + UpdateCatalogConfigurationRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Put, + Path = string.Format( + "catalogs/{0}/configuration", + ValueConvert.ToPathParameterString(catalogId) + ), + Body = request, + QueryString = _queryString, + Headers = _headers, + ContentType = "application/json", + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize( + responseBody + )!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task< + WithRawResponse + > GetCreditBundlesInCatalogAsyncCore( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Get, + Path = string.Format( + "catalogs/{0}/credit-bundles", + ValueConvert.ToPathParameterString(catalogId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize( + responseBody + )!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task AddCreditBundleAsyncCore( + string catalogId, + string creditBundleId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Post, + Path = string.Format( + "catalogs/{0}/credit-bundles/{1}", + ValueConvert.ToPathParameterString(catalogId), + ValueConvert.ToPathParameterString(creditBundleId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + return new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }; + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task RemoveCreditBundleAsyncCore( + string catalogId, + string creditBundleId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Delete, + Path = string.Format( + "catalogs/{0}/credit-bundles/{1}", + ValueConvert.ToPathParameterString(catalogId), + ValueConvert.ToPathParameterString(creditBundleId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + return new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }; + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task> GetDerivedFeaturesAsyncCore( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Get, + Path = string.Format( + "catalogs/{0}/features", + ValueConvert.ToPathParameterString(catalogId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task> GetPlansInCatalogAsyncCore( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Get, + Path = string.Format( + "catalogs/{0}/plans", + ValueConvert.ToPathParameterString(catalogId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task AddPlanAsyncCore( + string catalogId, + string planId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Post, + Path = string.Format( + "catalogs/{0}/plans/{1}", + ValueConvert.ToPathParameterString(catalogId), + ValueConvert.ToPathParameterString(planId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + return new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }; + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + private async Task RemovePlanAsyncCore( + string catalogId, + string planId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Delete, + Path = string.Format( + "catalogs/{0}/plans/{1}", + ValueConvert.ToPathParameterString(catalogId), + ValueConvert.ToPathParameterString(planId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + return new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }; + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + + /// + /// await client.Catalogs.ListCatalogsAsync( + /// new ListCatalogsRequest + /// { + /// IsDefault = true, + /// Q = "q", + /// Limit = 1000000, + /// Offset = 1000000, + /// } + /// ); + /// + public WithRawResponseTask ListCatalogsAsync( + ListCatalogsRequest request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + ListCatalogsAsyncCore(request, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.CreateCatalogAsync( + /// new CreateCatalogRequestBody { IsDefault = true, Name = "name" } + /// ); + /// + public WithRawResponseTask CreateCatalogAsync( + CreateCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + CreateCatalogAsyncCore(request, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.GetCatalogAsync("catalog_id"); + /// + public WithRawResponseTask GetCatalogAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + GetCatalogAsyncCore(catalogId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.UpdateCatalogAsync("catalog_id", new UpdateCatalogRequestBody()); + /// + public WithRawResponseTask UpdateCatalogAsync( + string catalogId, + UpdateCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + UpdateCatalogAsyncCore(catalogId, request, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.DeleteCatalogAsync("catalog_id"); + /// + public WithRawResponseTask DeleteCatalogAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + DeleteCatalogAsyncCore(catalogId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.GetConfigurationAsync("catalog_id"); + /// + public WithRawResponseTask GetConfigurationAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + GetConfigurationAsyncCore(catalogId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.UpdateConfigurationAsync( + /// "catalog_id", + /// new UpdateCatalogConfigurationRequestBody() + /// ); + /// + public WithRawResponseTask UpdateConfigurationAsync( + string catalogId, + UpdateCatalogConfigurationRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + UpdateConfigurationAsyncCore(catalogId, request, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.GetCreditBundlesInCatalogAsync("catalog_id"); + /// + public WithRawResponseTask GetCreditBundlesInCatalogAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + GetCreditBundlesInCatalogAsyncCore(catalogId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.AddCreditBundleAsync("catalog_id", "credit_bundle_id"); + /// + public WithRawResponseTask AddCreditBundleAsync( + string catalogId, + string creditBundleId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + AddCreditBundleAsyncCore(catalogId, creditBundleId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.RemoveCreditBundleAsync("catalog_id", "credit_bundle_id"); + /// + public WithRawResponseTask RemoveCreditBundleAsync( + string catalogId, + string creditBundleId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + RemoveCreditBundleAsyncCore(catalogId, creditBundleId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.GetDerivedFeaturesAsync("catalog_id"); + /// + public WithRawResponseTask GetDerivedFeaturesAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + GetDerivedFeaturesAsyncCore(catalogId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.GetPlansInCatalogAsync("catalog_id"); + /// + public WithRawResponseTask GetPlansInCatalogAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + GetPlansInCatalogAsyncCore(catalogId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.AddPlanAsync("catalog_id", "plan_id"); + /// + public WithRawResponseTask AddPlanAsync( + string catalogId, + string planId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + AddPlanAsyncCore(catalogId, planId, options, cancellationToken) + ); + } + + /// + /// await client.Catalogs.RemovePlanAsync("catalog_id", "plan_id"); + /// + public WithRawResponseTask RemovePlanAsync( + string catalogId, + string planId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + RemovePlanAsyncCore(catalogId, planId, options, cancellationToken) + ); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/ICatalogsClient.cs b/src/SchematicHQ.Client/Catalogs/ICatalogsClient.cs new file mode 100644 index 00000000..8f156553 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/ICatalogsClient.cs @@ -0,0 +1,94 @@ +namespace SchematicHQ.Client; + +public partial interface ICatalogsClient +{ + WithRawResponseTask ListCatalogsAsync( + ListCatalogsRequest request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask CreateCatalogAsync( + CreateCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask GetCatalogAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask UpdateCatalogAsync( + string catalogId, + UpdateCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask DeleteCatalogAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask GetConfigurationAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask UpdateConfigurationAsync( + string catalogId, + UpdateCatalogConfigurationRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask GetCreditBundlesInCatalogAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask AddCreditBundleAsync( + string catalogId, + string creditBundleId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask RemoveCreditBundleAsync( + string catalogId, + string creditBundleId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask GetDerivedFeaturesAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask GetPlansInCatalogAsync( + string catalogId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask AddPlanAsync( + string catalogId, + string planId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask RemovePlanAsync( + string catalogId, + string planId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); +} diff --git a/src/SchematicHQ.Client/Catalogs/Requests/CreateCatalogRequestBody.cs b/src/SchematicHQ.Client/Catalogs/Requests/CreateCatalogRequestBody.cs new file mode 100644 index 00000000..0a2e3a7c --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Requests/CreateCatalogRequestBody.cs @@ -0,0 +1,23 @@ +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CreateCatalogRequestBody +{ + [JsonPropertyName("description")] + public string? Description { get; set; } + + [JsonPropertyName("is_default")] + public required bool IsDefault { get; set; } + + [JsonPropertyName("name")] + public required string Name { get; set; } + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Requests/ListCatalogsRequest.cs b/src/SchematicHQ.Client/Catalogs/Requests/ListCatalogsRequest.cs new file mode 100644 index 00000000..e69f37ea --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Requests/ListCatalogsRequest.cs @@ -0,0 +1,35 @@ +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record ListCatalogsRequest +{ + [JsonIgnore] + public bool? IsDefault { get; set; } + + /// + /// Search by catalog name + /// + [JsonIgnore] + public string? Q { get; set; } + + /// + /// Page limit (default 100) + /// + [JsonIgnore] + public long? Limit { get; set; } + + /// + /// Page offset (default 0) + /// + [JsonIgnore] + public long? Offset { get; set; } + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Requests/UpdateCatalogConfigurationRequestBody.cs b/src/SchematicHQ.Client/Catalogs/Requests/UpdateCatalogConfigurationRequestBody.cs new file mode 100644 index 00000000..d64ff0a4 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Requests/UpdateCatalogConfigurationRequestBody.cs @@ -0,0 +1,41 @@ +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record UpdateCatalogConfigurationRequestBody +{ + [JsonPropertyName("custom_plan_cta_text")] + public string? CustomPlanCtaText { get; set; } + + [JsonPropertyName("custom_plan_cta_url")] + public string? CustomPlanCtaUrl { get; set; } + + [JsonPropertyName("custom_plan_price_text")] + public string? CustomPlanPriceText { get; set; } + + [JsonPropertyName("custom_plans_visible")] + public bool? CustomPlansVisible { get; set; } + + [JsonPropertyName("ordered_add_ons")] + public IEnumerable? OrderedAddOns { get; set; } + + [JsonPropertyName("ordered_bundles")] + public IEnumerable? OrderedBundles { get; set; } + + [JsonPropertyName("ordered_plans")] + public IEnumerable? OrderedPlans { get; set; } + + [JsonPropertyName("pricing_model")] + public string? PricingModel { get; set; } + + [JsonPropertyName("pricing_url")] + public string? PricingUrl { get; set; } + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Requests/UpdateCatalogRequestBody.cs b/src/SchematicHQ.Client/Catalogs/Requests/UpdateCatalogRequestBody.cs new file mode 100644 index 00000000..6be33c40 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Requests/UpdateCatalogRequestBody.cs @@ -0,0 +1,23 @@ +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record UpdateCatalogRequestBody +{ + [JsonPropertyName("description")] + public string? Description { get; set; } + + [JsonPropertyName("is_default")] + public bool? IsDefault { get; set; } + + [JsonPropertyName("name")] + public string? Name { get; set; } + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/CreateCatalogResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/CreateCatalogResponse.cs new file mode 100644 index 00000000..cb1a9a66 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/CreateCatalogResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CreateCatalogResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CatalogResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/DeleteCatalogResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/DeleteCatalogResponse.cs new file mode 100644 index 00000000..2acf9100 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/DeleteCatalogResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record DeleteCatalogResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required DeleteResponse Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/GetCatalogResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/GetCatalogResponse.cs new file mode 100644 index 00000000..12a074c4 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/GetCatalogResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record GetCatalogResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CatalogResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/GetConfigurationResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/GetConfigurationResponse.cs new file mode 100644 index 00000000..c1c1558d --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/GetConfigurationResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record GetConfigurationResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CatalogConfigurationResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/GetCreditBundlesInCatalogResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/GetCreditBundlesInCatalogResponse.cs new file mode 100644 index 00000000..006043a8 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/GetCreditBundlesInCatalogResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record GetCreditBundlesInCatalogResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CatalogCreditBundleIDsResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/GetDerivedFeaturesResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/GetDerivedFeaturesResponse.cs new file mode 100644 index 00000000..fa04b083 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/GetDerivedFeaturesResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record GetDerivedFeaturesResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CatalogDerivedFeaturesResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/GetPlansInCatalogResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/GetPlansInCatalogResponse.cs new file mode 100644 index 00000000..025a7d22 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/GetPlansInCatalogResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record GetPlansInCatalogResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CatalogPlanIDsResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/ListCatalogsParams.cs b/src/SchematicHQ.Client/Catalogs/Types/ListCatalogsParams.cs new file mode 100644 index 00000000..9d373558 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/ListCatalogsParams.cs @@ -0,0 +1,49 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +/// +/// Input parameters +/// +[Serializable] +public record ListCatalogsParams : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("is_default")] + public bool? IsDefault { get; set; } + + /// + /// Page limit (default 100) + /// + [JsonPropertyName("limit")] + public long? Limit { get; set; } + + /// + /// Page offset (default 0) + /// + [JsonPropertyName("offset")] + public long? Offset { get; set; } + + /// + /// Search by catalog name + /// + [JsonPropertyName("q")] + public string? Q { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/ListCatalogsResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/ListCatalogsResponse.cs new file mode 100644 index 00000000..9f8eed04 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/ListCatalogsResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record ListCatalogsResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public IEnumerable Data { get; set; } = new List(); + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public required ListCatalogsParams Params { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/UpdateCatalogResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/UpdateCatalogResponse.cs new file mode 100644 index 00000000..d6cd2caa --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/UpdateCatalogResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record UpdateCatalogResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CatalogResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Catalogs/Types/UpdateConfigurationResponse.cs b/src/SchematicHQ.Client/Catalogs/Types/UpdateConfigurationResponse.cs new file mode 100644 index 00000000..fdf76176 --- /dev/null +++ b/src/SchematicHQ.Client/Catalogs/Types/UpdateConfigurationResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record UpdateConfigurationResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CatalogResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Components/ComponentsClient.cs b/src/SchematicHQ.Client/Components/ComponentsClient.cs index 4b1403f6..73dea762 100644 --- a/src/SchematicHQ.Client/Components/ComponentsClient.cs +++ b/src/SchematicHQ.Client/Components/ComponentsClient.cs @@ -772,6 +772,163 @@ private async Task> DeleteComponentAsyn } } + private async Task> BindCatalogAsyncCore( + string componentId, + BindCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Put, + Path = string.Format( + "components/{0}/catalog", + ValueConvert.ToPathParameterString(componentId) + ), + Body = request, + QueryString = _queryString, + Headers = _headers, + ContentType = "application/json", + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + private async Task> CountComponentsAsyncCore( CountComponentsRequest request, RequestOptions? options = null, @@ -1149,6 +1306,21 @@ public WithRawResponseTask DeleteComponentAsync( ); } + /// + /// await client.Components.BindCatalogAsync("component_id", new BindCatalogRequestBody()); + /// + public WithRawResponseTask BindCatalogAsync( + string componentId, + BindCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + BindCatalogAsyncCore(componentId, request, options, cancellationToken) + ); + } + /// /// await client.Components.CountComponentsAsync( /// new CountComponentsRequest diff --git a/src/SchematicHQ.Client/Components/IComponentsClient.cs b/src/SchematicHQ.Client/Components/IComponentsClient.cs index ad1bded0..fff2f6db 100644 --- a/src/SchematicHQ.Client/Components/IComponentsClient.cs +++ b/src/SchematicHQ.Client/Components/IComponentsClient.cs @@ -33,6 +33,13 @@ WithRawResponseTask DeleteComponentAsync( CancellationToken cancellationToken = default ); + WithRawResponseTask BindCatalogAsync( + string componentId, + BindCatalogRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + WithRawResponseTask CountComponentsAsync( CountComponentsRequest request, RequestOptions? options = null, diff --git a/src/SchematicHQ.Client/Components/Requests/BindCatalogRequestBody.cs b/src/SchematicHQ.Client/Components/Requests/BindCatalogRequestBody.cs new file mode 100644 index 00000000..ea641ef8 --- /dev/null +++ b/src/SchematicHQ.Client/Components/Requests/BindCatalogRequestBody.cs @@ -0,0 +1,17 @@ +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record BindCatalogRequestBody +{ + [JsonPropertyName("catalog_id")] + public string? CatalogId { get; set; } + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Components/Types/BindCatalogResponse.cs b/src/SchematicHQ.Client/Components/Types/BindCatalogResponse.cs new file mode 100644 index 00000000..044287bb --- /dev/null +++ b/src/SchematicHQ.Client/Components/Types/BindCatalogResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record BindCatalogResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required ComponentResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Core/Public/Version.cs b/src/SchematicHQ.Client/Core/Public/Version.cs index 5e7eb8d5..1fb2f5c9 100644 --- a/src/SchematicHQ.Client/Core/Public/Version.cs +++ b/src/SchematicHQ.Client/Core/Public/Version.cs @@ -3,5 +3,5 @@ namespace SchematicHQ.Client; [Serializable] internal class Version { - public const string Current = "1.5.1"; + public const string Current = "1.5.2"; } diff --git a/src/SchematicHQ.Client/Dataexports/DataexportsClient.cs b/src/SchematicHQ.Client/Dataexports/DataexportsClient.cs index 547d53a4..e191e734 100644 --- a/src/SchematicHQ.Client/Dataexports/DataexportsClient.cs +++ b/src/SchematicHQ.Client/Dataexports/DataexportsClient.cs @@ -12,6 +12,161 @@ internal DataexportsClient(RawClient client) _client = client; } + private async Task> ListDataExportsAsyncCore( + ListDataExportsRequest request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 4) + .Add("export_type", request.ExportType) + .Add("status", request.Status) + .Add("limit", request.Limit) + .Add("offset", request.Offset) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Get, + Path = "data-exports", + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + private async Task> CreateDataExportAsyncCore( CreateDataExportRequestBody request, RequestOptions? options = null, @@ -165,6 +320,148 @@ private async Task> CreateDataExportAs } } + private async Task> GetDataExportAsyncCore( + string dataExportId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _queryString = new SchematicHQ.Client.Core.QueryStringBuilder.Builder(capacity: 0) + .MergeAdditional(options?.AdditionalQueryParameters) + .Build(); + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Get, + Path = string.Format( + "data-exports/{0}", + ValueConvert.ToPathParameterString(dataExportId) + ), + QueryString = _queryString, + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 401: + throw new UnauthorizedError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 403: + throw new ForbiddenError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 404: + throw new NotFoundError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody), + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = + response.Raw.RequestMessage?.RequestUri + ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody, + rawResponse: new SchematicHQ.Client.RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + } + ); + } + } + private async Task> GetDataExportArtifactAsyncCore( string dataExportId, RequestOptions? options = null, @@ -286,13 +583,34 @@ private async Task> CreateDataExportAs } } + /// + /// await client.Dataexports.ListDataExportsAsync( + /// new ListDataExportsRequest + /// { + /// ExportType = DataExportType.AuditLog, + /// Status = DataExportStatus.Failure, + /// Limit = 1000000, + /// Offset = 1000000, + /// } + /// ); + /// + public WithRawResponseTask ListDataExportsAsync( + ListDataExportsRequest request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + ListDataExportsAsyncCore(request, options, cancellationToken) + ); + } + /// /// await client.Dataexports.CreateDataExportAsync( /// new CreateDataExportRequestBody /// { - /// ExportType = "company-feature-usage", - /// Metadata = "metadata", - /// OutputFileType = "csv", + /// ExportType = DataExportType.AuditLog, + /// OutputFileType = DataExportOutputFileType.Csv, /// } /// ); /// @@ -307,6 +625,20 @@ public WithRawResponseTask CreateDataExportAsync( ); } + /// + /// await client.Dataexports.GetDataExportAsync("data_export_id"); + /// + public WithRawResponseTask GetDataExportAsync( + string dataExportId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + GetDataExportAsyncCore(dataExportId, options, cancellationToken) + ); + } + /// /// await client.Dataexports.GetDataExportArtifactAsync("data_export_id"); /// diff --git a/src/SchematicHQ.Client/Dataexports/IDataexportsClient.cs b/src/SchematicHQ.Client/Dataexports/IDataexportsClient.cs index 77880131..1ee3035d 100644 --- a/src/SchematicHQ.Client/Dataexports/IDataexportsClient.cs +++ b/src/SchematicHQ.Client/Dataexports/IDataexportsClient.cs @@ -2,12 +2,24 @@ namespace SchematicHQ.Client; public partial interface IDataexportsClient { + WithRawResponseTask ListDataExportsAsync( + ListDataExportsRequest request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + WithRawResponseTask CreateDataExportAsync( CreateDataExportRequestBody request, RequestOptions? options = null, CancellationToken cancellationToken = default ); + WithRawResponseTask GetDataExportAsync( + string dataExportId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + WithRawResponseTask GetDataExportArtifactAsync( string dataExportId, RequestOptions? options = null, diff --git a/src/SchematicHQ.Client/Dataexports/Requests/CreateDataExportRequestBody.cs b/src/SchematicHQ.Client/Dataexports/Requests/CreateDataExportRequestBody.cs index e827995b..9eff51aa 100644 --- a/src/SchematicHQ.Client/Dataexports/Requests/CreateDataExportRequestBody.cs +++ b/src/SchematicHQ.Client/Dataexports/Requests/CreateDataExportRequestBody.cs @@ -7,13 +7,13 @@ namespace SchematicHQ.Client; public record CreateDataExportRequestBody { [JsonPropertyName("export_type")] - public string ExportType { get; set; } = "company-feature-usage"; + public required DataExportType ExportType { get; set; } [JsonPropertyName("metadata")] - public required string Metadata { get; set; } + public DataExportMetadata? Metadata { get; set; } [JsonPropertyName("output_file_type")] - public string OutputFileType { get; set; } = "csv"; + public required DataExportOutputFileType OutputFileType { get; set; } /// public override string ToString() diff --git a/src/SchematicHQ.Client/Dataexports/Requests/ListDataExportsRequest.cs b/src/SchematicHQ.Client/Dataexports/Requests/ListDataExportsRequest.cs new file mode 100644 index 00000000..b3958bd9 --- /dev/null +++ b/src/SchematicHQ.Client/Dataexports/Requests/ListDataExportsRequest.cs @@ -0,0 +1,32 @@ +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record ListDataExportsRequest +{ + [JsonIgnore] + public DataExportType? ExportType { get; set; } + + [JsonIgnore] + public DataExportStatus? Status { get; set; } + + /// + /// Page limit (default 100) + /// + [JsonIgnore] + public long? Limit { get; set; } + + /// + /// Page offset (default 0) + /// + [JsonIgnore] + public long? Offset { get; set; } + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Dataexports/Types/GetDataExportResponse.cs b/src/SchematicHQ.Client/Dataexports/Types/GetDataExportResponse.cs new file mode 100644 index 00000000..37948755 --- /dev/null +++ b/src/SchematicHQ.Client/Dataexports/Types/GetDataExportResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record GetDataExportResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required DataExportResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Dataexports/Types/ListDataExportsParams.cs b/src/SchematicHQ.Client/Dataexports/Types/ListDataExportsParams.cs new file mode 100644 index 00000000..daed5514 --- /dev/null +++ b/src/SchematicHQ.Client/Dataexports/Types/ListDataExportsParams.cs @@ -0,0 +1,46 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +/// +/// Input parameters +/// +[Serializable] +public record ListDataExportsParams : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("export_type")] + public DataExportType? ExportType { get; set; } + + /// + /// Page limit (default 100) + /// + [JsonPropertyName("limit")] + public long? Limit { get; set; } + + /// + /// Page offset (default 0) + /// + [JsonPropertyName("offset")] + public long? Offset { get; set; } + + [JsonPropertyName("status")] + public DataExportStatus? Status { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Dataexports/Types/ListDataExportsResponse.cs b/src/SchematicHQ.Client/Dataexports/Types/ListDataExportsResponse.cs new file mode 100644 index 00000000..79033c97 --- /dev/null +++ b/src/SchematicHQ.Client/Dataexports/Types/ListDataExportsResponse.cs @@ -0,0 +1,35 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record ListDataExportsResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public IEnumerable Data { get; set; } = + new List(); + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public required ListDataExportsParams Params { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/ISchematicApi.cs b/src/SchematicHQ.Client/ISchematicApi.cs index 17490b4d..c7281e63 100644 --- a/src/SchematicHQ.Client/ISchematicApi.cs +++ b/src/SchematicHQ.Client/ISchematicApi.cs @@ -5,6 +5,7 @@ public partial interface ISchematicApi public IAccountsClient Accounts { get; } public IBillingClient Billing { get; } public ICreditsClient Credits { get; } + public ICatalogsClient Catalogs { get; } public ICheckoutClient Checkout { get; } public ICompaniesClient Companies { get; } public IEntitlementsClient Entitlements { get; } diff --git a/src/SchematicHQ.Client/Planbundle/Requests/CreateCustomPlanBundleRequestBody.cs b/src/SchematicHQ.Client/Planbundle/Requests/CreateCustomPlanBundleRequestBody.cs index fa11c65e..945ae3e1 100644 --- a/src/SchematicHQ.Client/Planbundle/Requests/CreateCustomPlanBundleRequestBody.cs +++ b/src/SchematicHQ.Client/Planbundle/Requests/CreateCustomPlanBundleRequestBody.cs @@ -9,6 +9,9 @@ public record CreateCustomPlanBundleRequestBody [JsonPropertyName("billing_product")] public UpsertBillingProductRequestBody? BillingProduct { get; set; } + [JsonPropertyName("credit_grants")] + public IEnumerable? CreditGrants { get; set; } + [JsonPropertyName("entitlements")] public IEnumerable Entitlements { get; set; } = new List(); diff --git a/src/SchematicHQ.Client/SchematicApi.cs b/src/SchematicHQ.Client/SchematicApi.cs index 90d7f109..fa3073a2 100644 --- a/src/SchematicHQ.Client/SchematicApi.cs +++ b/src/SchematicHQ.Client/SchematicApi.cs @@ -15,7 +15,7 @@ public SchematicApi(string? apiKey = null, ClientOptions? clientOptions = null) { "X-Fern-Language", "C#" }, { "X-Fern-SDK-Name", "SchematicHQ.Client" }, { "X-Fern-SDK-Version", Version.Current }, - { "User-Agent", "SchematicHQ.Client/1.5.1" }, + { "User-Agent", "SchematicHQ.Client/1.5.2" }, } ); foreach (var header in platformHeaders) @@ -37,6 +37,7 @@ public SchematicApi(string? apiKey = null, ClientOptions? clientOptions = null) Accounts = new AccountsClient(_client); Billing = new BillingClient(_client); Credits = new CreditsClient(_client); + Catalogs = new CatalogsClient(_client); Checkout = new CheckoutClient(_client); Companies = new CompaniesClient(_client); Entitlements = new EntitlementsClient(_client); @@ -62,6 +63,8 @@ public SchematicApi(string? apiKey = null, ClientOptions? clientOptions = null) public ICreditsClient Credits { get; } + public ICatalogsClient Catalogs { get; } + public ICheckoutClient Checkout { get; } public ICompaniesClient Companies { get; } diff --git a/src/SchematicHQ.Client/SchematicHQ.Client.csproj b/src/SchematicHQ.Client/SchematicHQ.Client.csproj index afa50c9a..e7d2f024 100644 --- a/src/SchematicHQ.Client/SchematicHQ.Client.csproj +++ b/src/SchematicHQ.Client/SchematicHQ.Client.csproj @@ -4,7 +4,7 @@ enable 12 enable - 1.5.1 + 1.5.2 $(Version) $(Version) README.md diff --git a/src/SchematicHQ.Client/Types/AuditLogExportMetadata.cs b/src/SchematicHQ.Client/Types/AuditLogExportMetadata.cs new file mode 100644 index 00000000..a9f42707 --- /dev/null +++ b/src/SchematicHQ.Client/Types/AuditLogExportMetadata.cs @@ -0,0 +1,55 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record AuditLogExportMetadata : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + /// + /// Restrict the export to audit log entries from this actor type + /// + [JsonPropertyName("actor_type")] + public string? ActorType { get; set; } + + /// + /// Restrict the export to audit log entries that started before this time + /// + [JsonPropertyName("end_time")] + public DateTime? EndTime { get; set; } + + /// + /// Account member emails to notify when the export completes; empty means the artifact is only retrievable via the API + /// + [JsonPropertyName("notification_email_recipient_email_addresses")] + public IEnumerable? NotificationEmailRecipientEmailAddresses { get; set; } + + /// + /// Free-text search over audit log entries + /// + [JsonPropertyName("q")] + public string? Q { get; set; } + + /// + /// Restrict the export to audit log entries that started at or after this time + /// + [JsonPropertyName("start_time")] + public DateTime? StartTime { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogConfigOrderedBundle.cs b/src/SchematicHQ.Client/Types/CatalogConfigOrderedBundle.cs new file mode 100644 index 00000000..fa6161cb --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogConfigOrderedBundle.cs @@ -0,0 +1,28 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogConfigOrderedBundle : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("bundle_id")] + public required string BundleId { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogConfigOrderedBundleResponseData.cs b/src/SchematicHQ.Client/Types/CatalogConfigOrderedBundleResponseData.cs new file mode 100644 index 00000000..6ee82ae1 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogConfigOrderedBundleResponseData.cs @@ -0,0 +1,28 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogConfigOrderedBundleResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("bundle_id")] + public required string BundleId { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogConfigOrderedEntitlement.cs b/src/SchematicHQ.Client/Types/CatalogConfigOrderedEntitlement.cs new file mode 100644 index 00000000..fcee1e65 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogConfigOrderedEntitlement.cs @@ -0,0 +1,31 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogConfigOrderedEntitlement : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("plan_entitlement_id")] + public required string PlanEntitlementId { get; set; } + + [JsonPropertyName("visible")] + public bool? Visible { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogConfigOrderedEntitlementResponseData.cs b/src/SchematicHQ.Client/Types/CatalogConfigOrderedEntitlementResponseData.cs new file mode 100644 index 00000000..79b4e949 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogConfigOrderedEntitlementResponseData.cs @@ -0,0 +1,31 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogConfigOrderedEntitlementResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("plan_entitlement_id")] + public required string PlanEntitlementId { get; set; } + + [JsonPropertyName("visible")] + public required bool Visible { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogConfigOrderedPlan.cs b/src/SchematicHQ.Client/Types/CatalogConfigOrderedPlan.cs new file mode 100644 index 00000000..7fd3eead --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogConfigOrderedPlan.cs @@ -0,0 +1,31 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogConfigOrderedPlan : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("entitlements")] + public IEnumerable? Entitlements { get; set; } + + [JsonPropertyName("plan_id")] + public required string PlanId { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogConfigOrderedPlanResponseData.cs b/src/SchematicHQ.Client/Types/CatalogConfigOrderedPlanResponseData.cs new file mode 100644 index 00000000..a3e5cdf4 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogConfigOrderedPlanResponseData.cs @@ -0,0 +1,32 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogConfigOrderedPlanResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("entitlements")] + public IEnumerable Entitlements { get; set; } = + new List(); + + [JsonPropertyName("plan_id")] + public required string PlanId { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogConfigurationResponseData.cs b/src/SchematicHQ.Client/Types/CatalogConfigurationResponseData.cs new file mode 100644 index 00000000..35c1aa83 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogConfigurationResponseData.cs @@ -0,0 +1,63 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogConfigurationResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("add_ons")] + public IEnumerable AddOns { get; set; } = + new List(); + + [JsonPropertyName("custom_plan_cta_text")] + public string? CustomPlanCtaText { get; set; } + + [JsonPropertyName("custom_plan_cta_url")] + public string? CustomPlanCtaUrl { get; set; } + + [JsonPropertyName("custom_plan_price_text")] + public string? CustomPlanPriceText { get; set; } + + [JsonPropertyName("custom_plans_visible")] + public required bool CustomPlansVisible { get; set; } + + [JsonPropertyName("ordered_add_ons")] + public IEnumerable OrderedAddOns { get; set; } = + new List(); + + [JsonPropertyName("ordered_bundles")] + public IEnumerable OrderedBundles { get; set; } = + new List(); + + [JsonPropertyName("ordered_plans")] + public IEnumerable OrderedPlans { get; set; } = + new List(); + + [JsonPropertyName("plans")] + public IEnumerable Plans { get; set; } = + new List(); + + [JsonPropertyName("pricing_model")] + public string? PricingModel { get; set; } + + [JsonPropertyName("pricing_url")] + public string? PricingUrl { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogCreditBundleIDsResponseData.cs b/src/SchematicHQ.Client/Types/CatalogCreditBundleIDsResponseData.cs new file mode 100644 index 00000000..cc9559c5 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogCreditBundleIDsResponseData.cs @@ -0,0 +1,28 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogCreditBundleIDsResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("credit_bundle_ids")] + public IEnumerable CreditBundleIds { get; set; } = new List(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogDerivedFeatureResponseData.cs b/src/SchematicHQ.Client/Types/CatalogDerivedFeatureResponseData.cs new file mode 100644 index 00000000..de397ea0 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogDerivedFeatureResponseData.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogDerivedFeatureResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("icon")] + public required string Icon { get; set; } + + [JsonPropertyName("id")] + public required string Id { get; set; } + + [JsonPropertyName("name")] + public required string Name { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogDerivedFeaturesResponseData.cs b/src/SchematicHQ.Client/Types/CatalogDerivedFeaturesResponseData.cs new file mode 100644 index 00000000..ca552102 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogDerivedFeaturesResponseData.cs @@ -0,0 +1,29 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogDerivedFeaturesResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("features")] + public IEnumerable Features { get; set; } = + new List(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogPlanIDsResponseData.cs b/src/SchematicHQ.Client/Types/CatalogPlanIDsResponseData.cs new file mode 100644 index 00000000..adfe3a93 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogPlanIDsResponseData.cs @@ -0,0 +1,28 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogPlanIDsResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("plan_ids")] + public IEnumerable PlanIds { get; set; } = new List(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CatalogResponseData.cs b/src/SchematicHQ.Client/Types/CatalogResponseData.cs new file mode 100644 index 00000000..09f01d13 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CatalogResponseData.cs @@ -0,0 +1,67 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CatalogResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("account_id")] + public required string AccountId { get; set; } + + [JsonPropertyName("created_at")] + public required DateTime CreatedAt { get; set; } + + [JsonPropertyName("custom_plan_cta_text")] + public string? CustomPlanCtaText { get; set; } + + [JsonPropertyName("custom_plan_cta_url")] + public string? CustomPlanCtaUrl { get; set; } + + [JsonPropertyName("custom_plan_price_text")] + public string? CustomPlanPriceText { get; set; } + + [JsonPropertyName("custom_plans_visible")] + public required bool CustomPlansVisible { get; set; } + + [JsonPropertyName("description")] + public string? Description { get; set; } + + [JsonPropertyName("environment_id")] + public required string EnvironmentId { get; set; } + + [JsonPropertyName("id")] + public required string Id { get; set; } + + [JsonPropertyName("is_default")] + public required bool IsDefault { get; set; } + + [JsonPropertyName("name")] + public required string Name { get; set; } + + [JsonPropertyName("pricing_model")] + public string? PricingModel { get; set; } + + [JsonPropertyName("pricing_url")] + public string? PricingUrl { get; set; } + + [JsonPropertyName("updated_at")] + public required DateTime UpdatedAt { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CompanyFeatureUsageExportMetadata.cs b/src/SchematicHQ.Client/Types/CompanyFeatureUsageExportMetadata.cs new file mode 100644 index 00000000..8c6b77d0 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CompanyFeatureUsageExportMetadata.cs @@ -0,0 +1,127 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CompanyFeatureUsageExportMetadata : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + /// + /// Restrict the export to these Schematic company IDs (starting with 'comp_') + /// + [JsonPropertyName("company_ids")] + public IEnumerable? CompanyIds { get; set; } + + /// + /// Restrict the export to companies with these billing credit type IDs + /// + [JsonPropertyName("credit_type_ids")] + public IEnumerable? CreditTypeIds { get; set; } + + /// + /// Schematic feature IDs (starting with 'feat_') to include as usage columns; at least one is required + /// + [JsonPropertyName("feature_ids")] + public IEnumerable FeatureIds { get; set; } = new List(); + + /// + /// Restrict the export to companies that do (or do not) have a scheduled downgrade + /// + [JsonPropertyName("has_scheduled_downgrade")] + public bool? HasScheduledDowngrade { get; set; } + + /// + /// Restrict the export to companies with (or without) a monetized subscription + /// + [JsonPropertyName("monetized_subscriptions")] + public bool? MonetizedSubscriptions { get; set; } + + /// + /// Account member emails to notify when the export completes; empty means the artifact is only retrievable via the API + /// + [JsonPropertyName("notification_email_recipient_email_addresses")] + public IEnumerable? NotificationEmailRecipientEmailAddresses { get; set; } + + /// + /// Restrict the export to companies on this plan ID (starting with 'plan_') + /// + [JsonPropertyName("plan_id")] + public string? PlanId { get; set; } + + /// + /// Restrict the export to companies on any of these plan IDs + /// + [JsonPropertyName("plan_ids")] + public IEnumerable? PlanIds { get; set; } + + /// + /// Restrict the export to companies on this plan version ID + /// + [JsonPropertyName("plan_version_id")] + public string? PlanVersionId { get; set; } + + /// + /// Free-text search over company name and keys + /// + [JsonPropertyName("q")] + public string? Q { get; set; } + + /// + /// Restrict the export to companies whose subscription has one of these statuses + /// + [JsonPropertyName("subscription_statuses")] + public IEnumerable? SubscriptionStatuses { get; set; } + + /// + /// Restrict the export to companies whose subscription has one of these types + /// + [JsonPropertyName("subscription_types")] + public IEnumerable? SubscriptionTypes { get; set; } + + /// + /// Restrict the export to companies that have an entitlement for this feature ID + /// + [JsonPropertyName("with_entitlement_for")] + public string? WithEntitlementFor { get; set; } + + /// + /// Restrict the export to companies with a subscription + /// + [JsonPropertyName("with_subscription")] + public bool? WithSubscription { get; set; } + + /// + /// Restrict the export to companies without a company-level override for this feature ID + /// + [JsonPropertyName("without_feature_override_for")] + public string? WithoutFeatureOverrideFor { get; set; } + + /// + /// Restrict the export to companies without a plan + /// + [JsonPropertyName("without_plan")] + public bool? WithoutPlan { get; set; } + + /// + /// Restrict the export to companies without a subscription + /// + [JsonPropertyName("without_subscription")] + public bool? WithoutSubscription { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/CompanyPlanDetailResponseData.cs b/src/SchematicHQ.Client/Types/CompanyPlanDetailResponseData.cs index 5de0b47a..42be92e6 100644 --- a/src/SchematicHQ.Client/Types/CompanyPlanDetailResponseData.cs +++ b/src/SchematicHQ.Client/Types/CompanyPlanDetailResponseData.cs @@ -30,6 +30,9 @@ public record CompanyPlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("billing_strategy")] public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("catalogs")] + public IEnumerable? Catalogs { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } diff --git a/src/SchematicHQ.Client/Types/ComponentResponseData.cs b/src/SchematicHQ.Client/Types/ComponentResponseData.cs index a5c7965a..99a59a45 100644 --- a/src/SchematicHQ.Client/Types/ComponentResponseData.cs +++ b/src/SchematicHQ.Client/Types/ComponentResponseData.cs @@ -14,6 +14,9 @@ public record ComponentResponseData : IJsonOnDeserialized [JsonPropertyName("ast")] public Dictionary? Ast { get; set; } + [JsonPropertyName("catalog_id")] + public string? CatalogId { get; set; } + [JsonPropertyName("created_at")] public required DateTime CreatedAt { get; set; } diff --git a/src/SchematicHQ.Client/Types/DataExportMetadata.cs b/src/SchematicHQ.Client/Types/DataExportMetadata.cs new file mode 100644 index 00000000..bfb7404b --- /dev/null +++ b/src/SchematicHQ.Client/Types/DataExportMetadata.cs @@ -0,0 +1,293 @@ +// ReSharper disable NullableWarningSuppressionIsUsed +// ReSharper disable InconsistentNaming + +using global::System.Text.Json; +using global::System.Text.Json.Nodes; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[JsonConverter(typeof(DataExportMetadata.JsonConverter))] +[Serializable] +public record DataExportMetadata +{ + internal DataExportMetadata(string type, object? value) + { + ExportType = type; + Value = value; + } + + /// + /// Create an instance of DataExportMetadata with . + /// + public DataExportMetadata(DataExportMetadata.AuditLog value) + { + ExportType = "audit-log"; + Value = value.Value; + } + + /// + /// Create an instance of DataExportMetadata with . + /// + public DataExportMetadata(DataExportMetadata.CompanyFeatureUsage value) + { + ExportType = "company-feature-usage"; + Value = value.Value; + } + + /// + /// Discriminant value + /// + [JsonPropertyName("export_type")] + public string ExportType { get; internal set; } + + /// + /// Discriminated union value + /// + public object? Value { get; internal set; } + + /// + /// Returns true if is "audit-log" + /// + public bool IsAuditLog => ExportType == "audit-log"; + + /// + /// Returns true if is "company-feature-usage" + /// + public bool IsCompanyFeatureUsage => ExportType == "company-feature-usage"; + + /// + /// Returns the value as a if is 'audit-log', otherwise throws an exception. + /// + /// Thrown when is not 'audit-log'. + public SchematicHQ.Client.AuditLogExportMetadata AsAuditLog() => + IsAuditLog + ? (SchematicHQ.Client.AuditLogExportMetadata)Value! + : throw new global::System.Exception( + "DataExportMetadata.ExportType is not 'audit-log'" + ); + + /// + /// Returns the value as a if is 'company-feature-usage', otherwise throws an exception. + /// + /// Thrown when is not 'company-feature-usage'. + public SchematicHQ.Client.CompanyFeatureUsageExportMetadata AsCompanyFeatureUsage() => + IsCompanyFeatureUsage + ? (SchematicHQ.Client.CompanyFeatureUsageExportMetadata)Value! + : throw new global::System.Exception( + "DataExportMetadata.ExportType is not 'company-feature-usage'" + ); + + public T Match( + Func onAuditLog, + Func onCompanyFeatureUsage, + Func onUnknown_ + ) + { + return ExportType switch + { + "audit-log" => onAuditLog(AsAuditLog()), + "company-feature-usage" => onCompanyFeatureUsage(AsCompanyFeatureUsage()), + _ => onUnknown_(ExportType, Value), + }; + } + + public void Visit( + Action onAuditLog, + Action onCompanyFeatureUsage, + Action onUnknown_ + ) + { + switch (ExportType) + { + case "audit-log": + onAuditLog(AsAuditLog()); + break; + case "company-feature-usage": + onCompanyFeatureUsage(AsCompanyFeatureUsage()); + break; + default: + onUnknown_(ExportType, Value); + break; + } + } + + /// + /// Attempts to cast the value to a and returns true if successful. + /// + public bool TryAsAuditLog(out SchematicHQ.Client.AuditLogExportMetadata? value) + { + if (ExportType == "audit-log") + { + value = (SchematicHQ.Client.AuditLogExportMetadata)Value!; + return true; + } + value = null; + return false; + } + + /// + /// Attempts to cast the value to a and returns true if successful. + /// + public bool TryAsCompanyFeatureUsage( + out SchematicHQ.Client.CompanyFeatureUsageExportMetadata? value + ) + { + if (ExportType == "company-feature-usage") + { + value = (SchematicHQ.Client.CompanyFeatureUsageExportMetadata)Value!; + return true; + } + value = null; + return false; + } + + public override string ToString() => JsonUtils.Serialize(this); + + public static implicit operator DataExportMetadata(DataExportMetadata.AuditLog value) => + new(value); + + public static implicit operator DataExportMetadata( + DataExportMetadata.CompanyFeatureUsage value + ) => new(value); + + [Serializable] + internal sealed class JsonConverter : JsonConverter + { + public override bool CanConvert(global::System.Type typeToConvert) => + typeof(DataExportMetadata).IsAssignableFrom(typeToConvert); + + public override DataExportMetadata Read( + ref Utf8JsonReader reader, + global::System.Type typeToConvert, + JsonSerializerOptions options + ) + { + var json = JsonElement.ParseValue(ref reader); + if (!json.TryGetProperty("export_type", out var discriminatorElement)) + { + throw new JsonException("Missing discriminator property 'export_type'"); + } + if (discriminatorElement.ValueKind != JsonValueKind.String) + { + if (discriminatorElement.ValueKind == JsonValueKind.Null) + { + throw new JsonException("Discriminator property 'export_type' is null"); + } + + throw new JsonException( + $"Discriminator property 'export_type' is not a string, instead is {discriminatorElement.ToString()}" + ); + } + + var discriminator = + discriminatorElement.GetString() + ?? throw new JsonException("Discriminator property 'export_type' is null"); + + // Strip the discriminant property to prevent it from leaking into AdditionalProperties + var jsonObject = System.Text.Json.Nodes.JsonObject.Create(json); + jsonObject?.Remove("export_type"); + var jsonWithoutDiscriminator = + jsonObject != null ? JsonSerializer.SerializeToElement(jsonObject, options) : json; + + var value = discriminator switch + { + "audit-log" => + jsonWithoutDiscriminator.Deserialize( + options + ) + ?? throw new JsonException( + "Failed to deserialize SchematicHQ.Client.AuditLogExportMetadata" + ), + "company-feature-usage" => + jsonWithoutDiscriminator.Deserialize( + options + ) + ?? throw new JsonException( + "Failed to deserialize SchematicHQ.Client.CompanyFeatureUsageExportMetadata" + ), + _ => json.Deserialize(options), + }; + return new DataExportMetadata(discriminator, value); + } + + public override void Write( + Utf8JsonWriter writer, + DataExportMetadata value, + JsonSerializerOptions options + ) + { + JsonNode json = + value.ExportType switch + { + "audit-log" => JsonSerializer.SerializeToNode(value.Value, options), + "company-feature-usage" => JsonSerializer.SerializeToNode(value.Value, options), + _ => JsonSerializer.SerializeToNode(value.Value, options), + } ?? new JsonObject(); + json["export_type"] = value.ExportType; + json.WriteTo(writer, options); + } + + public override DataExportMetadata ReadAsPropertyName( + ref Utf8JsonReader reader, + global::System.Type typeToConvert, + JsonSerializerOptions options + ) + { + var stringValue = + reader.GetString() + ?? throw new JsonException("The JSON property name could not be read as a string."); + return new DataExportMetadata(stringValue, stringValue); + } + + public override void WriteAsPropertyName( + Utf8JsonWriter writer, + DataExportMetadata value, + JsonSerializerOptions options + ) + { + writer.WritePropertyName(value.ExportType); + } + } + + /// + /// Discriminated union type for audit-log + /// + [Serializable] + public struct AuditLog + { + public AuditLog(SchematicHQ.Client.AuditLogExportMetadata value) + { + Value = value; + } + + internal SchematicHQ.Client.AuditLogExportMetadata Value { get; set; } + + public override string ToString() => Value.ToString() ?? "null"; + + public static implicit operator DataExportMetadata.AuditLog( + SchematicHQ.Client.AuditLogExportMetadata value + ) => new(value); + } + + /// + /// Discriminated union type for company-feature-usage + /// + [Serializable] + public struct CompanyFeatureUsage + { + public CompanyFeatureUsage(SchematicHQ.Client.CompanyFeatureUsageExportMetadata value) + { + Value = value; + } + + internal SchematicHQ.Client.CompanyFeatureUsageExportMetadata Value { get; set; } + + public override string ToString() => Value.ToString() ?? "null"; + + public static implicit operator DataExportMetadata.CompanyFeatureUsage( + SchematicHQ.Client.CompanyFeatureUsageExportMetadata value + ) => new(value); + } +} diff --git a/src/SchematicHQ.Client/Types/DataExportOutputFileType.cs b/src/SchematicHQ.Client/Types/DataExportOutputFileType.cs new file mode 100644 index 00000000..c245fabb --- /dev/null +++ b/src/SchematicHQ.Client/Types/DataExportOutputFileType.cs @@ -0,0 +1,115 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[JsonConverter(typeof(DataExportOutputFileType.DataExportOutputFileTypeSerializer))] +[Serializable] +public readonly record struct DataExportOutputFileType : IStringEnum +{ + public static readonly DataExportOutputFileType Csv = new(Values.Csv); + + public static readonly DataExportOutputFileType CsvGz = new(Values.CsvGz); + + public DataExportOutputFileType(string value) + { + Value = value; + } + + /// + /// The string value of the enum. + /// + public string Value { get; } + + /// + /// Create a string enum with the given value. + /// + public static DataExportOutputFileType FromCustom(string value) + { + return new DataExportOutputFileType(value); + } + + public bool Equals(string? other) + { + return Value.Equals(other); + } + + /// + /// Returns the string value of the enum. + /// + public override string ToString() + { + return Value; + } + + public static bool operator ==(DataExportOutputFileType value1, string value2) => + value1.Value.Equals(value2); + + public static bool operator !=(DataExportOutputFileType value1, string value2) => + !value1.Value.Equals(value2); + + public static explicit operator string(DataExportOutputFileType value) => value.Value; + + public static explicit operator DataExportOutputFileType(string value) => new(value); + + internal class DataExportOutputFileTypeSerializer : JsonConverter + { + public override DataExportOutputFileType Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + var stringValue = + reader.GetString() + ?? throw new global::System.Exception( + "The JSON value could not be read as a string." + ); + return new DataExportOutputFileType(stringValue); + } + + public override void Write( + Utf8JsonWriter writer, + DataExportOutputFileType value, + JsonSerializerOptions options + ) + { + writer.WriteStringValue(value.Value); + } + + public override DataExportOutputFileType ReadAsPropertyName( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + var stringValue = + reader.GetString() + ?? throw new global::System.Exception( + "The JSON property name could not be read as a string." + ); + return new DataExportOutputFileType(stringValue); + } + + public override void WriteAsPropertyName( + Utf8JsonWriter writer, + DataExportOutputFileType value, + JsonSerializerOptions options + ) + { + writer.WritePropertyName(value.Value); + } + } + + /// + /// Constant strings for enum values + /// + [Serializable] + public static class Values + { + public const string Csv = "csv"; + + public const string CsvGz = "csv.gz"; + } +} diff --git a/src/SchematicHQ.Client/Types/DataExportResponseData.cs b/src/SchematicHQ.Client/Types/DataExportResponseData.cs index c372bc2f..6602f449 100644 --- a/src/SchematicHQ.Client/Types/DataExportResponseData.cs +++ b/src/SchematicHQ.Client/Types/DataExportResponseData.cs @@ -21,16 +21,16 @@ public record DataExportResponseData : IJsonOnDeserialized public required string EnvironmentId { get; set; } [JsonPropertyName("export_type")] - public string ExportType { get; set; } = "company-feature-usage"; + public required DataExportType ExportType { get; set; } [JsonPropertyName("id")] public required string Id { get; set; } [JsonPropertyName("metadata")] - public required string Metadata { get; set; } + public DataExportMetadata? Metadata { get; set; } [JsonPropertyName("output_file_type")] - public string OutputFileType { get; set; } = "csv"; + public required DataExportOutputFileType OutputFileType { get; set; } [JsonPropertyName("status")] public required DataExportStatus Status { get; set; } diff --git a/src/SchematicHQ.Client/Types/DataExportType.cs b/src/SchematicHQ.Client/Types/DataExportType.cs new file mode 100644 index 00000000..3771fcd4 --- /dev/null +++ b/src/SchematicHQ.Client/Types/DataExportType.cs @@ -0,0 +1,115 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[JsonConverter(typeof(DataExportType.DataExportTypeSerializer))] +[Serializable] +public readonly record struct DataExportType : IStringEnum +{ + public static readonly DataExportType AuditLog = new(Values.AuditLog); + + public static readonly DataExportType CompanyFeatureUsage = new(Values.CompanyFeatureUsage); + + public DataExportType(string value) + { + Value = value; + } + + /// + /// The string value of the enum. + /// + public string Value { get; } + + /// + /// Create a string enum with the given value. + /// + public static DataExportType FromCustom(string value) + { + return new DataExportType(value); + } + + public bool Equals(string? other) + { + return Value.Equals(other); + } + + /// + /// Returns the string value of the enum. + /// + public override string ToString() + { + return Value; + } + + public static bool operator ==(DataExportType value1, string value2) => + value1.Value.Equals(value2); + + public static bool operator !=(DataExportType value1, string value2) => + !value1.Value.Equals(value2); + + public static explicit operator string(DataExportType value) => value.Value; + + public static explicit operator DataExportType(string value) => new(value); + + internal class DataExportTypeSerializer : JsonConverter + { + public override DataExportType Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + var stringValue = + reader.GetString() + ?? throw new global::System.Exception( + "The JSON value could not be read as a string." + ); + return new DataExportType(stringValue); + } + + public override void Write( + Utf8JsonWriter writer, + DataExportType value, + JsonSerializerOptions options + ) + { + writer.WriteStringValue(value.Value); + } + + public override DataExportType ReadAsPropertyName( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + var stringValue = + reader.GetString() + ?? throw new global::System.Exception( + "The JSON property name could not be read as a string." + ); + return new DataExportType(stringValue); + } + + public override void WriteAsPropertyName( + Utf8JsonWriter writer, + DataExportType value, + JsonSerializerOptions options + ) + { + writer.WritePropertyName(value.Value); + } + } + + /// + /// Constant strings for enum values + /// + [Serializable] + public static class Values + { + public const string AuditLog = "audit-log"; + + public const string CompanyFeatureUsage = "company-feature-usage"; + } +} diff --git a/src/SchematicHQ.Client/Types/FeatureEntitlement.cs b/src/SchematicHQ.Client/Types/FeatureEntitlement.cs index e77f4c76..16441263 100644 --- a/src/SchematicHQ.Client/Types/FeatureEntitlement.cs +++ b/src/SchematicHQ.Client/Types/FeatureEntitlement.cs @@ -119,6 +119,12 @@ public record FeatureEntitlement : IJsonOnDeserialized [JsonPropertyName("value_type")] public required EntitlementValueType ValueType { get; set; } + /// + /// Customer-defined usage warning thresholds configured on this entitlement + /// + [JsonPropertyName("warning_tiers")] + public IEnumerable? WarningTiers { get; set; } + [JsonIgnore] public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); diff --git a/src/SchematicHQ.Client/Types/PlanCatalogMembershipResponseData.cs b/src/SchematicHQ.Client/Types/PlanCatalogMembershipResponseData.cs new file mode 100644 index 00000000..ee3181d9 --- /dev/null +++ b/src/SchematicHQ.Client/Types/PlanCatalogMembershipResponseData.cs @@ -0,0 +1,31 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record PlanCatalogMembershipResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("id")] + public required string Id { get; set; } + + [JsonPropertyName("name")] + public required string Name { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/PlanDetailResponseData.cs b/src/SchematicHQ.Client/Types/PlanDetailResponseData.cs index 9ab6ff8e..4a0a5c79 100644 --- a/src/SchematicHQ.Client/Types/PlanDetailResponseData.cs +++ b/src/SchematicHQ.Client/Types/PlanDetailResponseData.cs @@ -26,6 +26,9 @@ public record PlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("billing_strategy")] public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("catalogs")] + public IEnumerable? Catalogs { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } diff --git a/src/SchematicHQ.Client/Types/PlanGroupPlanDetailResponseData.cs b/src/SchematicHQ.Client/Types/PlanGroupPlanDetailResponseData.cs index ef269b6a..42e3b8da 100644 --- a/src/SchematicHQ.Client/Types/PlanGroupPlanDetailResponseData.cs +++ b/src/SchematicHQ.Client/Types/PlanGroupPlanDetailResponseData.cs @@ -30,6 +30,9 @@ public record PlanGroupPlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("billing_strategy")] public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("catalogs")] + public IEnumerable? Catalogs { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } diff --git a/src/SchematicHQ.Client/Types/PlanViewPublicResponseData.cs b/src/SchematicHQ.Client/Types/PlanViewPublicResponseData.cs index bc7bd0dd..f880d57a 100644 --- a/src/SchematicHQ.Client/Types/PlanViewPublicResponseData.cs +++ b/src/SchematicHQ.Client/Types/PlanViewPublicResponseData.cs @@ -30,6 +30,9 @@ public record PlanViewPublicResponseData : IJsonOnDeserialized [JsonPropertyName("billing_strategy")] public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("catalogs")] + public IEnumerable? Catalogs { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } diff --git a/src/SchematicHQ.Client/Types/PreviewSubscriptionDiscountResponseData.cs b/src/SchematicHQ.Client/Types/PreviewSubscriptionDiscountResponseData.cs new file mode 100644 index 00000000..851bdf53 --- /dev/null +++ b/src/SchematicHQ.Client/Types/PreviewSubscriptionDiscountResponseData.cs @@ -0,0 +1,58 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record PreviewSubscriptionDiscountResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("amount_off")] + public long? AmountOff { get; set; } + + [JsonPropertyName("coupon_name")] + public required string CouponName { get; set; } + + [JsonPropertyName("currency")] + public string? Currency { get; set; } + + [JsonPropertyName("customer_facing_code")] + public string? CustomerFacingCode { get; set; } + + [JsonPropertyName("duration")] + public required string Duration { get; set; } + + [JsonPropertyName("duration_in_months")] + public long? DurationInMonths { get; set; } + + [JsonPropertyName("ended_at")] + public DateTime? EndedAt { get; set; } + + [JsonPropertyName("is_active")] + public required bool IsActive { get; set; } + + [JsonPropertyName("percent_off")] + public double? PercentOff { get; set; } + + [JsonPropertyName("promo_code_external_id")] + public string? PromoCodeExternalId { get; set; } + + [JsonPropertyName("started_at")] + public required DateTime StartedAt { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/PreviewSubscriptionFinanceResponseData.cs b/src/SchematicHQ.Client/Types/PreviewSubscriptionFinanceResponseData.cs index 99dffa76..e42a7f16 100644 --- a/src/SchematicHQ.Client/Types/PreviewSubscriptionFinanceResponseData.cs +++ b/src/SchematicHQ.Client/Types/PreviewSubscriptionFinanceResponseData.cs @@ -14,6 +14,10 @@ public record PreviewSubscriptionFinanceResponseData : IJsonOnDeserialized [JsonPropertyName("amount_off")] public required long AmountOff { get; set; } + [JsonPropertyName("discounts")] + public IEnumerable Discounts { get; set; } = + new List(); + [JsonPropertyName("due_now")] public required long DueNow { get; set; } @@ -23,6 +27,9 @@ public record PreviewSubscriptionFinanceResponseData : IJsonOnDeserialized [JsonPropertyName("percent_off")] public required double PercentOff { get; set; } + [JsonPropertyName("period_end")] + public required DateTime PeriodEnd { get; set; } + [JsonPropertyName("period_start")] public required DateTime PeriodStart { get; set; } diff --git a/src/SchematicHQ.Client/Types/RulesengineFeatureEntitlement.cs b/src/SchematicHQ.Client/Types/RulesengineFeatureEntitlement.cs index e8ab8056..18bf23c6 100644 --- a/src/SchematicHQ.Client/Types/RulesengineFeatureEntitlement.cs +++ b/src/SchematicHQ.Client/Types/RulesengineFeatureEntitlement.cs @@ -119,6 +119,12 @@ public record RulesengineFeatureEntitlement : IJsonOnDeserialized [JsonPropertyName("value_type")] public required RulesengineEntitlementValueType ValueType { get; set; } + /// + /// Customer-defined usage warning thresholds configured on this entitlement + /// + [JsonPropertyName("warning_tiers")] + public IEnumerable? WarningTiers { get; set; } + [JsonIgnore] public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); diff --git a/src/SchematicHQ.Client/Types/RulesengineWarningTier.cs b/src/SchematicHQ.Client/Types/RulesengineWarningTier.cs new file mode 100644 index 00000000..385d994c --- /dev/null +++ b/src/SchematicHQ.Client/Types/RulesengineWarningTier.cs @@ -0,0 +1,37 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record RulesengineWarningTier : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + /// + /// A customer-defined identifier for the warning tier + /// + [JsonPropertyName("key")] + public required string Key { get; set; } + + /// + /// The warning threshold, in the entitlement's usage units + /// + [JsonPropertyName("value")] + public required long Value { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/UpsertCompanyRequestBody.cs b/src/SchematicHQ.Client/Types/UpsertCompanyRequestBody.cs index d6b2e70f..a5e56494 100644 --- a/src/SchematicHQ.Client/Types/UpsertCompanyRequestBody.cs +++ b/src/SchematicHQ.Client/Types/UpsertCompanyRequestBody.cs @@ -11,6 +11,18 @@ public record UpsertCompanyRequestBody : IJsonOnDeserialized private readonly IDictionary _extensionData = new Dictionary(); + /// + /// Assign this base plan when creating the company (starts with plan_). Takes precedence over the environment's initial plan and must be provisionable without a payment method. + /// + [JsonPropertyName("base_plan_id")] + public string? BasePlanId { get; set; } + + /// + /// The Schematic price to provision for base_plan_id (starts with bilpp_). Required and must be $0 for a billing-linked plan; omit for a plan that is not billing-linked. + /// + [JsonPropertyName("base_plan_price_id")] + public string? BasePlanPriceId { get; set; } + /// /// If you know the Schematic ID, you can use that here instead of keys /// diff --git a/src/SchematicHQ.Client/Types/WarningTier.cs b/src/SchematicHQ.Client/Types/WarningTier.cs new file mode 100644 index 00000000..c673b79b --- /dev/null +++ b/src/SchematicHQ.Client/Types/WarningTier.cs @@ -0,0 +1,37 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record WarningTier : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + /// + /// A customer-defined identifier for the warning tier + /// + [JsonPropertyName("key")] + public required string Key { get; set; } + + /// + /// The warning threshold, in the entitlement's usage units + /// + [JsonPropertyName("value")] + public required long Value { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} From ac9de95a9a4ee812361c0f77832e31aa5975267b Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Mon, 20 Jul 2026 18:59:35 +0000 Subject: [PATCH 2/2] [fern-replay] Applied customizations Patches applied (1): - patch-0816e16a: chore: update rules engine WASM to v0.4.0 (#158) --- .fern/replay.lock | 10 ++++++++-- WASM_VERSION | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 WASM_VERSION diff --git a/.fern/replay.lock b/.fern/replay.lock index 28fcd44d..881deda6 100644 --- a/.fern/replay.lock +++ b/.fern/replay.lock @@ -30,14 +30,20 @@ generations: cli_version: unknown generator_versions: fernapi/fern-csharp-sdk: 2.71.1 -current_generation: 1b7ac10f82c1ca0f8c2636da1828f42ff6132896 + - commit_sha: b0fb07315fcf768f4b1170209dbe0c5f48ecccbf + tree_hash: 611bc6ad0a1d4a3fd37654ad9c318afafc67e7ca + timestamp: 2026-07-20T18:59:32.703Z + cli_version: unknown + generator_versions: + fernapi/fern-csharp-sdk: 2.71.1 +current_generation: b0fb07315fcf768f4b1170209dbe0c5f48ecccbf patches: - id: patch-0816e16a content_hash: sha256:17a9a52d7557e941a9879ef072a5b51bb135098a4021df914f5c6a344964a947 original_commit: 0816e16ac6deea213675e5288d1b96ade208183b original_message: "chore: update rules engine WASM to v0.4.0 (#158)" original_author: Schematic Bot - base_generation: 1b7ac10f82c1ca0f8c2636da1828f42ff6132896 + base_generation: b0fb07315fcf768f4b1170209dbe0c5f48ecccbf files: - WASM_VERSION patch_content: | diff --git a/WASM_VERSION b/WASM_VERSION new file mode 100644 index 00000000..1d0ba9ea --- /dev/null +++ b/WASM_VERSION @@ -0,0 +1 @@ +0.4.0