@pax2pay/model-banking 0.1.490 → 0.1.492
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/Account.ts +24 -0
- package/Backup/Base.ts +32 -0
- package/Backup/Card.ts +25 -0
- package/Backup/Operation.ts +25 -0
- package/Backup/Organization.ts +26 -0
- package/Backup/Rule.ts +25 -0
- package/Backup/Transaction.ts +28 -0
- package/Backup/User.ts +25 -0
- package/Backup/index.ts +30 -0
- package/Card/Meta.ts +1 -2
- package/Rule/State/Transaction.ts +19 -0
- package/Rule/State/index.ts +24 -0
- package/Transaction/PreTransaction/Authorization.ts +20 -0
- package/Transaction/PreTransaction/Base.ts +23 -0
- package/Transaction/PreTransaction/Incoming.ts +42 -0
- package/Transaction/PreTransaction/Outgoing.ts +8 -0
- package/Transaction/PreTransaction/index.ts +16 -0
- package/Transaction/index.ts +5 -4
- package/dist/cjs/Backup/Account.d.ts +15 -0
- package/dist/cjs/Backup/Account.js +20 -0
- package/dist/cjs/Backup/Account.js.map +1 -0
- package/dist/cjs/Backup/Base.d.ts +29 -0
- package/dist/cjs/Backup/Base.js +18 -0
- package/dist/cjs/Backup/Base.js.map +1 -0
- package/dist/cjs/Backup/Card.d.ts +14 -0
- package/dist/cjs/Backup/Card.js +20 -0
- package/dist/cjs/Backup/Card.js.map +1 -0
- package/dist/cjs/Backup/Operation.d.ts +15 -0
- package/dist/cjs/Backup/Operation.js +19 -0
- package/dist/cjs/Backup/Operation.js.map +1 -0
- package/dist/cjs/Backup/Organization.d.ts +13 -0
- package/dist/cjs/Backup/Organization.js +19 -0
- package/dist/cjs/Backup/Organization.js.map +1 -0
- package/dist/cjs/Backup/Rule.d.ts +17 -0
- package/dist/cjs/Backup/Rule.js +19 -0
- package/dist/cjs/Backup/Rule.js.map +1 -0
- package/dist/cjs/Backup/Transaction.d.ts +25 -0
- package/dist/cjs/Backup/Transaction.js +20 -0
- package/dist/cjs/Backup/Transaction.js.map +1 -0
- package/dist/cjs/Backup/User.d.ts +15 -0
- package/dist/cjs/Backup/User.js +18 -0
- package/dist/cjs/Backup/User.js.map +1 -0
- package/dist/cjs/Backup/index.d.ts +26 -0
- package/dist/cjs/Backup/index.js +23 -0
- package/dist/cjs/Backup/index.js.map +1 -0
- package/dist/cjs/Card/Meta.d.ts +1 -3
- package/dist/cjs/Card/Meta.js.map +1 -1
- package/dist/cjs/Rule/State/Transaction.d.ts +1 -0
- package/dist/cjs/Rule/State/Transaction.js +15 -0
- package/dist/cjs/Rule/State/Transaction.js.map +1 -1
- package/dist/cjs/Rule/State/index.d.ts +5 -0
- package/dist/cjs/Rule/State/index.js +15 -0
- package/dist/cjs/Rule/State/index.js.map +1 -1
- package/dist/cjs/Transaction/PreTransaction/Authorization.d.ts +14 -0
- package/dist/cjs/Transaction/PreTransaction/Authorization.js +17 -0
- package/dist/cjs/Transaction/PreTransaction/Authorization.js.map +1 -0
- package/dist/cjs/Transaction/PreTransaction/Base.d.ts +14 -0
- package/dist/cjs/Transaction/PreTransaction/Base.js +19 -0
- package/dist/cjs/Transaction/PreTransaction/Base.js.map +1 -0
- package/dist/cjs/Transaction/{Incoming.d.ts → PreTransaction/Incoming.d.ts} +7 -6
- package/dist/cjs/Transaction/{Incoming.js → PreTransaction/Incoming.js} +7 -5
- package/dist/cjs/Transaction/PreTransaction/Incoming.js.map +1 -0
- package/dist/cjs/Transaction/PreTransaction/Outgoing.d.ts +7 -0
- package/dist/cjs/Transaction/PreTransaction/Outgoing.js +8 -0
- package/dist/cjs/Transaction/PreTransaction/Outgoing.js.map +1 -0
- package/dist/cjs/Transaction/PreTransaction/index.d.ts +14 -0
- package/dist/cjs/Transaction/PreTransaction/index.js +13 -0
- package/dist/cjs/Transaction/PreTransaction/index.js.map +1 -0
- package/dist/cjs/Transaction/index.d.ts +3 -3
- package/dist/cjs/Transaction/index.js +3 -3
- package/dist/cjs/Transaction/index.js.map +1 -1
- package/dist/cjs/pax2pay.d.ts +1 -0
- package/dist/cjs/pax2pay.js +3 -1
- package/dist/cjs/pax2pay.js.map +1 -1
- package/dist/mjs/Backup/Account.d.ts +15 -0
- package/dist/mjs/Backup/Account.js +17 -0
- package/dist/mjs/Backup/Account.js.map +1 -0
- package/dist/mjs/Backup/Base.d.ts +29 -0
- package/dist/mjs/Backup/Base.js +15 -0
- package/dist/mjs/Backup/Base.js.map +1 -0
- package/dist/mjs/Backup/Card.d.ts +14 -0
- package/dist/mjs/Backup/Card.js +17 -0
- package/dist/mjs/Backup/Card.js.map +1 -0
- package/dist/mjs/Backup/Operation.d.ts +15 -0
- package/dist/mjs/Backup/Operation.js +16 -0
- package/dist/mjs/Backup/Operation.js.map +1 -0
- package/dist/mjs/Backup/Organization.d.ts +13 -0
- package/dist/mjs/Backup/Organization.js +16 -0
- package/dist/mjs/Backup/Organization.js.map +1 -0
- package/dist/mjs/Backup/Rule.d.ts +17 -0
- package/dist/mjs/Backup/Rule.js +16 -0
- package/dist/mjs/Backup/Rule.js.map +1 -0
- package/dist/mjs/Backup/Transaction.d.ts +25 -0
- package/dist/mjs/Backup/Transaction.js +17 -0
- package/dist/mjs/Backup/Transaction.js.map +1 -0
- package/dist/mjs/Backup/User.d.ts +15 -0
- package/dist/mjs/Backup/User.js +15 -0
- package/dist/mjs/Backup/User.js.map +1 -0
- package/dist/mjs/Backup/index.d.ts +26 -0
- package/dist/mjs/Backup/index.js +20 -0
- package/dist/mjs/Backup/index.js.map +1 -0
- package/dist/mjs/Card/Meta.d.ts +1 -3
- package/dist/mjs/Card/Meta.js.map +1 -1
- package/dist/mjs/Rule/State/Transaction.d.ts +1 -0
- package/dist/mjs/Rule/State/Transaction.js +15 -0
- package/dist/mjs/Rule/State/Transaction.js.map +1 -1
- package/dist/mjs/Rule/State/index.d.ts +5 -0
- package/dist/mjs/Rule/State/index.js +15 -0
- package/dist/mjs/Rule/State/index.js.map +1 -1
- package/dist/mjs/Transaction/PreTransaction/Authorization.d.ts +14 -0
- package/dist/mjs/Transaction/PreTransaction/Authorization.js +14 -0
- package/dist/mjs/Transaction/PreTransaction/Authorization.js.map +1 -0
- package/dist/mjs/Transaction/PreTransaction/Base.d.ts +14 -0
- package/dist/mjs/Transaction/PreTransaction/Base.js +16 -0
- package/dist/mjs/Transaction/PreTransaction/Base.js.map +1 -0
- package/dist/mjs/Transaction/{Incoming.d.ts → PreTransaction/Incoming.d.ts} +7 -6
- package/dist/mjs/Transaction/{Incoming.js → PreTransaction/Incoming.js} +7 -5
- package/dist/mjs/Transaction/PreTransaction/Incoming.js.map +1 -0
- package/dist/mjs/Transaction/PreTransaction/Outgoing.d.ts +7 -0
- package/dist/mjs/Transaction/PreTransaction/Outgoing.js +5 -0
- package/dist/mjs/Transaction/PreTransaction/Outgoing.js.map +1 -0
- package/dist/mjs/Transaction/PreTransaction/index.d.ts +14 -0
- package/dist/mjs/Transaction/PreTransaction/index.js +10 -0
- package/dist/mjs/Transaction/PreTransaction/index.js.map +1 -0
- package/dist/mjs/Transaction/index.d.ts +3 -3
- package/dist/mjs/Transaction/index.js +3 -3
- package/dist/mjs/Transaction/index.js.map +1 -1
- package/dist/mjs/pax2pay.d.ts +1 -0
- package/dist/mjs/pax2pay.js +1 -0
- package/dist/mjs/pax2pay.js.map +1 -1
- package/package.json +4 -4
- package/pax2pay.ts +1 -0
- package/tsconfig.json +1 -1
- package/dist/cjs/Transaction/Incoming.js.map +0 -1
- package/dist/mjs/Transaction/Incoming.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { Account as modelAccount } from "../Account"
|
|
3
|
+
import { Base } from "./Base"
|
|
4
|
+
|
|
5
|
+
export interface Account extends Base<modelAccount> {
|
|
6
|
+
entityType: "account"
|
|
7
|
+
entity: string
|
|
8
|
+
organization: string
|
|
9
|
+
account: string
|
|
10
|
+
meta: { key: string }
|
|
11
|
+
}
|
|
12
|
+
export namespace Account {
|
|
13
|
+
export const create: Base.Create<modelAccount, Account> = (value: modelAccount, action: Base.Action) => ({
|
|
14
|
+
entityType: "account",
|
|
15
|
+
entity: value.id,
|
|
16
|
+
organization: value.organization,
|
|
17
|
+
account: value.id,
|
|
18
|
+
action,
|
|
19
|
+
created: isoly.DateTime.now(),
|
|
20
|
+
meta: { key: value.key ?? "" },
|
|
21
|
+
value,
|
|
22
|
+
})
|
|
23
|
+
export const addSender = Base.pipeToSender(create)
|
|
24
|
+
}
|
package/Backup/Base.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { Realm } from "../Realm"
|
|
3
|
+
|
|
4
|
+
export type Base<T> = {
|
|
5
|
+
realm?: Realm
|
|
6
|
+
organization?: string
|
|
7
|
+
account?: string
|
|
8
|
+
entity: string
|
|
9
|
+
entityType: string
|
|
10
|
+
action: Base.Action
|
|
11
|
+
created: isoly.DateTime
|
|
12
|
+
isError?: true
|
|
13
|
+
meta?: any
|
|
14
|
+
value: T
|
|
15
|
+
}
|
|
16
|
+
export namespace Base {
|
|
17
|
+
export type Action = typeof Action.values[number]
|
|
18
|
+
export namespace Action {
|
|
19
|
+
export const values = ["created", "updated", "cancelled", "removed"] as const
|
|
20
|
+
}
|
|
21
|
+
export type Data = { realm?: Realm; organization?: string; account?: string; isError?: true; meta?: any }
|
|
22
|
+
export type Create<T, B extends Base<T>, D extends Data = Record<string, never>> = (...args: [T, Action, D?]) => B
|
|
23
|
+
export function pipeToSender<T, B extends Base<T>, D extends Data = Record<string, never>>(
|
|
24
|
+
mapper: Base.Create<T, B, D>
|
|
25
|
+
): (sender: (backup: B) => any | Promise<any>) => (...args: Parameters<typeof mapper>) => ReturnType<typeof sender> {
|
|
26
|
+
return sender =>
|
|
27
|
+
(...args) => {
|
|
28
|
+
const backup = mapper(...args)
|
|
29
|
+
return sender(backup)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/Backup/Card.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { Card as modelCard } from "../Card"
|
|
3
|
+
import { Realm } from "../Realm"
|
|
4
|
+
import { Base } from "./Base"
|
|
5
|
+
|
|
6
|
+
export interface Card extends Base<modelCard> {
|
|
7
|
+
realm: Realm
|
|
8
|
+
entityType: "card"
|
|
9
|
+
entity: string
|
|
10
|
+
organization: string
|
|
11
|
+
account: string
|
|
12
|
+
}
|
|
13
|
+
export namespace Card {
|
|
14
|
+
export const create: Base.Create<modelCard, Card> = (value: modelCard, action: Base.Action) => ({
|
|
15
|
+
realm: value.realm,
|
|
16
|
+
entityType: "card",
|
|
17
|
+
entity: value.id,
|
|
18
|
+
organization: value.organization,
|
|
19
|
+
account: value.account,
|
|
20
|
+
action,
|
|
21
|
+
created: isoly.DateTime.now(),
|
|
22
|
+
value,
|
|
23
|
+
})
|
|
24
|
+
export const addSender = Base.pipeToSender(create)
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { Operation as modelOperation } from "../Operation"
|
|
3
|
+
import { Base } from "./Base"
|
|
4
|
+
|
|
5
|
+
export interface Operation extends Base<modelOperation> {
|
|
6
|
+
entityType: "operation"
|
|
7
|
+
entity: string
|
|
8
|
+
account: string
|
|
9
|
+
}
|
|
10
|
+
export namespace Operation {
|
|
11
|
+
export const create: Base.Create<modelOperation, Operation, { organization: string }> = (
|
|
12
|
+
value: modelOperation,
|
|
13
|
+
action: Base.Action,
|
|
14
|
+
data?: { organization: string }
|
|
15
|
+
) => ({
|
|
16
|
+
entityType: "operation",
|
|
17
|
+
entity: value.signature ?? "",
|
|
18
|
+
...data,
|
|
19
|
+
account: value.account,
|
|
20
|
+
action,
|
|
21
|
+
created: isoly.DateTime.now(),
|
|
22
|
+
value,
|
|
23
|
+
})
|
|
24
|
+
export const addSender = Base.pipeToSender(create)
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { Organization as modelOrganization } from "../Organization"
|
|
3
|
+
import { Realm } from "../Realm"
|
|
4
|
+
import { Base } from "./Base"
|
|
5
|
+
|
|
6
|
+
export interface Organization extends Base<modelOrganization> {
|
|
7
|
+
realm: Realm
|
|
8
|
+
entityType: "organization"
|
|
9
|
+
entity: string
|
|
10
|
+
organization: string
|
|
11
|
+
}
|
|
12
|
+
export namespace Organization {
|
|
13
|
+
export const create: Base.Create<modelOrganization, Organization> = (
|
|
14
|
+
value: modelOrganization,
|
|
15
|
+
action: Base.Action
|
|
16
|
+
) => ({
|
|
17
|
+
realm: value.realm,
|
|
18
|
+
entityType: "organization",
|
|
19
|
+
entity: value.code,
|
|
20
|
+
organization: value.code,
|
|
21
|
+
action,
|
|
22
|
+
created: isoly.DateTime.now(),
|
|
23
|
+
value,
|
|
24
|
+
})
|
|
25
|
+
export const addSender = Base.pipeToSender(create)
|
|
26
|
+
}
|
package/Backup/Rule.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { Rule as modelRule } from "../Rule"
|
|
3
|
+
import { Base } from "./Base"
|
|
4
|
+
|
|
5
|
+
export interface Rule extends Base<modelRule> {
|
|
6
|
+
entityType: "rule"
|
|
7
|
+
entity: string
|
|
8
|
+
meta: string
|
|
9
|
+
}
|
|
10
|
+
export namespace Rule {
|
|
11
|
+
export const create: Base.Create<modelRule, Rule, { organization?: string; account?: string }> = (
|
|
12
|
+
value: modelRule,
|
|
13
|
+
action: Base.Action,
|
|
14
|
+
data?: { organization?: string; account?: string }
|
|
15
|
+
) => ({
|
|
16
|
+
entityType: "rule",
|
|
17
|
+
entity: value.code,
|
|
18
|
+
...data,
|
|
19
|
+
action,
|
|
20
|
+
created: isoly.DateTime.now(),
|
|
21
|
+
meta: `${value.category}.${value.type}.${value.action}`,
|
|
22
|
+
value,
|
|
23
|
+
})
|
|
24
|
+
export const addSender = Base.pipeToSender(create)
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { Transaction as modelTransaction } from "../Transaction"
|
|
3
|
+
import { Base } from "./Base"
|
|
4
|
+
|
|
5
|
+
export interface Transaction extends Base<modelTransaction & { state?: any }> {
|
|
6
|
+
entityType: "transaction"
|
|
7
|
+
entity: string
|
|
8
|
+
organization: string
|
|
9
|
+
account: string
|
|
10
|
+
isError?: true
|
|
11
|
+
}
|
|
12
|
+
export namespace Transaction {
|
|
13
|
+
export const create: Base.Create<modelTransaction & { state?: any }, Transaction, { isError?: true; meta?: any }> = (
|
|
14
|
+
value: modelTransaction & { state?: any },
|
|
15
|
+
action: Base.Action,
|
|
16
|
+
data?: { isError?: true; meta?: any }
|
|
17
|
+
) => ({
|
|
18
|
+
entityType: "transaction",
|
|
19
|
+
entity: value.id,
|
|
20
|
+
organization: value.organization,
|
|
21
|
+
account: value.accountId,
|
|
22
|
+
action,
|
|
23
|
+
...data,
|
|
24
|
+
created: isoly.DateTime.now(),
|
|
25
|
+
value,
|
|
26
|
+
})
|
|
27
|
+
export const addSender = Base.pipeToSender(create)
|
|
28
|
+
}
|
package/Backup/User.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { userwidgets } from "@userwidgets/model"
|
|
3
|
+
import { Realm } from "../Realm"
|
|
4
|
+
import { Base } from "./Base"
|
|
5
|
+
|
|
6
|
+
export type User = Base<userwidgets.User> & {
|
|
7
|
+
entityType: "user"
|
|
8
|
+
entity: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export namespace User {
|
|
12
|
+
export const create: Base.Create<userwidgets.User, User, { realm: Realm }> = (
|
|
13
|
+
value: userwidgets.User,
|
|
14
|
+
action: Base.Action,
|
|
15
|
+
data?: { realm: Realm }
|
|
16
|
+
) => ({
|
|
17
|
+
...data,
|
|
18
|
+
entityType: "user",
|
|
19
|
+
entity: value.email,
|
|
20
|
+
action,
|
|
21
|
+
created: isoly.DateTime.now(),
|
|
22
|
+
value,
|
|
23
|
+
})
|
|
24
|
+
export const addSender = Base.pipeToSender(create)
|
|
25
|
+
}
|
package/Backup/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Realm } from "../Realm"
|
|
2
|
+
import { Account as AccountBackup } from "./Account"
|
|
3
|
+
import { Base as BaseBackup } from "./Base"
|
|
4
|
+
import { Card as CardBackup } from "./Card"
|
|
5
|
+
import { Operation as OperationBackup } from "./Operation"
|
|
6
|
+
import { Organization as OrganizationBackup } from "./Organization"
|
|
7
|
+
import { Rule as RuleBackup } from "./Rule"
|
|
8
|
+
import { Transaction as TransactionBackup } from "./Transaction"
|
|
9
|
+
import { User as UserBackup } from "./User"
|
|
10
|
+
|
|
11
|
+
export type Backup = Backup.Partial & Backup.Identifier
|
|
12
|
+
export namespace Backup {
|
|
13
|
+
export type Identifier = { realm: Realm; version: string; source: string }
|
|
14
|
+
export type Partial =
|
|
15
|
+
| TransactionBackup
|
|
16
|
+
| OperationBackup
|
|
17
|
+
| OrganizationBackup
|
|
18
|
+
| RuleBackup
|
|
19
|
+
| AccountBackup
|
|
20
|
+
| CardBackup
|
|
21
|
+
| UserBackup
|
|
22
|
+
export import Base = BaseBackup
|
|
23
|
+
export import Transaction = TransactionBackup
|
|
24
|
+
export import Account = AccountBackup
|
|
25
|
+
export import Organization = OrganizationBackup
|
|
26
|
+
export import Rule = RuleBackup
|
|
27
|
+
export import Operation = OperationBackup
|
|
28
|
+
export import User = UserBackup
|
|
29
|
+
export import Card = CardBackup
|
|
30
|
+
}
|
package/Card/Meta.ts
CHANGED
|
@@ -48,4 +48,23 @@ export namespace Transaction {
|
|
|
48
48
|
},
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
export function fromPreTransaction(
|
|
52
|
+
accountName: string,
|
|
53
|
+
transaction: ModelTransaction.PreTransaction | ModelTransaction,
|
|
54
|
+
kind: Rule.Base.Kind,
|
|
55
|
+
stage: "finalize" | "initiate"
|
|
56
|
+
): Transaction {
|
|
57
|
+
return {
|
|
58
|
+
...transaction,
|
|
59
|
+
stage,
|
|
60
|
+
kind,
|
|
61
|
+
amount: Math.abs(typeof transaction.amount == "number" ? transaction.amount : transaction.amount.total),
|
|
62
|
+
type: ModelTransaction.getType(transaction.counterpart, accountName),
|
|
63
|
+
original: {
|
|
64
|
+
currency: transaction.currency,
|
|
65
|
+
amount: Math.abs(typeof transaction.amount == "number" ? transaction.amount : transaction.amount.original),
|
|
66
|
+
total: Math.abs(typeof transaction.amount == "number" ? transaction.amount : transaction.amount.total),
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
}
|
|
51
70
|
}
|
package/Rule/State/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isly } from "isly"
|
|
2
2
|
import { Account as ModelAccount } from "../../Account"
|
|
3
|
+
import type { Card as ModelCard } from "../../Card"
|
|
3
4
|
import { Rail } from "../../Rail"
|
|
4
5
|
import type { Transaction as ModelTransaction } from "../../Transaction"
|
|
5
6
|
import type { Rule } from "../index"
|
|
@@ -59,4 +60,27 @@ export namespace State {
|
|
|
59
60
|
organization,
|
|
60
61
|
}
|
|
61
62
|
}
|
|
63
|
+
export const type: Record<ModelTransaction.PreTransaction["type"], Rule.Base.Kind> = {
|
|
64
|
+
authorization: "authorization",
|
|
65
|
+
incoming: "inbound",
|
|
66
|
+
outgoing: "outbound",
|
|
67
|
+
}
|
|
68
|
+
export function fromPreTransaction(
|
|
69
|
+
data: Data,
|
|
70
|
+
account: ModelAccount,
|
|
71
|
+
address: Rail.Address,
|
|
72
|
+
transactions: Account.Transactions,
|
|
73
|
+
days: Account.Days,
|
|
74
|
+
transaction: ModelTransaction.PreTransaction,
|
|
75
|
+
card?: ModelCard & { statistics: Card.Statistics },
|
|
76
|
+
organization?: Organization
|
|
77
|
+
): State {
|
|
78
|
+
return {
|
|
79
|
+
data,
|
|
80
|
+
account: Account.from(account, address, transactions, days),
|
|
81
|
+
transaction: Transaction.from(account.name, transaction, type[transaction.type], "initiate"),
|
|
82
|
+
card: card ? Card.from(card, card.statistics) : undefined,
|
|
83
|
+
organization,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
62
86
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isly } from "isly"
|
|
2
|
+
import { Rail } from "../../Rail"
|
|
3
|
+
import { Base } from "./Base"
|
|
4
|
+
|
|
5
|
+
export interface Authorization extends Base {
|
|
6
|
+
type: "authorization"
|
|
7
|
+
account: Pick<Rail.Address.Card, "id" | "type">
|
|
8
|
+
counterpart: Rail.Address.Card.Counterpart
|
|
9
|
+
reference: { reference: string }
|
|
10
|
+
approvalCode?: string
|
|
11
|
+
}
|
|
12
|
+
export namespace Authorization {
|
|
13
|
+
export const type = Base.type.extend<Authorization>({
|
|
14
|
+
type: isly.string("authorization"),
|
|
15
|
+
account: Rail.Address.Card.type.pick(["id", "type"]),
|
|
16
|
+
counterpart: Rail.Address.Card.Counterpart.type,
|
|
17
|
+
reference: isly.object<{ reference: string }>({ reference: isly.string() }),
|
|
18
|
+
approvalCode: isly.string().optional(),
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { isly } from "isly"
|
|
3
|
+
import { Rail } from "../../Rail"
|
|
4
|
+
import { Exchange } from "../Exchange"
|
|
5
|
+
|
|
6
|
+
export interface Base {
|
|
7
|
+
type: "outgoing" | "incoming" | "authorization"
|
|
8
|
+
counterpart: Rail.Address
|
|
9
|
+
currency: isoly.Currency
|
|
10
|
+
amount: number
|
|
11
|
+
description: string
|
|
12
|
+
exchange?: Exchange
|
|
13
|
+
}
|
|
14
|
+
export namespace Base {
|
|
15
|
+
export const type = isly.object<Base>({
|
|
16
|
+
type: isly.string(["outgoing", "incoming", "authorization"]),
|
|
17
|
+
counterpart: Rail.Address.type,
|
|
18
|
+
currency: isly.fromIs("isoly.Currency", isoly.Currency.is),
|
|
19
|
+
amount: isly.number(),
|
|
20
|
+
description: isly.string(),
|
|
21
|
+
exchange: Exchange.type.optional(),
|
|
22
|
+
})
|
|
23
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { isly } from "isly"
|
|
3
|
+
import { Rail } from "../../Rail"
|
|
4
|
+
import { Settlement } from "../../Settlement"
|
|
5
|
+
import { Reference as TransactionReference } from "../Reference"
|
|
6
|
+
import { Base } from "./Base"
|
|
7
|
+
|
|
8
|
+
export interface Incoming extends Base {
|
|
9
|
+
type: "incoming"
|
|
10
|
+
account: Rail.Address
|
|
11
|
+
currency: isoly.Currency
|
|
12
|
+
amount: number
|
|
13
|
+
description: string
|
|
14
|
+
posted: string
|
|
15
|
+
rail?: Rail
|
|
16
|
+
reference?: TransactionReference
|
|
17
|
+
}
|
|
18
|
+
export namespace Incoming {
|
|
19
|
+
export const type = Base.type.extend<Incoming>({
|
|
20
|
+
type: isly.string("incoming"),
|
|
21
|
+
account: Rail.Address.type,
|
|
22
|
+
currency: isly.fromIs("Currency", isoly.Currency.is),
|
|
23
|
+
amount: isly.number(),
|
|
24
|
+
description: isly.string(),
|
|
25
|
+
posted: isly.string(),
|
|
26
|
+
rail: Rail.type.optional(),
|
|
27
|
+
reference: TransactionReference.type.optional(),
|
|
28
|
+
})
|
|
29
|
+
export function fromRefund(entry: Settlement.Entry.Creatable.Refund, card: Rail.Address.Card): Incoming {
|
|
30
|
+
const [currency, amount] = entry.amount
|
|
31
|
+
return {
|
|
32
|
+
type: "incoming",
|
|
33
|
+
account: card,
|
|
34
|
+
currency,
|
|
35
|
+
amount: isoly.Currency.add(currency, -amount, -(entry.fee.other[currency] ?? 0)),
|
|
36
|
+
posted: isoly.DateTime.now(),
|
|
37
|
+
counterpart: { type: "card", merchant: entry.merchant, acquirer: entry.acquirer },
|
|
38
|
+
description: "Refund transaction.",
|
|
39
|
+
rail: card.scheme,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Rail } from "../../Rail"
|
|
2
|
+
import { Authorization as PreTransactionAuthorization } from "./Authorization"
|
|
3
|
+
import { Incoming as PreTransactionIncoming } from "./Incoming"
|
|
4
|
+
import { Outgoing as PreTransactionOutgoing } from "./Outgoing"
|
|
5
|
+
|
|
6
|
+
export type PreTransaction = PreTransaction.Outgoing | PreTransaction.Authorization | PreTransaction.Incoming
|
|
7
|
+
export namespace PreTransaction {
|
|
8
|
+
export type Resolved =
|
|
9
|
+
| (PreTransaction & { counterpart: Rail.Address; type: "outgoing" })
|
|
10
|
+
| PreTransaction.Incoming
|
|
11
|
+
| PreTransaction.Authorization
|
|
12
|
+
|
|
13
|
+
export import Authorization = PreTransactionAuthorization
|
|
14
|
+
export import Incoming = PreTransactionIncoming
|
|
15
|
+
export import Outgoing = PreTransactionOutgoing
|
|
16
|
+
}
|
package/Transaction/index.ts
CHANGED
|
@@ -9,11 +9,12 @@ import type { Rule } from "../Rule"
|
|
|
9
9
|
import { Settlement } from "../Settlement"
|
|
10
10
|
import { Creatable as TransactionCreatable } from "./Creatable"
|
|
11
11
|
import { Exchange as TransactionExchange } from "./Exchange"
|
|
12
|
-
import { Incoming as TransactionIncoming } from "./Incoming"
|
|
13
12
|
import { Note as TransactionNote } from "./Note"
|
|
13
|
+
import { PreTransaction as TransactionPreTransaction } from "./PreTransaction"
|
|
14
14
|
import { Reference as TransactionReference } from "./Reference"
|
|
15
15
|
import { Statistics as TransactionStatistics } from "./Statistics"
|
|
16
16
|
import { Status as TransactionStatus } from "./Status"
|
|
17
|
+
|
|
17
18
|
export interface Transaction {
|
|
18
19
|
counterpart: Rail.Address & { code?: string }
|
|
19
20
|
currency: isoly.Currency
|
|
@@ -100,7 +101,7 @@ export namespace Transaction {
|
|
|
100
101
|
export const directions = ["inbound", "outbound"] as const
|
|
101
102
|
export type Direction = typeof directions[number]
|
|
102
103
|
export import Creatable = TransactionCreatable
|
|
103
|
-
export import
|
|
104
|
+
export import PreTransaction = TransactionPreTransaction
|
|
104
105
|
export import Reference = TransactionReference
|
|
105
106
|
export import Note = TransactionNote
|
|
106
107
|
export import Status = TransactionStatus
|
|
@@ -311,7 +312,7 @@ export namespace Transaction {
|
|
|
311
312
|
}
|
|
312
313
|
}
|
|
313
314
|
export function fromIncoming(
|
|
314
|
-
transaction: Transaction.Incoming,
|
|
315
|
+
transaction: Transaction.PreTransaction.Incoming,
|
|
315
316
|
id: string,
|
|
316
317
|
state: Rule.State.Evaluated,
|
|
317
318
|
account: { id: string; name: string; organization: string },
|
|
@@ -347,7 +348,7 @@ export namespace Transaction {
|
|
|
347
348
|
state: Rule.State.Evaluated
|
|
348
349
|
): Transaction {
|
|
349
350
|
return {
|
|
350
|
-
...Incoming.fromRefund(refund, card),
|
|
351
|
+
...Transaction.PreTransaction.Incoming.fromRefund(refund, card),
|
|
351
352
|
amount: Amount.fromState(state),
|
|
352
353
|
type: "card",
|
|
353
354
|
direction: "inbound",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Account as modelAccount } from "../Account";
|
|
2
|
+
import { Base } from "./Base";
|
|
3
|
+
export interface Account extends Base<modelAccount> {
|
|
4
|
+
entityType: "account";
|
|
5
|
+
entity: string;
|
|
6
|
+
organization: string;
|
|
7
|
+
account: string;
|
|
8
|
+
meta: {
|
|
9
|
+
key: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare namespace Account {
|
|
13
|
+
const create: Base.Create<modelAccount, Account>;
|
|
14
|
+
const addSender: (sender: (backup: Account) => any | Promise<any>) => (args_0: modelAccount, args_1: "created" | "cancelled" | "updated" | "removed", args_2?: Record<string, never> | undefined) => ReturnType<(backup: Account) => any | Promise<any>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Account = void 0;
|
|
4
|
+
const isoly_1 = require("isoly");
|
|
5
|
+
const Base_1 = require("./Base");
|
|
6
|
+
var Account;
|
|
7
|
+
(function (Account) {
|
|
8
|
+
Account.create = (value, action) => ({
|
|
9
|
+
entityType: "account",
|
|
10
|
+
entity: value.id,
|
|
11
|
+
organization: value.organization,
|
|
12
|
+
account: value.id,
|
|
13
|
+
action,
|
|
14
|
+
created: isoly_1.isoly.DateTime.now(),
|
|
15
|
+
meta: { key: value.key ?? "" },
|
|
16
|
+
value,
|
|
17
|
+
});
|
|
18
|
+
Account.addSender = Base_1.Base.pipeToSender(Account.create);
|
|
19
|
+
})(Account || (exports.Account = Account = {}));
|
|
20
|
+
//# sourceMappingURL=Account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.js","sourceRoot":"","sources":["../../../Backup/Account.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,iCAA6B;AAS7B,IAAiB,OAAO,CAYvB;AAZD,WAAiB,OAAO;IACV,cAAM,GAAuC,CAAC,KAAmB,EAAE,MAAmB,EAAE,EAAE,CAAC,CAAC;QACxG,UAAU,EAAE,SAAS;QACrB,MAAM,EAAE,KAAK,CAAC,EAAE;QAChB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,OAAO,EAAE,KAAK,CAAC,EAAE;QACjB,MAAM;QACN,OAAO,EAAE,aAAK,CAAC,QAAQ,CAAC,GAAG,EAAE;QAC7B,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,EAAE,EAAE;QAC9B,KAAK;KACL,CAAC,CAAA;IACW,iBAAS,GAAG,WAAI,CAAC,YAAY,CAAC,QAAA,MAAM,CAAC,CAAA;AACnD,CAAC,EAZgB,OAAO,uBAAP,OAAO,QAYvB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isoly } from "isoly";
|
|
2
|
+
import { Realm } from "../Realm";
|
|
3
|
+
export type Base<T> = {
|
|
4
|
+
realm?: Realm;
|
|
5
|
+
organization?: string;
|
|
6
|
+
account?: string;
|
|
7
|
+
entity: string;
|
|
8
|
+
entityType: string;
|
|
9
|
+
action: Base.Action;
|
|
10
|
+
created: isoly.DateTime;
|
|
11
|
+
isError?: true;
|
|
12
|
+
meta?: any;
|
|
13
|
+
value: T;
|
|
14
|
+
};
|
|
15
|
+
export declare namespace Base {
|
|
16
|
+
type Action = typeof Action.values[number];
|
|
17
|
+
namespace Action {
|
|
18
|
+
const values: readonly ["created", "updated", "cancelled", "removed"];
|
|
19
|
+
}
|
|
20
|
+
type Data = {
|
|
21
|
+
realm?: Realm;
|
|
22
|
+
organization?: string;
|
|
23
|
+
account?: string;
|
|
24
|
+
isError?: true;
|
|
25
|
+
meta?: any;
|
|
26
|
+
};
|
|
27
|
+
type Create<T, B extends Base<T>, D extends Data = Record<string, never>> = (...args: [T, Action, D?]) => B;
|
|
28
|
+
function pipeToSender<T, B extends Base<T>, D extends Data = Record<string, never>>(mapper: Base.Create<T, B, D>): (sender: (backup: B) => any | Promise<any>) => (...args: Parameters<typeof mapper>) => ReturnType<typeof sender>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Base = void 0;
|
|
4
|
+
var Base;
|
|
5
|
+
(function (Base) {
|
|
6
|
+
let Action;
|
|
7
|
+
(function (Action) {
|
|
8
|
+
Action.values = ["created", "updated", "cancelled", "removed"];
|
|
9
|
+
})(Action = Base.Action || (Base.Action = {}));
|
|
10
|
+
function pipeToSender(mapper) {
|
|
11
|
+
return sender => (...args) => {
|
|
12
|
+
const backup = mapper(...args);
|
|
13
|
+
return sender(backup);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Base.pipeToSender = pipeToSender;
|
|
17
|
+
})(Base || (exports.Base = Base = {}));
|
|
18
|
+
//# sourceMappingURL=Base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Base.js","sourceRoot":"","sources":["../../../Backup/Base.ts"],"names":[],"mappings":";;;AAeA,IAAiB,IAAI,CAgBpB;AAhBD,WAAiB,IAAI;IAEpB,IAAiB,MAAM,CAEtB;IAFD,WAAiB,MAAM;QACT,aAAM,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,CAAU,CAAA;IAC9E,CAAC,EAFgB,MAAM,GAAN,WAAM,KAAN,WAAM,QAEtB;IAGD,SAAgB,YAAY,CAC3B,MAA4B;QAE5B,OAAO,MAAM,CAAC,EAAE,CACf,CAAC,GAAG,IAAI,EAAE,EAAE;YACX,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;YAC9B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;QACtB,CAAC,CAAA;IACH,CAAC;IARe,iBAAY,eAQ3B,CAAA;AACF,CAAC,EAhBgB,IAAI,oBAAJ,IAAI,QAgBpB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Card as modelCard } from "../Card";
|
|
2
|
+
import { Realm } from "../Realm";
|
|
3
|
+
import { Base } from "./Base";
|
|
4
|
+
export interface Card extends Base<modelCard> {
|
|
5
|
+
realm: Realm;
|
|
6
|
+
entityType: "card";
|
|
7
|
+
entity: string;
|
|
8
|
+
organization: string;
|
|
9
|
+
account: string;
|
|
10
|
+
}
|
|
11
|
+
export declare namespace Card {
|
|
12
|
+
const create: Base.Create<modelCard, Card>;
|
|
13
|
+
const addSender: (sender: (backup: Card) => any | Promise<any>) => (args_0: modelCard, args_1: "created" | "cancelled" | "updated" | "removed", args_2?: Record<string, never> | undefined) => ReturnType<(backup: Card) => any | Promise<any>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Card = void 0;
|
|
4
|
+
const isoly_1 = require("isoly");
|
|
5
|
+
const Base_1 = require("./Base");
|
|
6
|
+
var Card;
|
|
7
|
+
(function (Card) {
|
|
8
|
+
Card.create = (value, action) => ({
|
|
9
|
+
realm: value.realm,
|
|
10
|
+
entityType: "card",
|
|
11
|
+
entity: value.id,
|
|
12
|
+
organization: value.organization,
|
|
13
|
+
account: value.account,
|
|
14
|
+
action,
|
|
15
|
+
created: isoly_1.isoly.DateTime.now(),
|
|
16
|
+
value,
|
|
17
|
+
});
|
|
18
|
+
Card.addSender = Base_1.Base.pipeToSender(Card.create);
|
|
19
|
+
})(Card || (exports.Card = Card = {}));
|
|
20
|
+
//# sourceMappingURL=Card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Card.js","sourceRoot":"","sources":["../../../Backup/Card.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAG7B,iCAA6B;AAS7B,IAAiB,IAAI,CAYpB;AAZD,WAAiB,IAAI;IACP,WAAM,GAAiC,CAAC,KAAgB,EAAE,MAAmB,EAAE,EAAE,CAAC,CAAC;QAC/F,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,UAAU,EAAE,MAAM;QAClB,MAAM,EAAE,KAAK,CAAC,EAAE;QAChB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM;QACN,OAAO,EAAE,aAAK,CAAC,QAAQ,CAAC,GAAG,EAAE;QAC7B,KAAK;KACL,CAAC,CAAA;IACW,cAAS,GAAG,WAAI,CAAC,YAAY,CAAC,KAAA,MAAM,CAAC,CAAA;AACnD,CAAC,EAZgB,IAAI,oBAAJ,IAAI,QAYpB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Operation as modelOperation } from "../Operation";
|
|
2
|
+
import { Base } from "./Base";
|
|
3
|
+
export interface Operation extends Base<modelOperation> {
|
|
4
|
+
entityType: "operation";
|
|
5
|
+
entity: string;
|
|
6
|
+
account: string;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace Operation {
|
|
9
|
+
const create: Base.Create<modelOperation, Operation, {
|
|
10
|
+
organization: string;
|
|
11
|
+
}>;
|
|
12
|
+
const addSender: (sender: (backup: Operation) => any | Promise<any>) => (args_0: modelOperation, args_1: "created" | "cancelled" | "updated" | "removed", args_2?: {
|
|
13
|
+
organization: string;
|
|
14
|
+
} | undefined) => ReturnType<(backup: Operation) => any | Promise<any>>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Operation = void 0;
|
|
4
|
+
const isoly_1 = require("isoly");
|
|
5
|
+
const Base_1 = require("./Base");
|
|
6
|
+
var Operation;
|
|
7
|
+
(function (Operation) {
|
|
8
|
+
Operation.create = (value, action, data) => ({
|
|
9
|
+
entityType: "operation",
|
|
10
|
+
entity: value.signature ?? "",
|
|
11
|
+
...data,
|
|
12
|
+
account: value.account,
|
|
13
|
+
action,
|
|
14
|
+
created: isoly_1.isoly.DateTime.now(),
|
|
15
|
+
value,
|
|
16
|
+
});
|
|
17
|
+
Operation.addSender = Base_1.Base.pipeToSender(Operation.create);
|
|
18
|
+
})(Operation || (exports.Operation = Operation = {}));
|
|
19
|
+
//# sourceMappingURL=Operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Operation.js","sourceRoot":"","sources":["../../../Backup/Operation.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,iCAA6B;AAO7B,IAAiB,SAAS,CAezB;AAfD,WAAiB,SAAS;IACZ,gBAAM,GAAqE,CACvF,KAAqB,EACrB,MAAmB,EACnB,IAA+B,EAC9B,EAAE,CAAC,CAAC;QACL,UAAU,EAAE,WAAW;QACvB,MAAM,EAAE,KAAK,CAAC,SAAS,IAAI,EAAE;QAC7B,GAAG,IAAI;QACP,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM;QACN,OAAO,EAAE,aAAK,CAAC,QAAQ,CAAC,GAAG,EAAE;QAC7B,KAAK;KACL,CAAC,CAAA;IACW,mBAAS,GAAG,WAAI,CAAC,YAAY,CAAC,UAAA,MAAM,CAAC,CAAA;AACnD,CAAC,EAfgB,SAAS,yBAAT,SAAS,QAezB"}
|