@pax2pay/model-banking 0.1.384 → 0.1.386

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 (82) hide show
  1. package/Card/Creatable.ts +2 -1
  2. package/Card/index.ts +2 -1
  3. package/Operation/Changes.ts +25 -0
  4. package/Operation/Creatable.ts +1 -18
  5. package/Organization/index.ts +2 -1
  6. package/Rule/{Rule/Base.ts → Base.ts} +7 -0
  7. package/Rule/Charge.ts +108 -0
  8. package/Rule/Other.ts +48 -0
  9. package/Rule/Reserve.ts +111 -0
  10. package/Rule/Score.ts +45 -0
  11. package/Rule/State/Transaction.ts +17 -4
  12. package/Rule/State/index.ts +3 -2
  13. package/Rule/control.ts +8 -0
  14. package/Rule/index.ts +76 -97
  15. package/Rule/type.ts +13 -0
  16. package/Transaction/index.ts +3 -3
  17. package/dist/Authorization/Status.d.ts +1 -1
  18. package/dist/Card/Creatable.d.ts +1 -1
  19. package/dist/Card/Creatable.js +1 -1
  20. package/dist/Card/Creatable.js.map +1 -1
  21. package/dist/Card/index.d.ts +1 -1
  22. package/dist/Card/index.js +1 -1
  23. package/dist/Card/index.js.map +1 -1
  24. package/dist/Operation/Changes.d.ts +2 -0
  25. package/dist/Operation/Changes.js +20 -0
  26. package/dist/Operation/Changes.js.map +1 -1
  27. package/dist/Operation/Creatable.d.ts +1 -1
  28. package/dist/Operation/Creatable.js +1 -13
  29. package/dist/Operation/Creatable.js.map +1 -1
  30. package/dist/Organization/index.d.ts +3 -3
  31. package/dist/Organization/index.js +1 -1
  32. package/dist/Organization/index.js.map +1 -1
  33. package/dist/Rail/index.d.ts +1 -1
  34. package/dist/Rule/{Rule/Base.d.ts → Base.d.ts} +1 -0
  35. package/dist/Rule/{Rule/Base.js → Base.js} +6 -0
  36. package/dist/Rule/Base.js.map +1 -0
  37. package/dist/Rule/Charge.d.ts +40 -0
  38. package/dist/Rule/Charge.js +68 -0
  39. package/dist/Rule/Charge.js.map +1 -0
  40. package/dist/Rule/{Rule/Other.d.ts → Other.d.ts} +8 -0
  41. package/dist/Rule/Other.js +38 -0
  42. package/dist/Rule/Other.js.map +1 -0
  43. package/dist/Rule/Reserve.d.ts +38 -0
  44. package/dist/Rule/Reserve.js +76 -0
  45. package/dist/Rule/Reserve.js.map +1 -0
  46. package/dist/Rule/{Rule/Score.d.ts → Score.d.ts} +6 -0
  47. package/dist/Rule/Score.js +30 -0
  48. package/dist/Rule/Score.js.map +1 -0
  49. package/dist/Rule/State/Transaction.d.ts +9 -4
  50. package/dist/Rule/State/Transaction.js +7 -2
  51. package/dist/Rule/State/Transaction.js.map +1 -1
  52. package/dist/Rule/State/index.d.ts +3 -3
  53. package/dist/Rule/State/index.js +2 -2
  54. package/dist/Rule/State/index.js.map +1 -1
  55. package/dist/Rule/control.d.ts +4 -0
  56. package/dist/Rule/control.js +6 -0
  57. package/dist/Rule/control.js.map +1 -0
  58. package/dist/Rule/index.d.ts +29 -13
  59. package/dist/Rule/index.js +68 -70
  60. package/dist/Rule/index.js.map +1 -1
  61. package/dist/Rule/type.d.ts +3 -0
  62. package/dist/Rule/type.js +7 -0
  63. package/dist/Rule/type.js.map +1 -0
  64. package/dist/Transaction/Status.d.ts +1 -1
  65. package/dist/Transaction/index.js +3 -3
  66. package/dist/Transaction/index.js.map +1 -1
  67. package/package.json +1 -1
  68. package/Rule/Rule/Charge.ts +0 -48
  69. package/Rule/Rule/Other.ts +0 -14
  70. package/Rule/Rule/Score.ts +0 -21
  71. package/Rule/Rule/index.ts +0 -37
  72. package/dist/Rule/Rule/Base.js.map +0 -1
  73. package/dist/Rule/Rule/Charge.d.ts +0 -29
  74. package/dist/Rule/Rule/Charge.js +0 -34
  75. package/dist/Rule/Rule/Charge.js.map +0 -1
  76. package/dist/Rule/Rule/Other.js +0 -12
  77. package/dist/Rule/Rule/Other.js.map +0 -1
  78. package/dist/Rule/Rule/Score.js +0 -16
  79. package/dist/Rule/Rule/Score.js.map +0 -1
  80. package/dist/Rule/Rule/index.d.ts +0 -24
  81. package/dist/Rule/Rule/index.js +0 -27
  82. package/dist/Rule/Rule/index.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Charge.js","sourceRoot":"../","sources":["Rule/Charge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AASnC,MAAM,KAAW,MAAM,CA2FtB;AA3FD,WAAiB,MAAM;IAEtB,IAAiB,MAAM,CAEtB;IAFD,WAAiB,MAAM;QACT,YAAK,GAAG,QAAQ,CAAA;IAC9B,CAAC,EAFgB,MAAM,GAAN,aAAM,KAAN,aAAM,QAEtB;IAQD,IAAiB,GAAG,CAQnB;IARD,WAAiB,GAAG;QACN,QAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAM;YACzC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YACjC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;gBACnB,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;gBACpC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAkB,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;aACzE,CAAC;SACF,CAAC,CAAA;IACH,CAAC,EARgB,GAAG,GAAH,UAAG,KAAH,UAAG,QAQnB;IAGD,SAAgB,OAAO,CAAC,IAAS,EAAE,QAAgC;QAClE,OAAO;YACN,GAAG,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,KAAY;QAC7E,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,eAAe;YAC/C,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,UAAU;YACpC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,SAAS;YACnC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC;YAC3G,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IAClH,CAAC;IANe,YAAK,QAMpB,CAAA;AACF,CAAC,EA3FgB,MAAM,KAAN,MAAM,QA2FtB"}
