@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,16 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<RootNamespace>Macrowing.InBiz.SDK</RootNamespace>
|
|
5
|
+
<AssemblyName>Macrowing.InBiz.SDK</AssemblyName>
|
|
6
|
+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
|
7
|
+
<NoWarn>$(NoWarn.Replace('CS1591', ''))</NoWarn>
|
|
8
|
+
<WarningsAsErrors>$(WarningsAsErrors);CS1591;CS1573</WarningsAsErrors>
|
|
9
|
+
</PropertyGroup>
|
|
10
|
+
|
|
11
|
+
<ItemGroup>
|
|
12
|
+
<PackageReference Include="Volo.Abp.Core" />
|
|
13
|
+
<PackageReference Include="Microsoft.Extensions.Http" />
|
|
14
|
+
</ItemGroup>
|
|
15
|
+
|
|
16
|
+
</Project>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
2
|
+
|
|
3
|
+
namespace Macrowing.InBiz.SDK.Message;
|
|
4
|
+
|
|
5
|
+
/// <summary>Looks up configured message templates and submits sends through the platform's configured channels.</summary>
|
|
6
|
+
public interface IMessageClient
|
|
7
|
+
{
|
|
8
|
+
/// <summary>Reads the configured content of each channel for a template.</summary>
|
|
9
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
10
|
+
/// <param name="templateKey">Template key in the application.</param>
|
|
11
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
12
|
+
/// <returns>Channel contents, or an empty list if none exist.</returns>
|
|
13
|
+
Task<IReadOnlyList<MessageTemplateContent>> GetTemplateAsync(InBizRequestContext context, string templateKey,
|
|
14
|
+
CancellationToken cancellationToken = default);
|
|
15
|
+
|
|
16
|
+
/// <summary>Sends one template with shared substitutions to the specified recipients. Does not retry.</summary>
|
|
17
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
18
|
+
/// <param name="request">Template, recipients and substitution values.</param>
|
|
19
|
+
/// <param name="cancellationToken">Cancels waiting, not an already-submitted message.</param>
|
|
20
|
+
/// <returns>The server's acceptance flag, not a delivery receipt. False is not success.</returns>
|
|
21
|
+
Task<bool> SendAsync(InBizRequestContext context, SendMessage request, CancellationToken cancellationToken = default);
|
|
22
|
+
|
|
23
|
+
/// <summary>Sends the same template with separate substitutions for multiple recipient groups. Does not retry.</summary>
|
|
24
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
25
|
+
/// <param name="request">Template and recipient groups.</param>
|
|
26
|
+
/// <param name="cancellationToken">Cancels waiting, not an already-submitted batch.</param>
|
|
27
|
+
/// <returns>The server's acceptance flag, not a delivery receipt for any recipient.</returns>
|
|
28
|
+
Task<bool> SendManyAsync(InBizRequestContext context, SendManyMessages request, CancellationToken cancellationToken = default);
|
|
29
|
+
|
|
30
|
+
/// <summary>Sends custom content without a template, through an application-configured channel. Does not retry.</summary>
|
|
31
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
32
|
+
/// <param name="request">Channel key, recipients, title and body.</param>
|
|
33
|
+
/// <param name="cancellationToken">Cancels waiting, not an already-submitted message.</param>
|
|
34
|
+
/// <returns>The server's acceptance flag, not a delivery receipt. False is not success.</returns>
|
|
35
|
+
Task<bool> SendCustomAsync(InBizRequestContext context, SendCustomMessage request, CancellationToken cancellationToken = default);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
internal sealed class MessageClient(InBizPlatformTransport transport) : IMessageClient
|
|
39
|
+
{
|
|
40
|
+
private const string Prefix = InBizPlatformTransport.PublicApi + "message";
|
|
41
|
+
|
|
42
|
+
public async Task<IReadOnlyList<MessageTemplateContent>> GetTemplateAsync(InBizRequestContext context,
|
|
43
|
+
string templateKey, CancellationToken cancellationToken)
|
|
44
|
+
{
|
|
45
|
+
var reply = await transport.SendAsync(context, HttpMethod.Get,
|
|
46
|
+
Prefix + "?key=" + InBizPlatformTransport.QueryValue(templateKey), cancellationToken).ConfigureAwait(false);
|
|
47
|
+
return reply.Require<IReadOnlyList<MessageTemplateContent>>();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async Task<bool> SendAsync(InBizRequestContext context, SendMessage request, CancellationToken cancellationToken)
|
|
51
|
+
{
|
|
52
|
+
ArgumentNullException.ThrowIfNull(request);
|
|
53
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(request.TemplateKey);
|
|
54
|
+
ValidateRecipients(request.MemberModels);
|
|
55
|
+
var reply = await transport.SendAsync(context, HttpMethod.Post, Prefix + "/send", cancellationToken, request).ConfigureAwait(false);
|
|
56
|
+
return reply.Require<bool>();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public async Task<bool> SendManyAsync(InBizRequestContext context, SendManyMessages request, CancellationToken cancellationToken)
|
|
60
|
+
{
|
|
61
|
+
ArgumentNullException.ThrowIfNull(context);
|
|
62
|
+
ArgumentNullException.ThrowIfNull(request);
|
|
63
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(request.TemplateKey);
|
|
64
|
+
if (request.MemberParas is not { Count: > 0 })
|
|
65
|
+
throw new ArgumentException("At least one recipient group is required.", nameof(request));
|
|
66
|
+
foreach (var group in request.MemberParas)
|
|
67
|
+
{
|
|
68
|
+
ArgumentNullException.ThrowIfNull(group);
|
|
69
|
+
ValidateRecipients(group.MemberModels);
|
|
70
|
+
}
|
|
71
|
+
// Unlike /send, the original batch DTO binds AppId and Token from its JSON body.
|
|
72
|
+
var reply = await transport.SendAsync(context, HttpMethod.Post, Prefix + "/sendMany", cancellationToken,
|
|
73
|
+
new { context.AppId, context.Token, request.TemplateKey, request.MemberParas, request.UniqueKey, request.UserId }).ConfigureAwait(false);
|
|
74
|
+
return reply.Require<bool>();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async Task<bool> SendCustomAsync(InBizRequestContext context, SendCustomMessage request, CancellationToken cancellationToken)
|
|
78
|
+
{
|
|
79
|
+
ArgumentNullException.ThrowIfNull(request);
|
|
80
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(request.MsgCategoryKey);
|
|
81
|
+
ValidateRecipients(request.MemberModels);
|
|
82
|
+
var reply = await transport.SendAsync(context, HttpMethod.Post, Prefix + "/sendCustom",
|
|
83
|
+
cancellationToken, request).ConfigureAwait(false);
|
|
84
|
+
return reply.Require<bool>();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private static void ValidateRecipients(IReadOnlyList<MessageRecipient> recipients)
|
|
88
|
+
{
|
|
89
|
+
if (recipients is not { Count: > 0 })
|
|
90
|
+
throw new ArgumentException("At least one recipient is required.", nameof(recipients));
|
|
91
|
+
foreach (var recipient in recipients)
|
|
92
|
+
{
|
|
93
|
+
ArgumentNullException.ThrowIfNull(recipient);
|
|
94
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(recipient.MemberId);
|
|
95
|
+
if (!Enum.IsDefined(recipient.MemberType))
|
|
96
|
+
throw new ArgumentOutOfRangeException(nameof(recipients), "Unknown recipient type.");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
namespace Macrowing.InBiz.SDK.Message;
|
|
2
|
+
|
|
3
|
+
/// <summary>Organization member types supported by the message engine.</summary>
|
|
4
|
+
public enum MessageMemberType
|
|
5
|
+
{
|
|
6
|
+
/// <summary>Individual organization user.</summary>
|
|
7
|
+
User = 0,
|
|
8
|
+
/// <summary>Organization group.</summary>
|
|
9
|
+
Group = 3,
|
|
10
|
+
/// <summary>Organization position.</summary>
|
|
11
|
+
Position = 4,
|
|
12
|
+
/// <summary>Organization department.</summary>
|
|
13
|
+
Department = 5
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/// <summary>An organization recipient to be resolved by the message engine.</summary>
|
|
17
|
+
/// <param name="MemberId">Organization member ID, not the display name or login name.</param>
|
|
18
|
+
/// <param name="MemberType">Kind of organization member.</param>
|
|
19
|
+
public sealed record MessageRecipient(string MemberId, MessageMemberType MemberType = MessageMemberType.User);
|
|
20
|
+
|
|
21
|
+
/// <summary>Submit a configured template with the same values for every recipient.</summary>
|
|
22
|
+
/// <param name="TemplateKey">Template key in the application.</param>
|
|
23
|
+
/// <param name="MemberModels">Recipients. Groups, departments and positions can resolve to multiple users.</param>
|
|
24
|
+
/// <param name="Parameter">Template substitution values keyed by placeholder name, without braces.</param>
|
|
25
|
+
/// <param name="UniqueKey">Optional engine key for non-repeat sends; omit for ordinary notifications.</param>
|
|
26
|
+
/// <param name="UserId">Optional sender user ID, subject to the server's identity and sender rules.</param>
|
|
27
|
+
public sealed record SendMessage(string TemplateKey, IReadOnlyList<MessageRecipient> MemberModels,
|
|
28
|
+
IReadOnlyDictionary<string, string>? Parameter = null, string? UniqueKey = null, string? UserId = null);
|
|
29
|
+
|
|
30
|
+
/// <summary>Submit a configured template with recipient-specific parameter sets.</summary>
|
|
31
|
+
/// <param name="TemplateKey">Template key in the application.</param>
|
|
32
|
+
/// <param name="MemberParas">Groups with separate recipients and substitutions.</param>
|
|
33
|
+
/// <param name="UniqueKey">Optional engine key for non-repeat sends; omit for ordinary notifications.</param>
|
|
34
|
+
/// <param name="UserId">Optional sender user ID, subject to the server's identity and sender rules.</param>
|
|
35
|
+
public sealed record SendManyMessages(string TemplateKey, IReadOnlyList<MessageRecipientGroup> MemberParas,
|
|
36
|
+
string? UniqueKey = null, string? UserId = null);
|
|
37
|
+
|
|
38
|
+
/// <summary>One group of recipients that shares a set of template substitutions.</summary>
|
|
39
|
+
/// <param name="MemberModels">Recipients for this substitution set.</param>
|
|
40
|
+
/// <param name="Parameter">Substitution values keyed by placeholder name, without braces.</param>
|
|
41
|
+
public sealed record MessageRecipientGroup(IReadOnlyList<MessageRecipient> MemberModels,
|
|
42
|
+
IReadOnlyDictionary<string, string>? Parameter = null);
|
|
43
|
+
|
|
44
|
+
/// <summary>Submit an application-configured notification channel with caller-provided title and content.</summary>
|
|
45
|
+
/// <param name="MsgCategoryKey">Configured application channel key, not a channel number or a template key.</param>
|
|
46
|
+
/// <param name="MemberModels">Organization recipients. A group may expand to several users.</param>
|
|
47
|
+
/// <param name="MsgTitle">Title to send. The engine does not substitute placeholders in the title.</param>
|
|
48
|
+
/// <param name="Content">Message body. The engine applies substitutions to this value.</param>
|
|
49
|
+
/// <param name="Parameter">Optional body substitutions keyed by placeholder name, without braces.</param>
|
|
50
|
+
/// <param name="UserId">Optional sender user ID, subject to the server's identity and sender rules.</param>
|
|
51
|
+
public sealed record SendCustomMessage(string MsgCategoryKey, IReadOnlyList<MessageRecipient> MemberModels,
|
|
52
|
+
string MsgTitle, string Content, IReadOnlyDictionary<string, string>? Parameter = null, string? UserId = null);
|
|
53
|
+
|
|
54
|
+
/// <summary>The content configured for one channel of a template. Values have not been substituted.</summary>
|
|
55
|
+
/// <param name="Id">Template content record ID.</param>
|
|
56
|
+
/// <param name="TemplateKey">Template key.</param>
|
|
57
|
+
/// <param name="Category">Platform channel code: 1 WeCom, 2 DingTalk, 3 email, 4 SMS, 5 in-app. Other values are preserved.</param>
|
|
58
|
+
/// <param name="Title">Configured title.</param>
|
|
59
|
+
/// <param name="Content">Configured body, which may include template placeholders or markup.</param>
|
|
60
|
+
/// <param name="LinkUrl">Configured destination link, if supplied.</param>
|
|
61
|
+
/// <param name="GroupKey">Message group key.</param>
|
|
62
|
+
public sealed record MessageTemplateContent(string? Id, string? TemplateKey, int Category, string? Title, string? Content,
|
|
63
|
+
[property: System.Text.Json.Serialization.JsonPropertyName("linkurl")] string? LinkUrl, string? GroupKey);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
using System.Net;
|
|
2
|
+
using System.Text.Json;
|
|
3
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
4
|
+
|
|
5
|
+
namespace Macrowing.InBiz.SDK.Model;
|
|
6
|
+
|
|
7
|
+
/// <summary>Reads and writes data in published models. Does not manage model definitions or permissions.</summary>
|
|
8
|
+
public interface IModelClient
|
|
9
|
+
{
|
|
10
|
+
/// <summary>Queries a published model-backed query definition. A non-model source may return no result.</summary>
|
|
11
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
12
|
+
/// <param name="query">Published query key, filters, sorting and pagination.</param>
|
|
13
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
14
|
+
/// <returns>A model page (including empty pages), or null if the engine returned no model result.</returns>
|
|
15
|
+
Task<ModelQueryResult?> QueryAsync(InBizRequestContext context, ModelQuery query, CancellationToken cancellationToken = default);
|
|
16
|
+
|
|
17
|
+
/// <summary>Reads one record from a published model by ID, including fields joined by the model engine.</summary>
|
|
18
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
19
|
+
/// <param name="modelName">Published model name.</param>
|
|
20
|
+
/// <param name="id">Record ID. Missing records are reported as platform errors.</param>
|
|
21
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
22
|
+
/// <returns>Record fields with original JSON types and names.</returns>
|
|
23
|
+
Task<IReadOnlyDictionary<string, JsonElement>> GetAsync(InBizRequestContext context, string modelName, string id,
|
|
24
|
+
CancellationToken cancellationToken = default);
|
|
25
|
+
|
|
26
|
+
/// <summary>Applies a batch of inserts, updates and deletes. The SDK does not retry writes.</summary>
|
|
27
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
28
|
+
/// <param name="write">Rows and their operations, with an optional relationship tree.</param>
|
|
29
|
+
/// <param name="cancellationToken">Cancels waiting; this does not roll back a submitted write.</param>
|
|
30
|
+
/// <returns>The record ID returned by the engine, if any. This is not a list of affected rows.</returns>
|
|
31
|
+
Task<string?> WriteAsync(InBizRequestContext context, ModelWrite write, CancellationToken cancellationToken = default);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
internal sealed class ModelClient(InBizPlatformTransport transport) : IModelClient
|
|
35
|
+
{
|
|
36
|
+
private const string Prefix = InBizPlatformTransport.PublicApi + "model/";
|
|
37
|
+
|
|
38
|
+
public async Task<ModelQueryResult?> QueryAsync(InBizRequestContext context, ModelQuery query, CancellationToken cancellationToken)
|
|
39
|
+
{
|
|
40
|
+
ArgumentNullException.ThrowIfNull(query);
|
|
41
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(query.Key);
|
|
42
|
+
if (query.PageInfo is { } page && (page.Index < 1 || page.Size < 1))
|
|
43
|
+
throw new ArgumentOutOfRangeException(nameof(query), "Page index and size must both be positive.");
|
|
44
|
+
var body = new
|
|
45
|
+
{
|
|
46
|
+
query.Key, query.PageInfo, query.Conditions, query.LazyModel, query.DropDownList,
|
|
47
|
+
OrderInfo = query.OrderInfo?.Select(sort => new { sort.ModelName, sort.FieldName, sort.Order, SortType = sort.Descending ? "desc" : "asc" })
|
|
48
|
+
};
|
|
49
|
+
var reply = await transport.SendAsync(context, HttpMethod.Post, Prefix + "queryDatas", cancellationToken, body).ConfigureAwait(false);
|
|
50
|
+
var result = reply.Status == HttpStatusCode.NoContent ? null : reply.Read<QueryReply>();
|
|
51
|
+
if (result is null)
|
|
52
|
+
return null;
|
|
53
|
+
if (result.Success is not int success)
|
|
54
|
+
throw reply.ProtocolFailure();
|
|
55
|
+
if (success != 0)
|
|
56
|
+
throw reply.BusinessFailure(success);
|
|
57
|
+
if (result.Total is not long total || result.Rows is null)
|
|
58
|
+
throw reply.ProtocolFailure();
|
|
59
|
+
return new(total, result.Rows, result.Primary, result.RelationField);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public async Task<IReadOnlyDictionary<string, JsonElement>> GetAsync(InBizRequestContext context, string modelName, string id,
|
|
63
|
+
CancellationToken cancellationToken)
|
|
64
|
+
{
|
|
65
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(modelName);
|
|
66
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(id);
|
|
67
|
+
var reply = await transport.SendAsync(context, HttpMethod.Post, Prefix + "selectData", cancellationToken,
|
|
68
|
+
new { ModelName = modelName, Id = id }).ConfigureAwait(false);
|
|
69
|
+
return reply.Require<Dictionary<string, JsonElement>>();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public async Task<string?> WriteAsync(InBizRequestContext context, ModelWrite write, CancellationToken cancellationToken)
|
|
73
|
+
{
|
|
74
|
+
ArgumentNullException.ThrowIfNull(write);
|
|
75
|
+
ArgumentNullException.ThrowIfNull(write.Data);
|
|
76
|
+
if (write.Data.Count == 0)
|
|
77
|
+
throw new ArgumentException("At least one model is required.", nameof(write));
|
|
78
|
+
|
|
79
|
+
if (write.Relation is { } relation)
|
|
80
|
+
{
|
|
81
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(relation.Name);
|
|
82
|
+
if (!write.Data.TryGetValue(relation.Name, out var master) || master is not { Count: > 0 } ||
|
|
83
|
+
master[0] is null || master[0].Operation == ModelRowOperation.Unchanged ||
|
|
84
|
+
master.Any(row => row is null || row.Operation != master[0].Operation))
|
|
85
|
+
throw new ArgumentException("A relationship write needs master rows with the same explicit operation.", nameof(write));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var data = write.Data.ToDictionary(model => model.Key, model =>
|
|
89
|
+
{
|
|
90
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(model.Key);
|
|
91
|
+
if (model.Value is not { Count: > 0 })
|
|
92
|
+
throw new ArgumentException("Each model must include at least one row.", nameof(write));
|
|
93
|
+
return model.Value.Select(ToWireRow).ToArray();
|
|
94
|
+
}, StringComparer.Ordinal);
|
|
95
|
+
var reply = await transport.SendAsync(context, HttpMethod.Post, Prefix + "data", cancellationToken,
|
|
96
|
+
new { write.Relation, Data = data }).ConfigureAwait(false);
|
|
97
|
+
var result = reply.Require<WriteReply>();
|
|
98
|
+
if (result.Result is not int status)
|
|
99
|
+
throw reply.ProtocolFailure();
|
|
100
|
+
if (status != 0)
|
|
101
|
+
throw reply.BusinessFailure(status, result.Code, result.Message);
|
|
102
|
+
return result.Data;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private static Dictionary<string, object?> ToWireRow(ModelRowChange row)
|
|
106
|
+
{
|
|
107
|
+
ArgumentNullException.ThrowIfNull(row);
|
|
108
|
+
ArgumentNullException.ThrowIfNull(row.Fields);
|
|
109
|
+
var fields = new Dictionary<string, object?>(row.Fields, StringComparer.Ordinal);
|
|
110
|
+
if (fields.ContainsKey("_opt"))
|
|
111
|
+
throw new ArgumentException("Set the model row operation through Operation, not the reserved _opt field.", nameof(row));
|
|
112
|
+
if (row.Operation is ModelRowOperation.Update or ModelRowOperation.Delete &&
|
|
113
|
+
(!fields.TryGetValue("id", out var id) || id is null || string.IsNullOrWhiteSpace(id.ToString())))
|
|
114
|
+
throw new ArgumentException("Updates and deletes require the platform's id field.", nameof(row));
|
|
115
|
+
var operation = row.Operation switch
|
|
116
|
+
{
|
|
117
|
+
ModelRowOperation.Insert => "add",
|
|
118
|
+
ModelRowOperation.Update => "edit",
|
|
119
|
+
ModelRowOperation.Delete => "del",
|
|
120
|
+
ModelRowOperation.Unchanged => null,
|
|
121
|
+
_ => throw new ArgumentOutOfRangeException(nameof(row))
|
|
122
|
+
};
|
|
123
|
+
if (operation is not null)
|
|
124
|
+
fields.Add("_opt", operation);
|
|
125
|
+
return fields;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private sealed record QueryReply(int? Success, long? Total, IReadOnlyList<IReadOnlyDictionary<string, JsonElement>>? Rows,
|
|
129
|
+
string? Primary, string? RelationField);
|
|
130
|
+
private sealed record WriteReply(int? Result, string? Code, string? Message, string? Data);
|
|
131
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
using System.Text.Json;
|
|
2
|
+
|
|
3
|
+
namespace Macrowing.InBiz.SDK.Model;
|
|
4
|
+
|
|
5
|
+
/// <summary>A query against a published query definition backed by the model engine.</summary>
|
|
6
|
+
/// <param name="Key">Published query key, not a model key or display name.</param>
|
|
7
|
+
public sealed record ModelQuery(string Key)
|
|
8
|
+
{
|
|
9
|
+
/// <summary>Page to request. Defaults to the first 20 rows; explicitly set null to omit pagination.</summary>
|
|
10
|
+
public ModelPage? PageInfo { get; init; } = new();
|
|
11
|
+
|
|
12
|
+
/// <summary>Additional filter groups, in the order interpreted by the platform.</summary>
|
|
13
|
+
public IReadOnlyList<ModelFilterGroup>? Conditions { get; init; }
|
|
14
|
+
|
|
15
|
+
/// <summary>Additional sort fields.</summary>
|
|
16
|
+
public IReadOnlyList<ModelSort>? OrderInfo { get; init; }
|
|
17
|
+
|
|
18
|
+
/// <summary>Comma-separated child model names to load eagerly.</summary>
|
|
19
|
+
public string? LazyModel { get; init; }
|
|
20
|
+
|
|
21
|
+
/// <summary>Enables the engine's dynamic-list query mode.</summary>
|
|
22
|
+
public bool DropDownList { get; init; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// <summary>A page of a model query.</summary>
|
|
26
|
+
/// <param name="Index">One-based page index.</param>
|
|
27
|
+
/// <param name="Size">Maximum number of rows per page.</param>
|
|
28
|
+
public sealed record ModelPage(int Index = 1, int Size = 20);
|
|
29
|
+
|
|
30
|
+
/// <summary>A filter group that can contain both conditions and nested groups.</summary>
|
|
31
|
+
/// <param name="Index">Group index within the query.</param>
|
|
32
|
+
/// <param name="Condition">Field comparisons in this group.</param>
|
|
33
|
+
/// <param name="Connector">How this group combines with the preceding group.</param>
|
|
34
|
+
/// <param name="ChildGroup">Nested filter groups.</param>
|
|
35
|
+
public sealed record ModelFilterGroup(int Index, IReadOnlyList<ModelFilter>? Condition = null,
|
|
36
|
+
ModelConnector Connector = ModelConnector.And, IReadOnlyList<ModelFilterGroup>? ChildGroup = null);
|
|
37
|
+
|
|
38
|
+
/// <summary>A comparison on a field of a model included in the query.</summary>
|
|
39
|
+
/// <param name="ModelName">Published model name.</param>
|
|
40
|
+
/// <param name="Field">Field name in that model.</param>
|
|
41
|
+
/// <param name="Operator">Comparison performed by the platform.</param>
|
|
42
|
+
/// <param name="Value">Platform string representation of the comparison value; omit for null checks.</param>
|
|
43
|
+
/// <param name="Connector">How this condition combines with the preceding condition.</param>
|
|
44
|
+
public sealed record ModelFilter(string ModelName, string Field, ModelOperator Operator, string? Value = null,
|
|
45
|
+
ModelConnector Connector = ModelConnector.And);
|
|
46
|
+
|
|
47
|
+
/// <summary>Platform boolean connectors.</summary>
|
|
48
|
+
public enum ModelConnector
|
|
49
|
+
{
|
|
50
|
+
/// <summary>Logical AND.</summary>
|
|
51
|
+
And = 0,
|
|
52
|
+
/// <summary>Logical OR.</summary>
|
|
53
|
+
Or = 1
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// <summary>Platform query operators. Numeric values are part of the wire contract.</summary>
|
|
57
|
+
public enum ModelOperator
|
|
58
|
+
{
|
|
59
|
+
/// <summary>Equals the value.</summary>
|
|
60
|
+
Equal = 0,
|
|
61
|
+
/// <summary>Does not equal the value.</summary>
|
|
62
|
+
NotEqual = 1,
|
|
63
|
+
/// <summary>Greater than the value.</summary>
|
|
64
|
+
GreaterThan = 2,
|
|
65
|
+
/// <summary>Greater than or equal to the value.</summary>
|
|
66
|
+
GreaterOrEqual = 3,
|
|
67
|
+
/// <summary>Less than the value.</summary>
|
|
68
|
+
LessThan = 4,
|
|
69
|
+
/// <summary>Less than or equal to the value.</summary>
|
|
70
|
+
LessOrEqual = 5,
|
|
71
|
+
/// <summary>Matches one of the supplied values.</summary>
|
|
72
|
+
In = 6,
|
|
73
|
+
/// <summary>Matches none of the supplied values.</summary>
|
|
74
|
+
NotIn = 7,
|
|
75
|
+
/// <summary>Text contains the value.</summary>
|
|
76
|
+
Contains = 8,
|
|
77
|
+
/// <summary>Matches within a comma-delimited text field.</summary>
|
|
78
|
+
ContainsDelimited = 9,
|
|
79
|
+
/// <summary>Text does not contain the value.</summary>
|
|
80
|
+
NotContains = 10,
|
|
81
|
+
/// <summary>Text starts with the value.</summary>
|
|
82
|
+
StartsWith = 11,
|
|
83
|
+
/// <summary>Text does not start with the value.</summary>
|
|
84
|
+
NotStartsWith = 12,
|
|
85
|
+
/// <summary>Text ends with the value.</summary>
|
|
86
|
+
EndsWith = 13,
|
|
87
|
+
/// <summary>Text does not end with the value.</summary>
|
|
88
|
+
NotEndsWith = 14,
|
|
89
|
+
/// <summary>Field is null.</summary>
|
|
90
|
+
IsNull = 15,
|
|
91
|
+
/// <summary>Field is not null.</summary>
|
|
92
|
+
IsNotNull = 16
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/// <summary>Sort specification for a field of a model included in the query.</summary>
|
|
96
|
+
/// <param name="ModelName">Published model name.</param>
|
|
97
|
+
/// <param name="FieldName">Field name in that model.</param>
|
|
98
|
+
/// <param name="Descending">False for ascending order; true for descending order.</param>
|
|
99
|
+
/// <param name="Order">Platform sort priority for multi-field sorting.</param>
|
|
100
|
+
public sealed record ModelSort(string ModelName, string FieldName, bool Descending = false, int Order = 0);
|
|
101
|
+
|
|
102
|
+
/// <summary>Successful page of data from a model-backed query.</summary>
|
|
103
|
+
/// <param name="Total">Total matching records reported by the engine.</param>
|
|
104
|
+
/// <param name="Rows">Rows in this page, with original field names and JSON types.</param>
|
|
105
|
+
/// <param name="Primary">Primary field name reported by the query, if supplied.</param>
|
|
106
|
+
/// <param name="RelationField">Relationship field reported for related or virtual models, if supplied.</param>
|
|
107
|
+
public sealed record ModelQueryResult(long Total, IReadOnlyList<IReadOnlyDictionary<string, JsonElement>> Rows,
|
|
108
|
+
string? Primary, string? RelationField);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
namespace Macrowing.InBiz.SDK.Model;
|
|
2
|
+
|
|
3
|
+
/// <summary>Write a batch of model rows, optionally connected by a model relationship tree.</summary>
|
|
4
|
+
/// <param name="Data">Rows keyed by published model name. Do not substitute display names or query keys.</param>
|
|
5
|
+
/// <param name="Relation">Relationship tree for master-detail writes; the master rows must have the same explicit operation. Omit for independent rows.</param>
|
|
6
|
+
public sealed record ModelWrite(
|
|
7
|
+
IReadOnlyDictionary<string, IReadOnlyList<ModelRowChange>> Data, ModelRelation? Relation = null);
|
|
8
|
+
|
|
9
|
+
/// <summary>A single row in a model write batch.</summary>
|
|
10
|
+
/// <param name="Operation">Action to apply to this row.</param>
|
|
11
|
+
/// <param name="Fields">Exact field names and JSON-serializable values. Supply the platform's <c>id</c> field when updating or deleting.</param>
|
|
12
|
+
public sealed record ModelRowChange(ModelRowOperation Operation, IReadOnlyDictionary<string, object?> Fields);
|
|
13
|
+
|
|
14
|
+
/// <summary>The action applied to a model row by the platform.</summary>
|
|
15
|
+
public enum ModelRowOperation
|
|
16
|
+
{
|
|
17
|
+
/// <summary>Leave an existing non-master row unchanged. Include the published model's primary field so the engine recognizes the row.</summary>
|
|
18
|
+
Unchanged,
|
|
19
|
+
/// <summary>Insert a row.</summary>
|
|
20
|
+
Insert,
|
|
21
|
+
/// <summary>Update a row; provide its record ID.</summary>
|
|
22
|
+
Update,
|
|
23
|
+
/// <summary>Delete a row by ID using the platform's configured deletion behavior.</summary>
|
|
24
|
+
Delete
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// <summary>Model relationships for a master-detail write.</summary>
|
|
28
|
+
/// <param name="Name">Published model name.</param>
|
|
29
|
+
/// <param name="Type">Relationship to the parent model.</param>
|
|
30
|
+
/// <param name="RefField">Persisted relationship field.</param>
|
|
31
|
+
/// <param name="TempField">Temporary association field used to match submitted parent and child rows.</param>
|
|
32
|
+
/// <param name="Children">Related child models.</param>
|
|
33
|
+
public sealed record ModelRelation(string Name, ModelRelationType Type = ModelRelationType.OneToOne,
|
|
34
|
+
string? RefField = null, string? TempField = null,
|
|
35
|
+
[property: System.Text.Json.Serialization.JsonPropertyName("childrens")] IReadOnlyList<ModelRelation>? Children = null);
|
|
36
|
+
|
|
37
|
+
/// <summary>Relationship shapes accepted by the model write endpoint.</summary>
|
|
38
|
+
public enum ModelRelationType
|
|
39
|
+
{
|
|
40
|
+
/// <summary>One related row per parent.</summary>
|
|
41
|
+
OneToOne = 0,
|
|
42
|
+
/// <summary>Multiple related rows per parent.</summary>
|
|
43
|
+
OneToMany = 1
|
|
44
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
2
|
+
using System.Text.Json.Serialization;
|
|
3
|
+
|
|
4
|
+
namespace Macrowing.InBiz.SDK.Permission;
|
|
5
|
+
|
|
6
|
+
/// <summary>Reads platform permission decisions for the authenticated caller.</summary>
|
|
7
|
+
public interface IPermissionClient
|
|
8
|
+
{
|
|
9
|
+
/// <summary>Checks the platform's application management decision, not page, button or record access.</summary>
|
|
10
|
+
/// <param name="context">Authorized application and caller being checked.</param>
|
|
11
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
12
|
+
/// <returns>True if the platform identifies the caller as an administrator in this application context.</returns>
|
|
13
|
+
Task<bool> HasApplicationManagementAccessAsync(InBizRequestContext context, CancellationToken cancellationToken = default);
|
|
14
|
+
|
|
15
|
+
/// <summary>Reads menu permission decisions for site routes; this is not a check that the route exists or that a record is accessible.</summary>
|
|
16
|
+
/// <param name="context">Authorized application and caller being checked.</param>
|
|
17
|
+
/// <param name="siteOutId">Published site OutId, not the application or version ID.</param>
|
|
18
|
+
/// <param name="routes">Menu route strings as configured in the site.</param>
|
|
19
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
20
|
+
/// <returns>The server's route decisions for this caller.</returns>
|
|
21
|
+
Task<IReadOnlyList<MenuRoutePermission>> GetMenuRoutesAsync(InBizRequestContext context, string siteOutId,
|
|
22
|
+
IReadOnlyList<string> routes, CancellationToken cancellationToken = default);
|
|
23
|
+
|
|
24
|
+
/// <summary>Reads operation permissions for models at a site; does not grant or modify permissions.</summary>
|
|
25
|
+
/// <param name="context">Authorized application and caller being checked.</param>
|
|
26
|
+
/// <param name="siteOutId">Published site OutId.</param>
|
|
27
|
+
/// <param name="checks">Model keys and operation codes to check.</param>
|
|
28
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
29
|
+
/// <returns>Permission values reported by InBiz. A missing entry is not an authorization grant.</returns>
|
|
30
|
+
Task<IReadOnlyList<ModelButtonPermission>> GetModelButtonsAsync(InBizRequestContext context, string siteOutId,
|
|
31
|
+
IReadOnlyList<ModelButtonCheck> checks, CancellationToken cancellationToken = default);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// <summary>The server's menu permission decision for one route.</summary>
|
|
35
|
+
/// <param name="Route">Menu route from the original request.</param>
|
|
36
|
+
/// <param name="IsHavePerm">Whether the caller has menu permission.</param>
|
|
37
|
+
public sealed record MenuRoutePermission(string Route, bool IsHavePerm);
|
|
38
|
+
|
|
39
|
+
/// <summary>The configured model and operation codes whose permissions should be checked.</summary>
|
|
40
|
+
/// <param name="ModelKey">Published model key, not its name or query key.</param>
|
|
41
|
+
/// <param name="ObjectValues">Operation codes, such as <c>add</c>, <c>edit</c>, <c>delete</c>, and <c>select</c>.</param>
|
|
42
|
+
public sealed record ModelButtonCheck(string ModelKey, IReadOnlyList<string> ObjectValues);
|
|
43
|
+
|
|
44
|
+
/// <summary>A permission value for a model operation.</summary>
|
|
45
|
+
/// <param name="ObjectValue">Operation code.</param>
|
|
46
|
+
/// <param name="ParentValue">Parent model key as returned by the server.</param>
|
|
47
|
+
/// <param name="PermissionValue">Original platform permission value, which may be serialized as a string to preserve 64-bit precision.</param>
|
|
48
|
+
public sealed record ModelButtonPermission(string ObjectValue, string ParentValue,
|
|
49
|
+
[property: JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] long PermissionValue);
|
|
50
|
+
|
|
51
|
+
internal sealed class PermissionClient(InBizPlatformTransport transport) : IPermissionClient
|
|
52
|
+
{
|
|
53
|
+
private const string Prefix = InBizPlatformTransport.PublicApi + "permission/";
|
|
54
|
+
|
|
55
|
+
public async Task<bool> HasApplicationManagementAccessAsync(InBizRequestContext context, CancellationToken cancellationToken)
|
|
56
|
+
{
|
|
57
|
+
var reply = await transport.SendAsync(context, HttpMethod.Get, Prefix + "haveAppPerm",
|
|
58
|
+
cancellationToken).ConfigureAwait(false);
|
|
59
|
+
return reply.Require<bool>();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public async Task<IReadOnlyList<MenuRoutePermission>> GetMenuRoutesAsync(InBizRequestContext context, string siteOutId,
|
|
63
|
+
IReadOnlyList<string> routes, CancellationToken cancellationToken)
|
|
64
|
+
{
|
|
65
|
+
ArgumentNullException.ThrowIfNull(routes);
|
|
66
|
+
if (routes.Count == 0)
|
|
67
|
+
throw new ArgumentException("Provide at least one menu route.", nameof(routes));
|
|
68
|
+
var route = Prefix + "havePerm?siteOutId=" + InBizPlatformTransport.QueryValue(siteOutId) +
|
|
69
|
+
string.Concat(routes.Select(value => "&routes=" + InBizPlatformTransport.QueryValue(value)));
|
|
70
|
+
var reply = await transport.SendAsync(context, HttpMethod.Get, route, cancellationToken).ConfigureAwait(false);
|
|
71
|
+
return reply.Require<IReadOnlyList<MenuRoutePermission>>();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public async Task<IReadOnlyList<ModelButtonPermission>> GetModelButtonsAsync(InBizRequestContext context, string siteOutId,
|
|
75
|
+
IReadOnlyList<ModelButtonCheck> checks, CancellationToken cancellationToken)
|
|
76
|
+
{
|
|
77
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(siteOutId);
|
|
78
|
+
ArgumentNullException.ThrowIfNull(checks);
|
|
79
|
+
if (checks.Count == 0 || checks.Any(check => check is null || string.IsNullOrWhiteSpace(check.ModelKey) ||
|
|
80
|
+
check.ObjectValues is not { Count: > 0 } || check.ObjectValues.Any(string.IsNullOrWhiteSpace)))
|
|
81
|
+
throw new ArgumentException("Provide at least one model key and operation for each check.", nameof(checks));
|
|
82
|
+
var reply = await transport.SendAsync(context, HttpMethod.Post, Prefix + "getButtonPerm",
|
|
83
|
+
cancellationToken, new { SiteOutId = siteOutId, List = checks }).ConfigureAwait(false);
|
|
84
|
+
return reply.Require<IReadOnlyList<ModelButtonPermission>>();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
using System.Net;
|
|
2
|
+
|
|
3
|
+
namespace Macrowing.InBiz.SDK.Platform;
|
|
4
|
+
|
|
5
|
+
/// <summary>Classifies a response the SDK cannot return as a successful result.</summary>
|
|
6
|
+
public enum InBizFailureKind
|
|
7
|
+
{
|
|
8
|
+
/// <summary>The gateway or service returned HTTP 401 or 403.</summary>
|
|
9
|
+
AuthenticationOrPermission,
|
|
10
|
+
/// <summary>The platform returned an ABP error or a nonzero engine result.</summary>
|
|
11
|
+
Business,
|
|
12
|
+
/// <summary>A non-success HTTP status without a recognized platform error, including redirects.</summary>
|
|
13
|
+
Http,
|
|
14
|
+
/// <summary>A success response that did not match the endpoint's contract.</summary>
|
|
15
|
+
Protocol
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// <summary>Platform response failure. Network and cancellation failures retain their standard .NET exception types.</summary>
|
|
19
|
+
public sealed class InBizPlatformException : Exception
|
|
20
|
+
{
|
|
21
|
+
internal InBizPlatformException(InBizFailureKind kind, HttpStatusCode statusCode, string? errorCode = null,
|
|
22
|
+
string? platformMessage = null, int? result = null)
|
|
23
|
+
: base($"InBiz returned a {kind} failure (HTTP {(int)statusCode}).")
|
|
24
|
+
{
|
|
25
|
+
Kind = kind;
|
|
26
|
+
StatusCode = statusCode;
|
|
27
|
+
ErrorCode = errorCode;
|
|
28
|
+
PlatformMessage = platformMessage;
|
|
29
|
+
Result = result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// <summary>How the failure was identified.</summary>
|
|
33
|
+
public InBizFailureKind Kind { get; }
|
|
34
|
+
/// <summary>Actual HTTP status, which can be 200 for engine-level errors.</summary>
|
|
35
|
+
public HttpStatusCode StatusCode { get; }
|
|
36
|
+
/// <summary>Platform error code, when supplied.</summary>
|
|
37
|
+
public string? ErrorCode { get; }
|
|
38
|
+
/// <summary>Server-provided diagnostic text. May contain business data; do not log it indiscriminately.</summary>
|
|
39
|
+
public string? PlatformMessage { get; }
|
|
40
|
+
/// <summary>Nonzero engine result or query status, when supplied.</summary>
|
|
41
|
+
public int? Result { get; }
|
|
42
|
+
}
|