From 4aa69bd77e8b5fcdd26950f126e3ace67fedefc6 Mon Sep 17 00:00:00 2001 From: DJ Steinmetz Date: Thu, 7 Nov 2024 10:45:45 -0500 Subject: [PATCH] updates for latest api version --- src/OrderCloud.SDK/Generated/ErrorCodes.cs | 7 +++ src/OrderCloud.SDK/Generated/Models.cs | 28 +++++++++++ src/OrderCloud.SDK/Generated/Resources.cs | 42 +++++++++++++++++ .../Generated/WebhookPayloads.cs | 47 +++++++++++++++++++ src/OrderCloud.SDK/OAuthModels.cs | 2 + src/OrderCloud.SDK/OrderCloud.SDK.csproj | 2 +- src/OrderCloud.SDK/OrderCloudClient.cs | 13 ++++- 7 files changed, 139 insertions(+), 2 deletions(-) diff --git a/src/OrderCloud.SDK/Generated/ErrorCodes.cs b/src/OrderCloud.SDK/Generated/ErrorCodes.cs index 26d1051..d3eae85 100644 --- a/src/OrderCloud.SDK/Generated/ErrorCodes.cs +++ b/src/OrderCloud.SDK/Generated/ErrorCodes.cs @@ -44,6 +44,13 @@ public static class ApiClient /// IsAnonBuyer can be true only when a buyer user is set as the Default Context User. public const string RequiredNotAnonBuyer = "ApiClient.RequiredNotAnonBuyer"; } + public static class ApiClientSecret + { + /// The maximum number of client secrets has been reached for this API client. + public const string MaximumClientSecretsReached = "ApiClientSecret.MaximumClientSecretsReached"; + /// Cannot create a client secret that is already expired. + public const string InvalidExpirationDate = "ApiClientSecret.InvalidExpirationDate"; + } public static class ApprovalRule { /// Cannot delete Approval Rule because it has pending Approvals. diff --git a/src/OrderCloud.SDK/Generated/Models.cs b/src/OrderCloud.SDK/Generated/Models.cs index 5fbc5a7..76e7ad6 100644 --- a/src/OrderCloud.SDK/Generated/Models.cs +++ b/src/OrderCloud.SDK/Generated/Models.cs @@ -201,6 +201,29 @@ public class ApiClientAssignment : OrderCloudModel /// ID of the supplier. Sortable: priority level 1. public string SupplierID { get => GetProp("SupplierID"); set => SetProp("SupplierID", value); } } + public class ApiClientSecret : OrderCloudModel + { + /// ID of the api client secret. Can only contain characters Aa-Zz, 0-9, -, and _. Searchable: priority level 1. Sortable: priority level 1. + public string ID { get => GetProp("ID"); set => SetProp("ID", value); } + /// Name of the api client secret. Required. + [Required] + public string Name { get => GetProp("Name"); set => SetProp("Name", value); } + /// Expiration of the api client secret. + public DateTimeOffset? Expiration { get => GetProp("Expiration"); set => SetProp("Expiration", value); } + } + public class ApiClientSecretCreateResponse : OrderCloudModel + { + /// Client secret of the api client secret create response. + [ApiReadOnly] + public string ClientSecret { get => GetProp("ClientSecret"); set => SetProp("ClientSecret", value); } + /// ID of the api client secret create response. Can only contain characters Aa-Zz, 0-9, -, and _. Searchable: priority level 1. Sortable: priority level 1. + public string ID { get => GetProp("ID"); set => SetProp("ID", value); } + /// Name of the api client secret create response. Required. + [Required] + public string Name { get => GetProp("Name"); set => SetProp("Name", value); } + /// Expiration of the api client secret create response. + public DateTimeOffset? Expiration { get => GetProp("Expiration"); set => SetProp("Expiration", value); } + } public class ApprovalInfo : OrderCloudModel { /// Comments to be saved with the order approval or denial. @@ -1080,6 +1103,8 @@ public class InventoryRecord : OrderCloudModel public bool OrderCanExceed { get => GetProp("OrderCanExceed"); set => SetProp("OrderCanExceed", value); } /// Quantity available of the inventory record. public int QuantityAvailable { get => GetProp("QuantityAvailable"); set => SetProp("QuantityAvailable", value); } + /// Notification point of the inventory record. + public int? NotificationPoint { get => GetProp("NotificationPoint"); set => SetProp("NotificationPoint", value); } /// Last updated of the inventory record. [ApiReadOnly] public DateTimeOffset LastUpdated { get => GetProp("LastUpdated"); set => SetProp("LastUpdated", value); } @@ -3122,6 +3147,8 @@ public class VariantInventory : OrderCloudModel { /// Quantity available of the variant inventory. public int? QuantityAvailable { get => GetProp("QuantityAvailable"); set => SetProp("QuantityAvailable", value); } + /// Notification point of the variant inventory. + public int? NotificationPoint { get => GetProp("NotificationPoint"); set => SetProp("NotificationPoint", value); } /// Last updated of the variant inventory. [ApiReadOnly] public DateTimeOffset LastUpdated { get => GetProp("LastUpdated"); set => SetProp("LastUpdated", value); } @@ -3195,6 +3222,7 @@ public class PartialApiClient : ApiClient, IPartial { } /// Specific type of the xp property. If not using a custom type, use the non-generic PartialApiClient class instead. public class PartialApiClient : PartialApiClient { } + public class PartialApiClientSecret : ApiClientSecret, IPartial { } public class PartialApprovalRule : ApprovalRule, IPartial { } /// Specific type of the xp property. If not using a custom type, use the non-generic PartialApprovalRule class instead. public class PartialApprovalRule : PartialApprovalRule diff --git a/src/OrderCloud.SDK/Generated/Resources.cs b/src/OrderCloud.SDK/Generated/Resources.cs index ef1c260..fa5a7b1 100644 --- a/src/OrderCloud.SDK/Generated/Resources.cs +++ b/src/OrderCloud.SDK/Generated/Resources.cs @@ -495,6 +495,42 @@ public interface IApiClientsResource /// ID of the supplier. /// Optional. Use to provide an existing token instead of authenticating implicitly. Task DeleteSupplierAssignmentAsync(string apiClientID, string supplierID, string accessToken = null); + /// Get a single API client secret. + /// ID of the api client. + /// ID of the api client secret. + /// Optional. Use to provide an existing token instead of authenticating implicitly. + Task GetSecretAsync(string apiClientID, string apiClientSecretID, string accessToken = null); + /// Get a list of API client secrets. + /// ID of the api client. + /// Word or phrase to search for. + /// Comma-delimited list of fields to search on. + /// Comma-delimited list of fields to sort by. + /// Page of results to return. Default: 1. When paginating through many items (> page 30), we recommend the "Last ID" method, as outlined in the Advanced Querying documentation. + /// Number of results to return per page. Default: 20, max: 100. + /// An object or dictionary representing key/value pairs to apply as filters. Valid keys are top-level properties of the returned model or 'xp.???' + /// Optional. Use to provide an existing token instead of authenticating implicitly. + Task> ListSecretsAsync(string apiClientID, string search = null, string searchOn = null, string sortBy = null, int page = 1, int pageSize = 20, object filters = null, string accessToken = null); + /// Get a list of API client secrets. + /// ID of the api client. + /// A lambda or function for specifying various list options fluently. + /// Optional. Use to provide an existing token instead of authenticating implicitly. + Task> ListSecretsAsync(string apiClientID, Action> buildListOpts, string accessToken = null); + /// Create a new API client secret. + /// ID of the api client. + /// The object that will be serialized to JSON and sent in the request body. + /// Optional. Use to provide an existing token instead of authenticating implicitly. + Task CreateSecretAsync(string apiClientID, ApiClientSecret apiClientSecret, string accessToken = null); + /// Partially update a API client secret. + /// ID of the api client. + /// ID of the api client secret. + /// The object that will be partially serialized to JSON and sent in the request body. + /// Optional. Use to provide an existing token instead of authenticating implicitly. + Task PatchSecretAsync(string apiClientID, string apiClientSecretID, PartialApiClientSecret partialApiClientSecret, string accessToken = null); + /// Delete a API client secret. + /// ID of the api client. + /// ID of the api client secret. + /// Optional. Use to provide an existing token instead of authenticating implicitly. + Task DeleteSecretAsync(string apiClientID, string apiClientSecretID, string accessToken = null); } public interface IApprovalRulesResource @@ -6741,6 +6777,12 @@ internal ApiClientsResource(OrderCloudClient client) : base(client) { } public Task SaveAssignmentAsync(ApiClientAssignment apiClientAssignment, string accessToken = null) => Request("v1", "apiclients", "assignments").WithOAuthBearerToken(accessToken).PostJsonAsync(ValidateModel(apiClientAssignment)); public Task DeleteBuyerAssignmentAsync(string apiClientID, string buyerID, string accessToken = null) => Request("v1", "buyers", buyerID, "ApiClients", "Assignments", apiClientID).WithOAuthBearerToken(accessToken).DeleteAsync(); public Task DeleteSupplierAssignmentAsync(string apiClientID, string supplierID, string accessToken = null) => Request("v1", "suppliers", supplierID, "ApiClients", "Assignments", apiClientID).WithOAuthBearerToken(accessToken).DeleteAsync(); + public Task GetSecretAsync(string apiClientID, string apiClientSecretID, string accessToken = null) => Request("v1", "apiclients", apiClientID, "secrets", apiClientSecretID).WithOAuthBearerToken(accessToken).GetJsonAsync(); + public Task> ListSecretsAsync(string apiClientID, string search = null, string searchOn = null, string sortBy = null, int page = 1, int pageSize = 20, object filters = null, string accessToken = null) => Request("v1", "apiclients", apiClientID, "secrets").WithOAuthBearerToken(accessToken).SetQueryParams(new { search, searchOn, sortBy, page, pageSize }).SetQueryParams(filters).GetJsonAsync>(); + public Task> ListSecretsAsync(string apiClientID, Action> buildListOpts, string accessToken = null) => Request("v1", "apiclients", apiClientID, "secrets").WithOAuthBearerToken(accessToken).SetListOptions(buildListOpts).GetJsonAsync>(); + public Task CreateSecretAsync(string apiClientID, ApiClientSecret apiClientSecret, string accessToken = null) => Request("v1", "apiclients", apiClientID, "secrets").WithOAuthBearerToken(accessToken).PostJsonAsync(ValidateModel(apiClientSecret)).ReceiveJson(); + public Task PatchSecretAsync(string apiClientID, string apiClientSecretID, PartialApiClientSecret partialApiClientSecret, string accessToken = null) => Request("v1", "apiclients", apiClientID, "secrets", apiClientSecretID).WithOAuthBearerToken(accessToken).PatchJsonAsync(ValidateModel(partialApiClientSecret)).ReceiveJson(); + public Task DeleteSecretAsync(string apiClientID, string apiClientSecretID, string accessToken = null) => Request("v1", "apiclients", apiClientID, "secrets", apiClientSecretID).WithOAuthBearerToken(accessToken).DeleteAsync(); } public class ApprovalRulesResource : OrderCloudResource, IApprovalRulesResource diff --git a/src/OrderCloud.SDK/Generated/WebhookPayloads.cs b/src/OrderCloud.SDK/Generated/WebhookPayloads.cs index 45f34be..6d2e5ac 100644 --- a/src/OrderCloud.SDK/Generated/WebhookPayloads.cs +++ b/src/OrderCloud.SDK/Generated/WebhookPayloads.cs @@ -408,6 +408,53 @@ public class DeleteSupplierAssignmentRouteParams public string ApiClientID { get; set; } public string SupplierID { get; set; } } + /// Webhook payload sent by OrderCloud on POST v1/apiclients/{apiClientID}/secrets. + [SentOn("POST", "v1/apiclients/{apiClientID}/secrets")] + public class CreateSecret : WebhookPayload { } + /// Webhook payload sent by OrderCloud on POST v1/apiclients/{apiClientID}/secrets. + /// Specific type of the ConfigData. If not using a custom type, specify dynamic. + /// Specific type of the ApiClientSecret. If not using a custom type, specify ApiClientSecret. + /// Specific type of the ApiClientSecretCreateResponse. If not using a custom type, specify ApiClientSecretCreateResponse. + [SentOn("POST", "v1/apiclients/{apiClientID}/secrets")] + public class CreateSecret : WebhookPayload + where TApiClientSecret : ApiClientSecret + where TApiClientSecretCreateResponse : ApiClientSecretCreateResponse + { } + /// Type used to represent route parameter name/value pairs for v1/apiclients/{apiClientID}/secrets. + public class CreateSecretRouteParams + { + public string ApiClientID { get; set; } + } + /// Webhook payload sent by OrderCloud on PATCH v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}. + [SentOn("PATCH", "v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}")] + public class PatchSecret : WebhookPayload { } + /// Webhook payload sent by OrderCloud on PATCH v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}. + /// Specific type of the ConfigData. If not using a custom type, specify dynamic. + /// Specific type of the ApiClientSecret. If not using a custom type, specify ApiClientSecret. + [SentOn("PATCH", "v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}")] + public class PatchSecret : WebhookPayload + where TApiClientSecret : ApiClientSecret + { } + /// Type used to represent route parameter name/value pairs for v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}. + public class PatchSecretRouteParams + { + public string ApiClientID { get; set; } + public string ApiClientSecretID { get; set; } + } + /// Webhook payload sent by OrderCloud on DELETE v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}. + [SentOn("DELETE", "v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}")] + public class DeleteSecret : WebhookPayload { } + /// Webhook payload sent by OrderCloud on DELETE v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}. + /// Specific type of the ConfigData. If not using a custom type, use the non-generic payload type instead. + [SentOn("DELETE", "v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}")] + public class DeleteSecret : WebhookPayload + { } + /// Type used to represent route parameter name/value pairs for v1/apiclients/{apiClientID}/secrets/{apiClientSecretID}. + public class DeleteSecretRouteParams + { + public string ApiClientID { get; set; } + public string ApiClientSecretID { get; set; } + } } public static class ApprovalRules { diff --git a/src/OrderCloud.SDK/OAuthModels.cs b/src/OrderCloud.SDK/OAuthModels.cs index 01bfe6a..beeeefd 100644 --- a/src/OrderCloud.SDK/OAuthModels.cs +++ b/src/OrderCloud.SDK/OAuthModels.cs @@ -27,6 +27,7 @@ public OAuthTokenRequestWithPasswordGrant() { public string username { get; set; } public string password { get; set; } + public string client_secret { get; set; } } internal class OAuthTokenRequestWithClientCredentialsGrant : OAuthTokenRequest @@ -45,5 +46,6 @@ public OAuthTokenRequestWithRefreshTokenGrant() { } public string refresh_token { get; set; } + public string client_secret { get; set; } } } diff --git a/src/OrderCloud.SDK/OrderCloud.SDK.csproj b/src/OrderCloud.SDK/OrderCloud.SDK.csproj index 9a5ad07..1d3ad75 100644 --- a/src/OrderCloud.SDK/OrderCloud.SDK.csproj +++ b/src/OrderCloud.SDK/OrderCloud.SDK.csproj @@ -4,7 +4,7 @@ netstandard2.0;net461 True - 0.16.0 + 0.16.1 OrderCloud.SDK OrderCloud SDK Todd Menier diff --git a/src/OrderCloud.SDK/OrderCloudClient.cs b/src/OrderCloud.SDK/OrderCloudClient.cs index 91f1a05..ebc19ba 100644 --- a/src/OrderCloud.SDK/OrderCloudClient.cs +++ b/src/OrderCloud.SDK/OrderCloudClient.cs @@ -104,6 +104,11 @@ public async Task AuthenticateAsync() { /// public Task AuthenticateAsync(string clientID, string username, string password, params ApiRole[] roles) { + return AuthenticateAsync(clientID, username, password, null, roles); + } + + /// + public Task AuthenticateAsync(string clientID, string username, string password, string clientSecret, params ApiRole[] roles) { Require(clientID, nameof(clientID)); Require(username, nameof(username)); Require(password, nameof(password)); @@ -112,6 +117,7 @@ public Task AuthenticateAsync(string clientID, string username, s client_id = clientID, username = username, password = password, + client_secret = clientSecret, scope = string.Join(" ", roles) }; return AuthenticateAsync(req); @@ -132,12 +138,17 @@ public Task RefreshTokenAsync(string refreshToken) { } public Task RefreshTokenAsync(string clientID, string refreshToken) { + return RefreshTokenAsync(clientID, refreshToken, null); + } + + public Task RefreshTokenAsync(string clientID, string refreshToken, string clientSecret) { Require(clientID, nameof(clientID)); Require(refreshToken, nameof(refreshToken)); var req = new OAuthTokenRequestWithRefreshTokenGrant { client_id = clientID, - refresh_token = refreshToken + refresh_token = refreshToken, + client_secret = clientSecret }; return AuthenticateAsync(req); }