@burgan-tech/morph-idm-runtime 0.0.1 → 0.0.3

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.
Files changed (180) hide show
  1. package/burgan-tech-morph-idm-runtime-0.0.3.tgz +0 -0
  2. package/morph-idm/Schemas/client/client-update-1.0.0.json +263 -0
  3. package/morph-idm/Schemas/{user → person}/person-master-1.0.0.json +1 -1
  4. package/morph-idm/Schemas/token/token-start-1.0.0.json +6 -19
  5. package/morph-idm/Schemas/user/user-master-1.0.0.json +46 -1
  6. package/morph-idm/Schemas/user-login/retry-login-1.0.0.json +39 -0
  7. package/morph-idm/Tasks/call-device-start-1.0.0.json +1 -1
  8. package/morph-idm/Tasks/call-device-update-1.0.0.json +1 -1
  9. package/morph-idm/Tasks/consent/consent-auto-select-script.json +16 -0
  10. package/morph-idm/Tasks/{user/send-push-task.json → device/search-device-task.json} +5 -5
  11. package/morph-idm/Tasks/get-device-1.0.0.json +1 -1
  12. package/morph-idm/Tasks/person/get-person-by-task.json +19 -0
  13. package/morph-idm/Tasks/person/person-update-direct-transition.json +23 -0
  14. package/morph-idm/Tasks/token/token-create-jwt.json +0 -1
  15. package/morph-idm/Tasks/token/token-redeem-trigger.json +22 -0
  16. package/morph-idm/Tasks/token/user-login-get-as-filterable.json +22 -0
  17. package/morph-idm/Tasks/user/evaluate-failed-login-script.json +18 -0
  18. package/morph-idm/Tasks/user/get-phone-from-person-task.json +20 -0
  19. package/morph-idm/Tasks/user/otp-code-generator.json +15 -0
  20. package/morph-idm/Tasks/user/send-otp-sms-task.json +26 -0
  21. package/morph-idm/Tasks/user/user-update-password-fail-count.json +24 -0
  22. package/morph-idm/Tasks/user-login/auth-code-generator.json +17 -0
  23. package/morph-idm/Tasks/user-login/increment-local-fail-count.json +17 -0
  24. package/morph-idm/Tasks/user-login/password-verify.json +26 -0
  25. package/morph-idm/Tasks/user-login/push-send-task.json +25 -0
  26. package/morph-idm/TestCases/test-123/.httpyac.json +15 -0
  27. package/morph-idm/TestCases/test-123/01-person.http +95 -0
  28. package/morph-idm/TestCases/test-123/02-user.http +83 -0
  29. package/morph-idm/TestCases/test-123/03-scope.http +65 -0
  30. package/morph-idm/TestCases/test-123/04-consent.http +66 -0
  31. package/morph-idm/TestCases/test-123/05-device.http +86 -0
  32. package/morph-idm/TestCases/test-123/06-user-login.http +206 -0
  33. package/morph-idm/TestCases/test-123/README.md +112 -0
  34. package/morph-idm/TestCases/test-123/cleanup.js +49 -0
  35. package/morph-idm/TestCases/test-123/cleanup.sh +20 -0
  36. package/morph-idm/TestCases/test-123/cleanup.sql +45 -0
  37. package/morph-idm/TestCases/test-123/http-client.env.json +13 -0
  38. package/morph-idm/TestCases/test-123/run-setup.sh +42 -0
  39. package/morph-idm/TestCases/test-auto-consent/.httpyac.json +14 -0
  40. package/morph-idm/TestCases/test-auto-consent/01-person.http +72 -0
  41. package/morph-idm/TestCases/test-auto-consent/02-user.http +74 -0
  42. package/morph-idm/TestCases/test-auto-consent/03-scope.http +66 -0
  43. package/morph-idm/TestCases/test-auto-consent/04-device.http +56 -0
  44. package/morph-idm/TestCases/test-auto-consent/05-user-login.http +132 -0
  45. package/morph-idm/TestCases/test-auto-consent/README.md +36 -0
  46. package/morph-idm/TestCases/test-auto-consent/cleanup.js +47 -0
  47. package/morph-idm/TestCases/test-auto-consent/run-setup.sh +50 -0
  48. package/morph-idm/TestCases/test-multiple-consent/.httpyac.json +17 -0
  49. package/morph-idm/TestCases/test-multiple-consent/01-person.http +103 -0
  50. package/morph-idm/TestCases/test-multiple-consent/02-user.http +83 -0
  51. package/morph-idm/TestCases/test-multiple-consent/03-scope-2.http +66 -0
  52. package/morph-idm/TestCases/test-multiple-consent/03-scope.http +66 -0
  53. package/morph-idm/TestCases/test-multiple-consent/04-consent-1.http +67 -0
  54. package/morph-idm/TestCases/test-multiple-consent/04-consent-2.http +66 -0
  55. package/morph-idm/TestCases/test-multiple-consent/05-device.http +87 -0
  56. package/morph-idm/TestCases/test-multiple-consent/06-user-login.http +183 -0
  57. package/morph-idm/TestCases/test-multiple-consent/README.md +37 -0
  58. package/morph-idm/TestCases/test-multiple-consent/cleanup.js +46 -0
  59. package/morph-idm/TestCases/test-multiple-consent/cleanup.sh +20 -0
  60. package/morph-idm/TestCases/test-multiple-consent/run-setup.sh +53 -0
  61. package/morph-idm/Views/user-login/push-waiting.json +28 -0
  62. package/morph-idm/Views/user-login/start.json +28 -0
  63. package/morph-idm/Workflows/client/client-1.0.0.json +8 -3
  64. package/morph-idm/Workflows/client/execute/client-update.http +763 -0
  65. package/morph-idm/Workflows/client/execute/client.http +13 -5
  66. package/morph-idm/Workflows/client/src/CreateRsaByHttpCallMapping.csx +10 -14
  67. package/morph-idm/Workflows/client/src/PasswordGeneratorMapping.csx +0 -1
  68. package/morph-idm/Workflows/consent-selection/consent-selection-1.0.0.json +37 -6
  69. package/morph-idm/Workflows/consent-selection/execute/multi-consent-selection.http +209 -0
  70. package/morph-idm/Workflows/consent-selection/src/ConsentSelectedMapping.csx +18 -22
  71. package/morph-idm/Workflows/consent-selection/src/CreateAutoConsentMapping.csx +45 -45
  72. package/morph-idm/Workflows/consent-selection/src/MultipleConsentsRule.csx +12 -8
  73. package/morph-idm/Workflows/consent-selection/src/NoConsentEligibleRule.csx +6 -22
  74. package/morph-idm/Workflows/consent-selection/src/SingleConsentAutoSelectMapping.csx +63 -0
  75. package/morph-idm/Workflows/consent-selection/src/SingleConsentRule.csx +11 -22
  76. package/morph-idm/Workflows/device/execute/device-ios.http +0 -6
  77. package/morph-idm/Workflows/device/execute/search.http +32 -0
  78. package/morph-idm/Workflows/person/execute/person-123.http +191 -0
  79. package/morph-idm/Workflows/person/execute/person.http +196 -0
  80. package/morph-idm/Workflows/{user → person}/person-1.0.0.json +24 -1
  81. package/morph-idm/Workflows/token/execute/token.http +14 -3
  82. package/morph-idm/Workflows/token/password-subflow.json +1 -1
  83. package/morph-idm/Workflows/token/src/AuthCodeRedeemMapping.csx +114 -0
  84. package/morph-idm/Workflows/token/src/AuthCodeValidationRule.csx +27 -0
  85. package/morph-idm/Workflows/token/src/CreateRsaJwtMapping.csx +28 -16
  86. package/morph-idm/Workflows/token/src/StatusSuccessRule.csx +27 -0
  87. package/morph-idm/Workflows/token/src/TokenCreatedRule.csx +32 -0
  88. package/morph-idm/Workflows/token/src/UserLoginGetAsFilterableMapping.csx +204 -0
  89. package/morph-idm/Workflows/token/token-1.0.0.json +109 -41
  90. package/morph-idm/Workflows/user/execute/create-user-1234567890.http +16 -4
  91. package/morph-idm/Workflows/user/execute/create-user-migration.http +179 -0
  92. package/morph-idm/Workflows/user/execute/create-user-person-password.http +78 -32
  93. package/morph-idm/Workflows/user/src/EvaluateFailedLoginMapping.csx +75 -0
  94. package/morph-idm/Workflows/user/src/FailCountMaxRule.csx +33 -0
  95. package/morph-idm/Workflows/user/src/GetPhoneFromPersonMapping.csx +139 -0
  96. package/morph-idm/Workflows/user/src/HasPasswordsRule.csx +43 -0
  97. package/morph-idm/Workflows/user/src/OtpSentSuccessRule.csx +46 -0
  98. package/morph-idm/Workflows/user/src/PasswordGeneratedSuccessRule.csx +73 -0
  99. package/morph-idm/Workflows/user/src/PhoneFetchedSuccessRule.csx +35 -0
  100. package/morph-idm/Workflows/user/src/ResetPasswordFailCountMapping.csx +88 -0
  101. package/morph-idm/Workflows/user/src/SendOtpSmsMapping.csx +357 -0
  102. package/morph-idm/Workflows/user/src/UserPasswordGeneratorMapping.csx +33 -6
  103. package/morph-idm/Workflows/user/user-1.0.0.json +365 -5
  104. package/morph-idm/Workflows/{user → user-login}/execute/user-login.http +155 -32
  105. package/morph-idm/Workflows/user-login/src/AuthCodeGeneratorMapping.csx +44 -0
  106. package/morph-idm/Workflows/{user/src/GetClientMapping.csx → user-login/src/ClientGetMapping.csx} +6 -4
  107. package/morph-idm/Workflows/{user/src/TriggerConsentSelectionAsSubFlowMapping.csx → user-login/src/ConsentSelectionSubFlowMapping.csx} +19 -20
  108. package/morph-idm/Workflows/user-login/src/DeviceSearchMapping.csx +128 -0
  109. package/morph-idm/Workflows/{user → user-login}/src/GrantValidationRule.csx +5 -1
  110. package/morph-idm/Workflows/user-login/src/HasFailCountRule.csx +32 -0
  111. package/morph-idm/Workflows/user-login/src/MaxRetriesReachedRule.csx +32 -0
  112. package/morph-idm/Workflows/user-login/src/NoSecurityImageRule.csx +33 -0
  113. package/morph-idm/Workflows/user-login/src/NoSecurityQuestionRule.csx +65 -0
  114. package/morph-idm/Workflows/user-login/src/OtpCodeGenerateMapping.csx +37 -0
  115. package/morph-idm/Workflows/{user/src/SendOtpMapping.csx → user-login/src/OtpSendMapping.csx} +13 -7
  116. package/morph-idm/Workflows/user-login/src/OtpVerifiedRule.csx +35 -0
  117. package/morph-idm/Workflows/user-login/src/PasswordFailCountResetMapping.csx +77 -0
  118. package/morph-idm/Workflows/user-login/src/PasswordFailCountUpdateMapping.csx +80 -0
  119. package/morph-idm/Workflows/user-login/src/PasswordVerifyMapping.csx +172 -0
  120. package/morph-idm/Workflows/user-login/src/PersonFetchedRule.csx +32 -0
  121. package/morph-idm/Workflows/user-login/src/PersonGetMapping.csx +61 -0
  122. package/morph-idm/Workflows/user-login/src/PersonUpdateMapping.csx +105 -0
  123. package/morph-idm/Workflows/user-login/src/PersonUpdatedRule.csx +32 -0
  124. package/morph-idm/Workflows/{user/src/SendPushMapping.csx → user-login/src/PushSendMapping.csx} +22 -11
  125. package/morph-idm/Workflows/user-login/src/PushVerifiedRule.csx +31 -0
  126. package/morph-idm/Workflows/{user/src/GetScopesByUserMapping.csx → user-login/src/ScopesByUserGetMapping.csx} +24 -22
  127. package/morph-idm/Workflows/user-login/src/TokenGenerationSuccessRule.csx +33 -0
  128. package/morph-idm/Workflows/{user/src/TriggerTokenWorkflowAsSubFlowMapping.csx → user-login/src/TokenSubFlowMapping.csx} +7 -13
  129. package/morph-idm/Workflows/user-login/src/UserFoundRule.csx +19 -0
  130. package/morph-idm/Workflows/{user/src/GetUserMapping.csx → user-login/src/UserGetMapping.csx} +5 -3
  131. package/morph-idm/Workflows/user-login/src/UserStatusActiveRule.csx +34 -0
  132. package/morph-idm/Workflows/user-login/src/UserValidHasFailCountRule.csx +39 -0
  133. package/morph-idm/Workflows/user-login/src/UserValidNoFailCountRule.csx +39 -0
  134. package/morph-idm/Workflows/user-login/user-login.1.0.0.json +1828 -0
  135. package/package.json +1 -1
  136. package/vnext.config.json +3 -3
  137. package/burgan-tech-morph-idm-runtime-0.0.1.tgz +0 -0
  138. package/morph-idm/Schemas/client/client-update-master-1.0.0.json +0 -201
  139. package/morph-idm/Workflows/client/client-update-1.0.0.json +0 -202
  140. package/morph-idm/Workflows/client-manager/client-manager-1.0.0.json +0 -217
  141. package/morph-idm/Workflows/client-manager/execute/client-manager.http +0 -214
  142. package/morph-idm/Workflows/client-manager/src/ClientCreatedRule.csx +0 -28
  143. package/morph-idm/Workflows/client-manager/src/ClientExistsRule.csx +0 -25
  144. package/morph-idm/Workflows/client-manager/src/CreateClientSubFlowMapping.csx +0 -63
  145. package/morph-idm/Workflows/client-manager/src/GetClientForManagerMapping.csx +0 -59
  146. package/morph-idm/Workflows/user/src/ApproveRule.csx +0 -16
  147. package/morph-idm/Workflows/user/src/AutoConsentCreatedRule.csx +0 -20
  148. package/morph-idm/Workflows/user/src/AutoConsentRequiredRule.csx +0 -77
  149. package/morph-idm/Workflows/user/src/CheckDeviceByUserReferenceMapping.csx +0 -66
  150. package/morph-idm/Workflows/user/src/ClientValidationFailRule.csx +0 -28
  151. package/morph-idm/Workflows/user/src/ConsentValidationRule.csx +0 -36
  152. package/morph-idm/Workflows/user/src/CreateAutoConsentMapping.csx +0 -171
  153. package/morph-idm/Workflows/user/src/DeviceFoundForLoginRule.csx +0 -32
  154. package/morph-idm/Workflows/user/src/DeviceNotFoundForLoginRule.csx +0 -31
  155. package/morph-idm/Workflows/user/src/GetConsentMapping.csx +0 -27
  156. package/morph-idm/Workflows/user/src/GetDeviceMapping.csx +0 -52
  157. package/morph-idm/Workflows/user/src/GetScopeMapping.csx +0 -139
  158. package/morph-idm/Workflows/user/src/GrantValidationFailRule.csx +0 -48
  159. package/morph-idm/Workflows/user/src/OtpVerifiedRule.csx +0 -31
  160. package/morph-idm/Workflows/user/src/PushVerifiedRule.csx +0 -31
  161. package/morph-idm/Workflows/user/src/RejectRule.csx +0 -16
  162. package/morph-idm/Workflows/user/src/ScopeValidationFailRule.csx +0 -67
  163. package/morph-idm/Workflows/user/src/ScopeValidationRule.csx +0 -67
  164. package/morph-idm/Workflows/user/src/TokenGenerationSuccessRule.csx +0 -28
  165. package/morph-idm/Workflows/user/src/UserValidationFailRule.csx +0 -36
  166. package/morph-idm/Workflows/user/src/VerifyOtpMapping.csx +0 -65
  167. package/morph-idm/Workflows/user/src/VerifyPushMapping.csx +0 -65
  168. package/morph-idm/Workflows/user/user-login.1.0.0.json +0 -1144
  169. /package/morph-idm/Workflows/{user → person}/person-cdc-worker.1.0.0.json +0 -0
  170. /package/morph-idm/Workflows/{user → person}/person-upsert-1.0.0.json +0 -0
  171. /package/morph-idm/Workflows/scope/execute/{scope-individual.http → scope-individual-1234567890-1234567890.http} +0 -0
  172. /package/morph-idm/Workflows/{user → user-login}/execute/README-LOGIN.md +0 -0
  173. /package/morph-idm/Workflows/{user → user-login}/src/ClientValidationRule.csx +0 -0
  174. /package/morph-idm/Workflows/{user → user-login}/src/ConsentSelectedRule.csx +0 -0
  175. /package/morph-idm/Workflows/{user → user-login}/src/IsIbWebClientWithDeviceRule.csx +0 -0
  176. /package/morph-idm/Workflows/{user → user-login}/src/NonIbWebClientWithDeviceRule.csx +0 -0
  177. /package/morph-idm/Workflows/{user → user-login}/src/OtpSentRule.csx +0 -0
  178. /package/morph-idm/Workflows/{user → user-login}/src/PushSentRule.csx +0 -0
  179. /package/morph-idm/Workflows/{user → user-login}/src/ScopeFetchedRule.csx +0 -0
  180. /package/morph-idm/Workflows/{user → user-login}/src/UserValidationRule.csx +0 -0