@@ -1,5 +1,8 @@
1
+ import { selectively } from "selectively";
1
2
  import { isly } from "isly";
3
+ import type { Note } from "../Transaction/Note";
2
4
  import { Base } from "./Base";
5
+ import type { State } from "./State";
3
6
  export interface Other extends Base {
4
7
  action: Other.Action;
5
8
  }
@@ -10,4 +13,9 @@ export declare namespace Other {
10
13
  const type: isly.Type<"review" | "reject" | "flag">;
11
14
  }
12
15
  const type: isly.object.ExtendableType<Other>;
16
+ function evaluate(rules: Other[], state: State, macros?: Record<string, selectively.Definition>): {
17
+ outcomes: Record<Other.Action, Other[]>;
18
+ notes: Note[];
19
+ flags: Set<string>;
20
+ };
13
21
  }
@@ -0,0 +1,38 @@
1
+ import { isoly } from "isoly";
2
+ import { isly } from "isly";
3
+ import { Base } from "./Base";
4
+ import { control } from "./control";
5
+ export var Other;
6
+ (function (Other) {
7
+ let Action;
8
+ (function (Action) {
9
+ Action.values = ["review", "reject", "flag"];
10
+ Action.type = isly.string(Action.values);
11
+ })(Action = Other.Action || (Other.Action = {}));
12
+ Other.type = Base.type.extend({ action: Action.type });
13
+ function evaluate(rules, state, macros) {
14
+ const now = isoly.DateTime.now();
15
+ const result = {
16
+ outcomes: {
17
+ review: [],
18
+ reject: [],
19
+ flag: [],
20
+ },
21
+ notes: [],
22
+ flags: new Set(),
23
+ };
24
+ if (state.transaction.stage == "initiate" &&
25
+ ["card", "external", "internal"].some(type => type == state.transaction.type))
26
+ for (const rule of rules) {
27
+ if (control(rule, state, macros)) {
28
+ result.outcomes[rule.action].push(rule);
29
+ result.notes.push({ author: "automatic", created: now, text: rule.name, rule });
30
+ rule.flags.forEach(f => result.flags.add(f));
31
+ rule.action == "review" && result.flags.add("review");
32
+ }
33
+ }
34
+ return result;
35
+ }
36
+ Other.evaluate = evaluate;
37
+ })(Other || (Other = {}));
38
+ //# sourceMappingURL=Other.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Other.js","sourceRoot":"../","sources":["Rule/Other.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,MAAM,KAAW,KAAK,CAoCrB;AApCD,WAAiB,KAAK;IAErB,IAAiB,MAAM,CAGtB;IAHD,WAAiB,MAAM;QACT,aAAM,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAA;QAC9C,WAAI,GAAG,IAAI,CAAC,MAAM,CAAS,OAAA,MAAM,CAAC,CAAA;IAChD,CAAC,EAHgB,MAAM,GAAN,YAAM,KAAN,YAAM,QAGtB;IACY,UAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;IACpE,SAAgB,QAAQ,CACvB,KAAc,EAC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+ import { isoly } from "isoly";
2
+ import { selectively } from "selectively";
3
+ import { isly } from "isly";
4
+ import { Amount } from "../Amount";
5
+ import { Exchange } from "../Exchange";
6
+ import { Realm } from "../Realm";
7
+ import { Base } from "./Base";
8
+ import type { State } from "./State";
9
+ export interface Reserve extends Reserve.Api {
10
+ reserve: {
11
+ percentage?: number;
12
+ fixed?: Amount;
13
+ };
14
+ }
15
+ export declare namespace Reserve {
16
+ type Action = typeof Action.value;
17
+ namespace Action {
18
+ const value = "reserve";
19
+ }
20
+ const type: isly.object.ExtendableType<Reserve>;
21
+ interface Api extends Base {
22
+ action: Reserve.Action;
23
+ reserve: {
24
+ percentage?: number;
25
+ fixed?: number | Amount;
26
+ };
27
+ }
28
+ namespace Api {
29
+ const type: isly.object.ExtendableType<Api>;
30
+ }
31
+ function fromApi(rule: Api, realm: Realm): Reserve;
32
+ function fromApi(rule: Api, currency: isoly.Currency): Reserve;
33
+ function evaluate(rules: Reserve[], state: State, macros?: Record<string, selectively.Definition>, table?: Exchange.Rates): {
34
+ outcomes: Reserve[];
35
+ reserve: number;
36
+ };
37
+ function apply(reserve: number, state: State): number;
38
+ }
@@ -0,0 +1,76 @@
1
+ import { isoly } from "isoly";
2
+ import { isly } from "isly";
3
+ import { Amount } from "../Amount";
4
+ import { Exchange } from "../Exchange";
5
+ import { Realm } from "../Realm";
6
+ import { Base } from "./Base";
7
+ import { control } from "./control";
8
+ export var Reserve;
9
+ (function (Reserve) {
10
+ let Action;
11
+ (function (Action) {
12
+ Action.value = "reserve";
13
+ })(Action = Reserve.Action || (Reserve.Action = {}));
14
+ Reserve.type = Base.type.extend({
15
+ action: isly.string(Action.value),
16
+ reserve: isly.object({
17
+ percentage: isly.number(),
18
+ fixed: Amount.type.optional(),
19
+ }),
20
+ });
21
+ let Api;
22
+ (function (Api) {
23
+ Api.type = Base.type.extend({
24
+ action: isly.string(Action.value),
25
+ reserve: isly.object({
26
+ percentage: isly.number().optional(),
27
+ fixed: isly.union(Amount.type, isly.number()).optional(),
28
+ }),
29
+ });
30
+ })(Api = Reserve.Api || (Reserve.Api = {}));
31
+ function fromApi(rule, currency) {
32
+ return {
33
+ ...rule,
34
+ reserve: {
35
+ ...rule.reserve,
36
+ fixed: typeof rule.reserve.fixed == "number"
37
+ ? [Realm.is(currency) ? Realm.currency[currency] : currency, rule.reserve.fixed]
38
+ : rule.reserve.fixed,
39
+ },
40
+ };
41
+ }
42
+ Reserve.fromApi = fromApi;
43
+ function evaluate(rules, state, macros, table = {}) {
44
+ const result = {
45
+ outcomes: [],
46
+ reserve: 0,
47
+ };
48
+ if (state.transaction.stage == "initiate" &&
49
+ ["authorization", "outbound"].some(kind => kind == state.transaction.kind) &&
50
+ ["card", "external"].some(type => type == state.transaction.type))
51
+ for (const rule of rules) {
52
+ if (control(rule, state, macros)) {
53
+ if (rule.reserve.percentage)
54
+ result.reserve = isoly.Currency.add(state.transaction.original.currency, result.reserve, isoly.Currency.multiply(state.transaction.original.currency, state.transaction.original.amount, rule.reserve.percentage / 100));
55
+ if (rule.reserve.fixed) {
56
+ const reserve = state.transaction.original.currency === rule.reserve.fixed[0]
57
+ ? rule.reserve.fixed[1]
58
+ : Exchange.convert(rule.reserve.fixed[1], rule.reserve.fixed[0], state.transaction.original.currency, table) ?? 0;
59
+ result.reserve = isoly.Currency.add(state.transaction.original.currency, result.reserve, reserve);
60
+ }
61
+ result.outcomes.push(rule);
62
+ }
63
+ }
64
+ return result;
65
+ }
66
+ Reserve.evaluate = evaluate;
67
+ function apply(reserve, state) {
68
+ return state.transaction.kind == "authorization" ||
69
+ state.transaction.kind == "outbound" ||
70
+ state.transaction.kind == "capture"
71
+ ? isoly.Currency.add(state.transaction.original.currency, state.transaction.original.total, reserve)
72
+ : isoly.Currency.subtract(state.transaction.original.currency, state.transaction.original.total, reserve);
73
+ }
74
+ Reserve.apply = apply;
75
+ })(Reserve || (Reserve = {}));
76
+ //# sourceMappingURL=Reserve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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e;YAC/C,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,UAAU;YACpC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,SAAS;YACnC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;YACpG,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC3G,CAAC;IANe,aAAK,QAMpB,CAAA;AACF,CAAC,EA9FgB,OAAO,KAAP,OAAO,QA8FvB"}
@@ -1,5 +1,7 @@
1
+ import { selectively } from "selectively";
1
2
  import { isly } from "isly";
