@xyo-network/payment-plugin 6.1.0 → 7.0.1
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/dist/neutral/Discount/Diviner.d.ts +5 -5
- package/dist/neutral/Discount/Diviner.d.ts.map +1 -1
- package/dist/neutral/Discount/lib/applyCoupons.d.ts.map +1 -1
- package/dist/neutral/Discount/lib/findUnfulfilledConditions.d.ts +2 -2
- package/dist/neutral/Discount/lib/findUnfulfilledConditions.d.ts.map +1 -1
- package/dist/neutral/Invoice/getInvoiceForEscrow.d.ts +2 -2
- package/dist/neutral/Invoice/getInvoiceForEscrow.d.ts.map +1 -1
- package/dist/neutral/Subtotal/Diviner.d.ts +2 -2
- package/dist/neutral/Subtotal/Diviner.d.ts.map +1 -1
- package/dist/neutral/Total/Diviner.d.ts +2 -2
- package/dist/neutral/Total/Diviner.d.ts.map +1 -1
- package/dist/neutral/index.mjs +64 -42
- package/dist/neutral/index.mjs.map +3 -3
- package/package.json +30 -36
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk
|
|
1
|
+
import type { Hash } from '@xylabs/sdk';
|
|
2
2
|
import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease';
|
|
3
3
|
import type { Condition, Coupon, Discount, EscrowTerms, PaymentDiscountDivinerParams } from '@xyo-network/payment-payload-plugins';
|
|
4
|
-
import type { ArchivistInstance, DivinerInstance, DivinerModuleEventData, Payload, XyoAddress } from '@xyo-network/sdk
|
|
5
|
-
import { AbstractDiviner } from '@xyo-network/sdk
|
|
4
|
+
import type { ArchivistInstance, DivinerInstance, DivinerModuleEventData, Payload, XyoAddress } from '@xyo-network/sdk';
|
|
5
|
+
import { AbstractDiviner } from '@xyo-network/sdk';
|
|
6
6
|
export type PaymentDiscountDivinerInputType = EscrowTerms | Coupon | HashLeaseEstimate | Payload;
|
|
7
7
|
export declare class PaymentDiscountDiviner<TParams extends PaymentDiscountDivinerParams = PaymentDiscountDivinerParams, TIn extends PaymentDiscountDivinerInputType = PaymentDiscountDivinerInputType, TOut extends Discount = Discount, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
8
8
|
static readonly configSchemas: ("network.xyo.diviner.payments.discount.config" & {
|
|
@@ -28,7 +28,7 @@ export declare class PaymentDiscountDiviner<TParams extends PaymentDiscountDivin
|
|
|
28
28
|
* @param payloads The payloads to search for the appraisals
|
|
29
29
|
* @returns The appraisals found in the payloads
|
|
30
30
|
*/
|
|
31
|
-
protected getEscrowAppraisals(terms: EscrowTerms, hashMap:
|
|
31
|
+
protected getEscrowAppraisals(terms: EscrowTerms, hashMap: Map<Hash, Payload>): HashLeaseEstimate[];
|
|
32
32
|
/**
|
|
33
33
|
* Finds the discounts specified by the escrow terms from the supplied payloads
|
|
34
34
|
* @param terms The escrow terms
|
|
@@ -36,7 +36,7 @@ export declare class PaymentDiscountDiviner<TParams extends PaymentDiscountDivin
|
|
|
36
36
|
* @returns A tuple containing all the escrow coupons and conditions referenced in those coupons
|
|
37
37
|
* that were found in the either the supplied payloads or the archivist
|
|
38
38
|
*/
|
|
39
|
-
protected getEscrowDiscounts(terms: EscrowTerms, hashMap:
|
|
39
|
+
protected getEscrowDiscounts(terms: EscrowTerms, hashMap: Map<Hash, Payload>): Promise<[Coupon[], Condition[]]>;
|
|
40
40
|
protected isCouponCurrent(coupon: Coupon): boolean;
|
|
41
41
|
}
|
|
42
42
|
//# sourceMappingURL=Diviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../src/Discount/Diviner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["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AI,OAAO,CAAC,iBAAiB,CAAC;cAMnD,+BAA+B,IAAI,OAAO,CAAC,eAAe,CAAC;IAM3E;;;;;OAKG;IACH,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,iBAAiB,EAAE;IAMnG;;;;;;OAMG;cACa,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAiDrH,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAInD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyCoupons.d.ts","sourceRoot":"","sources":["../../../../src/Discount/lib/applyCoupons.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACxE,OAAO,KAAK,EAEV,MAAM,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"applyCoupons.d.ts","sourceRoot":"","sources":["../../../../src/Discount/lib/applyCoupons.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACxE,OAAO,KAAK,EAEV,MAAM,EAAE,QAAQ,EAEjB,MAAM,sCAAsC,CAAA;AAQ7C,eAAO,MAAM,YAAY,GAAI,YAAY,iBAAiB,EAAE,EAAE,SAAS,MAAM,EAAE,KAAG,QAiDjF,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk
|
|
1
|
+
import type { Hash } from '@xylabs/sdk';
|
|
2
2
|
import type { Condition, Coupon } from '@xyo-network/payment-payload-plugins';
|
|
3
|
-
import type { Payload } from '@xyo-network/sdk
|
|
3
|
+
import type { Payload } from '@xyo-network/sdk';
|
|
4
4
|
/**
|
|
5
5
|
* Validates the conditions of a coupon against the provided payloads
|
|
6
6
|
* @param coupon The coupon to check
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findUnfulfilledConditions.d.ts","sourceRoot":"","sources":["../../../../src/Discount/lib/findUnfulfilledConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"findUnfulfilledConditions.d.ts","sourceRoot":"","sources":["../../../../src/Discount/lib/findUnfulfilledConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAA;AAE7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAiB/C;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GAAU,QAAQ,MAAM,EAAE,aAAY,SAAS,EAAO,EAAE,WAAU,OAAO,EAAO,KAAG,OAAO,CAAC,OAAO,CAGpI,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GAAU,QAAQ,MAAM,EAAE,aAAY,SAAS,EAAO,EAAE,WAAU,OAAO,EAAO,KAAG,OAAO,CAAC,IAAI,EAAE,CAoCtI,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk
|
|
1
|
+
import type { Hash } from '@xylabs/sdk';
|
|
2
2
|
import type { EscrowTerms, Invoice } from '@xyo-network/payment-payload-plugins';
|
|
3
|
-
import type { DivinerInstance, Payload } from '@xyo-network/sdk
|
|
3
|
+
import type { DivinerInstance, Payload } from '@xyo-network/sdk';
|
|
4
4
|
/**
|
|
5
5
|
* Validates the escrow terms to ensure they are valid for a purchase
|
|
6
6
|
* @returns A payment if the terms are valid for a purchase, undefined otherwise
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInvoiceForEscrow.d.ts","sourceRoot":"","sources":["../../../src/Invoice/getInvoiceForEscrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"getInvoiceForEscrow.d.ts","sourceRoot":"","sources":["../../../src/Invoice/getInvoiceForEscrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EACA,WAAW,EAAE,OAAO,EAE/B,MAAM,sCAAsC,CAAA;AAI7C,OAAO,KAAK,EACV,eAAe,EAAE,OAAO,EACzB,MAAM,kBAAkB,CAAA;AAGzB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,WAAW,EAClB,aAAa,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAClC,qBAAqB,eAAe,KACnC,OAAO,CAAC,OAAO,GAAG,SAAS,CAc7B,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease';
|
|
2
2
|
import type { EscrowTerms, PaymentSubtotalDivinerParams, Subtotal } from '@xyo-network/payment-payload-plugins';
|
|
3
|
-
import type { DivinerInstance, DivinerModuleEventData, Payload } from '@xyo-network/sdk
|
|
4
|
-
import { AbstractDiviner } from '@xyo-network/sdk
|
|
3
|
+
import type { DivinerInstance, DivinerModuleEventData, Payload } from '@xyo-network/sdk';
|
|
4
|
+
import { AbstractDiviner } from '@xyo-network/sdk';
|
|
5
5
|
/**
|
|
6
6
|
* Escrow terms that contain all the valid fields for calculating a subtotal
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../src/Subtotal/Diviner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../src/Subtotal/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAExE,OAAO,KAAK,EACV,WAAW,EAAE,4BAA4B,EAAE,QAAQ,EACpD,MAAM,sCAAsC,CAAA;AAI7C,OAAO,KAAK,EACV,eAAe,EAAE,sBAAsB,EAAE,OAAO,EACjD,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,eAAe,EAChB,MAAM,kBAAkB,CAAA;AAqBzB;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG,WAAW,GAAG,iBAAiB,GAAG,OAAO,CAAA;AAEvF,qBACa,sBAAsB,CACjC,OAAO,SAAS,4BAA4B,GAAG,4BAA4B,EAC3E,GAAG,SAAS,+BAA+B,GAAG,+BAA+B,EAC7E,IAAI,SAAS,QAAQ,GAAG,QAAQ,EAChC,UAAU,SAAS,sBAAsB,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa;;SAAuC;IAC7E,gBAAyB,mBAAmB;;MAAqC;cAEjE,aAAa,CAAC,QAAQ,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;CAwBrE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Discount, PaymentTotalDivinerParams, Subtotal, Total } from '@xyo-network/payment-payload-plugins';
|
|
2
2
|
import { PaymentTotalDivinerConfigSchema } from '@xyo-network/payment-payload-plugins';
|
|
3
|
-
import type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/sdk
|
|
4
|
-
import { AbstractDiviner } from '@xyo-network/sdk
|
|
3
|
+
import type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/sdk';
|
|
4
|
+
import { AbstractDiviner } from '@xyo-network/sdk';
|
|
5
5
|
import type { PaymentDiscountDiviner, PaymentDiscountDivinerInputType } from '../Discount/index.ts';
|
|
6
6
|
import type { PaymentSubtotalDiviner, PaymentSubtotalDivinerInputType } from '../Subtotal/index.ts';
|
|
7
7
|
type InputType = PaymentDiscountDivinerInputType | PaymentSubtotalDivinerInputType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../src/Total/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,QAAQ,EAAE,yBAAyB,EAAE,QAAQ,EAAE,KAAK,EACrD,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAGL,+BAA+B,EAChC,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../src/Total/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,QAAQ,EAAE,yBAAyB,EAAE,QAAQ,EAAE,KAAK,EACrD,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAGL,+BAA+B,EAChC,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EACV,eAAe,EAAE,sBAAsB,EACxC,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,eAAe,EAChB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAA;AACnG,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAA;AAEnG,KAAK,SAAS,GAAG,+BAA+B,GAAG,+BAA+B,CAAA;AAClF,KAAK,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAA;AAE7C,qBACa,mBAAmB,CAC9B,OAAO,SAAS,yBAAyB,GAAG,yBAAyB,EACrE,GAAG,SAAS,SAAS,GAAG,SAAS,EACjC,IAAI,SAAS,UAAU,GAAG,UAAU,EACpC,UAAU,SAAS,sBAAsB,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa;;SAAoC;IAC1E,gBAAyB,mBAAmB,EAAE,+BAA+B,CAAkC;cAE/F,aAAa,CAAC,QAAQ,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cAqBpD,0BAA0B,IAAI,OAAO,CAAC,sBAAsB,CAAC;cAM7D,yBAAyB,IAAI,OAAO,CAAC,sBAAsB,CAAC;CAK7E"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
assertEx as assertEx2,
|
|
17
17
|
exists as exists2,
|
|
18
18
|
filterAs
|
|
19
|
-
} from "@xylabs/sdk
|
|
19
|
+
} from "@xylabs/sdk";
|
|
20
20
|
import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness";
|
|
21
21
|
import { isHashLeaseEstimate } from "@xyo-network/diviner-hash-lease";
|
|
22
22
|
import {
|
|
@@ -34,10 +34,10 @@ import {
|
|
|
34
34
|
asDivinerInstance,
|
|
35
35
|
creatableModule,
|
|
36
36
|
PayloadBuilder as PayloadBuilder2
|
|
37
|
-
} from "@xyo-network/sdk
|
|
37
|
+
} from "@xyo-network/sdk";
|
|
38
38
|
|
|
39
39
|
// src/Discount/lib/applyCoupons.ts
|
|
40
|
-
import { assertEx, exists } from "@xylabs/sdk
|
|
40
|
+
import { assertEx, exists } from "@xylabs/sdk";
|
|
41
41
|
import {
|
|
42
42
|
DiscountSchema,
|
|
43
43
|
isFixedAmountCoupon,
|
|
@@ -51,11 +51,11 @@ var applyCoupons = (appraisals, coupons) => {
|
|
|
51
51
|
const allCouponsAreUSD = coupons.map((coupon) => coupon?.currency).filter(exists).every((currency2) => currency2 === "USD");
|
|
52
52
|
assertEx(allCouponsAreUSD, () => "All coupons must be in USD");
|
|
53
53
|
const total = appraisals.reduce((acc, appraisal) => acc + appraisal.price, 0);
|
|
54
|
-
const singularFixedDiscount = Math.max(...coupons.filter((coupon) => isFixedAmountCoupon(coupon) &&
|
|
55
|
-
const singularPercentageDiscount = Math.max(...coupons.filter((coupon) => isFixedPercentageCoupon(coupon) &&
|
|
54
|
+
const singularFixedDiscount = Math.max(...coupons.filter((coupon) => isFixedAmountCoupon(coupon) && isStackable(coupon) !== true).map((coupon) => coupon.amount), 0);
|
|
55
|
+
const singularPercentageDiscount = Math.max(...coupons.filter((coupon) => isFixedPercentageCoupon(coupon) && isStackable(coupon) !== true).map((coupon) => coupon.percentage), 0) * total;
|
|
56
56
|
const singularFixedPriceDiscount = calculateSingularFixedPriceDiscount(total, appraisals, coupons, false);
|
|
57
|
-
const stackedFixedDiscount = coupons.filter((coupon) => isFixedAmountCoupon(coupon) && isStackable(coupon)).reduce((acc, coupon) => acc + coupon.amount, 0);
|
|
58
|
-
const stackedPercentageDiscount = coupons.filter((coupon) => isFixedPercentageCoupon(coupon) && isStackable(coupon)).reduce((acc, coupon) => acc + coupon.percentage, 0) * (total - stackedFixedDiscount);
|
|
57
|
+
const stackedFixedDiscount = coupons.filter((coupon) => isFixedAmountCoupon(coupon) && isStackable(coupon) === true).reduce((acc, coupon) => acc + coupon.amount, 0);
|
|
58
|
+
const stackedPercentageDiscount = coupons.filter((coupon) => isFixedPercentageCoupon(coupon) && isStackable(coupon) === true).reduce((acc, coupon) => acc + coupon.percentage, 0) * (total - stackedFixedDiscount);
|
|
59
59
|
const stackedFixedPriceDiscount = calculateSingularFixedPriceDiscount(total, appraisals, coupons, true);
|
|
60
60
|
const stackedDiscount = stackedFixedDiscount + stackedPercentageDiscount + stackedFixedPriceDiscount;
|
|
61
61
|
const maxDiscount = Math.max(
|
|
@@ -73,7 +73,7 @@ var applyCoupons = (appraisals, coupons) => {
|
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
var calculateSingularFixedPriceDiscount = (total, appraisals, coupons, stackable = false) => {
|
|
76
|
-
const singularFixedPriceDiscounts = coupons.filter(isFixedPriceCoupon).filter((coupon) => stackable ? isStackable(coupon) :
|
|
76
|
+
const singularFixedPriceDiscounts = coupons.filter(isFixedPriceCoupon).filter((coupon) => stackable ? isStackable(coupon) === true : isStackable(coupon) !== true).map((coupon) => coupon.amount).filter((amount) => amount > 0);
|
|
77
77
|
if (singularFixedPriceDiscounts.length === 0) return 0;
|
|
78
78
|
const lowestFixedPrice = Math.min(...singularFixedPriceDiscounts);
|
|
79
79
|
const reducedPrices = appraisals.map((appraisal) => (
|
|
@@ -87,27 +87,29 @@ var calculateSingularFixedPriceDiscount = (total, appraisals, coupons, stackable
|
|
|
87
87
|
|
|
88
88
|
// src/Discount/lib/findUnfulfilledConditions.ts
|
|
89
89
|
import { isCondition } from "@xyo-network/payment-payload-plugins";
|
|
90
|
-
import { isSchemaPayload, PayloadBuilder } from "@xyo-network/sdk
|
|
90
|
+
import { isSchemaPayload, PayloadBuilder } from "@xyo-network/sdk";
|
|
91
91
|
import { Ajv } from "ajv";
|
|
92
92
|
var ajv = new Ajv({ strict: false });
|
|
93
93
|
var schemaCache = /* @__PURE__ */ new Map();
|
|
94
|
-
var
|
|
94
|
+
var toHashLookup = async (payloads) => new Map(Object.entries(await PayloadBuilder.toAllHashMap(payloads)));
|
|
95
|
+
var areConditionsFulfilled = async (coupon, conditions = [], payloads = []) => {
|
|
96
|
+
const unfulfilled = await findUnfulfilledConditions(coupon, conditions, payloads);
|
|
97
|
+
return unfulfilled.length === 0;
|
|
98
|
+
};
|
|
95
99
|
var findUnfulfilledConditions = async (coupon, conditions = [], payloads = []) => {
|
|
96
100
|
const unfulfilledConditions = [];
|
|
97
101
|
if (!coupon.conditions || coupon.conditions.length === 0) return unfulfilledConditions;
|
|
98
|
-
const hashMap = await
|
|
99
|
-
const foundConditions = coupon.conditions.map((hash) => hashMap
|
|
102
|
+
const hashMap = await toHashLookup([...conditions, ...payloads]);
|
|
103
|
+
const foundConditions = coupon.conditions.map((hash) => hashMap.get(hash)).filter(isCondition);
|
|
100
104
|
if (foundConditions.length !== coupon.conditions.length) {
|
|
101
|
-
const missing = coupon.conditions.filter((hash) => !hashMap
|
|
105
|
+
const missing = coupon.conditions.filter((hash) => !hashMap.has(hash));
|
|
102
106
|
unfulfilledConditions.push(...missing);
|
|
103
107
|
return unfulfilledConditions;
|
|
104
108
|
}
|
|
105
109
|
for (const hash of coupon.conditions) {
|
|
106
|
-
let validator;
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
} else {
|
|
110
|
-
const payload = hashMap[hash];
|
|
110
|
+
let validator = schemaCache.get(hash);
|
|
111
|
+
if (!validator) {
|
|
112
|
+
const payload = hashMap.get(hash);
|
|
111
113
|
const definition = isSchemaPayload(payload) ? payload.definition : void 0;
|
|
112
114
|
if (definition) {
|
|
113
115
|
validator = ajv.compile(definition);
|
|
@@ -128,6 +130,14 @@ var DEFAULT_BOUND_WITNESS_DIVINER_QUERY_PROPS = {
|
|
|
128
130
|
order: "desc",
|
|
129
131
|
schema: BoundWitnessDivinerQuerySchema
|
|
130
132
|
};
|
|
133
|
+
var toHashLookup2 = async (payloads) => {
|
|
134
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
135
|
+
for (const [payload, hash] of await PayloadBuilder2.hashPairs(payloads)) {
|
|
136
|
+
lookup.set(hash, payload);
|
|
137
|
+
lookup.set(await PayloadBuilder2.dataHash(payload), payload);
|
|
138
|
+
}
|
|
139
|
+
return lookup;
|
|
140
|
+
};
|
|
131
141
|
var PaymentDiscountDiviner = class extends AbstractDiviner {
|
|
132
142
|
get couponAuthorities() {
|
|
133
143
|
return [...this.config.couponAuthorities ?? [], ...this.params.couponAuthorities ?? []];
|
|
@@ -139,7 +149,7 @@ var PaymentDiscountDiviner = class extends AbstractDiviner {
|
|
|
139
149
|
$sources.push(await PayloadBuilder2.hash(terms));
|
|
140
150
|
const termsAppraisals = terms?.appraisals;
|
|
141
151
|
if (!termsAppraisals || termsAppraisals.length === 0) return [{ ...NO_DISCOUNT, $sources }];
|
|
142
|
-
const hashMap = await
|
|
152
|
+
const hashMap = await toHashLookup2(payloads);
|
|
143
153
|
const appraisals = this.getEscrowAppraisals(terms, hashMap);
|
|
144
154
|
$sources.push(...termsAppraisals);
|
|
145
155
|
if (appraisals.length !== termsAppraisals.length) return [{ ...NO_DISCOUNT, $sources }];
|
|
@@ -147,7 +157,10 @@ var PaymentDiscountDiviner = class extends AbstractDiviner {
|
|
|
147
157
|
const couponHashes = await PayloadBuilder2.hashes(coupons);
|
|
148
158
|
$sources.push(...couponHashes);
|
|
149
159
|
const currentCoupons = coupons.filter((coupon) => this.isCouponCurrent(coupon));
|
|
150
|
-
const
|
|
160
|
+
const checkedCoupons = await Promise.all(
|
|
161
|
+
currentCoupons.map(async (coupon) => await areConditionsFulfilled(coupon, conditions, payloads) ? coupon : void 0)
|
|
162
|
+
);
|
|
163
|
+
const conditionsMetCoupons = checkedCoupons.filter(exists2);
|
|
151
164
|
const validCoupons = await this.filterToSigned(conditionsMetCoupons);
|
|
152
165
|
if (validCoupons.length === 0) return [{ ...NO_DISCOUNT, $sources }];
|
|
153
166
|
const discount = applyCoupons(appraisals, validCoupons);
|
|
@@ -161,12 +174,13 @@ var PaymentDiscountDiviner = class extends AbstractDiviner {
|
|
|
161
174
|
*/
|
|
162
175
|
async filterToSigned(coupons) {
|
|
163
176
|
const signed = [];
|
|
164
|
-
const dataHashMap =
|
|
177
|
+
const dataHashMap = /* @__PURE__ */ new Map();
|
|
178
|
+
for (const [coupon, hash] of await PayloadBuilder2.dataHashPairs(coupons)) {
|
|
179
|
+
dataHashMap.set(hash, coupon);
|
|
180
|
+
}
|
|
165
181
|
const boundWitnessDiviner = await this.getDiscountsBoundWitnessDiviner();
|
|
166
|
-
const hashes = Object.keys(dataHashMap);
|
|
167
182
|
const addresses = this.couponAuthorities;
|
|
168
|
-
await Promise.all(
|
|
169
|
-
const hash = h;
|
|
183
|
+
await Promise.all([...dataHashMap].map(([hash, coupon]) => {
|
|
170
184
|
return Promise.all(addresses.map(async (address) => {
|
|
171
185
|
const query = {
|
|
172
186
|
...DEFAULT_BOUND_WITNESS_DIVINER_QUERY_PROPS,
|
|
@@ -174,7 +188,7 @@ var PaymentDiscountDiviner = class extends AbstractDiviner {
|
|
|
174
188
|
payload_hashes: [hash]
|
|
175
189
|
};
|
|
176
190
|
const result = await boundWitnessDiviner.divine([query]);
|
|
177
|
-
if (result.length > 0) signed.push(
|
|
191
|
+
if (result.length > 0) signed.push(coupon);
|
|
178
192
|
}));
|
|
179
193
|
}));
|
|
180
194
|
return signed;
|
|
@@ -198,7 +212,7 @@ var PaymentDiscountDiviner = class extends AbstractDiviner {
|
|
|
198
212
|
getEscrowAppraisals(terms, hashMap) {
|
|
199
213
|
const hashes = terms?.appraisals ?? [];
|
|
200
214
|
if (hashes.length === 0) return [];
|
|
201
|
-
return hashes.map((hash) => hashMap
|
|
215
|
+
return hashes.map((hash) => hashMap.get(hash)).filter(exists2).filter(isHashLeaseEstimate);
|
|
202
216
|
}
|
|
203
217
|
/**
|
|
204
218
|
* Finds the discounts specified by the escrow terms from the supplied payloads
|
|
@@ -210,8 +224,8 @@ var PaymentDiscountDiviner = class extends AbstractDiviner {
|
|
|
210
224
|
async getEscrowDiscounts(terms, hashMap) {
|
|
211
225
|
const discountsHashes = terms.discounts ?? [];
|
|
212
226
|
if (discountsHashes.length === 0) return [[], []];
|
|
213
|
-
const discounts = discountsHashes.map((hash) => hashMap
|
|
214
|
-
const missingDiscounts = discountsHashes.filter((hash) => !hashMap
|
|
227
|
+
const discounts = discountsHashes.map((hash) => hashMap.get(hash)).filter(exists2).filter(isCoupon);
|
|
228
|
+
const missingDiscounts = discountsHashes.filter((hash) => !hashMap.has(hash));
|
|
215
229
|
if (missingDiscounts.length > 0) {
|
|
216
230
|
const discountsArchivist = await this.getDiscountsArchivist();
|
|
217
231
|
const payloads = await discountsArchivist.get(missingDiscounts);
|
|
@@ -225,8 +239,8 @@ var PaymentDiscountDiviner = class extends AbstractDiviner {
|
|
|
225
239
|
}
|
|
226
240
|
}
|
|
227
241
|
const conditionsHashes = discounts.flatMap((discount) => discount.conditions ?? []);
|
|
228
|
-
const conditions = conditionsHashes.map((hash) => hashMap
|
|
229
|
-
const missingConditions = conditionsHashes.filter((hash) => !hashMap
|
|
242
|
+
const conditions = conditionsHashes.map((hash) => hashMap.get(hash)).filter(exists2).filter(isCondition2);
|
|
243
|
+
const missingConditions = conditionsHashes.filter((hash) => !hashMap.has(hash));
|
|
230
244
|
if (missingConditions.length > 0) {
|
|
231
245
|
const discountsArchivist = await this.getDiscountsArchivist();
|
|
232
246
|
const payloads = await discountsArchivist.get(missingConditions);
|
|
@@ -259,7 +273,7 @@ import {
|
|
|
259
273
|
isTotal,
|
|
260
274
|
PaymentSchema
|
|
261
275
|
} from "@xyo-network/payment-payload-plugins";
|
|
262
|
-
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk
|
|
276
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk";
|
|
263
277
|
var getInvoiceForEscrow = async (terms, dataHashMap, paymentTotalDiviner) => {
|
|
264
278
|
const payloads = Object.values(dataHashMap);
|
|
265
279
|
const results = await paymentTotalDiviner.divine([terms, ...payloads]);
|
|
@@ -294,7 +308,7 @@ import {
|
|
|
294
308
|
AbstractDiviner as AbstractDiviner2,
|
|
295
309
|
creatableModule as creatableModule2,
|
|
296
310
|
PayloadBuilder as PayloadBuilder4
|
|
297
|
-
} from "@xyo-network/sdk
|
|
311
|
+
} from "@xyo-network/sdk";
|
|
298
312
|
|
|
299
313
|
// src/Subtotal/lib/appraisalValidators.ts
|
|
300
314
|
import { isIso4217CurrencyCode } from "@xyo-network/payment-payload-plugins";
|
|
@@ -303,17 +317,17 @@ import { isIso4217CurrencyCode } from "@xyo-network/payment-payload-plugins";
|
|
|
303
317
|
var FIVE_MINUTES = 1e3 * 60 * 5;
|
|
304
318
|
var validateDuration = (value, windowMs = FIVE_MINUTES) => {
|
|
305
319
|
const now = Date.now();
|
|
306
|
-
if (
|
|
307
|
-
return !(
|
|
320
|
+
if (value.nbf == null || value.nbf === 0 || value.nbf > now) return false;
|
|
321
|
+
return !(value.exp == null || value.exp === 0 || value.exp - now < windowMs);
|
|
308
322
|
};
|
|
309
323
|
|
|
310
324
|
// src/Subtotal/lib/appraisalValidators.ts
|
|
311
325
|
var validateAppraisalAmount = (appraisals) => {
|
|
312
326
|
if (appraisals.some((appraisal) => typeof appraisal.price !== "number")) return false;
|
|
313
|
-
return
|
|
327
|
+
return appraisals.every((appraisal) => appraisal.price >= 0);
|
|
314
328
|
};
|
|
315
329
|
var validateAppraisalCurrency = (appraisals) => {
|
|
316
|
-
if (
|
|
330
|
+
if (appraisals.some((appraisal) => appraisal.currency != "USD")) return false;
|
|
317
331
|
return appraisals.every((appraisal) => isIso4217CurrencyCode(appraisal.currency));
|
|
318
332
|
};
|
|
319
333
|
var validateAppraisalConsistentCurrency = (appraisals) => {
|
|
@@ -343,16 +357,24 @@ var termsValidators = [
|
|
|
343
357
|
|
|
344
358
|
// src/Subtotal/Diviner.ts
|
|
345
359
|
var currency = "USD";
|
|
360
|
+
var toHashLookup3 = async (payloads) => {
|
|
361
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
362
|
+
for (const [payload, hash] of await PayloadBuilder4.hashPairs(payloads)) {
|
|
363
|
+
lookup.set(hash, payload);
|
|
364
|
+
lookup.set(await PayloadBuilder4.dataHash(payload), payload);
|
|
365
|
+
}
|
|
366
|
+
return lookup;
|
|
367
|
+
};
|
|
346
368
|
var PaymentSubtotalDiviner = class extends AbstractDiviner2 {
|
|
347
369
|
async divineHandler(payloads = []) {
|
|
348
370
|
const terms = payloads.find(isEscrowTerms2);
|
|
349
371
|
if (!terms) return [];
|
|
350
|
-
if (
|
|
372
|
+
if (termsValidators.some((validator) => !validator(terms))) return [];
|
|
351
373
|
const validTerms = terms;
|
|
352
|
-
const hashMap = await
|
|
353
|
-
const appraisals = validTerms.appraisals.map((appraisal) => hashMap
|
|
374
|
+
const hashMap = await toHashLookup3(payloads);
|
|
375
|
+
const appraisals = validTerms.appraisals.map((appraisal) => hashMap.get(appraisal)).filter(isHashLeaseEstimate2);
|
|
354
376
|
if (appraisals.length !== validTerms.appraisals.length) return [];
|
|
355
|
-
if (
|
|
377
|
+
if (appraisalValidators.some((validator) => !validator(appraisals))) return [];
|
|
356
378
|
const amount = calculateSubtotal(appraisals);
|
|
357
379
|
const $sources = [await PayloadBuilder4.dataHash(validTerms), ...validTerms.appraisals];
|
|
358
380
|
return [{
|
|
@@ -373,7 +395,7 @@ var calculateSubtotal = (appraisals) => {
|
|
|
373
395
|
};
|
|
374
396
|
|
|
375
397
|
// src/Total/Diviner.ts
|
|
376
|
-
import { assertEx as assertEx3 } from "@xylabs/sdk
|
|
398
|
+
import { assertEx as assertEx3 } from "@xylabs/sdk";
|
|
377
399
|
import {
|
|
378
400
|
isDiscount as isDiscount2,
|
|
379
401
|
isSubtotal as isSubtotal2,
|
|
@@ -385,7 +407,7 @@ import {
|
|
|
385
407
|
asDivinerInstance as asDivinerInstance2,
|
|
386
408
|
creatableModule as creatableModule3,
|
|
387
409
|
PayloadBuilder as PayloadBuilder5
|
|
388
|
-
} from "@xyo-network/sdk
|
|
410
|
+
} from "@xyo-network/sdk";
|
|
389
411
|
var PaymentTotalDiviner = class extends AbstractDiviner3 {
|
|
390
412
|
async divineHandler(payloads = []) {
|
|
391
413
|
const subtotalDiviner = await this.getPaymentSubtotalDiviner();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Discount/Diviner.ts", "../../src/Discount/lib/applyCoupons.ts", "../../src/Discount/lib/findUnfulfilledConditions.ts", "../../src/Invoice/getInvoiceForEscrow.ts", "../../src/Subtotal/Diviner.ts", "../../src/Subtotal/lib/appraisalValidators.ts", "../../src/Subtotal/lib/durationValidators.ts", "../../src/Subtotal/lib/termsValidators.ts", "../../src/Total/Diviner.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Hash } from '@xylabs/sdk-js'\nimport {\n assertEx, exists, filterAs,\n} from '@xylabs/sdk-js'\nimport type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness'\nimport type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport { isHashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport type {\n Condition,\n Coupon,\n Discount,\n EscrowTerms, PaymentDiscountDivinerParams,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n asCondition,\n asCoupon, isCondition, isCoupon,\n isEscrowTerms, NO_DISCOUNT, PaymentDiscountDivinerConfigSchema,\n} from '@xyo-network/payment-payload-plugins'\nimport type {\n ArchivistInstance, DivinerInstance, DivinerModuleEventData, Payload, XyoAddress,\n} from '@xyo-network/sdk-js'\nimport {\n AbstractDiviner, asArchivistInstance, asDivinerInstance, creatableModule, PayloadBuilder,\n} from '@xyo-network/sdk-js'\n\nimport { applyCoupons, areConditionsFulfilled } from './lib/index.ts'\n\nconst DEFAULT_BOUND_WITNESS_DIVINER_QUERY_PROPS: Readonly<BoundWitnessDivinerQueryPayload> = {\n limit: 1,\n order: 'desc',\n schema: BoundWitnessDivinerQuerySchema,\n}\n\nexport type PaymentDiscountDivinerInputType = EscrowTerms | Coupon | HashLeaseEstimate | Payload\n\n@creatableModule()\nexport class PaymentDiscountDiviner<\n TParams extends PaymentDiscountDivinerParams = PaymentDiscountDivinerParams,\n TIn extends PaymentDiscountDivinerInputType = PaymentDiscountDivinerInputType,\n TOut extends Discount = Discount,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas = [PaymentDiscountDivinerConfigSchema]\n static override readonly defaultConfigSchema = PaymentDiscountDivinerConfigSchema\n\n protected get couponAuthorities(): XyoAddress[] {\n return [...(this.config.couponAuthorities ?? []), ...(this.params.couponAuthorities ?? [])]\n }\n\n protected async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n const $sources: Hash[] = []\n\n // Parse terms\n const terms = payloads.find(isEscrowTerms) as EscrowTerms | undefined\n if (!terms) return [{ ...NO_DISCOUNT, $sources }] as TOut[]\n $sources.push(await PayloadBuilder.hash(terms))\n\n // Parse appraisals\n const termsAppraisals = terms?.appraisals\n // If the escrow terms do not have appraisals, return no discount\n if (!termsAppraisals || termsAppraisals.length === 0) return [{ ...NO_DISCOUNT, $sources }] as TOut[]\n const hashMap = await PayloadBuilder.toAllHashMap(payloads) as Record<Hash, Payload>\n const appraisals = this.getEscrowAppraisals(terms, hashMap)\n // Add the appraisals that were found to the sources\n $sources.push(...termsAppraisals)\n // If not all appraisals are found, return no discount\n if (appraisals.length !== termsAppraisals.length) return [{ ...NO_DISCOUNT, $sources }] as TOut[]\n\n // Parse coupons\n const [coupons, conditions] = await this.getEscrowDiscounts(terms, hashMap)\n // Add the coupons that were found to the sources\n // TODO: Should we throw if not all coupons are found?\n const couponHashes = await PayloadBuilder.hashes(coupons)\n $sources.push(...couponHashes)\n\n const currentCoupons = coupons.filter(coupon => this.isCouponCurrent(coupon))\n const conditionsMetCoupons = (\n await Promise.all(currentCoupons.map(async coupon => await areConditionsFulfilled(coupon, conditions, payloads) ? coupon : undefined))).filter(exists)\n\n const validCoupons = await this.filterToSigned(conditionsMetCoupons)\n // TODO: Should we throw if not all coupons are valid?\n if (validCoupons.length === 0) return [{ ...NO_DISCOUNT, $sources }] as TOut[]\n\n // TODO: Call paymentSubtotalDiviner to get the subtotal to centralize the logic\n const discount = applyCoupons(appraisals, validCoupons)\n return [{ ...discount, $sources }] as TOut[]\n }\n\n /**\n * Filters the supplied list of coupons to only those that are signed by\n * addresses specified in the couponAuthorities\n * @param coupons The list of coupons to filter\n * @returns The filtered list of coupons that are signed by the couponAuthorities\n */\n protected async filterToSigned(coupons: Coupon[]): Promise<Coupon[]> {\n const signed: Coupon[] = []\n const dataHashMap = await PayloadBuilder.toDataHashMap(coupons)\n const boundWitnessDiviner = await this.getDiscountsBoundWitnessDiviner()\n const hashes = Object.keys(dataHashMap)\n const addresses = this.couponAuthorities\n // TODO: Keep an in memory cache of the hashes queried and their results\n // to avoid querying the same hash multiple times\n await Promise.all(hashes.map((h) => {\n const hash = h as Hash\n return Promise.all(addresses.map(async (address) => {\n const query: BoundWitnessDivinerQueryPayload = {\n ...DEFAULT_BOUND_WITNESS_DIVINER_QUERY_PROPS, addresses: [address], payload_hashes: [hash],\n }\n const result = await boundWitnessDiviner.divine([query])\n if (result.length > 0) signed.push(dataHashMap[hash])\n }))\n }))\n return signed\n }\n\n protected async getDiscountsArchivist(): Promise<ArchivistInstance> {\n const name = assertEx(this.config.archivist, () => 'Missing archivist in config')\n const mod = assertEx(await this.resolve(name), () => `Error resolving archivist: ${name}`)\n return assertEx(asArchivistInstance(mod), () => `Resolved module ${mod.address} not a valid Archivist`)\n }\n\n protected async getDiscountsBoundWitnessDiviner(): Promise<DivinerInstance> {\n const name = assertEx(this.config.boundWitnessDiviner, () => 'Missing boundWitnessDiviner in config')\n const mod = assertEx(await this.resolve(name), () => `Error resolving boundWitnessDiviner: ${name}`)\n return assertEx(asDivinerInstance(mod), () => `Resolved module ${mod.address} not a valid Diviner`)\n }\n\n /**\n * Finds the appraisals specified by the escrow terms from the supplied payloads\n * @param terms The escrow terms\n * @param payloads The payloads to search for the appraisals\n * @returns The appraisals found in the payloads\n */\n protected getEscrowAppraisals(terms: EscrowTerms, hashMap: Record<Hash, Payload>): HashLeaseEstimate[] {\n const hashes = terms?.appraisals ?? []\n if (hashes.length === 0) return []\n return hashes.map(hash => hashMap[hash]).filter(exists).filter(isHashLeaseEstimate)\n }\n\n /**\n * Finds the discounts specified by the escrow terms from the supplied payloads\n * @param terms The escrow terms\n * @param hashMap The payloads to search for the discounts\n * @returns A tuple containing all the escrow coupons and conditions referenced in those coupons\n * that were found in the either the supplied payloads or the archivist\n */\n protected async getEscrowDiscounts(terms: EscrowTerms, hashMap: Record<Hash, Payload>): Promise<[Coupon[], Condition[]]> {\n // Parse discounts\n const discountsHashes = terms.discounts ?? []\n if (discountsHashes.length === 0) return [[], []]\n\n // Use the supplied payloads to find the discounts\n const discounts: Coupon[] = discountsHashes.map(hash => hashMap[hash]).filter(exists).filter(isCoupon)\n const missingDiscounts = discountsHashes.filter(hash => !hashMap[hash])\n // If not all discounts are found\n if (missingDiscounts.length > 0) {\n // Find any remaining from discounts archivist\n const discountsArchivist = await this.getDiscountsArchivist()\n const payloads = await discountsArchivist.get(missingDiscounts)\n discounts.push(...filterAs(payloads, asCoupon))\n }\n // If not all discounts are found\n if (discounts.length !== discountsHashes.length) {\n const termsHash = await PayloadBuilder.hash(terms)\n const foundHashes = await PayloadBuilder.hashes(discounts)\n // Log individual discounts that were not found\n for (const hash of discountsHashes) {\n if (!foundHashes.includes(hash)) console.warn(`Discount ${hash} not found for terms ${termsHash}`)\n }\n }\n\n const conditionsHashes: Hash[] = discounts.flatMap(discount => discount.conditions ?? [])\n const conditions: Condition[] = conditionsHashes.map(hash => hashMap[hash]).filter(exists).filter(isCondition)\n const missingConditions = conditionsHashes.filter(hash => !hashMap[hash])\n\n // If not all conditions are found\n if (missingConditions.length > 0) {\n // Find any remaining from discounts archivist\n const discountsArchivist = await this.getDiscountsArchivist()\n const payloads = await discountsArchivist.get(missingConditions)\n conditions.push(...filterAs(payloads, asCondition))\n }\n // If not all conditions are found\n if (conditions.length !== conditionsHashes.length) {\n const termsHash = await PayloadBuilder.hash(terms)\n const foundHashes = await PayloadBuilder.hashes(conditions)\n // Log individual conditions that were not found\n for (const hash of discountsHashes) {\n if (!foundHashes.includes(hash)) console.warn(`Coupon condition ${hash} not found for terms ${termsHash}`)\n }\n }\n\n return [discounts, conditions]\n }\n\n protected isCouponCurrent(coupon: Coupon): boolean {\n const now = Date.now()\n return coupon.exp > now && coupon.nbf < now\n }\n}\n", "import { assertEx, exists } from '@xylabs/sdk-js'\nimport type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport type {\n AmountFields,\n Coupon, Discount, FixedAmountCoupon,\n FixedPercentageCoupon,\n FixedPriceCoupon,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n DiscountSchema,\n isFixedAmountCoupon, isFixedPercentageCoupon,\n isFixedPriceCoupon,\n isStackable,\n} from '@xyo-network/payment-payload-plugins'\n\nexport const applyCoupons = (appraisals: HashLeaseEstimate[], coupons: Coupon[]): Discount => {\n // Ensure all appraisals and coupons are in USD\n const allAppraisalsAreUSD = appraisals.every(appraisal => appraisal.currency === 'USD')\n assertEx(allAppraisalsAreUSD, () => 'All appraisals must be in USD')\n const allCouponsAreUSD = coupons.map(coupon => (coupon as Partial<AmountFields>)?.currency).filter(exists).every(currency => currency === 'USD')\n assertEx(allCouponsAreUSD, () => 'All coupons must be in USD')\n const total = appraisals.reduce((acc, appraisal) => acc + appraisal.price, 0)\n\n // Calculated non-stackable discount coupons\n const singularFixedDiscount = Math.max(...coupons\n .filter(coupon => isFixedAmountCoupon(coupon) && !isStackable(coupon))\n .map(coupon => (coupon as FixedAmountCoupon).amount), 0)\n const singularPercentageDiscount = (Math.max(...coupons\n .filter(coupon => isFixedPercentageCoupon(coupon) && !isStackable(coupon))\n .map(coupon => (coupon as FixedPercentageCoupon).percentage), 0)) * total\n const singularFixedPriceDiscount = calculateSingularFixedPriceDiscount(total, appraisals, coupons, false)\n\n // Calculate stackable discount coupons\n // First calculate the total discount from fixed amount coupons\n const stackedFixedDiscount = coupons\n .filter(coupon => isFixedAmountCoupon(coupon) && isStackable(coupon))\n .reduce((acc, coupon) => acc + (coupon as FixedAmountCoupon).amount, 0)\n // Then calculate the total discount from percentage coupons and apply\n // the percentage discount to the remaining total after fixed discounts\n const stackedPercentageDiscount = coupons\n .filter(coupon => isFixedPercentageCoupon(coupon) && isStackable(coupon))\n .reduce((acc, coupon) => acc + (coupon as FixedPercentageCoupon).percentage, 0) * (total - stackedFixedDiscount)\n // Then calculate the total discount from fixed price coupons\n const stackedFixedPriceDiscount = calculateSingularFixedPriceDiscount(total, appraisals, coupons, true)\n\n // Sum all stackable discounts\n const stackedDiscount = stackedFixedDiscount + stackedPercentageDiscount + stackedFixedPriceDiscount\n\n // Find the best coupon(s) to apply\n const maxDiscount = Math.max(\n singularFixedDiscount,\n singularFixedPriceDiscount,\n singularPercentageDiscount,\n stackedDiscount,\n 0,\n )\n\n // Ensure discount is not more than the total\n const amount = Math.min(maxDiscount, total)\n\n // Return single discount payload\n return {\n amount, schema: DiscountSchema, currency: 'USD',\n }\n}\n\nconst calculateSingularFixedPriceDiscount = (total: number, appraisals: HashLeaseEstimate[], coupons: Coupon[], stackable = false): number => {\n // Find all singular fixed price discounts\n const singularFixedPriceDiscounts = coupons\n .filter(isFixedPriceCoupon)\n .filter(coupon => stackable ? isStackable(coupon) : !isStackable(coupon))\n .map(coupon => (coupon as FixedPriceCoupon).amount)\n // Ensure all fixed price discounts are positive\n .filter(amount => amount > 0)\n\n // If there are no singular fixed price discounts, return no discount\n if (singularFixedPriceDiscounts.length === 0) return 0\n\n // Find the maximum discount (the lowest fixed price)\n const lowestFixedPrice = Math.min(...singularFixedPriceDiscounts)\n\n // Apply the fixed price to all appraisals to get the reduced prices\n const reducedPrices = appraisals.map(appraisal =>\n // If the appraisal price is less than the fixed price\n Math.min(appraisal.price, lowestFixedPrice))\n\n // Calculate the reduced total using the reduced prices\n const reducedTotal = reducedPrices.reduce((acc, price) => acc + price, 0)\n\n // Calculate the discount\n const discount = total - reducedTotal\n\n // Return the discount or 0 if the discount would have resulted in a negative value\n return Math.max(discount, 0)\n}\n", "import type { Hash } from '@xylabs/sdk-js'\nimport type { Condition, Coupon } from '@xyo-network/payment-payload-plugins'\nimport { isCondition } from '@xyo-network/payment-payload-plugins'\nimport type { Payload, SchemaPayload } from '@xyo-network/sdk-js'\nimport { isSchemaPayload, PayloadBuilder } from '@xyo-network/sdk-js'\nimport type { ValidateFunction } from 'ajv'\nimport { Ajv } from 'ajv'\n\n// TODO: Use our schema cache\nconst ajv = new Ajv({ strict: false }) // Create the Ajv instance once\nconst schemaCache = new Map() // Cache to store compiled validators\n\n/**\n * Validates the conditions of a coupon against the provided payloads\n * @param coupon The coupon to check\n * @param conditions The conditions associated with the coupon\n * @param payloads The associated payloads (containing the conditions and data to validate the conditions against)\n * @returns True if all conditions are fulfilled, false otherwise\n */\nexport const areConditionsFulfilled = async (coupon: Coupon, conditions: Condition[] = [], payloads: Payload[] = []): Promise<boolean> =>\n (await findUnfulfilledConditions(coupon, conditions, payloads)).length === 0\n\n/**\n * Validates the conditions of a coupon against the provided payloads\n * @param coupon The coupon to check\n * @param conditions The conditions associated with the coupon\n * @param payloads The associated payloads (containing the conditions and data to validate the conditions against)\n * @returns The unfulfilled condition hashes\n */\nexport const findUnfulfilledConditions = async (coupon: Coupon, conditions: Condition[] = [], payloads: Payload[] = []): Promise<Hash[]> => {\n const unfulfilledConditions: Hash[] = []\n // If there are no conditions, then they are fulfilled\n if (!coupon.conditions || coupon.conditions.length === 0) return unfulfilledConditions\n const hashMap = await PayloadBuilder.toAllHashMap([...conditions, ...payloads])\n // Find all the conditions\n const foundConditions = coupon.conditions.map(hash => hashMap[hash]).filter(isCondition)\n // Not all conditions were found\n if (foundConditions.length !== coupon.conditions.length) {\n const missing = coupon.conditions.filter(hash => !hashMap[hash])\n unfulfilledConditions.push(...missing)\n return unfulfilledConditions\n }\n\n // Test each condition\n for (const hash of coupon.conditions) {\n let validator: ValidateFunction\n\n // Check if the schema is already cached\n if (schemaCache.has(hash)) {\n validator = schemaCache.get(hash)\n } else {\n const payload = hashMap[hash]\n const definition = isSchemaPayload(payload) ? (payload as SchemaPayload).definition : undefined\n if (definition) {\n // Compile and cache the validator\n validator = ajv.compile(definition)\n schemaCache.set(hash, validator)\n\n // Validate the payload\n } else {\n unfulfilledConditions.push(hash)\n continue\n }\n }\n if (!validator(payloads)) unfulfilledConditions.push(hash)\n }\n\n // All conditions passed\n return unfulfilledConditions\n}\n", "import type { Hash } from '@xylabs/sdk-js'\nimport type {\n Discount, EscrowTerms, Invoice, Payment,\n Subtotal, Total,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n isDiscount, isSubtotal, isTotal, PaymentSchema,\n} from '@xyo-network/payment-payload-plugins'\nimport type { DivinerInstance, Payload } from '@xyo-network/sdk-js'\nimport { PayloadBuilder } from '@xyo-network/sdk-js'\n\n/**\n * Validates the escrow terms to ensure they are valid for a purchase\n * @returns A payment if the terms are valid for a purchase, undefined otherwise\n */\nexport const getInvoiceForEscrow = async (\n terms: EscrowTerms,\n dataHashMap: Record<Hash, Payload>,\n paymentTotalDiviner: DivinerInstance,\n): Promise<Invoice | undefined> => {\n const payloads = Object.values(dataHashMap)\n const results = await paymentTotalDiviner.divine([terms, ...payloads])\n const subtotal = results.find(isSubtotal) as Subtotal | undefined\n const discount = results.find(isDiscount) as Discount | undefined\n const total = results.find(isTotal) as Total | undefined\n if (!subtotal || !total) return undefined\n const { amount, currency } = total\n if (currency !== 'USD') return undefined\n const $sources = await getSources(terms, subtotal, total, discount)\n const payment: Payment = {\n amount, currency, schema: PaymentSchema, $sources,\n }\n return discount ? [subtotal, total, payment, discount] : [subtotal, total, payment]\n}\n\nconst getSources = async (terms: EscrowTerms, subtotal: Subtotal, total: Total, discount?: Discount): Promise<Hash[]> => {\n const sources = discount ? [terms, subtotal, total, discount] : [terms, subtotal, total]\n return await Promise.all(sources.map(p => PayloadBuilder.dataHash(p)))\n}\n", "import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport { isHashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport type {\n EscrowTerms, PaymentSubtotalDivinerParams, Subtotal,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n isEscrowTerms, PaymentSubtotalDivinerConfigSchema, SubtotalSchema,\n} from '@xyo-network/payment-payload-plugins'\nimport type {\n DivinerInstance, DivinerModuleEventData, Payload,\n} from '@xyo-network/sdk-js'\nimport {\n AbstractDiviner, creatableModule, PayloadBuilder,\n} from '@xyo-network/sdk-js'\n\nimport type { ValidEscrowTerms } from './lib/index.ts'\nimport { appraisalValidators, termsValidators } from './lib/index.ts'\n\nconst currency = 'USD'\n\n/**\n * Escrow terms that contain all the valid fields for calculating a subtotal\n */\nexport type PaymentSubtotalDivinerInputType = EscrowTerms | HashLeaseEstimate | Payload\n\n@creatableModule()\nexport class PaymentSubtotalDiviner<\n TParams extends PaymentSubtotalDivinerParams = PaymentSubtotalDivinerParams,\n TIn extends PaymentSubtotalDivinerInputType = PaymentSubtotalDivinerInputType,\n TOut extends Subtotal = Subtotal,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas = [PaymentSubtotalDivinerConfigSchema]\n static override readonly defaultConfigSchema = PaymentSubtotalDivinerConfigSchema\n\n protected async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n // Find the escrow terms\n const terms = payloads.find(isEscrowTerms) as EscrowTerms | undefined\n if (!terms) return []\n\n // Run all terms validations\n if (!termsValidators.every(validator => validator(terms))) return []\n const validTerms = terms as ValidEscrowTerms\n\n // Retrieve all appraisals from terms\n const hashMap = await PayloadBuilder.toAllHashMap(payloads)\n const appraisals = validTerms.appraisals.map(appraisal => hashMap[appraisal]).filter(isHashLeaseEstimate) as unknown as HashLeaseEstimate[]\n\n // Ensure all appraisals are present\n if (appraisals.length !== validTerms.appraisals.length) return []\n\n // Run all appraisal validations\n if (!appraisalValidators.every(validator => validator(appraisals))) return []\n const amount = calculateSubtotal(appraisals)\n const $sources = [await PayloadBuilder.dataHash(validTerms), ...validTerms.appraisals]\n return [{\n amount, currency, schema: SubtotalSchema, $sources,\n }] as TOut[]\n }\n}\n\n// TODO: Add support for other currencies\nconst calculateSubtotal = (appraisals: HashLeaseEstimate[]): number => {\n return appraisals.reduce((sum, appraisal) => sum + appraisal.price, 0)\n}\n", "import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport { isIso4217CurrencyCode } from '@xyo-network/payment-payload-plugins'\n\nimport { validateDuration } from './durationValidators.ts'\n\nconst validateAppraisalAmount = (appraisals: HashLeaseEstimate[]): boolean => {\n // Ensure all appraisals are numeric\n if (appraisals.some(appraisal => typeof appraisal.price !== 'number')) return false\n // Ensure all appraisals are positive numbers\n return !(appraisals.some(appraisal => appraisal.price < 0))\n}\n\nconst validateAppraisalCurrency = (appraisals: HashLeaseEstimate[]): boolean => {\n // Only supporting USD for now, the remaining checks are for future-proofing.\n if (!appraisals.every(appraisal => appraisal.currency == 'USD')) return false\n\n // Check every object in the array to ensure they all are in a supported currency.\n return (appraisals.every(appraisal => isIso4217CurrencyCode(appraisal.currency)))\n}\n\nconst validateAppraisalConsistentCurrency = (appraisals: HashLeaseEstimate[]): boolean => {\n // Check if the array is empty or contains only one element, no need to compare.\n if (appraisals.length <= 1) return true\n\n // Get the currency of the first element to compare with others.\n const { currency } = appraisals[0]\n if (!currency) return false\n\n // Check every object in the array to ensure they all have the same currency.\n return (appraisals.every(item => item.currency === currency))\n}\n\nconst validateAppraisalWindow = (appraisals: HashLeaseEstimate[]): boolean => appraisals.every(validateDuration)\n\nexport const appraisalValidators = [\n validateAppraisalAmount,\n validateAppraisalCurrency,\n validateAppraisalConsistentCurrency,\n validateAppraisalWindow,\n]\n", "import type { DurationFields } from '@xyo-network/xns-record-payload-plugins'\n\nconst FIVE_MINUTES = 1000 * 60 * 5\n\n/**\n * Validates that the current time is within the duration window, within a configurable a buffer\n * @param value The duration value\n * @param windowMs The window in milliseconds to allow for a buffer\n * @returns True if the duration is valid, false otherwise\n */\nexport const validateDuration = (value: Partial<DurationFields>, windowMs = FIVE_MINUTES): boolean => {\n const now = Date.now()\n if (!value.nbf || value.nbf > now) return false\n // If already expired (include for a 5 minute buffer to allow for a reasonable\n // minimum amount of time for the transaction to be processed)\n return !(!value.exp || value.exp - now < windowMs)\n}\n", "import type { Hash } from '@xylabs/sdk-js'\nimport type { EscrowTerms } from '@xyo-network/payment-payload-plugins'\n\nimport { validateDuration } from './durationValidators.ts'\n\nexport type ValidEscrowTerms = Required<EscrowTerms>\n\nconst validateTermsAppraisals = (terms: EscrowTerms): terms is Required<EscrowTerms & { appraisals: Hash[] }> => {\n if (!terms.appraisals) return false\n return terms.appraisals.length > 0\n}\nconst validateTermsWindow = (terms: EscrowTerms): boolean => validateDuration(terms)\n\nexport const termsValidators = [\n validateTermsAppraisals,\n validateTermsWindow,\n]\n", "import type { Hash } from '@xylabs/sdk-js'\nimport { assertEx } from '@xylabs/sdk-js'\nimport type {\n Discount, PaymentTotalDivinerParams, Subtotal, Total,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n isDiscount,\n isSubtotal,\n PaymentTotalDivinerConfigSchema, TotalSchema,\n} from '@xyo-network/payment-payload-plugins'\nimport type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/sdk-js'\nimport {\n AbstractDiviner, asDivinerInstance, creatableModule, PayloadBuilder,\n} from '@xyo-network/sdk-js'\n\nimport type { PaymentDiscountDiviner, PaymentDiscountDivinerInputType } from '../Discount/index.ts'\nimport type { PaymentSubtotalDiviner, PaymentSubtotalDivinerInputType } from '../Subtotal/index.ts'\n\ntype InputType = PaymentDiscountDivinerInputType | PaymentSubtotalDivinerInputType\ntype OutputType = Subtotal | Discount | Total\n\n@creatableModule()\nexport class PaymentTotalDiviner<\n TParams extends PaymentTotalDivinerParams = PaymentTotalDivinerParams,\n TIn extends InputType = InputType,\n TOut extends OutputType = OutputType,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas = [PaymentTotalDivinerConfigSchema]\n static override readonly defaultConfigSchema: PaymentTotalDivinerConfigSchema = PaymentTotalDivinerConfigSchema\n\n protected async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n const subtotalDiviner = await this.getPaymentSubtotalDiviner()\n const subtotalResult = await subtotalDiviner.divine(payloads)\n const subtotal = subtotalResult.find(isSubtotal)\n if (!subtotal) return []\n const discountDiviner = await this.getPaymentDiscountsDiviner()\n const discountResult = await discountDiviner.divine(payloads)\n const discount = discountResult.find(isDiscount)\n if (!discount) return []\n const { currency: subtotalCurrency } = subtotal\n const { currency: discountCurrency } = discount\n assertEx(subtotalCurrency === discountCurrency, () => `Subtotal currency ${subtotalCurrency} does not match discount currency ${discountCurrency}`)\n const amount = Math.max(0, subtotal.amount - discount.amount)\n const currency = subtotalCurrency\n const $sources = [await PayloadBuilder.dataHash(subtotal), await PayloadBuilder.dataHash(discount)] as Hash[]\n const total: Total = {\n amount, currency, $sources, schema: TotalSchema,\n }\n return [subtotal, discount, total] as TOut[]\n }\n\n protected async getPaymentDiscountsDiviner(): Promise<PaymentDiscountDiviner> {\n const name = assertEx(this.config.paymentDiscountDiviner, () => 'Missing paymentDiscountDiviner in config')\n const mod = assertEx(await this.resolve(name), () => `Error resolving paymentDiscountDiviner: ${name}`)\n return assertEx(asDivinerInstance(mod), () => `Resolved module ${mod.address} not a valid Diviner`) as PaymentDiscountDiviner\n }\n\n protected async getPaymentSubtotalDiviner(): Promise<PaymentSubtotalDiviner> {\n const name = assertEx(this.config.paymentSubtotalDiviner, () => 'Missing paymentSubtotalDiviner in config')\n const mod = assertEx(await this.resolve(name), () => `Error resolving paymentSubtotalDiviner: ${name}`)\n return assertEx(asDivinerInstance(mod), () => `Resolved module ${mod.address} not a valid Diviner`) as PaymentSubtotalDiviner\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;AACA;AAAA,EACE,YAAAA;AAAA,EAAU,UAAAC;AAAA,EAAQ;AAAA,OACb;AAEP,SAAS,sCAAsC;AAE/C,SAAS,2BAA2B;AAOpC;AAAA,EACE;AAAA,EACA;AAAA,EAAU,eAAAC;AAAA,EAAa;AAAA,EACvB;AAAA,EAAe;AAAA,EAAa;AAAA,OACvB;AAIP;AAAA,EACE;AAAA,EAAiB;AAAA,EAAqB;AAAA,EAAmB;AAAA,EAAiB,kBAAAC;AAAA,OACrE;;;ACxBP,SAAS,UAAU,cAAc;AAQjC;AAAA,EACE;AAAA,EACA;AAAA,EAAqB;AAAA,EACrB;AAAA,EACA;AAAA,OACK;AAEA,IAAM,eAAe,CAAC,YAAiC,YAAgC;AAE5F,QAAM,sBAAsB,WAAW,MAAM,eAAa,UAAU,aAAa,KAAK;AACtF,WAAS,qBAAqB,MAAM,+BAA+B;AACnE,QAAM,mBAAmB,QAAQ,IAAI,YAAW,QAAkC,QAAQ,EAAE,OAAO,MAAM,EAAE,MAAM,CAAAC,cAAYA,cAAa,KAAK;AAC/I,WAAS,kBAAkB,MAAM,4BAA4B;AAC7D,QAAM,QAAQ,WAAW,OAAO,CAAC,KAAK,cAAc,MAAM,UAAU,OAAO,CAAC;AAG5E,QAAM,wBAAwB,KAAK,IAAI,GAAG,QACvC,OAAO,YAAU,oBAAoB,MAAM,KAAK,CAAC,YAAY,MAAM,CAAC,EACpE,IAAI,YAAW,OAA6B,MAAM,GAAG,CAAC;AACzD,QAAM,6BAA8B,KAAK,IAAI,GAAG,QAC7C,OAAO,YAAU,wBAAwB,MAAM,KAAK,CAAC,YAAY,MAAM,CAAC,EACxE,IAAI,YA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AAS,KAAK,IAAI,GAAG,SAAS,SAAS,SAAS,MAAM;AAC5D,UAAMC,YAAW;AACjB,UAAM,WAAW,CAAC,MAAMC,gBAAe,SAAS,QAAQ,GAAG,MAAMA,gBAAe,SAAS,QAAQ,CAAC;AAClG,UAAM,QAAe;AAAA,MACnB;AAAA,MAAQ,UAAAD;AAAA,MAAU;AAAA,MAAU,QAAQ;AAAA,IACtC;AACA,WAAO,CAAC,UAAU,UAAU,KAAK;AAAA,EACnC;AAAA,EAEA,MAAgB,6BAA8D;AAC5E,UAAM,OAAOD,UAAS,KAAK,OAAO,wBAAwB,MAAM,0CAA0C;AAC1G,UAAM,MAAMA,UAAS,MAAM,KAAK,QAAQ,IAAI,GAAG,MAAM,2CAA2C,IAAI,EAAE;AACtG,WAAOA,UAASG,mBAAkB,GAAG,GAAG,MAAM,mBAAmB,IAAI,OAAO,sBAAsB;AAAA,EACpG;AAAA,EAEA,MAAgB,4BAA6D;AAC3E,UAAM,OAAOH,UAAS,KAAK,OAAO,wBAAwB,MAAM,0CAA0C;AAC1G,UAAM,MAAMA,UAAS,MAAM,KAAK,QAAQ,IAAI,GAAG,MAAM,2CAA2C,IAAI,EAAE;AACtG,WAAOA,UAASG,mBAAkB,GAAG,GAAG,MAAM,mBAAmB,IAAI,OAAO,sBAAsB;AAAA,EACpG;AACF;AAnCE,cAVW,qBAUc,iBAAgB,CAAC,+BAA+B;AACzE,cAXW,qBAWc,uBAAuD;AAXrE,sBAAN;AAAA,EADNC,iBAAgB;AAAA,GACJ;",
|
|
6
|
-
"names": ["assertEx", "exists", "isCondition", "PayloadBuilder", "currency", "PayloadBuilder", "exists", "assertEx", "isCondition", "PayloadBuilder", "currency", "isHashLeaseEstimate", "isEscrowTerms", "AbstractDiviner", "creatableModule", "PayloadBuilder", "currency", "
|
|
4
|
+
"sourcesContent": ["import type { Hash } from '@xylabs/sdk'\nimport {\n assertEx, exists, filterAs,\n} from '@xylabs/sdk'\nimport type { BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness'\nimport type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport { isHashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport type {\n Condition,\n Coupon,\n Discount,\n EscrowTerms, PaymentDiscountDivinerParams,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n asCondition,\n asCoupon, isCondition, isCoupon,\n isEscrowTerms, NO_DISCOUNT, PaymentDiscountDivinerConfigSchema,\n} from '@xyo-network/payment-payload-plugins'\nimport type {\n ArchivistInstance, DivinerInstance, DivinerModuleEventData, Payload, WithSources, XyoAddress,\n} from '@xyo-network/sdk'\nimport {\n AbstractDiviner, asArchivistInstance, asDivinerInstance, creatableModule, PayloadBuilder,\n} from '@xyo-network/sdk'\n\nimport { applyCoupons, areConditionsFulfilled } from './lib/index.ts'\n\nconst DEFAULT_BOUND_WITNESS_DIVINER_QUERY_PROPS: Readonly<BoundWitnessDivinerQueryPayload> = {\n limit: 1,\n order: 'desc',\n schema: BoundWitnessDivinerQuerySchema,\n}\n\n/**\n * Builds a lookup of both the root hash and data hash of every payload to the payload\n * @param payloads The payloads to index\n * @returns A Map of hash to payload\n */\nconst toHashLookup = async (payloads: Payload[]): Promise<Map<Hash, Payload>> => {\n const lookup = new Map<Hash, Payload>()\n for (const [payload, hash] of await PayloadBuilder.hashPairs(payloads)) {\n lookup.set(hash, payload)\n lookup.set(await PayloadBuilder.dataHash(payload), payload)\n }\n return lookup\n}\n\nexport type PaymentDiscountDivinerInputType = EscrowTerms | Coupon | HashLeaseEstimate | Payload\n\n@creatableModule()\nexport class PaymentDiscountDiviner<\n TParams extends PaymentDiscountDivinerParams = PaymentDiscountDivinerParams,\n TIn extends PaymentDiscountDivinerInputType = PaymentDiscountDivinerInputType,\n TOut extends Discount = Discount,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas = [PaymentDiscountDivinerConfigSchema]\n static override readonly defaultConfigSchema = PaymentDiscountDivinerConfigSchema\n\n protected get couponAuthorities(): XyoAddress[] {\n return [...(this.config.couponAuthorities ?? []), ...(this.params.couponAuthorities ?? [])]\n }\n\n protected async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n const $sources: Hash[] = []\n\n // Parse terms\n const terms = payloads.find(isEscrowTerms) as EscrowTerms | undefined\n if (!terms) return [{ ...NO_DISCOUNT, $sources }] as WithSources<TOut>[]\n $sources.push(await PayloadBuilder.hash(terms))\n\n // Parse appraisals\n const termsAppraisals = terms?.appraisals\n // If the escrow terms do not have appraisals, return no discount\n if (!termsAppraisals || termsAppraisals.length === 0) return [{ ...NO_DISCOUNT, $sources }] as WithSources<TOut>[]\n const hashMap = await toHashLookup(payloads)\n const appraisals = this.getEscrowAppraisals(terms, hashMap)\n // Add the appraisals that were found to the sources\n $sources.push(...termsAppraisals)\n // If not all appraisals are found, return no discount\n if (appraisals.length !== termsAppraisals.length) return [{ ...NO_DISCOUNT, $sources }] as WithSources<TOut>[]\n\n // Parse coupons\n const [coupons, conditions] = await this.getEscrowDiscounts(terms, hashMap)\n // Add the coupons that were found to the sources\n // TODO: Should we throw if not all coupons are found?\n const couponHashes = await PayloadBuilder.hashes(coupons)\n $sources.push(...couponHashes)\n\n const currentCoupons = coupons.filter(coupon => this.isCouponCurrent(coupon))\n const checkedCoupons = await Promise.all(\n currentCoupons.map(async coupon => await areConditionsFulfilled(coupon, conditions, payloads) ? coupon : undefined),\n )\n const conditionsMetCoupons = checkedCoupons.filter(exists)\n\n const validCoupons = await this.filterToSigned(conditionsMetCoupons)\n // TODO: Should we throw if not all coupons are valid?\n if (validCoupons.length === 0) return [{ ...NO_DISCOUNT, $sources }] as WithSources<TOut>[]\n\n // TODO: Call paymentSubtotalDiviner to get the subtotal to centralize the logic\n const discount = applyCoupons(appraisals, validCoupons)\n return [{ ...discount, $sources }] as WithSources<TOut>[]\n }\n\n /**\n * Filters the supplied list of coupons to only those that are signed by\n * addresses specified in the couponAuthorities\n * @param coupons The list of coupons to filter\n * @returns The filtered list of coupons that are signed by the couponAuthorities\n */\n protected async filterToSigned(coupons: Coupon[]): Promise<Coupon[]> {\n const signed: Coupon[] = []\n // Deduplicate coupons by their data hash, keyed by Hash\n const dataHashMap = new Map<Hash, Coupon>()\n for (const [coupon, hash] of await PayloadBuilder.dataHashPairs(coupons)) {\n dataHashMap.set(hash, coupon)\n }\n const boundWitnessDiviner = await this.getDiscountsBoundWitnessDiviner()\n const addresses = this.couponAuthorities\n // TODO: Keep an in memory cache of the hashes queried and their results\n // to avoid querying the same hash multiple times\n await Promise.all([...dataHashMap].map(([hash, coupon]) => {\n return Promise.all(addresses.map(async (address) => {\n const query: BoundWitnessDivinerQueryPayload = {\n ...DEFAULT_BOUND_WITNESS_DIVINER_QUERY_PROPS, addresses: [address], payload_hashes: [hash],\n }\n const result = await boundWitnessDiviner.divine([query])\n if (result.length > 0) signed.push(coupon)\n }))\n }))\n return signed\n }\n\n protected async getDiscountsArchivist(): Promise<ArchivistInstance> {\n const name = assertEx(this.config.archivist, () => 'Missing archivist in config')\n const mod = assertEx(await this.resolve(name), () => `Error resolving archivist: ${name}`)\n return assertEx(asArchivistInstance(mod), () => `Resolved module ${mod.address} not a valid Archivist`)\n }\n\n protected async getDiscountsBoundWitnessDiviner(): Promise<DivinerInstance> {\n const name = assertEx(this.config.boundWitnessDiviner, () => 'Missing boundWitnessDiviner in config')\n const mod = assertEx(await this.resolve(name), () => `Error resolving boundWitnessDiviner: ${name}`)\n return assertEx(asDivinerInstance(mod), () => `Resolved module ${mod.address} not a valid Diviner`)\n }\n\n /**\n * Finds the appraisals specified by the escrow terms from the supplied payloads\n * @param terms The escrow terms\n * @param payloads The payloads to search for the appraisals\n * @returns The appraisals found in the payloads\n */\n protected getEscrowAppraisals(terms: EscrowTerms, hashMap: Map<Hash, Payload>): HashLeaseEstimate[] {\n const hashes = terms?.appraisals ?? []\n if (hashes.length === 0) return []\n return hashes.map(hash => hashMap.get(hash)).filter(exists).filter(isHashLeaseEstimate)\n }\n\n /**\n * Finds the discounts specified by the escrow terms from the supplied payloads\n * @param terms The escrow terms\n * @param hashMap The payloads to search for the discounts\n * @returns A tuple containing all the escrow coupons and conditions referenced in those coupons\n * that were found in the either the supplied payloads or the archivist\n */\n protected async getEscrowDiscounts(terms: EscrowTerms, hashMap: Map<Hash, Payload>): Promise<[Coupon[], Condition[]]> {\n // Parse discounts\n const discountsHashes = terms.discounts ?? []\n if (discountsHashes.length === 0) return [[], []]\n\n // Use the supplied payloads to find the discounts\n const discounts: Coupon[] = discountsHashes.map(hash => hashMap.get(hash)).filter(exists).filter(isCoupon)\n const missingDiscounts = discountsHashes.filter(hash => !hashMap.has(hash))\n // If not all discounts are found\n if (missingDiscounts.length > 0) {\n // Find any remaining from discounts archivist\n const discountsArchivist = await this.getDiscountsArchivist()\n const payloads = await discountsArchivist.get(missingDiscounts)\n discounts.push(...filterAs(payloads, asCoupon))\n }\n // If not all discounts are found\n if (discounts.length !== discountsHashes.length) {\n const termsHash = await PayloadBuilder.hash(terms)\n const foundHashes = await PayloadBuilder.hashes(discounts)\n // Log individual discounts that were not found\n for (const hash of discountsHashes) {\n if (!foundHashes.includes(hash)) console.warn(`Discount ${hash} not found for terms ${termsHash}`)\n }\n }\n\n const conditionsHashes: Hash[] = discounts.flatMap(discount => discount.conditions ?? [])\n const conditions: Condition[] = conditionsHashes.map(hash => hashMap.get(hash)).filter(exists).filter(isCondition)\n const missingConditions = conditionsHashes.filter(hash => !hashMap.has(hash))\n\n // If not all conditions are found\n if (missingConditions.length > 0) {\n // Find any remaining from discounts archivist\n const discountsArchivist = await this.getDiscountsArchivist()\n const payloads = await discountsArchivist.get(missingConditions)\n conditions.push(...filterAs(payloads, asCondition))\n }\n // If not all conditions are found\n if (conditions.length !== conditionsHashes.length) {\n const termsHash = await PayloadBuilder.hash(terms)\n const foundHashes = await PayloadBuilder.hashes(conditions)\n // Log individual conditions that were not found\n for (const hash of discountsHashes) {\n if (!foundHashes.includes(hash)) console.warn(`Coupon condition ${hash} not found for terms ${termsHash}`)\n }\n }\n\n return [discounts, conditions]\n }\n\n protected isCouponCurrent(coupon: Coupon): boolean {\n const now = Date.now()\n return coupon.exp > now && coupon.nbf < now\n }\n}\n", "import { assertEx, exists } from '@xylabs/sdk'\nimport type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport type {\n AmountFields,\n Coupon, Discount, FixedAmountCoupon,\n FixedPercentageCoupon,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n DiscountSchema,\n isFixedAmountCoupon, isFixedPercentageCoupon,\n isFixedPriceCoupon,\n isStackable,\n} from '@xyo-network/payment-payload-plugins'\n\nexport const applyCoupons = (appraisals: HashLeaseEstimate[], coupons: Coupon[]): Discount => {\n // Ensure all appraisals and coupons are in USD\n const allAppraisalsAreUSD = appraisals.every(appraisal => appraisal.currency === 'USD')\n assertEx(allAppraisalsAreUSD, () => 'All appraisals must be in USD')\n const allCouponsAreUSD = coupons.map(coupon => (coupon as Partial<AmountFields>)?.currency).filter(exists).every(currency => currency === 'USD')\n assertEx(allCouponsAreUSD, () => 'All coupons must be in USD')\n const total = appraisals.reduce((acc, appraisal) => acc + appraisal.price, 0)\n\n // Calculated non-stackable discount coupons\n const singularFixedDiscount = Math.max(...coupons\n .filter(coupon => isFixedAmountCoupon(coupon) && isStackable(coupon) !== true)\n .map(coupon => (coupon as FixedAmountCoupon).amount), 0)\n const singularPercentageDiscount = (Math.max(...coupons\n .filter(coupon => isFixedPercentageCoupon(coupon) && isStackable(coupon) !== true)\n .map(coupon => (coupon as FixedPercentageCoupon).percentage), 0)) * total\n const singularFixedPriceDiscount = calculateSingularFixedPriceDiscount(total, appraisals, coupons, false)\n\n // Calculate stackable discount coupons\n // First calculate the total discount from fixed amount coupons\n const stackedFixedDiscount = coupons\n .filter(coupon => isFixedAmountCoupon(coupon) && isStackable(coupon) === true)\n .reduce((acc, coupon) => acc + (coupon as FixedAmountCoupon).amount, 0)\n // Then calculate the total discount from percentage coupons and apply\n // the percentage discount to the remaining total after fixed discounts\n const stackedPercentageDiscount = coupons\n .filter(coupon => isFixedPercentageCoupon(coupon) && isStackable(coupon) === true)\n .reduce((acc, coupon) => acc + (coupon as FixedPercentageCoupon).percentage, 0) * (total - stackedFixedDiscount)\n // Then calculate the total discount from fixed price coupons\n const stackedFixedPriceDiscount = calculateSingularFixedPriceDiscount(total, appraisals, coupons, true)\n\n // Sum all stackable discounts\n const stackedDiscount = stackedFixedDiscount + stackedPercentageDiscount + stackedFixedPriceDiscount\n\n // Find the best coupon(s) to apply\n const maxDiscount = Math.max(\n singularFixedDiscount,\n singularFixedPriceDiscount,\n singularPercentageDiscount,\n stackedDiscount,\n 0,\n )\n\n // Ensure discount is not more than the total\n const amount = Math.min(maxDiscount, total)\n\n // Return single discount payload\n return {\n amount, schema: DiscountSchema, currency: 'USD',\n }\n}\n\nconst calculateSingularFixedPriceDiscount = (total: number, appraisals: HashLeaseEstimate[], coupons: Coupon[], stackable = false): number => {\n // Find all singular fixed price discounts\n const singularFixedPriceDiscounts = coupons\n .filter(isFixedPriceCoupon)\n .filter(coupon => stackable ? isStackable(coupon) === true : isStackable(coupon) !== true)\n .map(coupon => (coupon).amount)\n // Ensure all fixed price discounts are positive\n .filter(amount => amount > 0)\n\n // If there are no singular fixed price discounts, return no discount\n if (singularFixedPriceDiscounts.length === 0) return 0\n\n // Find the maximum discount (the lowest fixed price)\n const lowestFixedPrice = Math.min(...singularFixedPriceDiscounts)\n\n // Apply the fixed price to all appraisals to get the reduced prices\n const reducedPrices = appraisals.map(appraisal =>\n // If the appraisal price is less than the fixed price\n Math.min(appraisal.price, lowestFixedPrice))\n\n // Calculate the reduced total using the reduced prices\n const reducedTotal = reducedPrices.reduce((acc, price) => acc + price, 0)\n\n // Calculate the discount\n const discount = total - reducedTotal\n\n // Return the discount or 0 if the discount would have resulted in a negative value\n return Math.max(discount, 0)\n}\n", "import type { Hash } from '@xylabs/sdk'\nimport type { Condition, Coupon } from '@xyo-network/payment-payload-plugins'\nimport { isCondition } from '@xyo-network/payment-payload-plugins'\nimport type { Payload } from '@xyo-network/sdk'\nimport { isSchemaPayload, PayloadBuilder } from '@xyo-network/sdk'\nimport type { ValidateFunction } from 'ajv'\nimport { Ajv } from 'ajv'\n\n// TODO: Use our schema cache\nconst ajv = new Ajv({ strict: false }) // Create the Ajv instance once\nconst schemaCache = new Map<Hash, ValidateFunction>() // Cache to store compiled validators\n\n/**\n * Builds a lookup of both the root hash and data hash of every payload to the payload\n * @param payloads The payloads to index\n * @returns A Map of hash to payload\n */\nconst toHashLookup = async (payloads: Payload[]): Promise<Map<string, Payload>> =>\n new Map(Object.entries(await PayloadBuilder.toAllHashMap(payloads)))\n\n/**\n * Validates the conditions of a coupon against the provided payloads\n * @param coupon The coupon to check\n * @param conditions The conditions associated with the coupon\n * @param payloads The associated payloads (containing the conditions and data to validate the conditions against)\n * @returns True if all conditions are fulfilled, false otherwise\n */\nexport const areConditionsFulfilled = async (coupon: Coupon, conditions: Condition[] = [], payloads: Payload[] = []): Promise<boolean> => {\n const unfulfilled = await findUnfulfilledConditions(coupon, conditions, payloads)\n return unfulfilled.length === 0\n}\n\n/**\n * Validates the conditions of a coupon against the provided payloads\n * @param coupon The coupon to check\n * @param conditions The conditions associated with the coupon\n * @param payloads The associated payloads (containing the conditions and data to validate the conditions against)\n * @returns The unfulfilled condition hashes\n */\nexport const findUnfulfilledConditions = async (coupon: Coupon, conditions: Condition[] = [], payloads: Payload[] = []): Promise<Hash[]> => {\n const unfulfilledConditions: Hash[] = []\n // If there are no conditions, then they are fulfilled\n if (!coupon.conditions || coupon.conditions.length === 0) return unfulfilledConditions\n // Build a map of every (root and data) hash to its payload, keyed by Hash\n const hashMap = await toHashLookup([...conditions, ...payloads])\n // Find all the conditions\n const foundConditions = coupon.conditions.map(hash => hashMap.get(hash)).filter(isCondition)\n // Not all conditions were found\n if (foundConditions.length !== coupon.conditions.length) {\n const missing = coupon.conditions.filter(hash => !hashMap.has(hash))\n unfulfilledConditions.push(...missing)\n return unfulfilledConditions\n }\n\n // Test each condition\n for (const hash of coupon.conditions) {\n let validator = schemaCache.get(hash)\n\n // Compile and cache the validator if it is not already cached\n if (!validator) {\n const payload = hashMap.get(hash)\n const definition = isSchemaPayload(payload) ? (payload).definition : undefined\n if (definition) {\n validator = ajv.compile(definition)\n schemaCache.set(hash, validator)\n } else {\n unfulfilledConditions.push(hash)\n continue\n }\n }\n if (!validator(payloads)) unfulfilledConditions.push(hash)\n }\n\n // All conditions passed\n return unfulfilledConditions\n}\n", "import type { Hash } from '@xylabs/sdk'\nimport type {\n Discount, EscrowTerms, Invoice, Payment,\n Subtotal, Total,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n isDiscount, isSubtotal, isTotal, PaymentSchema,\n} from '@xyo-network/payment-payload-plugins'\nimport type {\n DivinerInstance, Payload, WithSources,\n} from '@xyo-network/sdk'\nimport { PayloadBuilder } from '@xyo-network/sdk'\n\n/**\n * Validates the escrow terms to ensure they are valid for a purchase\n * @returns A payment if the terms are valid for a purchase, undefined otherwise\n */\nexport const getInvoiceForEscrow = async (\n terms: EscrowTerms,\n dataHashMap: Record<Hash, Payload>,\n paymentTotalDiviner: DivinerInstance,\n): Promise<Invoice | undefined> => {\n const payloads = Object.values(dataHashMap)\n const results = await paymentTotalDiviner.divine([terms, ...payloads])\n const subtotal = results.find(isSubtotal)\n const discount = results.find(isDiscount)\n const total = results.find(isTotal)\n if (!subtotal || !total) return undefined\n const { amount, currency } = total\n if (currency !== 'USD') return undefined\n const $sources = await getSources(terms, subtotal, total, discount)\n const payment: WithSources<Payment> = {\n amount, currency, schema: PaymentSchema, $sources,\n }\n return discount ? [subtotal, total, payment, discount] : [subtotal, total, payment]\n}\n\nconst getSources = async (terms: EscrowTerms, subtotal: Subtotal, total: Total, discount?: Discount): Promise<Hash[]> => {\n const sources = discount ? [terms, subtotal, total, discount] : [terms, subtotal, total]\n return await Promise.all(sources.map(p => PayloadBuilder.dataHash(p)))\n}\n", "import type { Hash } from '@xylabs/sdk'\nimport type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport { isHashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport type {\n EscrowTerms, PaymentSubtotalDivinerParams, Subtotal,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n isEscrowTerms, PaymentSubtotalDivinerConfigSchema, SubtotalSchema,\n} from '@xyo-network/payment-payload-plugins'\nimport type {\n DivinerInstance, DivinerModuleEventData, Payload, WithSources,\n} from '@xyo-network/sdk'\nimport {\n AbstractDiviner, creatableModule, PayloadBuilder,\n} from '@xyo-network/sdk'\n\nimport type { ValidEscrowTerms } from './lib/index.ts'\nimport { appraisalValidators, termsValidators } from './lib/index.ts'\n\nconst currency = 'USD'\n\n/**\n * Builds a lookup of both the root hash and data hash of every payload to the payload\n * @param payloads The payloads to index\n * @returns A Map of hash to payload\n */\nconst toHashLookup = async (payloads: Payload[]): Promise<Map<Hash, Payload>> => {\n const lookup = new Map<Hash, Payload>()\n for (const [payload, hash] of await PayloadBuilder.hashPairs(payloads)) {\n lookup.set(hash, payload)\n lookup.set(await PayloadBuilder.dataHash(payload), payload)\n }\n return lookup\n}\n\n/**\n * Escrow terms that contain all the valid fields for calculating a subtotal\n */\nexport type PaymentSubtotalDivinerInputType = EscrowTerms | HashLeaseEstimate | Payload\n\n@creatableModule()\nexport class PaymentSubtotalDiviner<\n TParams extends PaymentSubtotalDivinerParams = PaymentSubtotalDivinerParams,\n TIn extends PaymentSubtotalDivinerInputType = PaymentSubtotalDivinerInputType,\n TOut extends Subtotal = Subtotal,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas = [PaymentSubtotalDivinerConfigSchema]\n static override readonly defaultConfigSchema = PaymentSubtotalDivinerConfigSchema\n\n protected async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n // Find the escrow terms\n const terms = payloads.find(isEscrowTerms) as EscrowTerms | undefined\n if (!terms) return []\n\n // Run all terms validations\n if (termsValidators.some(validator => !validator(terms))) return []\n const validTerms = terms as ValidEscrowTerms\n\n // Retrieve all appraisals from terms\n const hashMap = await toHashLookup(payloads)\n const appraisals = validTerms.appraisals.map(appraisal => hashMap.get(appraisal)).filter(isHashLeaseEstimate)\n\n // Ensure all appraisals are present\n if (appraisals.length !== validTerms.appraisals.length) return []\n\n // Run all appraisal validations\n if (appraisalValidators.some(validator => !validator(appraisals))) return []\n const amount = calculateSubtotal(appraisals)\n const $sources = [await PayloadBuilder.dataHash(validTerms), ...validTerms.appraisals]\n return [{\n amount, currency, schema: SubtotalSchema, $sources,\n }] as WithSources<TOut>[]\n }\n}\n\n// TODO: Add support for other currencies\nconst calculateSubtotal = (appraisals: HashLeaseEstimate[]): number => {\n return appraisals.reduce((sum, appraisal) => sum + appraisal.price, 0)\n}\n", "import type { HashLeaseEstimate } from '@xyo-network/diviner-hash-lease'\nimport { isIso4217CurrencyCode } from '@xyo-network/payment-payload-plugins'\n\nimport { validateDuration } from './durationValidators.ts'\n\nconst validateAppraisalAmount = (appraisals: HashLeaseEstimate[]): boolean => {\n // Ensure all appraisals are numeric\n if (appraisals.some(appraisal => typeof appraisal.price !== 'number')) return false\n // Ensure all appraisals are positive numbers\n return (appraisals.every(appraisal => appraisal.price >= 0))\n}\n\nconst validateAppraisalCurrency = (appraisals: HashLeaseEstimate[]): boolean => {\n // Only supporting USD for now, the remaining checks are for future-proofing.\n if (appraisals.some(appraisal => appraisal.currency != 'USD')) return false\n\n // Check every object in the array to ensure they all are in a supported currency.\n return (appraisals.every(appraisal => isIso4217CurrencyCode(appraisal.currency)))\n}\n\nconst validateAppraisalConsistentCurrency = (appraisals: HashLeaseEstimate[]): boolean => {\n // Check if the array is empty or contains only one element, no need to compare.\n if (appraisals.length <= 1) return true\n\n // Get the currency of the first element to compare with others.\n const { currency } = appraisals[0]\n if (!currency) return false\n\n // Check every object in the array to ensure they all have the same currency.\n return (appraisals.every(item => item.currency === currency))\n}\n\nconst validateAppraisalWindow = (appraisals: HashLeaseEstimate[]): boolean => appraisals.every(validateDuration)\n\nexport const appraisalValidators = [\n validateAppraisalAmount,\n validateAppraisalCurrency,\n validateAppraisalConsistentCurrency,\n validateAppraisalWindow,\n]\n", "import type { DurationFields } from '@xyo-network/xns-record-payload-plugins'\n\nconst FIVE_MINUTES = 1000 * 60 * 5\n\n/**\n * Validates that the current time is within the duration window, within a configurable a buffer\n * @param value The duration value\n * @param windowMs The window in milliseconds to allow for a buffer\n * @returns True if the duration is valid, false otherwise\n */\nexport const validateDuration = (value: Partial<DurationFields>, windowMs = FIVE_MINUTES): boolean => {\n const now = Date.now()\n if (value.nbf == null || value.nbf === 0 || value.nbf > now) return false\n // If already expired (include for a 5 minute buffer to allow for a reasonable\n // minimum amount of time for the transaction to be processed)\n return !(value.exp == null || value.exp === 0 || value.exp - now < windowMs)\n}\n", "import type { Hash } from '@xylabs/sdk'\nimport type { EscrowTerms } from '@xyo-network/payment-payload-plugins'\n\nimport { validateDuration } from './durationValidators.ts'\n\nexport type ValidEscrowTerms = Required<EscrowTerms>\n\nconst validateTermsAppraisals = (terms: EscrowTerms): terms is Required<EscrowTerms & { appraisals: Hash[] }> => {\n if (!terms.appraisals) return false\n return terms.appraisals.length > 0\n}\nconst validateTermsWindow = (terms: EscrowTerms): boolean => validateDuration(terms)\n\nexport const termsValidators = [\n validateTermsAppraisals,\n validateTermsWindow,\n]\n", "import type { Hash } from '@xylabs/sdk'\nimport { assertEx } from '@xylabs/sdk'\nimport type {\n Discount, PaymentTotalDivinerParams, Subtotal, Total,\n} from '@xyo-network/payment-payload-plugins'\nimport {\n isDiscount,\n isSubtotal,\n PaymentTotalDivinerConfigSchema, TotalSchema,\n} from '@xyo-network/payment-payload-plugins'\nimport type {\n DivinerInstance, DivinerModuleEventData, WithSources,\n} from '@xyo-network/sdk'\nimport {\n AbstractDiviner, asDivinerInstance, creatableModule, PayloadBuilder,\n} from '@xyo-network/sdk'\n\nimport type { PaymentDiscountDiviner, PaymentDiscountDivinerInputType } from '../Discount/index.ts'\nimport type { PaymentSubtotalDiviner, PaymentSubtotalDivinerInputType } from '../Subtotal/index.ts'\n\ntype InputType = PaymentDiscountDivinerInputType | PaymentSubtotalDivinerInputType\ntype OutputType = Subtotal | Discount | Total\n\n@creatableModule()\nexport class PaymentTotalDiviner<\n TParams extends PaymentTotalDivinerParams = PaymentTotalDivinerParams,\n TIn extends InputType = InputType,\n TOut extends OutputType = OutputType,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas = [PaymentTotalDivinerConfigSchema]\n static override readonly defaultConfigSchema: PaymentTotalDivinerConfigSchema = PaymentTotalDivinerConfigSchema\n\n protected async divineHandler(payloads: TIn[] = []): Promise<TOut[]> {\n const subtotalDiviner = await this.getPaymentSubtotalDiviner()\n const subtotalResult = await subtotalDiviner.divine(payloads)\n const subtotal = subtotalResult.find(isSubtotal)\n if (!subtotal) return []\n const discountDiviner = await this.getPaymentDiscountsDiviner()\n const discountResult = await discountDiviner.divine(payloads)\n const discount = discountResult.find(isDiscount)\n if (!discount) return []\n const { currency: subtotalCurrency } = subtotal\n const { currency: discountCurrency } = discount\n assertEx(subtotalCurrency === discountCurrency, () => `Subtotal currency ${subtotalCurrency} does not match discount currency ${discountCurrency}`)\n const amount = Math.max(0, subtotal.amount - discount.amount)\n const currency = subtotalCurrency\n const $sources = [await PayloadBuilder.dataHash(subtotal), await PayloadBuilder.dataHash(discount)] as Hash[]\n const total: WithSources<Total> = {\n amount, currency, $sources, schema: TotalSchema,\n }\n return [subtotal, discount, total] as TOut[]\n }\n\n protected async getPaymentDiscountsDiviner(): Promise<PaymentDiscountDiviner> {\n const name = assertEx(this.config.paymentDiscountDiviner, () => 'Missing paymentDiscountDiviner in config')\n const mod = assertEx(await this.resolve(name), () => `Error resolving paymentDiscountDiviner: ${name}`)\n return assertEx(asDivinerInstance(mod), () => `Resolved module ${mod.address} not a valid Diviner`)\n }\n\n protected async getPaymentSubtotalDiviner(): Promise<PaymentSubtotalDiviner> {\n const name = assertEx(this.config.paymentSubtotalDiviner, () => 'Missing paymentSubtotalDiviner in config')\n const mod = assertEx(await this.resolve(name), () => `Error resolving paymentSubtotalDiviner: ${name}`)\n return assertEx(asDivinerInstance(mod), () => `Resolved module ${mod.address} not a valid Diviner`)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AACA;AAAA,EACE,YAAAA;AAAA,EAAU,UAAAC;AAAA,EAAQ;AAAA,OACb;AAEP,SAAS,sCAAsC;AAE/C,SAAS,2BAA2B;AAOpC;AAAA,EACE;AAAA,EACA;AAAA,EAAU,eAAAC;AAAA,EAAa;AAAA,EACvB;AAAA,EAAe;AAAA,EAAa;AAAA,OACvB;AAIP;AAAA,EACE;AAAA,EAAiB;AAAA,EAAqB;AAAA,EAAmB;AAAA,EAAiB,kBAAAC;AAAA,OACrE;;;ACxBP,SAAS,UAAU,cAAc;AAOjC;AAAA,EACE;AAAA,EACA;AAAA,EAAqB;AAAA,EACrB;AAAA,EACA;AAAA,OACK;AAEA,IAAM,eAAe,CAAC,YAAiC,YAAgC;AAE5F,QAAM,sBAAsB,WAAW,MAAM,eAAa,UAAU,aAAa,KAAK;AACtF,WAAS,qBAAqB,MAAM,+BAA+B;AACnE,QAAM,mBAAmB,QAAQ,IAAI,YAAW,QAAkC,QAAQ,EAAE,OAAO,MAAM,EAAE,MAAM,CAAAC,cAA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C,YAAW;AACjB,UAAM,WAAW,CAAC,MAAMC,gBAAe,SAAS,QAAQ,GAAG,MAAMA,gBAAe,SAAS,QAAQ,CAAC;AAClG,UAAM,QAA4B;AAAA,MAChC;AAAA,MAAQ,UAAAD;AAAA,MAAU;AAAA,MAAU,QAAQ;AAAA,IACtC;AACA,WAAO,CAAC,UAAU,UAAU,KAAK;AAAA,EACnC;AAAA,EAEA,MAAgB,6BAA8D;AAC5E,UAAM,OAAOD,UAAS,KAAK,OAAO,wBAAwB,MAAM,0CAA0C;AAC1G,UAAM,MAAMA,UAAS,MAAM,KAAK,QAAQ,IAAI,GAAG,MAAM,2CAA2C,IAAI,EAAE;AACtG,WAAOA,UAASG,mBAAkB,GAAG,GAAG,MAAM,mBAAmB,IAAI,OAAO,sBAAsB;AAAA,EACpG;AAAA,EAEA,MAAgB,4BAA6D;AAC3E,UAAM,OAAOH,UAAS,KAAK,OAAO,wBAAwB,MAAM,0CAA0C;AAC1G,UAAM,MAAMA,UAAS,MAAM,KAAK,QAAQ,IAAI,GAAG,MAAM,2CAA2C,IAAI,EAAE;AACtG,WAAOA,UAASG,mBAAkB,GAAG,GAAG,MAAM,mBAAmB,IAAI,OAAO,sBAAsB;AAAA,EACpG;AACF;AAnCE,cAVW,qBAUc,iBAAgB,CAAC,+BAA+B;AACzE,cAXW,qBAWc,uBAAuD;AAXrE,sBAAN;AAAA,EADNC,iBAAgB;AAAA,GACJ;",
|
|
6
|
+
"names": ["assertEx", "exists", "isCondition", "PayloadBuilder", "currency", "toHashLookup", "PayloadBuilder", "exists", "assertEx", "isCondition", "PayloadBuilder", "currency", "isHashLeaseEstimate", "isEscrowTerms", "AbstractDiviner", "creatableModule", "PayloadBuilder", "currency", "toHashLookup", "PayloadBuilder", "AbstractDiviner", "isEscrowTerms", "isHashLeaseEstimate", "creatableModule", "assertEx", "isDiscount", "isSubtotal", "AbstractDiviner", "asDivinerInstance", "creatableModule", "PayloadBuilder", "AbstractDiviner", "isSubtotal", "isDiscount", "assertEx", "currency", "PayloadBuilder", "asDivinerInstance", "creatableModule"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/payment-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -31,66 +31,61 @@
|
|
|
31
31
|
"README.md"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@xyo-network/payment-payload-plugins": "~
|
|
34
|
+
"@xyo-network/payment-payload-plugins": "~7.0.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@bitauth/libauth": "~3.0.0",
|
|
38
|
-
"@metamask/providers": "^22.1.1",
|
|
39
38
|
"@noble/post-quantum": "~0.6.1",
|
|
40
39
|
"@opentelemetry/api": "^1.9.1",
|
|
41
|
-
"@opentelemetry/sdk-trace-base": "^2.
|
|
40
|
+
"@opentelemetry/sdk-trace-base": "^2.8.0",
|
|
42
41
|
"@scure/base": "^2.2.0",
|
|
43
42
|
"@scure/bip39": "~2.2.0",
|
|
44
|
-
"@xylabs/crypto": "
|
|
45
|
-
"@xylabs/geo": "^
|
|
46
|
-
"@xylabs/sdk
|
|
47
|
-
"@xylabs/threads": "^
|
|
48
|
-
"@xylabs/toolchain": "~8.
|
|
49
|
-
"@xylabs/tsconfig": "~8.
|
|
50
|
-
"@xylabs/vitest-extended": "
|
|
51
|
-
"@xyo-network/boundwitness
|
|
52
|
-
"@xyo-network/
|
|
53
|
-
"@xyo-network/
|
|
54
|
-
"@xyo-network/
|
|
55
|
-
"@xyo-network/node-memory": "~6.1.0",
|
|
56
|
-
"@xyo-network/sdk-js": "^6.1.0",
|
|
57
|
-
"@xyo-network/sdk-protocol-js": "~6.1",
|
|
58
|
-
"@xyo-network/wallet-model": "~6.1.0",
|
|
43
|
+
"@xylabs/crypto": "~7.0.1",
|
|
44
|
+
"@xylabs/geo": "^7.0.1",
|
|
45
|
+
"@xylabs/sdk": "^7.0.1",
|
|
46
|
+
"@xylabs/threads": "^7.0.1",
|
|
47
|
+
"@xylabs/toolchain": "~8.5.3",
|
|
48
|
+
"@xylabs/tsconfig": "~8.5.3",
|
|
49
|
+
"@xylabs/vitest-extended": "^7.0.1",
|
|
50
|
+
"@xyo-network/diviner-boundwitness": "^7.0.3",
|
|
51
|
+
"@xyo-network/diviner-hash-lease": "^7.0.3",
|
|
52
|
+
"@xyo-network/sdk": "~7.0.3",
|
|
53
|
+
"@xyo-network/sdk-protocol": "^7.0.4",
|
|
59
54
|
"ajv": "^8.20.0",
|
|
60
55
|
"async-mutex": "^0.5.0",
|
|
56
|
+
"browserslist": "4.28.4",
|
|
61
57
|
"crypto-js": "~4.2.0",
|
|
62
58
|
"debug": "~4.4.3",
|
|
63
|
-
"eslint": "^10.
|
|
64
|
-
"
|
|
59
|
+
"eslint": "^10.6.0",
|
|
60
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
61
|
+
"ethers": "^6.17.0",
|
|
65
62
|
"hash-wasm": "^4.12.0",
|
|
66
63
|
"idb": "^8.0.3",
|
|
67
64
|
"lru-cache": "^11.5.1",
|
|
68
65
|
"observable-fns": "~0.6.1",
|
|
69
66
|
"tslib": "^2.8.1",
|
|
70
67
|
"typescript": "~6.0.3",
|
|
71
|
-
"vite": "^8.0
|
|
72
|
-
"vitest": "
|
|
73
|
-
"webextension-polyfill": "^0.12.0",
|
|
68
|
+
"vite": "^8.1.0",
|
|
69
|
+
"vitest": "^4.1.9",
|
|
74
70
|
"zod": "^4.4.3",
|
|
75
|
-
"@xyo-network/rebilly-payment-payload-plugin": "~
|
|
76
|
-
"@xyo-network/xns-record-payload-plugins": "~
|
|
71
|
+
"@xyo-network/rebilly-payment-payload-plugin": "~7.0.1",
|
|
72
|
+
"@xyo-network/xns-record-payload-plugins": "~7.0.1"
|
|
77
73
|
},
|
|
78
74
|
"peerDependencies": {
|
|
79
75
|
"@bitauth/libauth": "~3.0",
|
|
80
|
-
"@metamask/providers": "^22.1",
|
|
81
76
|
"@noble/post-quantum": "~0.6.1",
|
|
82
77
|
"@opentelemetry/api": "^1.9",
|
|
83
78
|
"@opentelemetry/sdk-trace-base": "^2.7",
|
|
84
79
|
"@scure/base": "^2.2",
|
|
85
80
|
"@scure/bip39": "~2.2",
|
|
86
|
-
"@xylabs/crypto": "^
|
|
87
|
-
"@xylabs/geo": "^
|
|
88
|
-
"@xylabs/sdk
|
|
89
|
-
"@xylabs/threads": "^
|
|
90
|
-
"@xyo-network/diviner-boundwitness": "^
|
|
91
|
-
"@xyo-network/diviner-hash-lease": "^
|
|
92
|
-
"@xyo-network/sdk
|
|
93
|
-
"@xyo-network/sdk-protocol
|
|
81
|
+
"@xylabs/crypto": "^7.0",
|
|
82
|
+
"@xylabs/geo": "^7.0",
|
|
83
|
+
"@xylabs/sdk": "^7.0",
|
|
84
|
+
"@xylabs/threads": "^7.0",
|
|
85
|
+
"@xyo-network/diviner-boundwitness": "^7.0",
|
|
86
|
+
"@xyo-network/diviner-hash-lease": "^7.0",
|
|
87
|
+
"@xyo-network/sdk": "^7.0",
|
|
88
|
+
"@xyo-network/sdk-protocol": "^7.0",
|
|
94
89
|
"ajv": "^8.20",
|
|
95
90
|
"async-mutex": "^0.5",
|
|
96
91
|
"crypto-js": "~4.2",
|
|
@@ -100,7 +95,6 @@
|
|
|
100
95
|
"idb": "^8.0",
|
|
101
96
|
"lru-cache": "^11.3",
|
|
102
97
|
"observable-fns": "~0.6",
|
|
103
|
-
"webextension-polyfill": "^0.12",
|
|
104
98
|
"zod": "^4.4"
|
|
105
99
|
},
|
|
106
100
|
"engines": {
|