@@ -0,0 +1,65 @@
1
+ using System.Threading.Tasks;
2
+ using System.Collections.Generic;
3
+ using System.Linq;
4
+ using BBT.Workflow.Scripting;
5
+ using BBT.Workflow.Scripting.Functions;
6
+
7
+ /// <summary>
8
+ /// Rule: Check if security question is missing
9
+ /// Returns true if personSnapshot.securityQuestion array is empty or not set - triggers security question change flow
10
+ /// securityQuestion format: [{ answer, question, algorithm, lastUpdatedDate }]
11
+ /// </summary>
12
+ public class NoSecurityQuestionRule : ScriptBase, IConditionMapping
13
+ {
14
+ public async Task<bool> Handler(ScriptContext context)
15
+ {
16
+ // Check if personSnapshot exists
17
+ if (!HasProperty(context.Instance?.Data, "personSnapshot"))
18
+ {
19
+ LogWarning("NoSecurityQuestionRule: personSnapshot not found");
20
+ return true; // No person data, needs to set security question
21
+ }
22
+
23
+ var personSnapshot = context.Instance?.Data?.personSnapshot;
24
+
25
+ // Check if securityQuestion property exists
26
+ if (!HasProperty(personSnapshot, "securityQuestion"))
27
+ {
28
+ LogWarning("NoSecurityQuestionRule: securityQuestion property not found, needs to be set");
29
+ return true;
30
+ }
31
+
32
+ var securityQuestion = personSnapshot?.securityQuestion;
33
+
34
+ // Check if securityQuestion is null
35
+ if (securityQuestion == null)
36
+ {
37
+ LogWarning("NoSecurityQuestionRule: securityQuestion is null, needs to be set");
38
+ return true;
39
+ }
40
+
41
+ // Cast to enumerable and check if array has items
42
+ try
43
+ {
44
+ var securityQuestionList = securityQuestion as IEnumerable<dynamic>;
45
+ if (securityQuestionList == null)
46
+ {
47
+ LogWarning("NoSecurityQuestionRule: securityQuestion is not an array, needs to be set");
48
+ return true;
49
+ }
50
+
51
+ var count = securityQuestionList.Count();
52
+ if (count == 0)
53
+ {
54
+ LogWarning("NoSecurityQuestionRule: securityQuestion array is empty, needs to be set");
55
+ return true;
56
+ }
57
+ return false;
58
+ }
59
+ catch
60
+ {
61
+ LogWarning("NoSecurityQuestionRule: Failed to parse securityQuestion as array");
62
+ return true;
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,37 @@
1
+ using System;
2
+ using System.Threading.Tasks;
3
+ using BBT.Workflow.Scripting;
4
+ using BBT.Workflow.Definitions;
5
+ using BBT.Workflow.Scripting.Functions;
6
+
7
+ /// <summary>
8
+ /// Script task mapping for generating OTP code
9
+ /// Generates a 6-digit random OTP code and stores it in instance data
10
+ /// </summary>
11
+ public class OtpCodeGenerateMapping : ScriptBase, IMapping
12
+ {
13
+ public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
14
+ {
15
+ return Task.FromResult(new ScriptResponse());
16
+ }
17
+
18
+ /// <summary>
19
+ /// Generate a 6-digit OTP code and store it in instance data
20
+ /// </summary>
21
+ public async Task<ScriptResponse> OutputHandler(ScriptContext context)
22
+ {
23
+ // Generate 6-digit OTP code
24
+ var otpCode = Random.Shared.Next(100000, 999999);
25
+
26
+ LogInformation($"OtpCodeGenerateMapping: Generated OTP code for user");
27
+
28
+ return new ScriptResponse
29
+ {
30
+ Data = new
31
+ {
32
+ otpCode = otpCode,
33
+ }
34
+ };
35
+ }
36
+ }
37
+
@@ -1,4 +1,5 @@
1
1
  using System;
2
+ using System.Collections.Generic;
2
3
  using System.Threading.Tasks;
3
4
  using BBT.Workflow.Definitions;
4
5
  using BBT.Workflow.Scripting;
@@ -7,8 +8,9 @@ using BBT.Workflow.Scripting.Functions;
7
8
  /// <summary>
8
9
  /// Mapping for sending OTP via HTTP task
9
10
  /// Calls Mockoon mock server at port 3030
11
+ /// OTP code is generated by otp-code-generator task and stored in instance data
10
12
  /// </summary>
11
- public class SendOtpMapping : ScriptBase, IMapping
13
+ public class OtpSendMapping : ScriptBase, IMapping
12
14
  {
13
15
  public async Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
14
16
  {
@@ -17,14 +19,18 @@ public class SendOtpMapping : ScriptBase, IMapping
17
19
  // Get user phone from instance data
18
20
  var userName = context.Instance?.Data?.userName?.ToString() ?? string.Empty;
19
21
  var phone = HasProperty(context.Instance?.Data.userSnapshot.person, "phone") ? context.Instance.Data.userSnapshot.person.phone.ToString() : "+905551234567";
20
-
22
+
23
+ // Get OTP code from instance data (generated by otp-code-generator task)
24
+ var otpCode = HasProperty(context.Instance?.Data, "otpCode") ? context.Instance.Data.otpCode : 0;
25
+
21
26
  // Set request body
22
27
  context.SetBody(new
23
28
  {
24
29
  userName = userName,
25
30
  phone = phone,
26
31
  channel = "sms",
27
- purpose = "login"
32
+ purpose = "login",
33
+ code = otpCode
28
34
  });
29
35
  // Set Headers
30
36
  var headers = new Dictionary<string, string?>
@@ -34,7 +40,7 @@ public class SendOtpMapping : ScriptBase, IMapping
34
40
 
35
41
  httpTask.SetHeaders(headers);
36
42
 
37
- LogInformation($"SendOtpMapping InputHandler: Sending OTP to {phone} for user {userName}");
43
+ LogInformation($"OtpSendMapping InputHandler: Sending OTP to {phone} for user {userName}");
38
44
 
39
45
  return new ScriptResponse();
40
46
  }
@@ -43,7 +49,7 @@ public class SendOtpMapping : ScriptBase, IMapping
43
49
  {
44
50
  if (!HasProperty(context.Body, "data"))
45
51
  {
46
- LogWarning("SendOtpMapping OutputHandler: Invalid response - missing data");
52
+ LogWarning("OtpSendMapping OutputHandler: Invalid response - missing data");
47
53
  return new ScriptResponse
48
54
  {
49
55
  Data = new
@@ -57,7 +63,7 @@ public class SendOtpMapping : ScriptBase, IMapping
57
63
  }
58
64
  if (!HasProperty(context.Body.data, "success"))
59
65
  {
60
- LogWarning("SendOtpMapping OutputHandler: Invalid response - missing data.success");
66
+ LogWarning("OtpSendMapping OutputHandler: Invalid response - missing data.success");
61
67
  return new ScriptResponse
62
68
  {
63
69
  Data = new
@@ -70,7 +76,7 @@ public class SendOtpMapping : ScriptBase, IMapping
70
76
  }
71
77
  if (context.Body.data.success != true)
72
78
  {
73
- LogWarning("SendOtpMapping OutputHandler: OTP send failed");
79
+ LogWarning("OtpSendMapping OutputHandler: OTP send failed");
74
80
  return new ScriptResponse
75
81
  {
76
82
  Data = new
@@ -0,0 +1,35 @@
1
+ using System.Threading.Tasks;
2
+ using BBT.Workflow.Scripting;
3
+ using BBT.Workflow.Scripting.Functions;
4
+
5
+ /// <summary>
6
+ /// Rule: OTP verified successfully
7
+ /// Returns true if OTP was verified successfully
8
+ /// </summary>
9
+ public class OtpVerifiedRule : ScriptBase, IConditionMapping
10
+ {
11
+ public async Task<bool> Handler(ScriptContext context)
12
+ {
13
+ if (!HasProperty(context.Instance.Data, "otpCode"))
14
+ {
15
+ LogWarning("VerifyOtpMapping InputHandler: otpCode is missing");
16
+ return false;
17
+ }
18
+ if (!HasProperty(context.Instance.Data, "otpReference"))
19
+ {
20
+ LogWarning("VerifyOtpMapping InputHandler: otpReference is missing");
21
+ return false;
22
+ }
23
+
24
+ // Get OTP code from request body and reference from instance
25
+ var otpCode = context.Instance.Data.otpCode.ToString();
26
+ var otpReference = context.Instance.Data.otpReference.ToString();
27
+ if (otpReference == otpCode)
28
+ {
29
+ return true;
30
+ }
31
+ LogWarning($"OtpVerifiedRule: OTP verification failed. otpReference={otpReference} != otpCode={otpCode}");
32
+ return false;
33
+ }
34
+ }
35
+
@@ -0,0 +1,77 @@
1
+ using System;
2
+ using System.Threading.Tasks;
3
+ using BBT.Workflow.Scripting;
4
+ using BBT.Workflow.Scripting.Functions;
5
+
6
+ /// <summary>
7
+ /// Mapping to reset password fail count in user instance after successful login.
8
+ /// </summary>
9
+ public class PasswordFailCountResetMapping : ScriptBase, IMapping
10
+ {
11
+ public async Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
12
+ {
13
+ var directTask = (task as DirectTriggerTask)!;
14
+
15
+ // Get user key from userSnapshot
16
+ var userKey = string.Empty;
17
+
18
+ if (HasProperty(context.Instance?.Data, "userName"))
19
+ {
20
+ // Fallback to userName if userSnapshot is not available
21
+ userKey = context.Instance?.Data?.userName?.ToString();
22
+ }
23
+
24
+ if (string.IsNullOrEmpty(userKey))
25
+ {
26
+ LogWarning("PasswordFailCountResetMapping: User key not found in instance data");
27
+ return new ScriptResponse
28
+ {
29
+ Data = new { error = "User key not found" }
30
+ };
31
+ }
32
+
33
+ // Set the instance key to update
34
+ directTask.SetKey(userKey);
35
+
36
+ // Build update body with password fail count increment
37
+ dynamic updateBody = new ExpandoObject();
38
+ updateBody.failCount = 0;
39
+
40
+ directTask.SetBody(updateBody);
41
+
42
+ LogInformation($"PasswordFailCountResetMapping: Resetting password fail count for user={userKey}");
43
+
44
+ return new ScriptResponse();
45
+ }
46
+
47
+ public async Task<ScriptResponse> OutputHandler(ScriptContext context)
48
+ {
49
+ // Check if update was successful
50
+ if (HasProperty(context.Body, "data"))
51
+ {
52
+ LogInformation("PasswordFailCountResetMapping: Password fail count updated successfully");
53
+
54
+ return new ScriptResponse
55
+ {
56
+ Data = new
57
+ {
58
+ userResetPasswordFailCount = true,
59
+ updatedAt = DateTime.UtcNow
60
+ }
61
+ };
62
+ }
63
+ else
64
+ {
65
+ LogWarning("PasswordFailCountResetMapping: Failed to update password fail count");
66
+
67
+ return new ScriptResponse
68
+ {
69
+ Data = new
70
+ {
71
+ passwordFailCountUpdated = false,
72
+ error = "Failed to update password fail count"
73
+ }
74
+ };
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,80 @@
1
+ using System;
2
+ using System.Dynamic;
3
+ using System.Threading.Tasks;
4
+ using BBT.Workflow.Scripting;
5
+ using BBT.Workflow.Definitions;
6
+ using BBT.Workflow.Scripting.Functions;
7
+
8
+ /// <summary>
9
+ /// Mapping for updating password fail count on user workflow.
10
+ /// Uses DirectTriggerTask to call the "update-password-fail-count" transition on user workflow.
11
+ /// </summary>
12
+ public class PasswordFailCountUpdateMapping : ScriptBase, IMapping
13
+ {
14
+ public async Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
15
+ {
16
+ var directTask = (task as DirectTriggerTask)!;
17
+
18
+ // Get user key from userSnapshot
19
+ var userKey = string.Empty;
20
+
21
+ if (HasProperty(context.Instance?.Data, "userName"))
22
+ {
23
+ // Fallback to userName if userSnapshot is not available
24
+ userKey = context.Instance?.Data?.userName?.ToString();
25
+ }
26
+
27
+ if (string.IsNullOrEmpty(userKey))
28
+ {
29
+ LogWarning("PasswordFailCountUpdateMapping: User key not found in instance data");
30
+ return new ScriptResponse
31
+ {
32
+ Data = new { error = "User key not found" }
33
+ };
34
+ }
35
+
36
+ // Set the instance key to update
37
+ directTask.SetKey(userKey);
38
+
39
+ // Build update body with password fail count increment
40
+ dynamic updateBody = new ExpandoObject();
41
+ updateBody.failCount = context.Instance?.Data?.failCount;
42
+
43
+ directTask.SetBody(updateBody);
44
+
45
+ LogInformation($"PasswordFailCountUpdateMapping: Updating password fail count for user={userKey}");
46
+
47
+ return new ScriptResponse();
48
+ }
49
+
50
+ public async Task<ScriptResponse> OutputHandler(ScriptContext context)
51
+ {
52
+ // Check if update was successful
53
+ if (HasProperty(context.Body, "data"))
54
+ {
55
+ LogInformation("UpdatePasswordFailCountMapping: Password fail count updated successfully");
56
+
57
+ return new ScriptResponse
58
+ {
59
+ Data = new
60
+ {
61
+ passwordFailCountUpdated = true,
62
+ updatedAt = DateTime.UtcNow
63
+ }
64
+ };
65
+ }
66
+ else
67
+ {
68
+ LogWarning("UpdatePasswordFailCountMapping: Failed to update password fail count");
69
+
70
+ return new ScriptResponse
71
+ {
72
+ Data = new
73
+ {
74
+ passwordFailCountUpdated = false,
75
+ error = "Failed to update password fail count"
76
+ }
77
+ };
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,172 @@
1
+ using System;
2
+ using System.Threading.Tasks;
3
+ using BBT.Workflow.Definitions;
4
+ using BBT.Workflow.Scripting;
5
+ using BBT.Workflow.Scripting.Functions;
6
+
7
+ /// <summary>
8
+ /// Mapping for password verification HTTP task.
9
+ /// Sends encrypted password to verification endpoint.
10
+ /// </summary>
11
+ public class PasswordVerifyMapping : ScriptBase, IMapping
12
+ {
13
+ public async Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
14
+ {
15
+ var httpTask = (task as HttpTask)!;
16
+ if (httpTask == null)
17
+ {
18
+ throw new InvalidOperationException("Task must be an HttpTask");
19
+ }
20
+ string utilBaseAddress = string.Empty;
21
+ try
22
+ {
23
+ var utilBaseAddress = await GetSecretAsync("vnext-secret", "workflow-secret", "UtilBaseAddress");
24
+ }
25
+ catch (Exception ex)
26
+ {
27
+ LogError("PasswordVerifyMapping InputHandler: Error getting UtilBaseAddress from secrets", ex.Message);
28
+ }
29
+
30
+ // Replace placeholders in URL
31
+ httpTask.Url = httpTask.Url.Replace("{UtilBaseAddress}", utilBaseAddress);
32
+
33
+ // Get encrypted password from instance data
34
+ var encryptedPassword = HasProperty(context.Instance?.Data, "password")
35
+ ? context.Instance?.Data?.password?.ToString()
36
+ : string.Empty;
37
+
38
+ // Get user flow key (userName / TC kimlik no)
39
+ var userFlowKey = HasProperty(context.Instance?.Data, "userName")
40
+ ? context.Instance?.Data?.userName?.ToString()
41
+ : string.Empty;
42
+
43
+ // Get private key from client snapshot
44
+ var privateKey = string.Empty;
45
+ if (HasProperty(context.Instance?.Data, "clientSnapshot") &&
46
+ HasProperty(context.Instance?.Data?.clientSnapshot, "privateKey"))
47
+ {
48
+ privateKey = context.Instance?.Data?.clientSnapshot?.privateKey?.ToString() ?? string.Empty;
49
+ }
50
+
51
+ LogInformation($"PasswordVerifyMapping InputHandler: userFlowKey={userFlowKey}, hasPrivateKey={!string.IsNullOrEmpty(privateKey)}, url={httpTask.Url}");
52
+
53
+ // Build request body
54
+ var requestBody = new
55
+ {
56
+ encryptedPassword = encryptedPassword,
57
+ privateKey = privateKey,
58
+ userFlowKey = userFlowKey
59
+ };
60
+
61
+ httpTask.SetBody(requestBody);
62
+
63
+ return await Task.FromResult(new ScriptResponse());
64
+ }
65
+
66
+ public async Task<ScriptResponse> OutputHandler(ScriptContext context)
67
+ {
68
+ LogInformation("PasswordVerifyMapping OutputHandler: Processing password verification response");
69
+
70
+ try
71
+ {
72
+ int failCount = 0;
73
+ // Check if we got a response with data
74
+ if (!HasProperty(context.Body, "data"))
75
+ {
76
+ LogWarning("PasswordVerifyMapping OutputHandler: Invalid response - missing data");
77
+
78
+ failCount = GetFailCount(context);
79
+ failCount++;
80
+
81
+ return new ScriptResponse
82
+ {
83
+ Data = new
84
+ {
85
+ userValid = false,
86
+ failCount = failCount,
87
+ passwordVerified = false,
88
+ validationError = "Invalid response from password verification service"
89
+ }
90
+ };
91
+ }
92
+
93
+ var responseData = context.Body.data;
94
+
95
+ // Check if response indicates success
96
+ bool isValid = false;
97
+
98
+ if (HasProperty(responseData, "success"))
99
+ {
100
+ LogWarning($"PasswordVerifyMapping OutputHandler: Password verification failed, failCount={failCount}, error={responseData.success}");
101
+ isValid = responseData.success == true;
102
+ }
103
+
104
+
105
+ // Get fail count from instance data
106
+ failCount = GetFailCount(context);
107
+
108
+ if (isValid)
109
+ {
110
+
111
+
112
+ return new ScriptResponse
113
+ {
114
+ Data = new
115
+ {
116
+ userValid = true,
117
+ failCount = failCount,
118
+ passwordVerified = true
119
+ }
120
+ };
121
+ }
122
+ else
123
+ {
124
+ // Increment fail count on failed verification
125
+ failCount++;
126
+ var errorMessage = HasProperty(responseData, "error") ? responseData.error?.ToString() : "Invalid password";
127
+
128
+ LogWarning($"PasswordVerifyMapping OutputHandler: Password verification failed, failCount={failCount}, error={errorMessage}");
129
+
130
+ return new ScriptResponse
131
+ {
132
+ Data = new
133
+ {
134
+ userValid = false,
135
+ failCount = failCount,
136
+ passwordVerified = false,
137
+ validationError = errorMessage,
138
+ passwordVerificationResponse = responseData
139
+ }
140
+ };
141
+ }
142
+ }
143
+ catch (Exception ex)
144
+ {
145
+ LogError($"PasswordVerifyMapping OutputHandler: Error processing response - {ex.Message}");
146
+
147
+ int failCount = GetFailCount(context);
148
+ failCount++;
149
+
150
+ return new ScriptResponse
151
+ {
152
+ Data = new
153
+ {
154
+ userValid = false,
155
+ failCount = failCount,
156
+ passwordVerified = false,
157
+ validationError = $"Password verification error: {ex.Message}"
158
+ }
159
+ };
160
+ }
161
+ }
162
+
163
+ private int GetFailCount(ScriptContext context)
164
+ {
165
+ int failCount = 0;
166
+ if (HasProperty(context.Instance?.Data, "failCount"))
167
+ {
168
+ int.TryParse(context.Instance?.Data?.failCount?.ToString() ?? "0", out failCount);
169
+ }
170
+ return failCount;
171
+ }
172
+ }
@@ -0,0 +1,32 @@
1
+ using System.Threading.Tasks;
2
+ using BBT.Workflow.Scripting;
3
+ using BBT.Workflow.Scripting.Functions;
4
+
5
+ /// <summary>
6
+ /// Rule: Check if person was fetched successfully
7
+ /// Returns true if personSnapshot exists and is not null
8
+ /// </summary>
9
+ public class PersonFetchedRule : ScriptBase, IConditionMapping
10
+ {
11
+ public async Task<bool> Handler(ScriptContext context)
12
+ {
13
+ // Check if person snapshot exists
14
+ if (!HasProperty(context.Instance?.Data, "personSnapshot"))
15
+ {
16
+ LogWarning("PersonFetchedRule: personSnapshot property not found");
17
+ return false;
18
+ }
19
+
20
+ var personSnapshot = context.Instance?.Data?.personSnapshot;
21
+
22
+ if (personSnapshot != null)
23
+ {
24
+ LogInformation("PersonFetchedRule: Person fetched successfully");
25
+ return true;
26
+ }
27
+
28
+ LogWarning("PersonFetchedRule: personSnapshot is null");
29
+ return false;
30
+ }
31
+ }
32
+
@@ -0,0 +1,61 @@
1
+ using System.Threading.Tasks;
2
+ using BBT.Workflow.Definitions;
3
+ using BBT.Workflow.Scripting;
4
+ using BBT.Workflow.Scripting.Functions;
5
+
6
+ /// <summary>
7
+ /// Mapping for fetching person instance data from person workflow.
8
+ /// Uses the person key from userSnapshot to get person details.
9
+ /// </summary>
10
+ public class PersonGetMapping : ScriptBase, IMapping
11
+ {
12
+ public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
13
+ {
14
+ var triggerTask = (task as GetInstanceDataTask)!;
15
+
16
+ // Get person key from userSnapshot.person.key
17
+ var personKey = string.Empty;
18
+
19
+ if (HasProperty(context.Instance?.Data, "userSnapshot") &&
20
+ HasProperty(context.Instance?.Data?.userSnapshot, "person") &&
21
+ HasProperty(context.Instance?.Data?.userSnapshot?.person, "key"))
22
+ {
23
+ personKey = context.Instance?.Data?.userSnapshot?.person?.key?.ToString() ?? string.Empty;
24
+ }
25
+
26
+ LogInformation($"PersonGetMapping InputHandler: Fetching person with key={personKey}");
27
+
28
+ triggerTask.SetKey(personKey);
29
+ return Task.FromResult(new ScriptResponse());
30
+ }
31
+
32
+ public async Task<ScriptResponse> OutputHandler(ScriptContext context)
33
+ {
34
+ if (HasProperty(context.Body, "data") && HasProperty(context.Body.data, "data"))
35
+ {
36
+ LogInformation("PersonGetMapping OutputHandler: Person data fetched successfully");
37
+
38
+ return new ScriptResponse
39
+ {
40
+ Data = new
41
+ {
42
+ personSnapshot = context.Body.data.data
43
+ }
44
+ };
45
+ }
46
+ else
47
+ {
48
+ LogWarning("PersonGetMapping OutputHandler: Person not found");
49
+
50
+ return new ScriptResponse
51
+ {
52
+ Data = new
53
+ {
54
+ personSnapshot = (object?)null,
55
+ personFetchError = "Person not found"
56
+ }
57
+ };
58
+ }
59
+ }
60
+ }
61
+