2
3
  import { Base } from "./Base";
4
+ import type { State } from "./State";
3
5
  export interface Score extends Base {
4
6
  action: Score.Action;
5
7
  category: "fincrime";
@@ -13,4 +15,8 @@ export declare namespace Score {
13
15
  type Risk = number;
14
16
  const Risk: isly.Type<number>;
15
17
  const type: isly.object.ExtendableType<Score>;
18
+ function evaluate(rules: Score[], state: State, macros?: Record<string, selectively.Definition>): {
19
+ outcomes: Score[];
20
+ risk?: number | undefined;
21
+ };
16
22
  }
@@ -0,0 +1,30 @@
1
+ import { isly } from "isly";
2
+ import { Base } from "./Base";
3
+ import { control } from "./control";
4
+ export var Score;
5
+ (function (Score) {
6
+ let Action;
7
+ (function (Action) {
8
+ Action.value = "score";
9
+ })(Action = Score.Action || (Score.Action = {}));
10
+ Score.Risk = isly.number(["positive", "integer"]);
11
+ Score.type = Base.type.extend({
12
+ action: isly.string(Action.value),
13
+ category: isly.string("fincrime"),
14
+ risk: Score.Risk,
15
+ });
16
+ function evaluate(rules, state, macros) {
17
+ const result = { outcomes: [] };
18
+ if (state.transaction.stage == "initiate" &&
19
+ ["card", "external", "internal"].some(type => type == state.transaction.type))
20
+ for (const rule of rules) {
21
+ if (control(rule, state, macros)) {
22
+ result.risk = (result.risk ?? 100) * (rule.risk / 100);
23
+ result.outcomes.push(rule);
24
+ }
25
+ }
26
+ return result;
27
+ }
28
+ Score.evaluate = evaluate;
29
+ })(Score || (Score = {}));
30
+ //# sourceMappingURL=Score.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Score.js","sourceRoot":"../","sources":["Rule/Score.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQnC,MAAM,KAAW,KAAK,CAiCrB;AAjCD,WAAiB,KAAK;IAErB,IAAiB,MAAM,CAEtB;IAFD,WAAiB,MAAM;QACT,YAAK,GAAG,OAAO,CAAA;IAC7B,CAAC,EAFgB,MAAM,GAAN,YAAM,KAAN,YAAM,QAEtB;IAEY,UAAI,GAAG,IAAI,CAAC,MAAM,CAAO,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAA;IACjD,UAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAQ;QAC3C,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;QACjC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;QACjC,IAAI,EAAE,MAAA,IAAI;KACV,CAAC,CAAA;IACF,SAAgB,QAAQ,CACvB,KAAc,EACd,KAAY,EACZ,MAA+C;QAK/C,MAAM,MAAM,GAAgC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAA;QAC5D,IACC,KAAK,CAAC,WAAW,CAAC,KAAK,IAAI,UAAU;YACrC,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;YAE7E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;oBAClC,MAAM,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,CAAA;oBACtD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBAC3B,CAAC;YACF,CAAC;QACF,OAAO,MAAM,CAAA;IACd,CAAC;IApBe,cAAQ,WAoBvB,CAAA;AACF,CAAC,EAjCgB,KAAK,KAAL,KAAK,QAiCrB"}
@@ -1,21 +1,26 @@
1
1
  import { isoly } from "isoly";
2
2
  import type { Address } from "../../Rail/Address";
3
3
  import { Transaction as ModelTransaction } from "../../Transaction";
4
- import { Rule } from "../Rule";
4
+ import type { Rule } from "../index";
5
5
  export interface Transaction extends ModelTransaction.Creatable {
6
6
  kind: Rule.Base.Kind;
7
+ stage: "finalize" | "initiate";
7
8
  amount: number;
8
9
  type: ModelTransaction.Types;
9
10
  risk?: number;
10
11
  original: {
11
12
  currency: isoly.Currency;
13
+ total: number;
12
14
  amount: number;
13
- charge?: number;
14
- total?: number;
15
+ charge?: {
16
+ current: number;
17
+ total: number;
18
+ };
19
+ reserve?: number;
15
20
  };
16
21
  }
17
22
  export declare namespace Transaction {
18
23
  function from(accountName: string, transaction: ModelTransaction.Creatable & {
19
24
  counterpart: Address;
20
- }, kind: Rule.Base.Kind): Transaction;
25
+ }, kind: Rule.Base.Kind, stage: "finalize" | "initiate"): Transaction;
21
26
  }
