@pax2pay/model-banking 0.1.653 → 0.1.655
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/Backup/Rule.ts +13 -9
- package/Organization/Creatable.ts +1 -1
- package/Organization/index.ts +1 -1
- package/Rule/State/Transaction.ts +2 -2
- package/Rule/State/index.ts +2 -2
- package/Rule/index.ts +7 -36
- package/Rule/type.ts +5 -2
- package/Transaction/Amount/index.ts +0 -18
- package/Transaction/Incoming.ts +0 -14
- package/Transaction/Note.ts +10 -2
- package/Transaction/index.ts +37 -76
- package/dist/cjs/Audit.d.ts +1 -1
- package/dist/cjs/Backup/Rule.d.ts +1 -1
- package/dist/cjs/Backup/Rule.js +12 -9
- package/dist/cjs/Backup/Rule.js.map +1 -1
- package/dist/cjs/Organization/Creatable.d.ts +1 -1
- package/dist/cjs/Organization/index.d.ts +1 -1
- package/dist/cjs/Rule/State/Transaction.d.ts +2 -2
- package/dist/cjs/Rule/State/Transaction.js.map +1 -1
- package/dist/cjs/Rule/State/index.d.ts +3 -3
- package/dist/cjs/Rule/State/index.js.map +1 -1
- package/dist/cjs/Rule/index.d.ts +8 -14
- package/dist/cjs/Rule/index.js +6 -33
- package/dist/cjs/Rule/index.js.map +1 -1
- package/dist/cjs/Rule/type.d.ts +2 -2
- package/dist/cjs/Rule/type.js +2 -2
- package/dist/cjs/Rule/type.js.map +1 -1
- package/dist/cjs/Transaction/Amount/index.d.ts +0 -3
- package/dist/cjs/Transaction/Amount/index.js +0 -14
- package/dist/cjs/Transaction/Amount/index.js.map +1 -1
- package/dist/cjs/Transaction/Note.d.ts +10 -2
- package/dist/cjs/Transaction/Note.js.map +1 -1
- package/dist/cjs/Transaction/index.d.ts +3 -23
- package/dist/cjs/Transaction/index.js +27 -63
- package/dist/cjs/Transaction/index.js.map +1 -1
- package/dist/cjs/User/Access/Permission.d.ts +4 -4
- package/dist/cjs/User/Access/index.d.ts +3 -3
- package/dist/cjs/User/JWT/Payload.d.ts +12 -12
- package/dist/cjs/User/index.d.ts +6 -6
- package/dist/mjs/Audit.d.ts +1 -1
- package/dist/mjs/Backup/Rule.d.ts +1 -1
- package/dist/mjs/Backup/Rule.js +12 -9
- package/dist/mjs/Backup/Rule.js.map +1 -1
- package/dist/mjs/Organization/Creatable.d.ts +1 -1
- package/dist/mjs/Organization/index.d.ts +1 -1
- package/dist/mjs/Rule/State/Transaction.d.ts +2 -2
- package/dist/mjs/Rule/State/Transaction.js.map +1 -1
- package/dist/mjs/Rule/State/index.d.ts +3 -3
- package/dist/mjs/Rule/State/index.js.map +1 -1
- package/dist/mjs/Rule/index.d.ts +8 -14
- package/dist/mjs/Rule/index.js +6 -33
- package/dist/mjs/Rule/index.js.map +1 -1
- package/dist/mjs/Rule/type.d.ts +2 -2
- package/dist/mjs/Rule/type.js +2 -2
- package/dist/mjs/Rule/type.js.map +1 -1
- package/dist/mjs/Transaction/Amount/index.d.ts +0 -3
- package/dist/mjs/Transaction/Amount/index.js +0 -14
- package/dist/mjs/Transaction/Amount/index.js.map +1 -1
- package/dist/mjs/Transaction/Note.d.ts +10 -2
- package/dist/mjs/Transaction/Note.js.map +1 -1
- package/dist/mjs/Transaction/index.d.ts +3 -23
- package/dist/mjs/Transaction/index.js +27 -63
- package/dist/mjs/Transaction/index.js.map +1 -1
- package/dist/mjs/User/Access/Permission.d.ts +4 -4
- package/dist/mjs/User/Access/index.d.ts +3 -3
- package/dist/mjs/User/JWT/Payload.d.ts +12 -12
- package/dist/mjs/User/index.d.ts +6 -6
- package/package.json +1 -1
- package/Rule/Base.ts +0 -43
- package/Rule/Other.ts +0 -47
- package/Rule/control.ts +0 -7
- package/dist/cjs/Rule/Base.d.ts +0 -27
- package/dist/cjs/Rule/Base.js +0 -36
- package/dist/cjs/Rule/Base.js.map +0 -1
- package/dist/cjs/Rule/Other.d.ts +0 -20
- package/dist/cjs/Rule/Other.js +0 -42
- package/dist/cjs/Rule/Other.js.map +0 -1
- package/dist/cjs/Rule/control.d.ts +0 -4
- package/dist/cjs/Rule/control.js +0 -8
- package/dist/cjs/Rule/control.js.map +0 -1
- package/dist/mjs/Rule/Base.d.ts +0 -27
- package/dist/mjs/Rule/Base.js +0 -33
- package/dist/mjs/Rule/Base.js.map +0 -1
- package/dist/mjs/Rule/Other.d.ts +0 -20
- package/dist/mjs/Rule/Other.js +0 -39
- package/dist/mjs/Rule/Other.js.map +0 -1
- package/dist/mjs/Rule/control.d.ts +0 -4
- package/dist/mjs/Rule/control.js +0 -5
- package/dist/mjs/Rule/control.js.map +0 -1
package/Backup/Rule.ts
CHANGED
|
@@ -12,14 +12,18 @@ export namespace Rule {
|
|
|
12
12
|
value: modelRule,
|
|
13
13
|
action: Base.Action,
|
|
14
14
|
data?: { organization?: string; account?: string }
|
|
15
|
-
) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
) => {
|
|
16
|
+
// Rule is currently typed as `never`, so its fields are read via a cast until rules are retyped.
|
|
17
|
+
const rule = value as { code: string; category: string; type: string; action: string }
|
|
18
|
+
return {
|
|
19
|
+
entityType: "rule",
|
|
20
|
+
entity: rule.code,
|
|
21
|
+
...data,
|
|
22
|
+
action,
|
|
23
|
+
created: isoly.DateTime.now(),
|
|
24
|
+
meta: `${rule.category}.${rule.type}.${rule.action}`,
|
|
25
|
+
value,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
24
28
|
export const addSender = Base.pipeToSender(create)
|
|
25
29
|
}
|
package/Organization/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isly } from "isly"
|
|
2
2
|
import { Type } from "../Account/Type"
|
|
3
3
|
import { Realm } from "../Realm"
|
|
4
|
-
import { Rule } from "../Rule"
|
|
4
|
+
import type { Rule } from "../Rule"
|
|
5
5
|
import { type as ruleType } from "../Rule/type"
|
|
6
6
|
import { Changeable as OrganizationChangeable } from "./Changeable"
|
|
7
7
|
import { Contact as OrganizationContact } from "./Contact"
|
|
@@ -5,7 +5,7 @@ import type { Rule } from "../index"
|
|
|
5
5
|
|
|
6
6
|
export type Transaction = ModelTransaction.Creatable.Resolved & {
|
|
7
7
|
id: string
|
|
8
|
-
kind: Rule.
|
|
8
|
+
kind: Rule.Kind
|
|
9
9
|
stage: "finalize" | "initiate"
|
|
10
10
|
amount: number
|
|
11
11
|
type: ModelTransaction.Types
|
|
@@ -19,7 +19,7 @@ export namespace Transaction {
|
|
|
19
19
|
export function from(
|
|
20
20
|
account: ModelAccount,
|
|
21
21
|
transaction: ModelTransaction.Creatable.Resolved | ModelTransaction,
|
|
22
|
-
kind: Rule.
|
|
22
|
+
kind: Rule.Kind,
|
|
23
23
|
stage: "finalize" | "initiate"
|
|
24
24
|
): Transaction {
|
|
25
25
|
const amount = Math.abs(typeof transaction.amount == "number" ? transaction.amount : transaction.amount.original)
|
package/Rule/State/index.ts
CHANGED
|
@@ -39,7 +39,7 @@ export namespace State {
|
|
|
39
39
|
account: ModelAccount,
|
|
40
40
|
address: Rail.Address,
|
|
41
41
|
transaction: ModelTransaction.Creatable.Resolved | ModelTransaction,
|
|
42
|
-
kind: Rule.
|
|
42
|
+
kind: Rule.Kind,
|
|
43
43
|
stage: "finalize" | "initiate",
|
|
44
44
|
card?: Card,
|
|
45
45
|
organization?: Organization
|
|
@@ -52,7 +52,7 @@ export namespace State {
|
|
|
52
52
|
organization,
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
export const type: Record<ModelTransaction.PreTransaction["type"], Rule.
|
|
55
|
+
export const type: Record<ModelTransaction.PreTransaction["type"], Rule.Kind> = {
|
|
56
56
|
authorization: "authorization",
|
|
57
57
|
incoming: "inbound",
|
|
58
58
|
outgoing: "outbound",
|
package/Rule/index.ts
CHANGED
|
@@ -1,48 +1,19 @@
|
|
|
1
1
|
import { isly } from "isly"
|
|
2
|
-
import type { Note } from "../Transaction/Note"
|
|
3
|
-
import { Base as RuleBase } from "./Base"
|
|
4
|
-
import { control as ruleControl } from "./control"
|
|
5
|
-
import { Other as RuleOther } from "./Other"
|
|
6
2
|
import { State as RuleState } from "./State"
|
|
7
3
|
import { type as ruleType } from "./type"
|
|
8
4
|
|
|
9
|
-
export type Rule =
|
|
5
|
+
export type Rule = never
|
|
10
6
|
export namespace Rule {
|
|
11
|
-
export import Other = RuleOther
|
|
12
7
|
export import State = RuleState
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
export type Kind = (typeof Kind.values)[number]
|
|
9
|
+
export namespace Kind {
|
|
10
|
+
export const values = ["authorization", "outbound", "inbound", "capture", "refund"] as const
|
|
11
|
+
export const type = isly.string<Kind>(values)
|
|
12
|
+
}
|
|
18
13
|
export type Action = (typeof Action.values)[number]
|
|
19
14
|
export namespace Action {
|
|
20
|
-
export const values = [
|
|
15
|
+
export const values = ["review", "reject", "flag"] as const
|
|
21
16
|
export const type = isly.string<Action>(values)
|
|
22
17
|
}
|
|
23
18
|
export const type = ruleType
|
|
24
|
-
export function evaluate(rules: Rule[], state: RuleState): RuleState.Evaluated {
|
|
25
|
-
const outcomes: Record<Rule.Action, Rule[]> = {
|
|
26
|
-
review: [],
|
|
27
|
-
reject: [],
|
|
28
|
-
flag: [],
|
|
29
|
-
}
|
|
30
|
-
const notes: Note[] = []
|
|
31
|
-
const evaluated = Other.evaluate(
|
|
32
|
-
rules.filter(rule => Base.Kind.is(state.transaction.kind, rule, state.organization?.groups, state.card?.preset)),
|
|
33
|
-
state
|
|
34
|
-
)
|
|
35
|
-
notes.push(...evaluated.notes)
|
|
36
|
-
outcomes.flag.push(...evaluated.outcomes.flag)
|
|
37
|
-
outcomes.review.push(...evaluated.outcomes.review)
|
|
38
|
-
outcomes.reject.push(...evaluated.outcomes.reject)
|
|
39
|
-
const outcome = outcomes.reject.length > 0 ? "reject" : outcomes.review.length > 0 ? "review" : "approve"
|
|
40
|
-
return { ...state, flags: [...evaluated.flags], notes, outcomes, outcome }
|
|
41
|
-
}
|
|
42
|
-
export function isLegacy(rule: Rule): boolean {
|
|
43
|
-
return !Rule.Base.Category.type.is(rule.category)
|
|
44
|
-
}
|
|
45
|
-
export function fromLegacy(rule: Rule): Rule {
|
|
46
|
-
return isLegacy(rule) ? { ...rule, category: "fincrime" } : rule
|
|
47
|
-
}
|
|
48
19
|
}
|
package/Rule/type.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isly } from "isly"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// Standalone isly type for rules, kept out of Rule/index.ts to avoid a circular
|
|
4
|
+
// import (Rule/index → Rule/State → State/Card → Card → Rule). Rule is currently
|
|
5
|
+
// typed as `never`, so this validates to `never[]` when used as an array.
|
|
6
|
+
export const type = isly.any<never>()
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { isoly } from "isoly"
|
|
2
2
|
import { isly } from "isly"
|
|
3
|
-
import { fx } from "../../fx"
|
|
4
|
-
import type { Rule } from "../../Rule"
|
|
5
3
|
import { Exchange } from "../Exchange"
|
|
6
4
|
import { Charge as AmountCharge } from "./Charge"
|
|
7
5
|
|
|
@@ -21,22 +19,6 @@ export namespace Amount {
|
|
|
21
19
|
total: isly.number(),
|
|
22
20
|
exchange: Exchange.type.optional(),
|
|
23
21
|
})
|
|
24
|
-
export function fromState(state: Rule.State, charges?: Charge, quote?: fx.Quote): Amount {
|
|
25
|
-
const sign = ["outbound", "authorization", "capture"].some(direction => direction == state.transaction.kind)
|
|
26
|
-
? -1
|
|
27
|
-
: 1
|
|
28
|
-
return {
|
|
29
|
-
original: sign * state.transaction.original.amount,
|
|
30
|
-
charge: 0,
|
|
31
|
-
charges: charges ?? (quote && fx.Quote.toCharge(quote)),
|
|
32
|
-
total: isoly.Currency.add(
|
|
33
|
-
state.transaction.original.currency,
|
|
34
|
-
sign * state.transaction.original.total,
|
|
35
|
-
Amount.Charge.total(state.transaction.original.currency, charges ?? {})
|
|
36
|
-
),
|
|
37
|
-
exchange: state?.transaction.exchange ?? state.authorization?.exchange,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
22
|
export function change(
|
|
41
23
|
currency: isoly.Currency,
|
|
42
24
|
amount: Amount,
|
package/Transaction/Incoming.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isoly } from "isoly"
|
|
2
2
|
import { isly } from "isly"
|
|
3
3
|
import { Rail } from "../Rail"
|
|
4
|
-
import { Settlement } from "../Settlement"
|
|
5
4
|
import { Reference as TransactionReference } from "./Reference"
|
|
6
5
|
|
|
7
6
|
export interface Incoming {
|
|
@@ -25,17 +24,4 @@ export namespace Incoming {
|
|
|
25
24
|
rail: Rail.type.optional(),
|
|
26
25
|
reference: TransactionReference.type.optional(),
|
|
27
26
|
})
|
|
28
|
-
|
|
29
|
-
export function fromRefund(entry: Settlement.Entry.Creatable.Refund, card: Rail.Address.Card): Incoming {
|
|
30
|
-
const [currency, amount] = entry.amount
|
|
31
|
-
return {
|
|
32
|
-
account: card,
|
|
33
|
-
currency,
|
|
34
|
-
amount: isoly.Currency.add(currency, -amount, -(entry.fee.other[currency] ?? 0)),
|
|
35
|
-
posted: isoly.DateTime.now(),
|
|
36
|
-
counterpart: { type: "card", merchant: entry.merchant, acquirer: entry.acquirer },
|
|
37
|
-
description: "Refund transaction.",
|
|
38
|
-
rail: card.scheme,
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
27
|
}
|
package/Transaction/Note.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isoly } from "isoly"
|
|
2
2
|
import { isly } from "isly"
|
|
3
|
-
import type { Rule } from "../Rule"
|
|
4
3
|
|
|
5
4
|
export interface Note extends Note.Creatable {
|
|
6
5
|
author: string
|
|
@@ -15,7 +14,16 @@ export namespace Note {
|
|
|
15
14
|
text?: string
|
|
16
15
|
action?: "approve" | "reject"
|
|
17
16
|
flags?: string[]
|
|
18
|
-
rule?:
|
|
17
|
+
rule?: {
|
|
18
|
+
action: "reject"
|
|
19
|
+
code: string
|
|
20
|
+
name: string
|
|
21
|
+
type: "authorization"
|
|
22
|
+
category: "fincrime"
|
|
23
|
+
condition: ""
|
|
24
|
+
description: string
|
|
25
|
+
flags: ["category", "merchant"]
|
|
26
|
+
}
|
|
19
27
|
}
|
|
20
28
|
export namespace Creatable {
|
|
21
29
|
export const type = isly.object<Creatable>({
|
package/Transaction/index.ts
CHANGED
|
@@ -164,7 +164,17 @@ export namespace Transaction {
|
|
|
164
164
|
: "fasterpayments"
|
|
165
165
|
return {
|
|
166
166
|
...creatable,
|
|
167
|
-
amount:
|
|
167
|
+
amount: {
|
|
168
|
+
original: -creatable.amount,
|
|
169
|
+
charge: 0,
|
|
170
|
+
charges: charges ?? (quote && fx.Quote.toCharge(quote)),
|
|
171
|
+
total: -isoly.Currency.add(
|
|
172
|
+
creatable.currency,
|
|
173
|
+
creatable.amount,
|
|
174
|
+
Amount.Charge.total(creatable.currency, charges ?? {})
|
|
175
|
+
),
|
|
176
|
+
exchange: creatable.exchange,
|
|
177
|
+
},
|
|
168
178
|
type: getType(creatable.counterpart, account.name),
|
|
169
179
|
direction: "outbound",
|
|
170
180
|
organization: account.organization,
|
|
@@ -183,32 +193,6 @@ export namespace Transaction {
|
|
|
183
193
|
state,
|
|
184
194
|
}
|
|
185
195
|
}
|
|
186
|
-
export function system(
|
|
187
|
-
creatable: Creatable.Resolved,
|
|
188
|
-
account: { id: string; name: string; organization: string; address: Rail.Address },
|
|
189
|
-
balance: { actual: number; reserved: number; available: number },
|
|
190
|
-
by: string | undefined
|
|
191
|
-
): Transaction {
|
|
192
|
-
return {
|
|
193
|
-
...creatable,
|
|
194
|
-
amount: { original: creatable.amount, charge: 0, total: creatable.amount },
|
|
195
|
-
type: getType(creatable.counterpart, account.name),
|
|
196
|
-
direction: "inbound",
|
|
197
|
-
organization: account.organization,
|
|
198
|
-
accountId: account.id,
|
|
199
|
-
accountName: account.name,
|
|
200
|
-
account: account.address,
|
|
201
|
-
id: Identifier.generate(),
|
|
202
|
-
posted: isoly.DateTime.now(),
|
|
203
|
-
by,
|
|
204
|
-
balance,
|
|
205
|
-
status: "review",
|
|
206
|
-
rail: "internal",
|
|
207
|
-
flags: [],
|
|
208
|
-
oldFlags: [],
|
|
209
|
-
notes: [],
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
196
|
export function empty(
|
|
213
197
|
creatable: Creatable.Resolved,
|
|
214
198
|
account: { id: string; name: string; organization: string; address: Rail.Address },
|
|
@@ -235,41 +219,6 @@ export namespace Transaction {
|
|
|
235
219
|
notes: [],
|
|
236
220
|
}
|
|
237
221
|
}
|
|
238
|
-
export function buffer(
|
|
239
|
-
id: Identifier,
|
|
240
|
-
account: { id: string; name: string; organization: string; address: Rail.Address },
|
|
241
|
-
currency: isoly.Currency,
|
|
242
|
-
balance: { actual: number; reserved: number; available: number },
|
|
243
|
-
by: string | undefined
|
|
244
|
-
): Transaction {
|
|
245
|
-
return {
|
|
246
|
-
id,
|
|
247
|
-
currency,
|
|
248
|
-
counterpart: {
|
|
249
|
-
type: "internal",
|
|
250
|
-
identifier: account.id,
|
|
251
|
-
name: account.name,
|
|
252
|
-
organization: account.organization,
|
|
253
|
-
},
|
|
254
|
-
amount: { original: 0, charge: 0, total: 0 },
|
|
255
|
-
type: "internal",
|
|
256
|
-
direction: "inbound",
|
|
257
|
-
organization: account.organization,
|
|
258
|
-
accountId: account.id,
|
|
259
|
-
accountName: account.name,
|
|
260
|
-
account: account.address,
|
|
261
|
-
posted: isoly.DateTime.now(),
|
|
262
|
-
transacted: isoly.DateTime.now(),
|
|
263
|
-
by,
|
|
264
|
-
balance,
|
|
265
|
-
status: "finalized",
|
|
266
|
-
rail: "internal",
|
|
267
|
-
flags: [],
|
|
268
|
-
oldFlags: [],
|
|
269
|
-
notes: [],
|
|
270
|
-
description: "Buffer adjustment.",
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
222
|
export function fromIncoming(
|
|
274
223
|
transaction: Transaction.PreTransaction.Incoming,
|
|
275
224
|
state: Rule.State.Evaluated,
|
|
@@ -280,7 +229,12 @@ export namespace Transaction {
|
|
|
280
229
|
state.outcome == "reject" ? ["rejected", "denied"] : state.outcome == "review" ? "review" : "processing"
|
|
281
230
|
return {
|
|
282
231
|
...transaction,
|
|
283
|
-
amount:
|
|
232
|
+
amount: {
|
|
233
|
+
original: transaction.amount,
|
|
234
|
+
charge: 0,
|
|
235
|
+
total: transaction.amount,
|
|
236
|
+
exchange: state?.transaction.exchange ?? state.authorization?.exchange,
|
|
237
|
+
},
|
|
284
238
|
type: getType(transaction.counterpart, account.name),
|
|
285
239
|
direction: "inbound",
|
|
286
240
|
organization: account.organization,
|
|
@@ -296,30 +250,37 @@ export namespace Transaction {
|
|
|
296
250
|
}
|
|
297
251
|
}
|
|
298
252
|
export function fromRefund(
|
|
299
|
-
refund: Settlement.Entry.Creatable.Refund,
|
|
300
253
|
id: string,
|
|
301
|
-
account: { id: string; name: string; organization: string },
|
|
302
254
|
card: Rail.Address.Card,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
255
|
+
refund: Settlement.Entry.Creatable.Refund,
|
|
256
|
+
account: { id: string; name: string; organization: string },
|
|
257
|
+
balance: { actual: number; reserved: number; available: number }
|
|
258
|
+
): CardTransaction {
|
|
259
|
+
const original = isoly.Currency.add(
|
|
260
|
+
refund.amount[0],
|
|
261
|
+
Math.abs(refund.amount[1]),
|
|
262
|
+
Math.abs(refund.fee.other[refund.amount[0]] ?? 0)
|
|
263
|
+
)
|
|
308
264
|
return {
|
|
309
|
-
|
|
310
|
-
amount,
|
|
265
|
+
id,
|
|
311
266
|
type: "card",
|
|
267
|
+
status: "review",
|
|
268
|
+
posted: isoly.DateTime.now(),
|
|
269
|
+
account: card,
|
|
312
270
|
direction: "inbound",
|
|
313
|
-
|
|
271
|
+
currency: refund.amount[0],
|
|
272
|
+
amount: { charge: 0, original, total: original },
|
|
273
|
+
counterpart: { type: "card", merchant: refund.merchant, acquirer: refund.acquirer },
|
|
314
274
|
accountId: account.id,
|
|
315
275
|
accountName: account.name,
|
|
276
|
+
organization: account.organization,
|
|
316
277
|
balance,
|
|
317
|
-
|
|
318
|
-
|
|
278
|
+
rail: card.scheme,
|
|
279
|
+
notes: [],
|
|
319
280
|
flags: [],
|
|
320
281
|
oldFlags: [],
|
|
321
|
-
notes: [],
|
|
322
282
|
reference: { reference: refund.reference },
|
|
283
|
+
description: "Refund transaction.",
|
|
323
284
|
}
|
|
324
285
|
}
|
|
325
286
|
export function isIdentifier(value: string | any): value is string {
|
package/dist/cjs/Audit.d.ts
CHANGED
|
@@ -38,6 +38,6 @@ export declare namespace Audit {
|
|
|
38
38
|
readonly clearbank: readonly ["assessmentFailed", "validationFailed"];
|
|
39
39
|
};
|
|
40
40
|
const keys: (keyof typeof value)[];
|
|
41
|
-
const type: isly.Type<"clearbank" | "
|
|
41
|
+
const type: isly.Type<"clearbank" | "account" | "transaction" | "organization" | "rule" | "settlements" | "user" | "marqeta" | "label" | "route">;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -10,7 +10,7 @@ export declare namespace Rule {
|
|
|
10
10
|
organization?: string;
|
|
11
11
|
account?: string;
|
|
12
12
|
}>;
|
|
13
|
-
const addSender: (sender: (backup: Rule) => any | Promise<any>) => (args_0:
|
|
13
|
+
const addSender: (sender: (backup: Rule) => any | Promise<any>) => (args_0: never, args_1: "created" | "cancelled" | "updated" | "removed" | "inactivated", args_2?: {
|
|
14
14
|
organization?: string;
|
|
15
15
|
account?: string;
|
|
16
16
|
} | undefined) => ReturnType<(backup: Rule) => any | Promise<any>>;
|
package/dist/cjs/Backup/Rule.js
CHANGED
|
@@ -5,15 +5,18 @@ const isoly_1 = require("isoly");
|
|
|
5
5
|
const Base_1 = require("./Base");
|
|
6
6
|
var Rule;
|
|
7
7
|
(function (Rule) {
|
|
8
|
-
Rule.create = (value, action, data) =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
Rule.create = (value, action, data) => {
|
|
9
|
+
const rule = value;
|
|
10
|
+
return {
|
|
11
|
+
entityType: "rule",
|
|
12
|
+
entity: rule.code,
|
|
13
|
+
...data,
|
|
14
|
+
action,
|
|
15
|
+
created: isoly_1.isoly.DateTime.now(),
|
|
16
|
+
meta: `${rule.category}.${rule.type}.${rule.action}`,
|
|
17
|
+
value,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
17
20
|
Rule.addSender = Base_1.Base.pipeToSender(Rule.create);
|
|
18
21
|
})(Rule || (exports.Rule = Rule = {}));
|
|
19
22
|
//# sourceMappingURL=Rule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rule.js","sourceRoot":"","sources":["../../../Backup/Rule.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,iCAA6B;AAO7B,IAAiB,IAAI,
|
|
1
|
+
{"version":3,"file":"Rule.js","sourceRoot":"","sources":["../../../Backup/Rule.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,iCAA6B;AAO7B,IAAiB,IAAI,CAmBpB;AAnBD,WAAiB,IAAI;IACP,WAAM,GAA8E,CAChG,KAAgB,EAChB,MAAmB,EACnB,IAAkD,EACjD,EAAE;QAEH,MAAM,IAAI,GAAG,KAAyE,CAAA;QACtF,OAAO;YACN,UAAU,EAAE,MAAM;YAClB,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,GAAG,IAAI;YACP,MAAM;YACN,OAAO,EAAE,aAAK,CAAC,QAAQ,CAAC,GAAG,EAAE;YAC7B,IAAI,EAAE,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE;YACpD,KAAK;SACL,CAAA;IACF,CAAC,CAAA;IACY,cAAS,GAAG,WAAI,CAAC,YAAY,CAAC,KAAA,MAAM,CAAC,CAAA;AACnD,CAAC,EAnBgB,IAAI,oBAAJ,IAAI,QAmBpB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from "../Account/Type";
|
|
2
2
|
import { Realm } from "../Realm";
|
|
3
|
-
import { Rule } from "../Rule";
|
|
3
|
+
import type { Rule } from "../Rule";
|
|
4
4
|
import { Changeable as OrganizationChangeable } from "./Changeable";
|
|
5
5
|
import { Contact as OrganizationContact } from "./Contact";
|
|
6
6
|
import { Creatable as OrganizationCreatable } from "./Creatable";
|
|
@@ -4,7 +4,7 @@ import { Transaction as ModelTransaction } from "../../Transaction";
|
|
|
4
4
|
import type { Rule } from "../index";
|
|
5
5
|
export type Transaction = ModelTransaction.Creatable.Resolved & {
|
|
6
6
|
id: string;
|
|
7
|
-
kind: Rule.
|
|
7
|
+
kind: Rule.Kind;
|
|
8
8
|
stage: "finalize" | "initiate";
|
|
9
9
|
amount: number;
|
|
10
10
|
type: ModelTransaction.Types;
|
|
@@ -15,5 +15,5 @@ export type Transaction = ModelTransaction.Creatable.Resolved & {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
export declare namespace Transaction {
|
|
18
|
-
function from(account: ModelAccount, transaction: ModelTransaction.Creatable.Resolved | ModelTransaction, kind: Rule.
|
|
18
|
+
function from(account: ModelAccount, transaction: ModelTransaction.Creatable.Resolved | ModelTransaction, kind: Rule.Kind, stage: "finalize" | "initiate"): Transaction;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../../Rule/State/Transaction.ts"],"names":[],"mappings":";;;AAEA,mDAAmE;AAenE,IAAiB,WAAW,CAkB3B;AAlBD,WAAiB,WAAW;IAC3B,SAAgB,IAAI,CACnB,OAAqB,EACrB,WAAmE,EACnE,
|
|
1
|
+
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../../Rule/State/Transaction.ts"],"names":[],"mappings":";;;AAEA,mDAAmE;AAenE,IAAiB,WAAW,CAkB3B;AAlBD,WAAiB,WAAW;IAC3B,SAAgB,IAAI,CACnB,OAAqB,EACrB,WAAmE,EACnE,IAAe,EACf,KAA8B;QAE9B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,WAAW,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACjH,OAAO;YACN,GAAG,WAAW;YACd,EAAE,EAAE,IAAI,IAAI,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,yBAAgB,CAAC,UAAU,CAAC,QAAQ,EAAE;YACjF,KAAK;YACL,IAAI;YACJ,MAAM;YACN,IAAI,EAAE,yBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC;YACrE,QAAQ,EAAE,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;SACnE,CAAA;IACF,CAAC;IAhBe,gBAAI,OAgBnB,CAAA;AACF,CAAC,EAlBgB,WAAW,2BAAX,WAAW,QAkB3B"}
|
|
@@ -26,7 +26,7 @@ export declare namespace State {
|
|
|
26
26
|
type Outcome = (typeof Outcome.values)[number];
|
|
27
27
|
namespace Outcome {
|
|
28
28
|
const values: readonly ["approve", "reject", "review"];
|
|
29
|
-
const type: isly.Type<"
|
|
29
|
+
const type: isly.Type<"review" | "approve" | "reject">;
|
|
30
30
|
}
|
|
31
31
|
interface Evaluated extends State {
|
|
32
32
|
outcomes: globalThis.Partial<Record<Rule.Action, Rule[]>>;
|
|
@@ -34,6 +34,6 @@ export declare namespace State {
|
|
|
34
34
|
flags: string[];
|
|
35
35
|
notes: ModelTransaction.Note[];
|
|
36
36
|
}
|
|
37
|
-
function from(account: ModelAccount, address: Rail.Address, transaction: ModelTransaction.Creatable.Resolved | ModelTransaction, kind: Rule.
|
|
38
|
-
const type: Record<ModelTransaction.PreTransaction["type"], Rule.
|
|
37
|
+
function from(account: ModelAccount, address: Rail.Address, transaction: ModelTransaction.Creatable.Resolved | ModelTransaction, kind: Rule.Kind, stage: "finalize" | "initiate", card?: Card, organization?: Organization): State;
|
|
38
|
+
const type: Record<ModelTransaction.PreTransaction["type"], Rule.Kind>;
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../Rule/State/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAK3B,uCAAmD;AACnD,mDAAqE;AACrE,iCAA0C;AAC1C,iDAAkE;AAClE,uCAAmD;AACnD,+CAA+D;AAS/D,IAAiB,KAAK,CAwCrB;AAxCD,WAAiB,KAAK;IACP,aAAO,GAAG,iBAAY,CAAA;IACtB,mBAAa,GAAG,6BAAkB,CAAA;IAClC,UAAI,GAAG,WAAS,CAAA;IAChB,aAAO,GAAG,iBAAY,CAAA;IACtB,iBAAW,GAAG,yBAAgB,CAAA;IAC9B,kBAAY,GAAG,2BAAiB,CAAA;IAE9C,IAAiB,OAAO,CAGvB;IAHD,WAAiB,OAAO;QACV,cAAM,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAA;QACjD,YAAI,GAAG,WAAI,CAAC,MAAM,CAAU,QAAA,MAAM,CAAC,CAAA;IACjD,CAAC,EAHgB,OAAO,GAAP,aAAO,KAAP,aAAO,QAGvB;IAOD,SAAgB,IAAI,CACnB,OAAqB,EACrB,OAAqB,EACrB,WAAmE,EACnE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../Rule/State/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAK3B,uCAAmD;AACnD,mDAAqE;AACrE,iCAA0C;AAC1C,iDAAkE;AAClE,uCAAmD;AACnD,+CAA+D;AAS/D,IAAiB,KAAK,CAwCrB;AAxCD,WAAiB,KAAK;IACP,aAAO,GAAG,iBAAY,CAAA;IACtB,mBAAa,GAAG,6BAAkB,CAAA;IAClC,UAAI,GAAG,WAAS,CAAA;IAChB,aAAO,GAAG,iBAAY,CAAA;IACtB,iBAAW,GAAG,yBAAgB,CAAA;IAC9B,kBAAY,GAAG,2BAAiB,CAAA;IAE9C,IAAiB,OAAO,CAGvB;IAHD,WAAiB,OAAO;QACV,cAAM,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAA;QACjD,YAAI,GAAG,WAAI,CAAC,MAAM,CAAU,QAAA,MAAM,CAAC,CAAA;IACjD,CAAC,EAHgB,OAAO,GAAP,aAAO,KAAP,aAAO,QAGvB;IAOD,SAAgB,IAAI,CACnB,OAAqB,EACrB,OAAqB,EACrB,WAAmE,EACnE,IAAe,EACf,KAA8B,EAC9B,IAAW,EACX,YAA2B;QAE3B,OAAO;YACN,OAAO,EAAE,MAAA,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;YACvC,WAAW,EAAE,MAAA,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC;YAChE,aAAa,EAAE,MAAA,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC;YAC9C,IAAI;YACJ,YAAY;SACZ,CAAA;IACF,CAAC;IAhBe,UAAI,OAgBnB,CAAA;IACY,UAAI,GAA+D;QAC/E,aAAa,EAAE,eAAe;QAC9B,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,UAAU;KACpB,CAAA;AACF,CAAC,EAxCgB,KAAK,qBAAL,KAAK,QAwCrB"}
|
package/dist/cjs/Rule/index.d.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import { isly } from "isly";
|
|
2
|
-
import { Base as RuleBase } from "./Base";
|
|
3
|
-
import { control as ruleControl } from "./control";
|
|
4
|
-
import { Other as RuleOther } from "./Other";
|
|
5
2
|
import { State as RuleState } from "./State";
|
|
6
|
-
export type Rule =
|
|
3
|
+
export type Rule = never;
|
|
7
4
|
export declare namespace Rule {
|
|
8
|
-
export import Other = RuleOther;
|
|
9
5
|
export import State = RuleState;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
type Kind = (typeof Kind.values)[number];
|
|
7
|
+
namespace Kind {
|
|
8
|
+
const values: readonly ["authorization", "outbound", "inbound", "capture", "refund"];
|
|
9
|
+
const type: isly.Type<"capture" | "refund" | "authorization" | "inbound" | "outbound">;
|
|
10
|
+
}
|
|
14
11
|
type Action = (typeof Action.values)[number];
|
|
15
12
|
namespace Action {
|
|
16
13
|
const values: readonly ["review", "reject", "flag"];
|
|
17
|
-
const type: isly.Type<"
|
|
14
|
+
const type: isly.Type<"review" | "reject" | "flag">;
|
|
18
15
|
}
|
|
19
|
-
const type:
|
|
20
|
-
function evaluate(rules: Rule[], state: RuleState): RuleState.Evaluated;
|
|
21
|
-
function isLegacy(rule: Rule): boolean;
|
|
22
|
-
function fromLegacy(rule: Rule): Rule;
|
|
16
|
+
const type: isly.Type<never>;
|
|
23
17
|
}
|
package/dist/cjs/Rule/index.js
CHANGED
|
@@ -2,48 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Rule = void 0;
|
|
4
4
|
const isly_1 = require("isly");
|
|
5
|
-
const Base_1 = require("./Base");
|
|
6
|
-
const control_1 = require("./control");
|
|
7
|
-
const Other_1 = require("./Other");
|
|
8
5
|
const State_1 = require("./State");
|
|
9
6
|
const type_1 = require("./type");
|
|
10
7
|
var Rule;
|
|
11
8
|
(function (Rule) {
|
|
12
|
-
Rule.Other = Other_1.Other;
|
|
13
9
|
Rule.State = State_1.State;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
let Kind;
|
|
11
|
+
(function (Kind) {
|
|
12
|
+
Kind.values = ["authorization", "outbound", "inbound", "capture", "refund"];
|
|
13
|
+
Kind.type = isly_1.isly.string(Kind.values);
|
|
14
|
+
})(Kind = Rule.Kind || (Rule.Kind = {}));
|
|
18
15
|
let Action;
|
|
19
16
|
(function (Action) {
|
|
20
|
-
Action.values = [
|
|
17
|
+
Action.values = ["review", "reject", "flag"];
|
|
21
18
|
Action.type = isly_1.isly.string(Action.values);
|
|
22
19
|
})(Action = Rule.Action || (Rule.Action = {}));
|
|
23
20
|
Rule.type = type_1.type;
|
|
24
|
-
function evaluate(rules, state) {
|
|
25
|
-
const outcomes = {
|
|
26
|
-
review: [],
|
|
27
|
-
reject: [],
|
|
28
|
-
flag: [],
|
|
29
|
-
};
|
|
30
|
-
const notes = [];
|
|
31
|
-
const evaluated = Rule.Other.evaluate(rules.filter(rule => Rule.Base.Kind.is(state.transaction.kind, rule, state.organization?.groups, state.card?.preset)), state);
|
|
32
|
-
notes.push(...evaluated.notes);
|
|
33
|
-
outcomes.flag.push(...evaluated.outcomes.flag);
|
|
34
|
-
outcomes.review.push(...evaluated.outcomes.review);
|
|
35
|
-
outcomes.reject.push(...evaluated.outcomes.reject);
|
|
36
|
-
const outcome = outcomes.reject.length > 0 ? "reject" : outcomes.review.length > 0 ? "review" : "approve";
|
|
37
|
-
return { ...state, flags: [...evaluated.flags], notes, outcomes, outcome };
|
|
38
|
-
}
|
|
39
|
-
Rule.evaluate = evaluate;
|
|
40
|
-
function isLegacy(rule) {
|
|
41
|
-
return !Rule.Base.Category.type.is(rule.category);
|
|
42
|
-
}
|
|
43
|
-
Rule.isLegacy = isLegacy;
|
|
44
|
-
function fromLegacy(rule) {
|
|
45
|
-
return isLegacy(rule) ? { ...rule, category: "fincrime" } : rule;
|
|
46
|
-
}
|
|
47
|
-
Rule.fromLegacy = fromLegacy;
|
|
48
21
|
})(Rule || (exports.Rule = Rule = {}));
|
|
49
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../Rule/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../Rule/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAC3B,mCAA4C;AAC5C,iCAAyC;AAGzC,IAAiB,IAAI,CAapB;AAbD,WAAiB,IAAI;IACN,UAAK,GAAG,aAAS,CAAA;IAE/B,IAAiB,IAAI,CAGpB;IAHD,WAAiB,IAAI;QACP,WAAM,GAAG,CAAC,eAAe,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAA;QAC/E,SAAI,GAAG,WAAI,CAAC,MAAM,CAAO,KAAA,MAAM,CAAC,CAAA;IAC9C,CAAC,EAHgB,IAAI,GAAJ,SAAI,KAAJ,SAAI,QAGpB;IAED,IAAiB,MAAM,CAGtB;IAHD,WAAiB,MAAM;QACT,aAAM,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAA;QAC9C,WAAI,GAAG,WAAI,CAAC,MAAM,CAAS,OAAA,MAAM,CAAC,CAAA;IAChD,CAAC,EAHgB,MAAM,GAAN,WAAM,KAAN,WAAM,QAGtB;IACY,SAAI,GAAG,WAAQ,CAAA;AAC7B,CAAC,EAbgB,IAAI,oBAAJ,IAAI,QAapB"}
|
package/dist/cjs/Rule/type.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const type:
|
|
1
|
+
import { isly } from "isly";
|
|
2
|
+
export declare const type: isly.Type<never>;
|
package/dist/cjs/Rule/type.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.type = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.type =
|
|
4
|
+
const isly_1 = require("isly");
|
|
5
|
+
exports.type = isly_1.isly.any();
|
|
6
6
|
//# sourceMappingURL=type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../Rule/type.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../Rule/type.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAKd,QAAA,IAAI,GAAG,WAAI,CAAC,GAAG,EAAS,CAAA"}
|