@f-o-t/money 1.1.1 → 1.2.2
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/LICENSE +21 -0
- package/README.md +147 -0
- package/package.json +33 -57
- package/dist/index.d.ts +0 -863
- package/dist/index.js +0 -521
- package/dist/operators/index.d.ts +0 -69
- package/dist/operators/index.js +0 -39
- package/dist/shared/chunk-jf6gzvp1.js +0 -852
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FOT (F-O-T)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -482,6 +482,153 @@ const result = evaluator.evaluate(
|
|
|
482
482
|
// - money_positive, money_negative, money_zero
|
|
483
483
|
```
|
|
484
484
|
|
|
485
|
+
### Rules Engine Integration
|
|
486
|
+
|
|
487
|
+
Use money operators with `@f-o-t/rules-engine` to build complex financial business rules:
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
import { createEngine } from "@f-o-t/rules-engine";
|
|
491
|
+
import { moneyOperators } from "@f-o-t/money/plugins/operators";
|
|
492
|
+
import { z } from "zod";
|
|
493
|
+
|
|
494
|
+
// Define consequence types for your rules
|
|
495
|
+
const TransactionConsequences = {
|
|
496
|
+
approve: z.object({ approved: z.boolean() }),
|
|
497
|
+
require_review: z.object({ reason: z.string() }),
|
|
498
|
+
reject: z.object({ reason: z.string() }),
|
|
499
|
+
apply_fee: z.object({ amount: z.string(), currency: z.string() }),
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// Create engine with money operators
|
|
503
|
+
const engine = createEngine({
|
|
504
|
+
operators: moneyOperators,
|
|
505
|
+
consequences: TransactionConsequences,
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// Add rules for high-value transactions
|
|
509
|
+
engine.addRule({
|
|
510
|
+
name: "high-value-transaction-review",
|
|
511
|
+
priority: 100,
|
|
512
|
+
conditions: {
|
|
513
|
+
id: "g1",
|
|
514
|
+
operator: "AND",
|
|
515
|
+
conditions: [
|
|
516
|
+
{
|
|
517
|
+
id: "c1",
|
|
518
|
+
type: "custom",
|
|
519
|
+
field: "amount",
|
|
520
|
+
operator: "money_gt",
|
|
521
|
+
value: { amount: "10000.00", currency: "BRL" },
|
|
522
|
+
},
|
|
523
|
+
],
|
|
524
|
+
},
|
|
525
|
+
consequences: [
|
|
526
|
+
{
|
|
527
|
+
type: "require_review",
|
|
528
|
+
payload: { reason: "High value transaction requires approval" },
|
|
529
|
+
},
|
|
530
|
+
],
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
// Add rules for transaction fees
|
|
534
|
+
engine.addRule({
|
|
535
|
+
name: "pix-fee-waiver",
|
|
536
|
+
priority: 50,
|
|
537
|
+
conditions: {
|
|
538
|
+
id: "g2",
|
|
539
|
+
operator: "AND",
|
|
540
|
+
conditions: [
|
|
541
|
+
{
|
|
542
|
+
id: "c1",
|
|
543
|
+
type: "string",
|
|
544
|
+
field: "paymentMethod",
|
|
545
|
+
operator: "eq",
|
|
546
|
+
value: "pix",
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
id: "c2",
|
|
550
|
+
type: "custom",
|
|
551
|
+
field: "amount",
|
|
552
|
+
operator: "money_lt",
|
|
553
|
+
value: { amount: "100.00", currency: "BRL" },
|
|
554
|
+
},
|
|
555
|
+
],
|
|
556
|
+
},
|
|
557
|
+
consequences: [
|
|
558
|
+
{
|
|
559
|
+
type: "apply_fee",
|
|
560
|
+
payload: { amount: "0.00", currency: "BRL" },
|
|
561
|
+
},
|
|
562
|
+
],
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
// Evaluate rules
|
|
566
|
+
const result = await engine.evaluate({
|
|
567
|
+
amount: { amount: "15000.00", currency: "BRL" },
|
|
568
|
+
paymentMethod: "pix",
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
console.log(result.matchedRules); // Rules that matched
|
|
572
|
+
console.log(result.consequences); // Actions to take
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
**Complex multi-condition rules:**
|
|
576
|
+
|
|
577
|
+
```typescript
|
|
578
|
+
// Discount eligibility with money conditions
|
|
579
|
+
engine.addRule({
|
|
580
|
+
name: "volume-discount",
|
|
581
|
+
conditions: {
|
|
582
|
+
id: "g1",
|
|
583
|
+
operator: "AND",
|
|
584
|
+
conditions: [
|
|
585
|
+
{
|
|
586
|
+
id: "c1",
|
|
587
|
+
type: "custom",
|
|
588
|
+
field: "cartTotal",
|
|
589
|
+
operator: "money_between",
|
|
590
|
+
value: [
|
|
591
|
+
{ amount: "500.00", currency: "BRL" },
|
|
592
|
+
{ amount: "2000.00", currency: "BRL" },
|
|
593
|
+
],
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
id: "c2",
|
|
597
|
+
type: "custom",
|
|
598
|
+
field: "customerLifetimeValue",
|
|
599
|
+
operator: "money_gt",
|
|
600
|
+
value: { amount: "5000.00", currency: "BRL" },
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
id: "c3",
|
|
604
|
+
type: "boolean",
|
|
605
|
+
field: "isPremiumMember",
|
|
606
|
+
operator: "eq",
|
|
607
|
+
value: true,
|
|
608
|
+
},
|
|
609
|
+
],
|
|
610
|
+
},
|
|
611
|
+
consequences: [
|
|
612
|
+
{
|
|
613
|
+
type: "apply_discount",
|
|
614
|
+
payload: { percentage: 15 },
|
|
615
|
+
},
|
|
616
|
+
],
|
|
617
|
+
});
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
**Available money operators for rules:**
|
|
621
|
+
- `money_eq` - Equal to
|
|
622
|
+
- `money_neq` - Not equal to
|
|
623
|
+
- `money_gt` - Greater than
|
|
624
|
+
- `money_gte` - Greater than or equal
|
|
625
|
+
- `money_lt` - Less than
|
|
626
|
+
- `money_lte` - Less than or equal
|
|
627
|
+
- `money_between` - Between two values (inclusive)
|
|
628
|
+
- `money_positive` - Is positive (> 0)
|
|
629
|
+
- `money_negative` - Is negative (< 0)
|
|
630
|
+
- `money_zero` - Is zero
|
|
631
|
+
|
|
485
632
|
### Custom Currencies
|
|
486
633
|
|
|
487
634
|
Register currencies not in ISO 4217:
|
package/package.json
CHANGED
|
@@ -1,72 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
2
|
+
"name": "@f-o-t/money",
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./plugins/operators": {
|
|
16
|
+
"types": "./dist/plugins/operators/index.d.ts",
|
|
17
|
+
"default": "./dist/plugins/operators/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "bun x --bun fot build",
|
|
22
|
+
"test": "bun x --bun fot test",
|
|
23
|
+
"lint": "bun x --bun fot lint",
|
|
24
|
+
"format": "bun x --bun fot format",
|
|
25
|
+
"typecheck": "bun x --bun fot typecheck"
|
|
4
26
|
},
|
|
5
27
|
"dependencies": {
|
|
6
|
-
"@f-o-t/
|
|
7
|
-
"zod": "4.3.
|
|
28
|
+
"@f-o-t/bigint": "^1.0.0",
|
|
29
|
+
"zod": "^4.3.6"
|
|
8
30
|
},
|
|
9
|
-
"description": "Type-safe money handling library with BigInt precision and ISO 4217 currency support",
|
|
10
31
|
"devDependencies": {
|
|
11
|
-
"@
|
|
12
|
-
"@
|
|
13
|
-
"bumpp": "10.3.2",
|
|
14
|
-
"bunup": "0.16.11",
|
|
15
|
-
"typescript": "5.9.3"
|
|
32
|
+
"@f-o-t/cli": "^1.0.0",
|
|
33
|
+
"@f-o-t/config": "^1.0.0"
|
|
16
34
|
},
|
|
17
|
-
"exports": {
|
|
18
|
-
".": {
|
|
19
|
-
"bun": "./src/index.ts",
|
|
20
|
-
"import": {
|
|
21
|
-
"default": "./dist/index.js",
|
|
22
|
-
"types": "./dist/index.d.ts"
|
|
23
|
-
},
|
|
24
|
-
"types": "./src/index.ts"
|
|
25
|
-
},
|
|
26
|
-
"./operators": {
|
|
27
|
-
"bun": "./src/operators/index.ts",
|
|
28
|
-
"import": {
|
|
29
|
-
"default": "./dist/operators/index.js",
|
|
30
|
-
"types": "./dist/operators/index.d.ts"
|
|
31
|
-
},
|
|
32
|
-
"types": "./src/operators/index.ts"
|
|
33
|
-
},
|
|
34
|
-
"./package.json": "./package.json"
|
|
35
|
-
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
],
|
|
39
|
-
"homepage": "https://github.com/F-O-T/montte-nx/blob/master/libraries/money",
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"module": "./dist/index.js",
|
|
42
|
-
"name": "@f-o-t/money",
|
|
43
35
|
"peerDependencies": {
|
|
44
|
-
"
|
|
36
|
+
"@f-o-t/condition-evaluator": "^2.0.2"
|
|
45
37
|
},
|
|
46
38
|
"peerDependenciesMeta": {
|
|
47
|
-
"
|
|
39
|
+
"@f-o-t/condition-evaluator": {
|
|
48
40
|
"optional": true
|
|
49
41
|
}
|
|
50
42
|
},
|
|
51
|
-
"private": false,
|
|
52
|
-
"publishConfig": {
|
|
53
|
-
"access": "public"
|
|
54
|
-
},
|
|
55
43
|
"repository": {
|
|
56
44
|
"type": "git",
|
|
57
|
-
"url": "https://github.com/F-O-T/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"build": "bunup",
|
|
61
|
-
"check": "biome check --write .",
|
|
62
|
-
"dev": "bunup --watch",
|
|
63
|
-
"release": "bumpp --commit --push --tag",
|
|
64
|
-
"test": "bun test",
|
|
65
|
-
"test:coverage": "bun test --coverage",
|
|
66
|
-
"test:watch": "bun test --watch",
|
|
67
|
-
"typecheck": "tsc"
|
|
68
|
-
},
|
|
69
|
-
"type": "module",
|
|
70
|
-
"types": "./dist/index.d.ts",
|
|
71
|
-
"version": "1.1.1"
|
|
45
|
+
"url": "https://github.com/F-O-T/libraries.git",
|
|
46
|
+
"directory": "libraries/money"
|
|
47
|
+
}
|
|
72
48
|
}
|