@@ -1,13 +1,18 @@
1
1
  import { Transaction as ModelTransaction } from "../../Transaction";
2
2
  export var Transaction;
3
3
  (function (Transaction) {
4
- function from(accountName, transaction, kind) {
4
+ function from(accountName, transaction, kind, stage) {
5
5
  return {
6
6
  ...transaction,
7
+ stage,
7
8
  kind,
8
9
  amount: Math.abs(transaction.amount),
9
10
  type: ModelTransaction.getType(transaction.counterpart, accountName),
10
- original: { currency: transaction.currency, amount: Math.abs(transaction.amount) },
11
+ original: {
12
+ currency: transaction.currency,
13
+ amount: Math.abs(transaction.amount),
14
+ total: Math.abs(transaction.amount),
15
+ },
11
16
  };
12
17
  }
13
18
  Transaction.from = from;
@@ -1 +1 @@
1
- {"version":3,"file":"Transaction.js","sourceRoot":"../","sources":["Rule/State/Transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAUnE,MAAM,KAAW,WAAW,CAc3B;AAdD,WAAiB,WAAW;IAC3B,SAAgB,IAAI,CACnB,WAAmB,EACnB,WAAkE,EAClE,IAAoB;QAEpB,OAAO;YACN,GAAG,WAAW;YACd,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC;YACpC,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,WAAW,CAAC;YACpE,QAAQ,EAAE,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;SAClF,CAAA;IACF,CAAC;IAZe,gBAAI,OAYnB,CAAA;AACF,CAAC,EAdgB,WAAW,KAAX,WAAW,QAc3B"}
1
+ {"version":3,"file":"Transaction.js","sourceRoot":"../","sources":["Rule/State/Transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAiBnE,MAAM,KAAW,WAAW,CAoB3B;AApBD,WAAiB,WAAW;IAC3B,SAAgB,IAAI,CACnB,WAAmB,EACnB,WAAkE,EAClE,IAAoB,EACpB,KAA8B;QAE9B,OAAO;YACN,GAAG,WAAW;YACd,KAAK;YACL,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC;YACpC,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,WAAW,CAAC;YACpE,QAAQ,EAAE;gBACT,QAAQ,EAAE,WAAW,CAAC,QAAQ;gBAC9B,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC;gBACpC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC;aACnC;SACD,CAAA;IACF,CAAC;IAlBe,gBAAI,OAkBnB,CAAA;AACF,CAAC,EApBgB,WAAW,KAAX,WAAW,QAoB3B"}
@@ -2,7 +2,7 @@ import { isly } from "isly";
2
2
  import { Account as ModelAccount } from "../../Account";
3
3
  import type { Address } from "../../Rail/Address";
4
4
  import type { Transaction as ModelTransaction } from "../../Transaction";
5
- import { Rule } from "../Rule";
5
+ import type { Rule } from "../index";
6
6
  import { Account as StateAccount } from "./Account";
7
7
  import { Authorization as StateAuthorization } from "./Authorization";
8
8
  import { Card as StateCard } from "./Card";
@@ -29,7 +29,7 @@ export declare namespace State {
29
29
  type Outcome = typeof Outcome.values[number];
30
30
  namespace Outcome {
31
31
  const values: readonly ["approve", "reject", "review"];
32
- const type: isly.Type<"review" | "reject" | "approve">;
32
+ const type: isly.Type<"review" | "approve" | "reject">;
33
33
  }
34
34
  interface Evaluated extends State {
35
35
  outcomes: globalThis.Partial<Record<Rule.Action, Rule[]>>;
@@ -39,5 +39,5 @@ export declare namespace State {
39
39
  }
40
40
  function from(data: Data, account: ModelAccount, transactions: Account.Transactions, days: Account.Days, transaction: ModelTransaction.Creatable & {
41
41
  counterpart: Address;
42
- }, kind: Rule.Base.Kind, authorization?: Authorization, card?: Card, organization?: Organization): State;
42
+ }, kind: Rule.Base.Kind, stage: "finalize" | "initiate", authorization?: Authorization, card?: Card, organization?: Organization): State;
43
43
  }
@@ -18,11 +18,11 @@ export var State;
18
18
  Outcome.values = ["approve", "reject", "review"];
19
19
  Outcome.type = isly.string(Outcome.values);
20
20
  })(Outcome = State.Outcome || (State.Outcome = {}));
21
- function from(data, account, transactions, days, transaction, kind, authorization, card, organization) {
21
+ function from(data, account, transactions, days, transaction, kind, stage, authorization, card, organization) {
22
22
  return {
23
23
  data,
24
24
  account: State.Account.from(account, transactions, days),
25
- transaction: State.Transaction.from(account.name, transaction, kind),
25
+ transaction: State.Transaction.from(account.name, transaction, kind, stage),
26
26
  authorization,
27
27
  card,
28
28
  organization,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../","sources":["Rule/State/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAK3B,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,aAAa,IAAI,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAA;AAE1C,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAU/D,MAAM,KAAW,KAAK,CAuCrB;AAvCD,WAAiB,KAAK;IACP,aAAO,GAAG,YAAY,CAAA;IACtB,mBAAa,GAAG,kBAAkB,CAAA;IAClC,UAAI,GAAG,SAAS,CAAA;IAChB,aAAO,GAAG,YAAY,CAAA;IACtB,iBAAW,GAAG,gBAAgB,CAAA;IAC9B,kBAAY,GAAG,iBAAiB,CAAA;IAG9C,IAAiB,OAAO,CAGvB;IAHD,WAAiB,OAAO;QACV,cAAM,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CA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SAAS,CAAA;IAChB,aAAO,GAAG,YAAY,CAAA;IACtB,iBAAW,GAAG,gBAAgB,CAAA;IAC9B,kBAAY,GAAG,iBAAiB,CAAA;IAG9C,IAAiB,OAAO,CAGvB;IAHD,WAAiB,OAAO;QACV,cAAM,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAA;QACjD,YAAI,GAAG,IAAI,CAAC,MAAM,CAAU,QAAA,MAAM,CAAC,CAAA;IACjD,CAAC,EAHgB,OAAO,GAAP,aAAO,KAAP,aAAO,QAGvB;IAOD,SAAgB,IAAI,CACnB,IAAU,EACV,OAAqB,EACrB,YAAkC,EAClC,IAAkB,EAClB,WAAkE,EAClE,IAAoB,EACpB,KAA8B,EAC9B,aAA6B,EAC7B,IAAW,EACX,YAA2B;QAE3B,OAAO;YACN,IAAI;YACJ,OAAO,EAAE,MAAA,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC;YAClD,WAAW,EAAE,MAAA,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC;YACrE,aAAa;YACb,IAAI;YACJ,YAAY;SACZ,CAAA;IACF,CAAC;IApBe,UAAI,OAoBnB,CAAA;AACF,CAAC,EAxCgB,KAAK,KAAL,KAAK,QAwCrB"}
@@ -0,0 +1,4 @@
1
+ import { selectively } from "selectively";
2
+ import type { Rule } from ".";
3
+ import type { State } from "./State";
4
+ export declare function control(rule: Rule, state: State, macros?: Record<string, selectively.Definition>): boolean;
@@ -0,0 +1,6 @@
1
+ import { selectively } from "selectively";
2
+ import { definitions } from "./definitions";
3
+ export function control(rule, state, macros) {
4
+ return selectively.resolve({ ...macros, ...definitions }, selectively.parse(rule.condition)).is(state);
5
+ }
6
+ //# sourceMappingURL=control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control.js","sourceRoot":"../","sources":["Rule/control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,MAAM,UAAU,OAAO,CAAC,IAAU,EAAE,KAAY,EAAE,MAA+C;IAChG,OAAO,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,WAAW,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;AACvG,CAAC"}
@@ -1,21 +1,37 @@
1
1
  import { selectively } from "selectively";
2
+ import { isly } from "isly";
2
3
  import { Exchange } from "../Exchange";
3
- import { Rule as ModelRule } from "./Rule";
4
+ import { Realm } from "../Realm";
5
+ import { Base as RuleBase } from "./Base";
6
+ import { Charge as RuleCharge } from "./Charge";
7
+ import { control as ruleControl } from "./control";
8
+ import { Other as RuleOther } from "./Other";
9
+ import { Reserve as RuleReserve } from "./Reserve";
10
+ import { Score as RuleScore } from "./Score";
4
11
  import { State as RuleState } from "./State";
5
- export type Rule = ModelRule;
12
+ export type Rule = Rule.Other | Rule.Score | Rule.Charge | Rule.Reserve;
6
13
  export declare namespace Rule {
7
- export import Api = ModelRule.Api;
8
- export import Action = ModelRule.Action;
9
- export import Category = ModelRule.Base.Category;
10
- export import Kind = ModelRule.Base.Kind;
11
- export import Other = ModelRule.Other;
12
- export import Score = ModelRule.Score;
13
- export import Charge = ModelRule.Charge;
14
+ export import Other = RuleOther;
15
+ export import Score = RuleScore;
16
+ export import Charge = RuleCharge;
14
17
  export import State = RuleState;
15
- const type: import("isly/dist/cjs/Type").Type<Charge | Other | Score>;
16
- const is: import("isly/dist/cjs/Type").Type.IsFunction<Charge | Other | Score>;
17
- const flaw: import("isly/dist/cjs/Type").Type.FlawFunction;
18
- function evaluate(rules: Rule[], state: State, macros?: Record<string, selectively.Definition>, table?: Exchange.Rates): State.Evaluated;
18
+ export import Reserve = RuleReserve;
19
+ export import Base = RuleBase;
20
+ export import Kind = Base.Kind;
21
+ export import Category = Base.Category;
22
+ const control: typeof ruleControl;
23
+ type Api = Rule.Other | Rule.Score | Rule.Charge.Api | Rule.Reserve.Api;
24
+ namespace Api {
25
+ const type: isly.Type<Api>;
26
+ }
27
+ function fromApi(rule: Rule.Api, realm: Realm): Rule;
28
+ type Action = typeof Action.values[number];
29
+ namespace Action {
30
+ const values: readonly ["review", "reject", "flag", "score", "charge", "reserve"];
31
+ const type: isly.Type<"charge" | "review" | "reject" | "flag" | "score" | "reserve">;
32
+ }
33
+ const type: isly.Type<Rule>;
34
+ function evaluate(rules: Rule[], state: RuleState, macros?: Record<string, selectively.Definition>, table?: Exchange.Rates): RuleState.Evaluated;
19
35
  function isLegacy(rule: Rule): boolean;
20
36
  function fromLegacy(rule: Rule): Rule;
21
37
  }
@@ -1,92 +1,90 @@
1
- import { isoly } from "isoly";
2
- import { selectively } from "selectively";
3
- import { Exchange } from "../Exchange";
4
- import { definitions } from "./definitions";
5
- import { Rule as ModelRule, type as ruleType } from "./Rule";
1
+ import { isly } from "isly";
2
+ import { Base as RuleBase } from "./Base";
3
+ import { Charge as RuleCharge } from "./Charge";
4
+ import { control as ruleControl } from "./control";
5
+ import { Other as RuleOther } from "./Other";
6
+ import { Reserve as RuleReserve } from "./Reserve";
7
+ import { Score as RuleScore } from "./Score";
6
8
  import { State as RuleState } from "./State";
9
+ import { type as ruleType } from "./type";
7
10
  export var Rule;
8
11
  (function (Rule) {
9
- Rule.Api = ModelRule.Api;
10
- Rule.Action = ModelRule.Action;
11
- Rule.Category = ModelRule.Base.Category;
12
- Rule.Kind = ModelRule.Base.Kind;
13
- Rule.Other = ModelRule.Other;
14
- Rule.Score = ModelRule.Score;
15
- Rule.Charge = ModelRule.Charge;
12
+ Rule.Other = RuleOther;
13
+ Rule.Score = RuleScore;
14
+ Rule.Charge = RuleCharge;
16
15
  Rule.State = RuleState;
17
- Rule.type = ruleType;
18
- Rule.is = ruleType.is;
19
- Rule.flaw = ruleType.flaw;
20
- function shouldUse(kind, rule, groups) {
21
- return (kind == rule.type &&
22
- (!rule.groups || rule.groups.some(ruleGroup => groups?.some(organizationGroup => organizationGroup == ruleGroup))));
23
- }
24
- function control(rule, state, macros) {
25
- return selectively.resolve({ ...macros, ...definitions }, selectively.parse(rule.condition)).is(state);
26
- }
27
- function score(rules, state, macros) {
28
- return rules.reduce((r, rule) => (control(rule, state, macros) ? (r ?? 100) * (rule.risk / 100) : r), undefined);
29
- }
30
- function charge(rules, state, macros, table = {}) {
31
- const result = { outcomes: [], charge: 0 };
32
- for (const rule of rules) {
33
- if (control(rule, state, macros)) {
34
- if (rule.charge.percentage)
35
- result.charge = isoly.Currency.add(state.transaction.currency, result.charge, isoly.Currency.multiply(state.transaction.currency, state.transaction.amount, rule.charge.percentage / 100));
36
- if (rule.charge.fixed) {
37
- const charge = state.transaction.currency === rule.charge.fixed[0]
38
- ? rule.charge.fixed[1]
39
- : Exchange.convert(rule.charge.fixed[1], rule.charge.fixed[0], state.transaction.currency, table) ?? 0;
40
- result.charge = isoly.Currency.add(state.transaction.currency, result.charge, charge);
41
- }
42
- result.outcomes.push(rule);
43
- }
44
- }
45
- return result;
16
+ Rule.Reserve = RuleReserve;
17
+ Rule.Base = RuleBase;
18
+ Rule.Kind = Rule.Base.Kind;
19
+ Rule.Category = Rule.Base.Category;
20
+ Rule.control = ruleControl;
21
+ let Api;
22
+ (function (Api) {
23
+ Api.type = isly.union(Rule.Other.type, Rule.Score.type, Rule.Charge.Api.type, Rule.Reserve.Api.type);
24
+ })(Api = Rule.Api || (Rule.Api = {}));
25
+ function fromApi(rule, realm) {
26
+ return rule.action == "charge"
27
+ ? Rule.Charge.fromApi(rule, realm)
28
+ : rule.action == "reserve"
29
+ ? Rule.Reserve.fromApi(rule, realm)
30
+ : rule;
46
31
  }
32
+ Rule.fromApi = fromApi;
33
+ let Action;
34
+ (function (Action) {
35
+ Action.values = [
36
+ ...Rule.Other.Action.values,
37
+ Rule.Score.Action.value,
38
+ Rule.Charge.Action.value,
39
+ Rule.Reserve.Action.value,
40
+ ];
41
+ Action.type = isly.string(Action.values);
42
+ })(Action = Rule.Action || (Rule.Action = {}));
43
+ Rule.type = ruleType;
47
44
  function evaluate(rules, state, macros, table = {}) {
48
45
  const outcomes = {
49
46
  review: [],
50
47
  reject: [],
51
48
  flag: [],
52
49
  charge: [],
50
+ score: [],
51
+ reserve: [],
53
52
  };
54
- const { other, chargers, scorers } = rules.reduce((r, rule) => {
55
- if (shouldUse(state.transaction.kind, rule, state.organization?.groups))
53
+ const { other, chargers, scorers, reservers } = sort(rules, state);
54
+ const scored = Rule.Score.evaluate(scorers, state, macros);
55
+ outcomes.score.push(...scored.outcomes);
56
+ state.transaction.risk = scored.risk;
57
+ const evaluated = Rule.Other.evaluate(other, state, macros);
58
+ outcomes.flag.push(...evaluated.outcomes.flag);
59
+ outcomes.review.push(...evaluated.outcomes.review);
60
+ outcomes.reject.push(...evaluated.outcomes.reject);
61
+ const reserved = Rule.Reserve.evaluate(reservers, state, macros, table);
62
+ outcomes.reserve.push(...reserved.outcomes);
63
+ state.transaction.original.reserve = reserved.reserve;
64
+ state.transaction.original.total = Rule.Reserve.apply(reserved.reserve, state);
65
+ const charged = Rule.Charge.evaluate(chargers, state, macros, table);
66
+ outcomes.charge.push(...charged.outcomes);
67
+ state.transaction.original.charge = charged.charge;
68
+ state.transaction.original.total = Rule.Charge.apply(charged.charge, state);
69
+ const outcome = outcomes.reject.length > 0 ? "reject" : outcomes.review.length > 0 ? "review" : "approve";
70
+ return { ...state, flags: [...evaluated.flags], notes: evaluated.notes, outcomes, outcome };
71
+ }
72
+ Rule.evaluate = evaluate;
73
+ function sort(rules, state) {
74
+ return rules.reduce((r, rule) => {
75
+ if (Rule.Base.Kind.is(state.transaction.kind, rule, state.organization?.groups))
56
76
  rule.action == "score"
57
77
  ? r.scorers.push(rule)
58
78
  : rule.action == "charge"
59
79
  ? r.chargers.push(rule)
60
- : r.other.push(rule);
80
+ : rule.action == "reserve"
81
+ ? r.reservers.push(rule)
82
+ : r.other.push(rule);
61
83
  return r;
62
- }, { other: [], chargers: [], scorers: [] });
63
- state.transaction.risk = score(scorers, state, macros);
64
- const notes = [];
65
- const flags = new Set();
66
- const now = isoly.DateTime.now();
67
- for (const rule of other) {
68
- if (control(rule, state, macros)) {
69
- outcomes[rule.action].push(rule);
70
- notes.push({ author: "automatic", created: now, text: rule.name, rule });
71
- rule.flags.forEach(f => flags.add(f));
72
- rule.action == "review" && flags.add("review");
73
- }
74
- }
75
- const charged = charge(chargers, state, macros, table);
76
- state.transaction.original.charge = isoly.Currency.add(state.transaction.original.currency, state.transaction.original.charge ?? 0, charged.charge);
77
- state.transaction.original.total =
78
- state.transaction.kind == "authorization" ||
79
- state.transaction.kind == "outbound" ||
80
- state.transaction.kind == "capture"
81
- ? isoly.Currency.add(state.transaction.original.currency, state.transaction.original.amount, charged.charge)
82
- : isoly.Currency.subtract(state.transaction.original.currency, state.transaction.original.amount, charged.charge);
83
- outcomes.charge.push(...charged.outcomes);
84
- const outcome = outcomes.reject.length > 0 ? "reject" : outcomes.review.length > 0 ? "review" : "approve";
85
- return { ...state, flags: [...flags], notes, outcomes, outcome };
84
+ }, { other: [], chargers: [], scorers: [], reservers: [] });
86
85
  }
87
- Rule.evaluate = evaluate;
88
86
  function isLegacy(rule) {
89
- return !ModelRule.Base.Category.type.is(rule.category);
87
+ return !Rule.Base.Category.type.is(rule.category);
90
88
  }
91
89
  Rule.isLegacy = isLegacy;
92
90
  function fromLegacy(rule) {