@macrowing/inbiz-codegen 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +592 -2
- package/bin/inbiz-codegen.mjs +7 -0
- package/package.json +32 -4
- package/scripts/prepare-templates.mjs +35 -0
- package/src/backend/init.mjs +170 -0
- package/src/config.mjs +150 -0
- package/src/favicon.mjs +100 -0
- package/src/generate.mjs +935 -0
- package/src/generated-output.mjs +107 -0
- package/src/index.mjs +346 -0
- package/src/menu/build.mjs +252 -0
- package/src/menu/check.mjs +163 -0
- package/src/menu/command.mjs +179 -0
- package/src/migrate-runtime.mjs +106 -0
- package/src/platform/client.mjs +167 -0
- package/src/platform/command.mjs +386 -0
- package/src/platform/pack.mjs +591 -0
- package/src/platform/recover.mjs +236 -0
- package/src/platform/startup.mjs +343 -0
- package/src/platform/state.mjs +116 -0
- package/src/platform/update.mjs +157 -0
- package/src/platform/zip.mjs +134 -0
- package/src/pull.mjs +284 -0
- package/src/scaffold/commands.mjs +349 -0
- package/src/scaffold/init.mjs +392 -0
- package/src/scaffold/template-files.mjs +40 -0
- package/src/scaffold/template-source.mjs +235 -0
- package/src/scaffold/template-sync.mjs +335 -0
- package/src/transform/heaviness.mjs +380 -0
- package/src/transform/preview-props.mjs +108 -0
- package/src/transform/published-page-links.mjs +61 -0
- package/src/transform/published-script.mjs +110 -0
- package/src/transform/registry.mjs +781 -0
- package/src/transform/schema-to-jsx.mjs +1708 -0
- package/src/util/des.mjs +10 -0
- package/templates/README.md +34 -0
- package/templates/backend/Directory.Build.props +19 -0
- package/templates/backend/Directory.Packages.props +49 -0
- package/templates/backend/Macrowing.Scaffold.slnx +13 -0
- package/templates/backend/host/Macrowing.Start/Init/app.json +8 -0
- package/templates/backend/host/Macrowing.Start/Init/menus.json +4 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationDefinition.cs +245 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationEndpoints.cs +57 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationHostedService.cs +63 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationOptions.cs +44 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationRunner.cs +294 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationState.cs +72 -0
- package/templates/backend/host/Macrowing.Start/Initialization/MenuFactory.cs +118 -0
- package/templates/backend/host/Macrowing.Start/Initialization/PackageBuilder.cs +317 -0
- package/templates/backend/host/Macrowing.Start/Initialization/PlatformAppImporter.cs +371 -0
- package/templates/backend/host/Macrowing.Start/Macrowing.Start.csproj +26 -0
- package/templates/backend/host/Macrowing.Start/Program.cs +33 -0
- package/templates/backend/host/Macrowing.Start/StartModule.cs +67 -0
- package/templates/backend/host/Macrowing.Start/appsettings.json +38 -0
- package/templates/backend/modules/Macrowing.Generated/Application/GeneratedApplicationAutoMapperProfile.cs +42 -0
- package/templates/backend/modules/Macrowing.Generated/Domain/Entities/GeneratedEntityBase.cs +72 -0
- package/templates/backend/modules/Macrowing.Generated/Domain/GeneratedConsts.cs +50 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContext.cs +55 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContextModelBuilderExtensions.cs +61 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/IGeneratedDbContext.cs +32 -0
- package/templates/backend/modules/Macrowing.Generated/GeneratedModule.cs +89 -0
- package/templates/backend/modules/Macrowing.Generated/Macrowing.Generated.csproj +22 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsClient.cs +95 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsModels.cs +81 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Dictionary/DictionaryClient.cs +44 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/InBizSdkModule.cs +16 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/InterfaceEngine/InterfaceEngineClient.cs +50 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Localization/LocalizationClient.cs +28 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Macrowing.InBiz.SDK.csproj +16 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageClient.cs +99 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageModels.cs +63 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelClient.cs +131 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelQuery.cs +108 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelWrite.cs +44 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Permission/PermissionClient.cs +86 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformException.cs +42 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformRegistration.cs +60 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformTransport.cs +96 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizRequestContext.cs +27 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/README.md +117 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsClient.cs +35 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsQuery.cs +20 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationRequests.cs +105 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationsClient.cs +53 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/README.md +132 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Tracking/WorkFlowTrackingClient.cs +50 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeClient.cs +78 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeModels.cs +34 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowContracts.cs +88 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowRegistration.cs +59 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowTransport.cs +163 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchClient.cs +59 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchModels.cs +76 -0
- package/templates/backend/modules/Macrowing.OC.SDK/Macrowing.OC.SDK.csproj +20 -0
- package/templates/backend/modules/Macrowing.OC.SDK/OcSdkModule.cs +18 -0
- package/templates/backend/modules/Macrowing.OC.SDK/Protos/README.md +22 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/Macrowing.InBiz.SDK.Tests.csproj +14 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformContractTests.cs +288 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformLiveTests.cs +173 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowHttpServer.cs +113 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowLiveTests.cs +269 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowOperationsTests.cs +80 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowQueryTests.cs +163 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowTransportTests.cs +111 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowUpgradeTests.cs +87 -0
- package/templates/frontend/components/README.md +39 -0
- package/templates/frontend/components/app-components/README.md +33 -0
- package/templates/frontend/components/app-components/common/.gitkeep +0 -0
- package/templates/frontend/components/app-components/components/.gitkeep +0 -0
- package/templates/frontend/components/app-components/package.json +20 -0
- package/templates/frontend/mgt/.umirc.ts +574 -0
- package/templates/frontend/mgt/package.json +96 -0
- package/templates/frontend/mgt/src/app-extends.ts +9 -0
- package/templates/frontend/mgt/src/app.tsx +20 -0
- package/templates/frontend/mgt/src/config/app.ts +31 -0
- package/templates/frontend/mgt/src/layout/header.tsx +14 -0
- package/templates/frontend/mgt/src/layout/index.tsx +11 -0
- package/templates/frontend/mgt/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/mgt/src/locales.ts +8 -0
- package/templates/frontend/mgt/src/pages/.gitkeep +0 -0
- package/templates/frontend/mgt/src/root.tsx +12 -0
- package/templates/frontend/mgt/src/route-view.tsx +3 -0
- package/templates/frontend/mgt/src/runtime.ts +21 -0
- package/templates/frontend/mgt/src/styles/app.css +1 -0
- package/templates/frontend/mgt/src/styles/layout.less +79 -0
- package/templates/frontend/mgt/tsconfig.json +65 -0
- package/templates/frontend/mgt/typings.d.ts +57 -0
- package/templates/frontend/wap/.umirc.ts +574 -0
- package/templates/frontend/wap/package.json +73 -0
- package/templates/frontend/wap/src/app-extends.ts +9 -0
- package/templates/frontend/wap/src/app.tsx +28 -0
- package/templates/frontend/wap/src/config/app.ts +31 -0
- package/templates/frontend/wap/src/layout/header.tsx +14 -0
- package/templates/frontend/wap/src/layout/index.tsx +18 -0
- package/templates/frontend/wap/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/wap/src/locales.ts +8 -0
- package/templates/frontend/wap/src/pages/.gitkeep +0 -0
- package/templates/frontend/wap/src/root.tsx +12 -0
- package/templates/frontend/wap/src/route-view.tsx +3 -0
- package/templates/frontend/wap/src/runtime.ts +21 -0
- package/templates/frontend/wap/src/styles/adaptation.less +190 -0
- package/templates/frontend/wap/src/styles/app.css +7 -0
- package/templates/frontend/wap/src/styles/global.less +81 -0
- package/templates/frontend/wap/src/styles/layout.less +92 -0
- package/templates/frontend/wap/tsconfig.json +66 -0
- package/templates/frontend/wap/typings.d.ts +24 -0
- package/templates/frontend/web/.umirc.ts +574 -0
- package/templates/frontend/web/package.json +26 -0
- package/templates/frontend/web/src/app-extends.ts +9 -0
- package/templates/frontend/web/src/app.tsx +25 -0
- package/templates/frontend/web/src/config/app.ts +31 -0
- package/templates/frontend/web/src/layout/header.tsx +14 -0
- package/templates/frontend/web/src/layout/index.tsx +11 -0
- package/templates/frontend/web/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/web/src/locales.ts +8 -0
- package/templates/frontend/web/src/root.tsx +12 -0
- package/templates/frontend/web/src/route-view.tsx +3 -0
- package/templates/frontend/web/src/runtime.ts +21 -0
- package/templates/frontend/web/src/styles/app.css +104 -0
- package/templates/frontend/web/src/styles/layout.less +124 -0
- package/templates/frontend/web/tsconfig.json +91 -0
- package/templates/frontend/web/typings.d.ts +46 -0
- package/templates/package.json +14 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
using Macrowing.InBiz.SDK.Cms;
|
|
2
|
+
using Macrowing.InBiz.SDK.Dictionary;
|
|
3
|
+
using Macrowing.InBiz.SDK.InterfaceEngine;
|
|
4
|
+
using Macrowing.InBiz.SDK.Localization;
|
|
5
|
+
using Macrowing.InBiz.SDK.Message;
|
|
6
|
+
using Macrowing.InBiz.SDK.Model;
|
|
7
|
+
using Macrowing.InBiz.SDK.Permission;
|
|
8
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
9
|
+
using Microsoft.Extensions.Options;
|
|
10
|
+
|
|
11
|
+
namespace Macrowing.InBiz.SDK.Platform;
|
|
12
|
+
|
|
13
|
+
/// <summary>Connection settings for the platform gateway. Workflow uses separate settings.</summary>
|
|
14
|
+
public sealed class InBizPlatformOptions
|
|
15
|
+
{
|
|
16
|
+
/// <summary>Configuration section for the platform gateway.</summary>
|
|
17
|
+
public const string SectionName = "InBiz:Platform";
|
|
18
|
+
|
|
19
|
+
/// <summary>Absolute platform URL including the mount path, for example https://inbiz.example/inbiz/.</summary>
|
|
20
|
+
public string? BaseUrl { get; set; }
|
|
21
|
+
|
|
22
|
+
/// <summary>Maximum duration of a request, including reading the response body. Defaults to 30 seconds.</summary>
|
|
23
|
+
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// <summary>Dependency injection setup for the platform clients.</summary>
|
|
27
|
+
public static class InBizPlatformRegistration
|
|
28
|
+
{
|
|
29
|
+
/// <summary>Registers the platform clients and binds <see cref="InBizPlatformOptions"/>. ABP hosts using <see cref="InBizSdkModule"/> already call this.</summary>
|
|
30
|
+
/// <param name="services">Host service collection.</param>
|
|
31
|
+
/// <returns>The same service collection.</returns>
|
|
32
|
+
public static IServiceCollection AddInBizPlatform(this IServiceCollection services)
|
|
33
|
+
{
|
|
34
|
+
services.AddOptions<InBizPlatformOptions>().BindConfiguration(InBizPlatformOptions.SectionName);
|
|
35
|
+
services.AddHttpClient(InBizPlatformTransport.ClientName, (provider, client) =>
|
|
36
|
+
{
|
|
37
|
+
var options = provider.GetRequiredService<IOptions<InBizPlatformOptions>>().Value;
|
|
38
|
+
if (!Uri.TryCreate(options.BaseUrl, UriKind.Absolute, out var uri) ||
|
|
39
|
+
uri.Scheme is not ("http" or "https") || uri.Host.Length == 0 ||
|
|
40
|
+
uri.Query.Length != 0 || uri.Fragment.Length != 0 || uri.UserInfo.Length != 0)
|
|
41
|
+
throw new InvalidOperationException("Configure InBiz:Platform:BaseUrl as an absolute HTTP(S) URL including the platform mount path and no credentials, query or fragment.");
|
|
42
|
+
|
|
43
|
+
client.BaseAddress = new Uri(uri.AbsoluteUri.TrimEnd('/') + "/");
|
|
44
|
+
client.Timeout = options.Timeout;
|
|
45
|
+
client.MaxResponseContentBufferSize = 32 * 1024 * 1024;
|
|
46
|
+
})
|
|
47
|
+
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { AllowAutoRedirect = false, UseCookies = false })
|
|
48
|
+
.RemoveAllLoggers();
|
|
49
|
+
|
|
50
|
+
services.AddTransient<InBizPlatformTransport>();
|
|
51
|
+
services.AddTransient<IModelClient, ModelClient>();
|
|
52
|
+
services.AddTransient<IMessageClient, MessageClient>();
|
|
53
|
+
services.AddTransient<IInterfaceEngineClient, InterfaceEngineClient>();
|
|
54
|
+
services.AddTransient<IDictionaryClient, DictionaryClient>();
|
|
55
|
+
services.AddTransient<ILocalizationClient, LocalizationClient>();
|
|
56
|
+
services.AddTransient<IPermissionClient, PermissionClient>();
|
|
57
|
+
services.AddTransient<ICmsClient, CmsClient>();
|
|
58
|
+
return services;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
using System.Net;
|
|
2
|
+
using System.Net.Http.Json;
|
|
3
|
+
using System.Text.Json;
|
|
4
|
+
using System.Text.Json.Serialization;
|
|
5
|
+
|
|
6
|
+
namespace Macrowing.InBiz.SDK.Platform;
|
|
7
|
+
|
|
8
|
+
internal sealed class InBizPlatformTransport(IHttpClientFactory factory)
|
|
9
|
+
{
|
|
10
|
+
internal const string ClientName = "InBiz.Platform";
|
|
11
|
+
internal const string PublicApi = "api/services/v1/";
|
|
12
|
+
internal static readonly JsonSerializerOptions Json = new(JsonSerializerDefaults.Web)
|
|
13
|
+
{
|
|
14
|
+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
|
15
|
+
NumberHandling = JsonNumberHandling.Strict
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
internal async Task<Reply> SendAsync(InBizRequestContext context, HttpMethod method, string route,
|
|
19
|
+
CancellationToken cancellationToken, object? body = null)
|
|
20
|
+
{
|
|
21
|
+
ArgumentNullException.ThrowIfNull(context);
|
|
22
|
+
using var client = factory.CreateClient(ClientName);
|
|
23
|
+
using var request = new HttpRequestMessage(method, route);
|
|
24
|
+
request.Headers.Add("token", context.Token);
|
|
25
|
+
request.Headers.Add("appId", context.AppId);
|
|
26
|
+
if (body is not null)
|
|
27
|
+
request.Content = JsonContent.Create(body, options: Json);
|
|
28
|
+
|
|
29
|
+
using var response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
|
30
|
+
var reply = new Reply(response.StatusCode, response.Content.Headers.ContentType?.MediaType,
|
|
31
|
+
await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false));
|
|
32
|
+
var isAbpError = response.Headers.Contains("_AbpErrorFormat");
|
|
33
|
+
if (!response.IsSuccessStatusCode || isAbpError)
|
|
34
|
+
{
|
|
35
|
+
var error = reply.TryGetError();
|
|
36
|
+
var kind = response.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden
|
|
37
|
+
? InBizFailureKind.AuthenticationOrPermission
|
|
38
|
+
: error is not null || isAbpError ? InBizFailureKind.Business : InBizFailureKind.Http;
|
|
39
|
+
throw new InBizPlatformException(kind, response.StatusCode, error?.Code, error?.Message);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return reply;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
internal static string QueryValue(string value)
|
|
46
|
+
{
|
|
47
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(value);
|
|
48
|
+
return Uri.EscapeDataString(value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
internal static string AppPath(InBizRequestContext context)
|
|
52
|
+
{
|
|
53
|
+
ArgumentNullException.ThrowIfNull(context);
|
|
54
|
+
return PathSegment(context.AppId);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
internal static string PathSegment(string value)
|
|
58
|
+
{
|
|
59
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(value);
|
|
60
|
+
if (value is "." or ".." || value.Contains('/') || value.Contains('\\'))
|
|
61
|
+
throw new ArgumentException("The value must be a single path segment.", nameof(value));
|
|
62
|
+
return Uri.EscapeDataString(value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
internal readonly record struct Reply(HttpStatusCode Status, string? MediaType, string Body)
|
|
66
|
+
{
|
|
67
|
+
internal bool IsJson => string.Equals(MediaType, "application/json", StringComparison.OrdinalIgnoreCase)
|
|
68
|
+
|| MediaType?.EndsWith("+json", StringComparison.OrdinalIgnoreCase) == true;
|
|
69
|
+
|
|
70
|
+
internal T? Read<T>()
|
|
71
|
+
{
|
|
72
|
+
try { return JsonSerializer.Deserialize<T>(Body, Json); }
|
|
73
|
+
catch (JsonException) { throw ProtocolFailure(); }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
internal T Require<T>() where T : notnull => Read<T>() is { } value ? value : throw ProtocolFailure();
|
|
77
|
+
|
|
78
|
+
internal InBizPlatformException ProtocolFailure() => new(InBizFailureKind.Protocol, Status);
|
|
79
|
+
|
|
80
|
+
internal InBizPlatformException BusinessFailure(int result, string? code = null, string? message = null) =>
|
|
81
|
+
new(InBizFailureKind.Business, Status, code, message, result);
|
|
82
|
+
|
|
83
|
+
internal AbpError? TryGetError()
|
|
84
|
+
{
|
|
85
|
+
try
|
|
86
|
+
{
|
|
87
|
+
var error = JsonSerializer.Deserialize<AbpErrorEnvelope>(Body, Json)?.Error;
|
|
88
|
+
return error is { Code: not null } or { Message: not null } ? error : null;
|
|
89
|
+
}
|
|
90
|
+
catch (JsonException) { return null; }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
internal sealed record AbpError(string? Code, string? Message);
|
|
95
|
+
private sealed record AbpErrorEnvelope(AbpError? Error);
|
|
96
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
namespace Macrowing.InBiz.SDK.Platform;
|
|
2
|
+
|
|
3
|
+
/// <summary>Application and authorized platform identity for one call. Never share a user's token with another caller.</summary>
|
|
4
|
+
public sealed class InBizRequestContext
|
|
5
|
+
{
|
|
6
|
+
/// <summary>Creates the context from an existing InBiz login or supported integration token.</summary>
|
|
7
|
+
/// <param name="appId">InBiz application ID, not a site version, display name or page route.</param>
|
|
8
|
+
/// <param name="token">Authorized InBiz token as issued, without a Bearer prefix.</param>
|
|
9
|
+
public InBizRequestContext(string appId, string token)
|
|
10
|
+
{
|
|
11
|
+
AppId = Validate(appId, nameof(appId));
|
|
12
|
+
Token = Validate(token, nameof(token));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// <summary>Application ID sent in the platform appId header.</summary>
|
|
16
|
+
public string AppId { get; }
|
|
17
|
+
|
|
18
|
+
internal string Token { get; }
|
|
19
|
+
|
|
20
|
+
private static string Validate(string value, string name)
|
|
21
|
+
{
|
|
22
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(value, name);
|
|
23
|
+
if (value.Any(c => c < '!' || c > '~') || value.Contains(','))
|
|
24
|
+
throw new ArgumentException("The value must be a single printable ASCII header value.", name);
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Macrowing.InBiz.SDK
|
|
2
|
+
|
|
3
|
+
用于出码后台调用 InBiz 引擎。按业务能力注入接口,不依赖前端 runtime、设计器或应用源码,也不用自己拼网关路径和凭据。
|
|
4
|
+
|
|
5
|
+
## 按场景选接口
|
|
6
|
+
|
|
7
|
+
目录名也是命名空间后缀,例如 `Macrowing.InBiz.SDK.Model`。
|
|
8
|
+
|
|
9
|
+
| 目录 | 注入接口 | 用途和原版路由 |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `Model` | `IModelClient` | `QueryAsync` 按发布查询器分页、筛选和排序:`POST v1/model/queryDatas`;`GetAsync` 按模型名称和记录 ID 查询:`POST v1/model/selectData`;`WriteAsync` 独立或关联模型批量增改删:`POST v1/model/data` |
|
|
12
|
+
| `Message` | `IMessageClient` | `GetTemplateAsync` 查模板渠道内容:`GET v1/message`;`SendAsync` 模板通知:`POST v1/message/send`;`SendManyAsync` 按接收组分别替换参数:`POST v1/message/sendMany`;`SendCustomAsync` 用应用配置的渠道发送自定义内容:`POST v1/message/sendCustom` |
|
|
13
|
+
| `InterfaceEngine` | `IInterfaceEngineClient` | `InvokeAsync` 按配置 Key 调用接口:`POST v1/apiEngineApp/invoke`;调用方不传目标 URL |
|
|
14
|
+
| `Dictionary` | `IDictionaryClient` | `GetGroupsAsync` 按分组 Key 批量读取选项:`GET front/modelengine/v3/dictData/groupIds/{appId}` |
|
|
15
|
+
| `Localization` | `ILocalizationClient` | `GetTextsAsync` 读取某个语言的业务词库:`GET languagengine/v3/language/json/{appId}?kindCode=…&type=0`;不混入设计器或组件词库 |
|
|
16
|
+
| `Permission` | `IPermissionClient` | `HasApplicationManagementAccessAsync` 应用管理:`GET v1/permission/haveAppPerm`;`GetMenuRoutesAsync` 菜单:`GET v1/permission/havePerm`;`GetModelButtonsAsync` 模型操作:`POST v1/permission/getButtonPerm` |
|
|
17
|
+
| `Cms` | `ICmsClient` | `GetCategoriesAsync` 分类:`GET cms/v3/cms/categoryTree/{parentId}`;`ListAsync` 列表:`GET cms/v3/cms/contentList`;`GetAsync` 详情:`GET cms/v3/cms/{id}/detailContentInfo` |
|
|
18
|
+
| `WorkFlow` | `IWorkFlowOperationsClient`、`IWorkFlowWorkbenchClient`、`IWorkFlowDetailsClient`、`IWorkFlowTrackingClient`、`IWorkFlowUpgradeClient` | 发起、办理、退回、终止、工作台、日志及流程图;升级仅供授权运维使用。参见 [WorkFlow 文档](WorkFlow/README.md) |
|
|
19
|
+
|
|
20
|
+
平台表中的相对路径均以网关的 `api/services/` 为前缀。旧的未实现门面 `IInBizPlatformClient` 已移除,改为注入对应领域接口。公开 API、参数和 DTO 字段的 XML 注释随 DLL 构建,IDE 悬浮可看用法;缺少公开注释或方法参数说明会使 SDK 编译失败。
|
|
21
|
+
|
|
22
|
+
## 快速接入
|
|
23
|
+
|
|
24
|
+
出码后台已通过 `InBizSdkModule` 注册。非 ABP 宿主引用本项目后,在已有 `IConfiguration` 的容器中调用 `services.AddInBizPlatform()`;需要流程时再调用 `services.AddInBizWorkFlow()`。
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"InBiz": {
|
|
29
|
+
"Platform": { "BaseUrl": "https://inbiz.example/inbiz/", "Timeout": "00:00:30" },
|
|
30
|
+
"WorkFlow": { "BaseUrl": "https://workflow.example/edoc2Flow-web/", "Timeout": "00:00:30" }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`BaseUrl` 填带部署路径的服务根地址,不填 Swagger 或单个接口。也可用环境变量 `InBiz__Platform__BaseUrl` 和 `InBiz__WorkFlow__BaseUrl`。每次平台调用都传真实应用 ID 和当前调用方的授权令牌;应用域名、站点 `OutId`、版本 ID 都不能代替应用 ID。流程使用独立的 `WorkFlowCredential`,不要混用两边的配置和凭据。部署时优先使用 HTTPS,不在配置、链接或日志中存放调用方令牌。
|
|
36
|
+
|
|
37
|
+
### 模型分页与详情
|
|
38
|
+
|
|
39
|
+
```csharp
|
|
40
|
+
using Macrowing.InBiz.SDK.Model;
|
|
41
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
42
|
+
|
|
43
|
+
// model 由 DI 注入;appId 和 token 来自宿主认可的应用与调用方上下文。
|
|
44
|
+
var context = new InBizRequestContext(appId, token);
|
|
45
|
+
var page = await model.QueryAsync(context, new ModelQuery("active-orders")
|
|
46
|
+
{
|
|
47
|
+
PageInfo = new(1, 20),
|
|
48
|
+
Conditions = [new(0, [new("Order", "Status", ModelOperator.Equal, "Open")])],
|
|
49
|
+
OrderInfo = [new("Order", "CreatedAt", Descending: true)]
|
|
50
|
+
}, cancellationToken);
|
|
51
|
+
var record = await model.GetAsync(context, "Order", orderId, cancellationToken);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
示例中的 Key、模型名、字段和 ID 都要换成应用的发布配置。`QueryAsync` 的空页和无模型结果 `null` 不等价。记录字段保留服务端原名、大小写和 JSON 类型。用 `ModelWrite.Data` 按模型名称分组;每行用 `ModelRowOperation` 声明动作,更新和删除提供 `id`。字段不传与显式传 `null` 不等价。关联写入用 `ModelRelation` 声明主子层级,主模型各行必须使用同一种显式操作;`Unchanged` 仅用于带真实主键的未改动非主模型行。写入返回引擎给出的记录 ID(如有),不是受影响记录清单。
|
|
55
|
+
|
|
56
|
+
### 消息通知
|
|
57
|
+
|
|
58
|
+
```csharp
|
|
59
|
+
using Macrowing.InBiz.SDK.Message;
|
|
60
|
+
|
|
61
|
+
// messages 由 DI 注入;使用专用测试用户验证发送,避免发给真实用户或组织组。
|
|
62
|
+
var channels = await messages.GetTemplateAsync(context, "order-ready", cancellationToken);
|
|
63
|
+
var accepted = await messages.SendAsync(context, new SendMessage(
|
|
64
|
+
"order-ready", [new MessageRecipient(recipientUserId)],
|
|
65
|
+
new Dictionary<string, string> { ["OrderId"] = orderId }), cancellationToken);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
按应用配置填模板 Key;自定义消息改用 `SendCustomAsync` 和渠道配置 Key,不是渠道数字。模板参数字典用 `OrderId`,模板或自定义正文里写 `{OrderId}`。消息接收组可能展开为多人。`false` 表示未接受,`true` 不是送达回执;不要在超时时盲目重发。
|
|
69
|
+
|
|
70
|
+
### 其他常用调用
|
|
71
|
+
|
|
72
|
+
```csharp
|
|
73
|
+
var options = await dictionaries.GetGroupsAsync(context, ["orderStatus"], "zh-cn", cancellationToken);
|
|
74
|
+
var texts = await localization.GetTextsAsync(context, "zh-cn", cancellationToken);
|
|
75
|
+
var menus = await permission.GetMenuRoutesAsync(context, siteOutId, ["/orders"], cancellationToken);
|
|
76
|
+
var categories = await cms.GetCategoriesAsync(context, CmsContentKind.News, cancellationToken: cancellationToken);
|
|
77
|
+
var response = await interfaces.InvokeAsync(context, new InterfaceInvocation(
|
|
78
|
+
"orders.lookup", Query: new Dictionary<string, object?> { ["id"] = orderId }), cancellationToken);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
字典的空分组可能不出现在返回对象中。菜单权限不是路由存在性、按钮权限或记录权限;按钮缺项不能视为授权。CMS 置顶内容单独返回,不与普通分页混合;CMS 客户端不下载文件。接口工厂可调用有副作用的操作,必须按配置的上游契约解释返回文本,不能把 SDK 请求成功当作上游业务成功。
|
|
82
|
+
|
|
83
|
+
## 失败与重试
|
|
84
|
+
|
|
85
|
+
`InBizPlatformException.Kind` 区分 HTTP 401/403、平台业务拒绝、其他 HTTP 错误和响应协议不符。`ErrorCode`/`Result` 用于判断业务原因;`PlatformMessage` 可能包含业务内容,不要无条件写日志。HTTP 403 不能直接解释为令牌过期。网络失败和取消保留 .NET 原异常。共享传输不自动跟随重定向,不共享 Cookie,不自动重试。取消或超时只结束本次等待,模型写入、消息发送或上游调用可能已经执行,应先查实际状态。
|
|
86
|
+
|
|
87
|
+
## 调研边界
|
|
88
|
+
|
|
89
|
+
实现按原版服务实现、网关路由与响应对照,不复制只用于展示 Swagger 的转发壳。组织能力有独立组织服务及 gRPC 契约,尚未确认应用侧目录查询所需的授权与部署入口,未在本包伪造接口。BI 的 SDK 模块没有确认可供应用使用的通用查询契约。应用导入发布、模型设计、字典和模板维护、权限写入属于管理面;环境变量的读取可能涉及密钥,不通过应用 SDK 暴露。文件下载与预览仍按 OC 或所属业务服务的契约处理。
|
|
90
|
+
|
|
91
|
+
## 验收
|
|
92
|
+
|
|
93
|
+
从后台模板根目录执行,默认使用 Kestrel 回环服务验证真实 HTTP 请求,不依赖任何内网账号,不写线上数据:
|
|
94
|
+
|
|
95
|
+
```powershell
|
|
96
|
+
dotnet test Macrowing.Scaffold.slnx -c Release
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
内网只读验收显式设置以下环境变量,然后执行:
|
|
100
|
+
|
|
101
|
+
```powershell
|
|
102
|
+
dotnet test tests/Macrowing.InBiz.SDK.Tests -c Release --filter 'Category=PlatformLive'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
下表所有设置名均以 `INBIZ_PLATFORM_` 开头。由调用方将短期测试令牌仅注入测试进程的 `INBIZ_PLATFORM_TOKEN`,不要提交到仓库或文档。
|
|
106
|
+
|
|
107
|
+
| 设置名后缀 | 用途 |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `LIVE=read-only`、`BASE_URL`、`APP_ID`、`TOKEN` | 启用验收、网关根地址、默认应用、授权令牌 |
|
|
110
|
+
| `SITE_OUT_ID`、`ALLOWED_ROUTES` | 站点 OutId 和允许访问的菜单路由,多个路由以逗号分隔;测试账号还须有应用管理权限 |
|
|
111
|
+
| `LANGUAGE`、`CMS_IMAGE_CATEGORY`、`CMS_IMAGE_CONTENT` | 平台语言代码和实际可读的图片分类及其内容 ID |
|
|
112
|
+
| `MODEL_QUERY_KEY`、`MODEL_NAME`、`MODEL_RECORD_ID`、`MODEL_PRIMARY_FIELD` | 可选的真实模型样本;需要时用 `MODEL_APP_ID` 覆盖应用 |
|
|
113
|
+
| `DICTIONARY_GROUP_KEY`、`DICTIONARY_VALUE` | 可选的字典样本;需要时用 `DICTIONARY_APP_ID` |
|
|
114
|
+
| `MESSAGE_TEMPLATE_KEY` | 可选的模板读取样本;需要时用 `MESSAGE_APP_ID` |
|
|
115
|
+
| `TRANSLATION_KEY`、`TRANSLATION_VALUE` | 可选的业务词条样本;需要时用 `LOCALIZATION_APP_ID` |
|
|
116
|
+
|
|
117
|
+
本轮在内网用 SDK 验证了模型分页和按 ID 取记录、模板渠道内容、字典选项、已发布词条、CMS 分类到详情、应用管理及菜单权限,以及未配置查询器、模型和接口的拒绝行为。模型写入、消息投递及接口工厂成功调用未在共享环境执行;回环契约通过不代表这些在线操作已经验收。流程写入验收独立,见 [WorkFlow 文档](WorkFlow/README.md)。
|
package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsClient.cs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
using System.Text.Json;
|
|
2
|
+
|
|
3
|
+
namespace Macrowing.InBiz.SDK.WorkFlow;
|
|
4
|
+
|
|
5
|
+
/// <summary>Read process form details before starting or for an existing task or instance.</summary>
|
|
6
|
+
public interface IWorkFlowDetailsClient
|
|
7
|
+
{
|
|
8
|
+
/// <summary>Loads form data and configuration for an existing workflow task or instance.</summary>
|
|
9
|
+
Task<WorkFlowResult<JsonElement?>> GetProcessDetailsAsync(WorkFlowCredential credential, WorkFlowDetailsQuery query, CancellationToken cancellationToken = default);
|
|
10
|
+
/// <summary>Loads the configured initiation form for a deployed definition without starting a process.</summary>
|
|
11
|
+
Task<WorkFlowResult<JsonElement?>> GetStartProcessDetailsAsync(WorkFlowCredential credential, WorkFlowDetailsQuery query, CancellationToken cancellationToken = default);
|
|
12
|
+
/// <summary>Returns whether the instance definition uses the engine's new-style process attributes.</summary>
|
|
13
|
+
Task<WorkFlowResult<bool?>> UsesNewProcessAttributesAsync(WorkFlowCredential credential, string processInstanceId, CancellationToken cancellationToken = default);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
internal sealed class WorkFlowDetailsClient(WorkFlowTransport transport) : IWorkFlowDetailsClient
|
|
17
|
+
{
|
|
18
|
+
private const string Prefix = "process/getResults/";
|
|
19
|
+
|
|
20
|
+
public Task<WorkFlowResult<JsonElement?>> GetProcessDetailsAsync(WorkFlowCredential credential, WorkFlowDetailsQuery query, CancellationToken cancellationToken) =>
|
|
21
|
+
Get<JsonElement?>(credential, "getProcessDetails", cancellationToken, DetailsQuery(query));
|
|
22
|
+
|
|
23
|
+
public Task<WorkFlowResult<JsonElement?>> GetStartProcessDetailsAsync(WorkFlowCredential credential, WorkFlowDetailsQuery query, CancellationToken cancellationToken) =>
|
|
24
|
+
Get<JsonElement?>(credential, "getInitProcessDetails", cancellationToken, DetailsQuery(query with { InitiateApplication = true }));
|
|
25
|
+
|
|
26
|
+
public Task<WorkFlowResult<bool?>> UsesNewProcessAttributesAsync(WorkFlowCredential credential, string processInstanceId, CancellationToken cancellationToken) =>
|
|
27
|
+
Get<bool?>(credential, "getProcessType", cancellationToken, [("processInstanceId", processInstanceId)]);
|
|
28
|
+
|
|
29
|
+
private Task<WorkFlowResult<T>> Get<T>(WorkFlowCredential credential, string action, CancellationToken cancellationToken,
|
|
30
|
+
(string Name, object? Value)[] query) => transport.GetResultAsync<T>(credential, HttpMethod.Get, Prefix + action, cancellationToken, query);
|
|
31
|
+
|
|
32
|
+
private static (string Name, object? Value)[] DetailsQuery(WorkFlowDetailsQuery query) =>
|
|
33
|
+
[("taskIds", query.TaskIds), ("processInstanceId", query.ProcessInstanceId), ("processDefinitionId", query.ProcessDefinitionId),
|
|
34
|
+
("inItiateApplication", query.InitiateApplication), ("siteType", query.SiteType), ("groupId", query.GroupId), ("processMark", query.ProcessMark)];
|
|
35
|
+
}
|
package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsQuery.cs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
namespace Macrowing.InBiz.SDK.WorkFlow;
|
|
2
|
+
|
|
3
|
+
/// <summary>Identifies the process form and its site context.</summary>
|
|
4
|
+
public sealed record WorkFlowDetailsQuery
|
|
5
|
+
{
|
|
6
|
+
/// <summary>One task ID or multiple comma-delimited task IDs.</summary>
|
|
7
|
+
public string? TaskIds { get; init; }
|
|
8
|
+
/// <summary>Existing workflow instance to load, when starting from an instance rather than task IDs.</summary>
|
|
9
|
+
public string? ProcessInstanceId { get; init; }
|
|
10
|
+
/// <summary>Exact deployed definition ID, used when opening a start form.</summary>
|
|
11
|
+
public string? ProcessDefinitionId { get; init; }
|
|
12
|
+
/// <summary>Requests initiation mode; the start-details method sets this automatically.</summary>
|
|
13
|
+
public bool InitiateApplication { get; init; }
|
|
14
|
+
/// <summary>Site type supplied by the workflow caller, when required.</summary>
|
|
15
|
+
public int? SiteType { get; init; }
|
|
16
|
+
/// <summary>Workflow group ID, when needed to resolve the form context.</summary>
|
|
17
|
+
public string? GroupId { get; init; }
|
|
18
|
+
/// <summary>Optional workflow process mark supplied by the host application.</summary>
|
|
19
|
+
public string? ProcessMark { get; init; }
|
|
20
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
using System.Text.Json;
|
|
2
|
+
using System.Text.Json.Serialization;
|
|
3
|
+
|
|
4
|
+
namespace Macrowing.InBiz.SDK.WorkFlow;
|
|
5
|
+
|
|
6
|
+
/// <summary>Common metadata sent with a workflow operation.</summary>
|
|
7
|
+
public abstract record WorkFlowOperation
|
|
8
|
+
{
|
|
9
|
+
/// <summary>Optional business summary shown in workflow views.</summary>
|
|
10
|
+
public string? Summary { get; init; }
|
|
11
|
+
/// <summary>Optional signature data in the format expected by the engine.</summary>
|
|
12
|
+
public string? SignDataStr { get; init; }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// <summary>Starts a deployed process definition.</summary>
|
|
16
|
+
/// <param name="Starter">Organization user ID of the initiator.</param>
|
|
17
|
+
public sealed record StartProcessRequest(string Starter) : WorkFlowOperation
|
|
18
|
+
{
|
|
19
|
+
/// <summary>Exact deployed definition ID. Required when setting a business key.</summary>
|
|
20
|
+
public string? ProcessDefinitionId { get; init; }
|
|
21
|
+
/// <summary>Definition key used when no exact definition ID is supplied.</summary>
|
|
22
|
+
public string? ProcessKey { get; init; }
|
|
23
|
+
/// <summary>Optional external business record key; requires <see cref="ProcessDefinitionId"/>.</summary>
|
|
24
|
+
public string? BusinessKey { get; init; }
|
|
25
|
+
/// <summary>Process variables supplied when starting the instance.</summary>
|
|
26
|
+
[JsonIgnore]
|
|
27
|
+
public IReadOnlyList<WorkFlowVariable>? Variables { get; init; }
|
|
28
|
+
[JsonInclude, JsonPropertyName("variablesParams")]
|
|
29
|
+
internal string? VariablesParams => WorkFlowVariable.Encode(Variables);
|
|
30
|
+
/// <summary>Optional engine-specific custom node selection.</summary>
|
|
31
|
+
public string? CustomNode { get; init; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// <summary>Submits a decision on a pending workflow task.</summary>
|
|
35
|
+
/// <param name="TaskId">Pending task ID, not a process instance ID.</param>
|
|
36
|
+
public sealed record CompleteTaskRequest(string TaskId) : WorkFlowOperation
|
|
37
|
+
{
|
|
38
|
+
/// <summary>Decision comment to store in workflow history.</summary>
|
|
39
|
+
public string? Comment { get; init; }
|
|
40
|
+
/// <summary>Process variables submitted with the decision.</summary>
|
|
41
|
+
[JsonIgnore]
|
|
42
|
+
public IReadOnlyList<WorkFlowVariable>? Variables { get; init; }
|
|
43
|
+
[JsonInclude, JsonPropertyName("variablesParams")]
|
|
44
|
+
internal string? VariablesParams => WorkFlowVariable.Encode(Variables);
|
|
45
|
+
/// <summary>Requests the engine's refusal outcome instead of ordinary completion.</summary>
|
|
46
|
+
[JsonPropertyName("isrefuse")]
|
|
47
|
+
public bool IsRefuse { get; init; }
|
|
48
|
+
/// <summary>Optional engine-specific custom node selection.</summary>
|
|
49
|
+
public string? CustomNode { get; init; }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// <summary>A text variable sent in the workflow engine's variables payload.</summary>
|
|
53
|
+
/// <param name="Name">Variable name defined by the process.</param>
|
|
54
|
+
/// <param name="Value">Value in the text format expected by the process.</param>
|
|
55
|
+
public sealed record WorkFlowVariable(
|
|
56
|
+
[property: JsonPropertyName("name")] string Name,
|
|
57
|
+
[property: JsonPropertyName("value")] string Value)
|
|
58
|
+
{
|
|
59
|
+
// The engine expects a JSON string containing the variable array.
|
|
60
|
+
internal static string? Encode(IReadOnlyList<WorkFlowVariable>? variables) =>
|
|
61
|
+
variables is null ? null : JsonSerializer.Serialize(variables);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// <summary>Return behavior for a pending workflow task.</summary>
|
|
65
|
+
public enum WorkFlowReturnTarget
|
|
66
|
+
{
|
|
67
|
+
/// <summary>Return to the previous step.</summary>
|
|
68
|
+
PreviousStep,
|
|
69
|
+
/// <summary>Return to the workflow initiator.</summary>
|
|
70
|
+
Originator,
|
|
71
|
+
/// <summary>Return to the initiator for revision.</summary>
|
|
72
|
+
OriginatorForRevision
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// <summary>Returns a pending workflow task to a previous step or to its initiator.</summary>
|
|
76
|
+
/// <param name="TaskId">Pending task ID.</param>
|
|
77
|
+
/// <param name="ReturnTarget">How the workflow engine should route the returned task.</param>
|
|
78
|
+
public sealed record ReturnTaskRequest(string TaskId, [property: JsonIgnore] WorkFlowReturnTarget ReturnTarget) : WorkFlowOperation
|
|
79
|
+
{
|
|
80
|
+
/// <summary>Return reason to store in workflow history.</summary>
|
|
81
|
+
public string? Comment { get; init; }
|
|
82
|
+
|
|
83
|
+
[JsonInclude, JsonPropertyName("retrunType")]
|
|
84
|
+
internal string EngineReturnType => ReturnTarget switch
|
|
85
|
+
{
|
|
86
|
+
WorkFlowReturnTarget.PreviousStep => "previousStep",
|
|
87
|
+
WorkFlowReturnTarget.Originator => "sponsor",
|
|
88
|
+
WorkFlowReturnTarget.OriginatorForRevision => "initiatorModif",
|
|
89
|
+
_ => throw new ArgumentOutOfRangeException(nameof(ReturnTarget))
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// <summary>Terminates an active process instance.</summary>
|
|
94
|
+
/// <param name="ProcessInstanceId">Instance to stop.</param>
|
|
95
|
+
public sealed record StopProcessRequest(string ProcessInstanceId) : WorkFlowOperation
|
|
96
|
+
{
|
|
97
|
+
/// <summary>Associated active task ID, when required by the caller's stop path.</summary>
|
|
98
|
+
public string? TaskId { get; init; }
|
|
99
|
+
/// <summary>Optional callback setting accepted by the workflow engine.</summary>
|
|
100
|
+
public string? Callback { get; init; }
|
|
101
|
+
/// <summary>Termination reason to store in workflow history.</summary>
|
|
102
|
+
public string? Comment { get; init; }
|
|
103
|
+
/// <summary>Requests management mode; the server still enforces authorization.</summary>
|
|
104
|
+
public bool? Manage { get; init; }
|
|
105
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
using System.Text.Json;
|
|
2
|
+
|
|
3
|
+
namespace Macrowing.InBiz.SDK.WorkFlow;
|
|
4
|
+
|
|
5
|
+
/// <summary>Start a process and act on its tasks.</summary>
|
|
6
|
+
public interface IWorkFlowOperationsClient
|
|
7
|
+
{
|
|
8
|
+
/// <summary>Starts a process and returns the new process instance ID.</summary>
|
|
9
|
+
Task<WorkFlowResult<string>> StartProcessAsync(WorkFlowCredential credential, StartProcessRequest request, CancellationToken cancellationToken = default);
|
|
10
|
+
/// <summary>Completes or refuses a pending task, updating the process and its history.</summary>
|
|
11
|
+
Task<WorkFlowResult<JsonElement?>> CompleteTaskAsync(WorkFlowCredential credential, CompleteTaskRequest request, CancellationToken cancellationToken = default);
|
|
12
|
+
/// <summary>Returns a pending task and lets the engine create or reassign tasks for the return target.</summary>
|
|
13
|
+
Task<WorkFlowResult<JsonElement?>> ReturnTaskAsync(WorkFlowCredential credential, ReturnTaskRequest request, CancellationToken cancellationToken = default);
|
|
14
|
+
/// <summary>Terminates the instance and closes its active tasks.</summary>
|
|
15
|
+
Task<WorkFlowResult<JsonElement?>> StopProcessAsync(WorkFlowCredential credential, StopProcessRequest request, CancellationToken cancellationToken = default);
|
|
16
|
+
/// <summary>Checks whether the process allows drafts; does not save a draft.</summary>
|
|
17
|
+
Task<bool> CanSaveDraftAsync(WorkFlowCredential credential, string processId, CancellationToken cancellationToken = default);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
internal sealed class WorkFlowOperationsClient(WorkFlowTransport transport) : IWorkFlowOperationsClient
|
|
21
|
+
{
|
|
22
|
+
private const string Prefix = "process/operation/";
|
|
23
|
+
|
|
24
|
+
public Task<WorkFlowResult<string>> StartProcessAsync(WorkFlowCredential credential, StartProcessRequest request, CancellationToken cancellationToken)
|
|
25
|
+
{
|
|
26
|
+
ArgumentNullException.ThrowIfNull(request);
|
|
27
|
+
if (string.IsNullOrWhiteSpace(request.ProcessDefinitionId)
|
|
28
|
+
&& (string.IsNullOrWhiteSpace(request.ProcessKey) || !string.IsNullOrWhiteSpace(request.BusinessKey)))
|
|
29
|
+
{
|
|
30
|
+
throw new ArgumentException("Provide a process definition ID, or a process key without a business key.", nameof(request));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return Post<string>(credential, "initiatingProcess", request, cancellationToken);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public Task<WorkFlowResult<JsonElement?>> CompleteTaskAsync(WorkFlowCredential credential, CompleteTaskRequest request, CancellationToken cancellationToken) =>
|
|
37
|
+
Post<JsonElement?>(credential, "processCompletion", request, cancellationToken);
|
|
38
|
+
|
|
39
|
+
public Task<WorkFlowResult<JsonElement?>> ReturnTaskAsync(WorkFlowCredential credential, ReturnTaskRequest request, CancellationToken cancellationToken) =>
|
|
40
|
+
Post<JsonElement?>(credential, "processReturn", request, cancellationToken);
|
|
41
|
+
|
|
42
|
+
public Task<WorkFlowResult<JsonElement?>> StopProcessAsync(WorkFlowCredential credential, StopProcessRequest request, CancellationToken cancellationToken) =>
|
|
43
|
+
Post<JsonElement?>(credential, "processStop", request, cancellationToken);
|
|
44
|
+
|
|
45
|
+
public Task<bool> CanSaveDraftAsync(WorkFlowCredential credential, string processId, CancellationToken cancellationToken) =>
|
|
46
|
+
transport.GetValueAsync<bool>(credential, Prefix + "getIsDrafts", JsonValueKind.True, cancellationToken, [("processId", processId)]);
|
|
47
|
+
|
|
48
|
+
private Task<WorkFlowResult<T>> Post<T>(WorkFlowCredential credential, string action, WorkFlowOperation request, CancellationToken cancellationToken)
|
|
49
|
+
{
|
|
50
|
+
ArgumentNullException.ThrowIfNull(request);
|
|
51
|
+
return transport.GetResultAsync<T>(credential, HttpMethod.Post, Prefix + action, cancellationToken, body: request);
|
|
52
|
+
}
|
|
53
|
+
}
|