@classytic/revenue 0.0.24 → 0.1.0
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/README.md +131 -19
- package/core/builder.js +39 -0
- package/dist/types/core/builder.d.ts +87 -0
- package/dist/types/core/container.d.ts +57 -0
- package/dist/types/core/errors.d.ts +122 -0
- package/dist/types/enums/escrow.enums.d.ts +24 -0
- package/dist/types/enums/index.d.ts +69 -0
- package/dist/types/enums/monetization.enums.d.ts +6 -0
- package/dist/types/enums/payment.enums.d.ts +16 -0
- package/dist/types/enums/split.enums.d.ts +25 -0
- package/dist/types/enums/subscription.enums.d.ts +15 -0
- package/dist/types/enums/transaction.enums.d.ts +24 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/providers/base.d.ts +126 -0
- package/dist/types/schemas/escrow/hold.schema.d.ts +54 -0
- package/dist/types/schemas/escrow/index.d.ts +6 -0
- package/dist/types/schemas/index.d.ts +506 -0
- package/dist/types/schemas/split/index.d.ts +8 -0
- package/dist/types/schemas/split/split.schema.d.ts +142 -0
- package/dist/types/schemas/subscription/index.d.ts +152 -0
- package/dist/types/schemas/subscription/info.schema.d.ts +128 -0
- package/dist/types/schemas/subscription/plan.schema.d.ts +39 -0
- package/dist/types/schemas/transaction/common.schema.d.ts +12 -0
- package/dist/types/schemas/transaction/gateway.schema.d.ts +86 -0
- package/dist/types/schemas/transaction/index.d.ts +202 -0
- package/dist/types/schemas/transaction/payment.schema.d.ts +145 -0
- package/dist/types/services/escrow.service.d.ts +51 -0
- package/dist/types/services/payment.service.d.ts +80 -0
- package/dist/types/services/subscription.service.d.ts +138 -0
- package/dist/types/services/transaction.service.d.ts +40 -0
- package/dist/types/utils/category-resolver.d.ts +46 -0
- package/dist/types/utils/commission-split.d.ts +56 -0
- package/dist/types/utils/commission.d.ts +29 -0
- package/dist/types/utils/hooks.d.ts +17 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/logger.d.ts +12 -0
- package/dist/types/utils/subscription/actions.d.ts +28 -0
- package/dist/types/utils/subscription/index.d.ts +2 -0
- package/dist/types/utils/subscription/period.d.ts +47 -0
- package/dist/types/utils/transaction-type.d.ts +102 -0
- package/enums/escrow.enums.js +36 -0
- package/enums/index.js +36 -0
- package/enums/split.enums.js +37 -0
- package/index.js +6 -0
- package/package.json +91 -74
- package/schemas/escrow/hold.schema.js +62 -0
- package/schemas/escrow/index.js +15 -0
- package/schemas/index.js +6 -0
- package/schemas/split/index.js +16 -0
- package/schemas/split/split.schema.js +86 -0
- package/services/escrow.service.js +353 -0
- package/services/payment.service.js +54 -3
- package/services/subscription.service.js +15 -9
- package/utils/commission-split.js +180 -0
- package/utils/index.js +6 -0
- package/revenue.d.ts +0 -350
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription Period Utilities
|
|
3
|
+
* @classytic/revenue/utils/subscription
|
|
4
|
+
*
|
|
5
|
+
* Universal period calculation, proration, and date utilities
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Add duration to date
|
|
9
|
+
*/
|
|
10
|
+
export function addDuration(startDate: any, duration: any, unit?: string): Date;
|
|
11
|
+
/**
|
|
12
|
+
* Calculate subscription period start/end dates
|
|
13
|
+
*/
|
|
14
|
+
export function calculatePeriodRange({ currentEndDate, startDate, duration, unit, now, }: {
|
|
15
|
+
currentEndDate?: any;
|
|
16
|
+
startDate?: any;
|
|
17
|
+
duration: any;
|
|
18
|
+
unit?: string;
|
|
19
|
+
now?: Date;
|
|
20
|
+
}): {
|
|
21
|
+
startDate: Date;
|
|
22
|
+
endDate: Date;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Calculate prorated refund amount for unused period
|
|
26
|
+
*/
|
|
27
|
+
export function calculateProratedAmount({ amountPaid, startDate, endDate, asOfDate, precision, }: {
|
|
28
|
+
amountPaid: any;
|
|
29
|
+
startDate: any;
|
|
30
|
+
endDate: any;
|
|
31
|
+
asOfDate?: Date;
|
|
32
|
+
precision?: number;
|
|
33
|
+
}): number;
|
|
34
|
+
/**
|
|
35
|
+
* Convert interval + count to duration/unit
|
|
36
|
+
*/
|
|
37
|
+
export function resolveIntervalToDuration(interval?: string, intervalCount?: number): {
|
|
38
|
+
duration: number;
|
|
39
|
+
unit: string;
|
|
40
|
+
};
|
|
41
|
+
declare namespace _default {
|
|
42
|
+
export { addDuration };
|
|
43
|
+
export { calculatePeriodRange };
|
|
44
|
+
export { calculateProratedAmount };
|
|
45
|
+
export { resolveIntervalToDuration };
|
|
46
|
+
}
|
|
47
|
+
export default _default;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if transaction is monetization-managed
|
|
3
|
+
*
|
|
4
|
+
* Monetization-managed means:
|
|
5
|
+
* - Created through subscription/purchase flows via the library
|
|
6
|
+
* - Status controlled by payment webhooks/verification
|
|
7
|
+
* - Amount/commission calculated by library
|
|
8
|
+
* - Protected fields: status, amount, commission, gateway, verifiedAt, verifiedBy
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} transaction - Transaction document or data
|
|
11
|
+
* @param {Object} options - Options
|
|
12
|
+
* @param {Array<string>} options.targetModels - Target models from config (default: ['Subscription', 'Membership'])
|
|
13
|
+
* @param {Array<string>} options.additionalCategories - Additional categories from user config
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
export function isMonetizationTransaction(transaction: any, options?: {
|
|
17
|
+
targetModels: Array<string>;
|
|
18
|
+
additionalCategories: Array<string>;
|
|
19
|
+
}): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if transaction is manual admin transaction
|
|
22
|
+
*
|
|
23
|
+
* Manual transactions:
|
|
24
|
+
* - Created directly by admins for operational expenses/income
|
|
25
|
+
* - Can be self-verified by admins
|
|
26
|
+
* - More flexible updates allowed
|
|
27
|
+
* - No commission/gateway complexity
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} transaction - Transaction document or data
|
|
30
|
+
* @param {Object} options - Options (same as isMonetizationTransaction)
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
export function isManualTransaction(transaction: any, options?: any): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get transaction type
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} transaction - Transaction document or data
|
|
38
|
+
* @param {Object} options - Options (same as isMonetizationTransaction)
|
|
39
|
+
* @returns {string} TRANSACTION_TYPE.MONETIZATION or TRANSACTION_TYPE.MANUAL
|
|
40
|
+
*/
|
|
41
|
+
export function getTransactionType(transaction: any, options?: any): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get allowed update fields based on transaction type and status
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} transaction - Transaction document
|
|
46
|
+
* @param {Object} options - Options for transaction type detection
|
|
47
|
+
* @returns {Array<string>} Allowed field names
|
|
48
|
+
*/
|
|
49
|
+
export function getAllowedUpdateFields(transaction: any, options?: any): Array<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Validate if field update is allowed
|
|
52
|
+
*
|
|
53
|
+
* @param {Object} transaction - Transaction document
|
|
54
|
+
* @param {string} fieldName - Field being updated
|
|
55
|
+
* @param {Object} options - Options for transaction type detection
|
|
56
|
+
* @returns {Object} { allowed: boolean, reason?: string }
|
|
57
|
+
*/
|
|
58
|
+
export function validateFieldUpdate(transaction: any, fieldName: string, options?: any): any;
|
|
59
|
+
/**
|
|
60
|
+
* Check if transaction can be self-verified by admin
|
|
61
|
+
*
|
|
62
|
+
* @param {Object} transaction - Transaction document
|
|
63
|
+
* @param {Object} options - Options for transaction type detection
|
|
64
|
+
* @returns {boolean}
|
|
65
|
+
*/
|
|
66
|
+
export function canSelfVerify(transaction: any, options?: any): boolean;
|
|
67
|
+
export namespace TRANSACTION_TYPE {
|
|
68
|
+
let MONETIZATION: string;
|
|
69
|
+
let MANUAL: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Protected fields for monetization transactions
|
|
73
|
+
* These fields cannot be updated directly by admins
|
|
74
|
+
*/
|
|
75
|
+
export const PROTECTED_MONETIZATION_FIELDS: string[];
|
|
76
|
+
/**
|
|
77
|
+
* Editable fields for monetization transactions (before verification)
|
|
78
|
+
* These fields can be updated by frontend/customer before payment is verified
|
|
79
|
+
*/
|
|
80
|
+
export const EDITABLE_MONETIZATION_FIELDS_PRE_VERIFICATION: string[];
|
|
81
|
+
/**
|
|
82
|
+
* Allowed fields for manual transaction creation
|
|
83
|
+
*/
|
|
84
|
+
export const MANUAL_TRANSACTION_CREATE_FIELDS: string[];
|
|
85
|
+
/**
|
|
86
|
+
* Allowed fields for manual transaction updates
|
|
87
|
+
*/
|
|
88
|
+
export const MANUAL_TRANSACTION_UPDATE_FIELDS: string[];
|
|
89
|
+
declare namespace _default {
|
|
90
|
+
export { TRANSACTION_TYPE };
|
|
91
|
+
export { isMonetizationTransaction };
|
|
92
|
+
export { isManualTransaction };
|
|
93
|
+
export { getTransactionType };
|
|
94
|
+
export { PROTECTED_MONETIZATION_FIELDS };
|
|
95
|
+
export { EDITABLE_MONETIZATION_FIELDS_PRE_VERIFICATION };
|
|
96
|
+
export { MANUAL_TRANSACTION_CREATE_FIELDS };
|
|
97
|
+
export { MANUAL_TRANSACTION_UPDATE_FIELDS };
|
|
98
|
+
export { getAllowedUpdateFields };
|
|
99
|
+
export { validateFieldUpdate };
|
|
100
|
+
export { canSelfVerify };
|
|
101
|
+
}
|
|
102
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escrow/Hold Enums
|
|
3
|
+
* @classytic/revenue
|
|
4
|
+
*
|
|
5
|
+
* Enums for platform-as-intermediary payment flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const HOLD_STATUS = {
|
|
9
|
+
PENDING: 'pending',
|
|
10
|
+
HELD: 'held',
|
|
11
|
+
RELEASED: 'released',
|
|
12
|
+
CANCELLED: 'cancelled',
|
|
13
|
+
EXPIRED: 'expired',
|
|
14
|
+
PARTIALLY_RELEASED: 'partially_released',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const HOLD_STATUS_VALUES = Object.values(HOLD_STATUS);
|
|
18
|
+
|
|
19
|
+
export const RELEASE_REASON = {
|
|
20
|
+
PAYMENT_VERIFIED: 'payment_verified',
|
|
21
|
+
MANUAL_RELEASE: 'manual_release',
|
|
22
|
+
AUTO_RELEASE: 'auto_release',
|
|
23
|
+
DISPUTE_RESOLVED: 'dispute_resolved',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const RELEASE_REASON_VALUES = Object.values(RELEASE_REASON);
|
|
27
|
+
|
|
28
|
+
export const HOLD_REASON = {
|
|
29
|
+
PAYMENT_VERIFICATION: 'payment_verification',
|
|
30
|
+
FRAUD_CHECK: 'fraud_check',
|
|
31
|
+
MANUAL_REVIEW: 'manual_review',
|
|
32
|
+
DISPUTE: 'dispute',
|
|
33
|
+
COMPLIANCE: 'compliance',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const HOLD_REASON_VALUES = Object.values(HOLD_REASON);
|
package/enums/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export * from './transaction.enums.js';
|
|
|
13
13
|
export * from './payment.enums.js';
|
|
14
14
|
export * from './subscription.enums.js';
|
|
15
15
|
export * from './monetization.enums.js';
|
|
16
|
+
export * from './escrow.enums.js';
|
|
17
|
+
export * from './split.enums.js';
|
|
16
18
|
|
|
17
19
|
// Default export for convenience
|
|
18
20
|
import {
|
|
@@ -45,6 +47,24 @@ import {
|
|
|
45
47
|
MONETIZATION_TYPE_VALUES,
|
|
46
48
|
} from './monetization.enums.js';
|
|
47
49
|
|
|
50
|
+
import {
|
|
51
|
+
HOLD_STATUS,
|
|
52
|
+
HOLD_STATUS_VALUES,
|
|
53
|
+
RELEASE_REASON,
|
|
54
|
+
RELEASE_REASON_VALUES,
|
|
55
|
+
HOLD_REASON,
|
|
56
|
+
HOLD_REASON_VALUES,
|
|
57
|
+
} from './escrow.enums.js';
|
|
58
|
+
|
|
59
|
+
import {
|
|
60
|
+
SPLIT_TYPE,
|
|
61
|
+
SPLIT_TYPE_VALUES,
|
|
62
|
+
SPLIT_STATUS,
|
|
63
|
+
SPLIT_STATUS_VALUES,
|
|
64
|
+
PAYOUT_METHOD,
|
|
65
|
+
PAYOUT_METHOD_VALUES,
|
|
66
|
+
} from './split.enums.js';
|
|
67
|
+
|
|
48
68
|
export default {
|
|
49
69
|
// Transaction enums
|
|
50
70
|
TRANSACTION_TYPE,
|
|
@@ -71,4 +91,20 @@ export default {
|
|
|
71
91
|
// Monetization enums
|
|
72
92
|
MONETIZATION_TYPES,
|
|
73
93
|
MONETIZATION_TYPE_VALUES,
|
|
94
|
+
|
|
95
|
+
// Escrow enums
|
|
96
|
+
HOLD_STATUS,
|
|
97
|
+
HOLD_STATUS_VALUES,
|
|
98
|
+
RELEASE_REASON,
|
|
99
|
+
RELEASE_REASON_VALUES,
|
|
100
|
+
HOLD_REASON,
|
|
101
|
+
HOLD_REASON_VALUES,
|
|
102
|
+
|
|
103
|
+
// Split enums
|
|
104
|
+
SPLIT_TYPE,
|
|
105
|
+
SPLIT_TYPE_VALUES,
|
|
106
|
+
SPLIT_STATUS,
|
|
107
|
+
SPLIT_STATUS_VALUES,
|
|
108
|
+
PAYOUT_METHOD,
|
|
109
|
+
PAYOUT_METHOD_VALUES,
|
|
74
110
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split Payment Enums
|
|
3
|
+
* @classytic/revenue
|
|
4
|
+
*
|
|
5
|
+
* Enums for multi-party commission splits
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const SPLIT_TYPE = {
|
|
9
|
+
PLATFORM_COMMISSION: 'platform_commission',
|
|
10
|
+
AFFILIATE_COMMISSION: 'affiliate_commission',
|
|
11
|
+
REFERRAL_COMMISSION: 'referral_commission',
|
|
12
|
+
PARTNER_COMMISSION: 'partner_commission',
|
|
13
|
+
CUSTOM: 'custom',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const SPLIT_TYPE_VALUES = Object.values(SPLIT_TYPE);
|
|
17
|
+
|
|
18
|
+
export const SPLIT_STATUS = {
|
|
19
|
+
PENDING: 'pending',
|
|
20
|
+
DUE: 'due',
|
|
21
|
+
PAID: 'paid',
|
|
22
|
+
WAIVED: 'waived',
|
|
23
|
+
CANCELLED: 'cancelled',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const SPLIT_STATUS_VALUES = Object.values(SPLIT_STATUS);
|
|
27
|
+
|
|
28
|
+
export const PAYOUT_METHOD = {
|
|
29
|
+
BANK_TRANSFER: 'bank_transfer',
|
|
30
|
+
MOBILE_WALLET: 'mobile_wallet',
|
|
31
|
+
PLATFORM_BALANCE: 'platform_balance',
|
|
32
|
+
CRYPTO: 'crypto',
|
|
33
|
+
CHECK: 'check',
|
|
34
|
+
MANUAL: 'manual',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const PAYOUT_METHOD_VALUES = Object.values(PAYOUT_METHOD);
|
package/index.js
CHANGED
|
@@ -38,6 +38,7 @@ import { PaymentProvider as _PaymentProvider } from './providers/base.js';
|
|
|
38
38
|
export { SubscriptionService } from './services/subscription.service.js';
|
|
39
39
|
export { PaymentService } from './services/payment.service.js';
|
|
40
40
|
export { TransactionService } from './services/transaction.service.js';
|
|
41
|
+
export { EscrowService } from './services/escrow.service.js';
|
|
41
42
|
|
|
42
43
|
// ============ ENUMS & SCHEMAS (FOR INJECTION) ============
|
|
43
44
|
export * from './enums/index.js';
|
|
@@ -49,6 +50,11 @@ export {
|
|
|
49
50
|
setLogger,
|
|
50
51
|
calculateCommission,
|
|
51
52
|
reverseCommission,
|
|
53
|
+
// Split/Escrow utilities
|
|
54
|
+
calculateSplits,
|
|
55
|
+
calculateOrganizationPayout,
|
|
56
|
+
reverseSplits,
|
|
57
|
+
calculateCommissionWithSplits,
|
|
52
58
|
// Subscription utilities
|
|
53
59
|
addDuration,
|
|
54
60
|
calculatePeriodRange,
|
package/package.json
CHANGED
|
@@ -1,74 +1,91 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@classytic/revenue",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Enterprise revenue management system with subscriptions, purchases, proration, and
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"types": "./
|
|
56
|
-
"default": "./
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@classytic/revenue",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Enterprise revenue management system with subscriptions, purchases, proration, payment processing, escrow, and multi-party splits",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"revenue",
|
|
9
|
+
"monetization",
|
|
10
|
+
"subscription",
|
|
11
|
+
"payment",
|
|
12
|
+
"saas",
|
|
13
|
+
"billing",
|
|
14
|
+
"proration",
|
|
15
|
+
"recurring",
|
|
16
|
+
"gateway",
|
|
17
|
+
"webhook",
|
|
18
|
+
"stripe",
|
|
19
|
+
"sslcommerz",
|
|
20
|
+
"bkash",
|
|
21
|
+
"transaction",
|
|
22
|
+
"invoice",
|
|
23
|
+
"escrow",
|
|
24
|
+
"hold",
|
|
25
|
+
"release",
|
|
26
|
+
"split",
|
|
27
|
+
"affiliate",
|
|
28
|
+
"commission",
|
|
29
|
+
"marketplace"
|
|
30
|
+
],
|
|
31
|
+
"author": "Sadman Chowdhury",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/classytic/revenue.git"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/classytic/revenue/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/classytic/revenue#readme",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"types": "tsc -p tsconfig.types.json",
|
|
43
|
+
"build": "npm run types",
|
|
44
|
+
"prepublishOnly": "npm run build",
|
|
45
|
+
"test": "node ../tests/run-all.js"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"mongoose": "^8.0.0"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"exports": {
|
|
54
|
+
".": {
|
|
55
|
+
"types": "./dist/types/index.d.ts",
|
|
56
|
+
"default": "./index.js"
|
|
57
|
+
},
|
|
58
|
+
"./enums": {
|
|
59
|
+
"types": "./dist/types/enums/index.d.ts",
|
|
60
|
+
"default": "./enums/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./schemas": {
|
|
63
|
+
"types": "./dist/types/schemas/index.d.ts",
|
|
64
|
+
"default": "./schemas/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./utils": {
|
|
67
|
+
"types": "./dist/types/utils/index.d.ts",
|
|
68
|
+
"default": "./utils/index.js"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"types": "./dist/types/index.d.ts",
|
|
72
|
+
"files": [
|
|
73
|
+
"index.js",
|
|
74
|
+
"LICENSE",
|
|
75
|
+
"README.md",
|
|
76
|
+
"core/",
|
|
77
|
+
"providers/",
|
|
78
|
+
"services/",
|
|
79
|
+
"enums/",
|
|
80
|
+
"schemas/",
|
|
81
|
+
"utils/",
|
|
82
|
+
"dist/types/"
|
|
83
|
+
],
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@types/node": "^22.8.7",
|
|
86
|
+
"typescript": "^5.6.3"
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"nanoid": "^5.1.6"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hold/Escrow Schema
|
|
3
|
+
* @classytic/revenue
|
|
4
|
+
*
|
|
5
|
+
* Schema for platform-as-intermediary escrow flow
|
|
6
|
+
* Spread into transaction schema when needed
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { HOLD_STATUS, HOLD_STATUS_VALUES, HOLD_REASON, HOLD_REASON_VALUES } from '../../enums/escrow.enums.js';
|
|
10
|
+
|
|
11
|
+
export const holdSchema = {
|
|
12
|
+
status: {
|
|
13
|
+
type: String,
|
|
14
|
+
enum: HOLD_STATUS_VALUES,
|
|
15
|
+
default: HOLD_STATUS.PENDING,
|
|
16
|
+
index: true,
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
heldAmount: {
|
|
20
|
+
type: Number,
|
|
21
|
+
required: false,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
releasedAmount: {
|
|
25
|
+
type: Number,
|
|
26
|
+
default: 0,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
reason: {
|
|
30
|
+
type: String,
|
|
31
|
+
enum: HOLD_REASON_VALUES,
|
|
32
|
+
required: false,
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
holdUntil: {
|
|
36
|
+
type: Date,
|
|
37
|
+
required: false,
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
heldAt: Date,
|
|
41
|
+
releasedAt: Date,
|
|
42
|
+
cancelledAt: Date,
|
|
43
|
+
|
|
44
|
+
releases: [
|
|
45
|
+
{
|
|
46
|
+
amount: Number,
|
|
47
|
+
recipientId: String,
|
|
48
|
+
recipientType: String,
|
|
49
|
+
releasedAt: Date,
|
|
50
|
+
releasedBy: String,
|
|
51
|
+
reason: String,
|
|
52
|
+
metadata: Object,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
|
|
56
|
+
metadata: {
|
|
57
|
+
type: Object,
|
|
58
|
+
default: {},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default holdSchema;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escrow Schemas
|
|
3
|
+
* @classytic/revenue
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Import first
|
|
7
|
+
import { holdSchema } from './hold.schema.js';
|
|
8
|
+
|
|
9
|
+
// Then re-export
|
|
10
|
+
export { holdSchema };
|
|
11
|
+
|
|
12
|
+
// Now it's in scope for default export
|
|
13
|
+
export default {
|
|
14
|
+
holdSchema,
|
|
15
|
+
};
|
package/schemas/index.js
CHANGED
|
@@ -10,12 +10,18 @@
|
|
|
10
10
|
// Re-export core schemas only
|
|
11
11
|
export * from './transaction/index.js';
|
|
12
12
|
export * from './subscription/index.js';
|
|
13
|
+
export * from './escrow/index.js';
|
|
14
|
+
export * from './split/index.js';
|
|
13
15
|
|
|
14
16
|
// Default export with core schemas
|
|
15
17
|
import transactionSchemas from './transaction/index.js';
|
|
16
18
|
import subscriptionSchemas from './subscription/index.js';
|
|
19
|
+
import escrowSchemas from './escrow/index.js';
|
|
20
|
+
import splitSchemas from './split/index.js';
|
|
17
21
|
|
|
18
22
|
export default {
|
|
19
23
|
...transactionSchemas,
|
|
20
24
|
...subscriptionSchemas,
|
|
25
|
+
...escrowSchemas,
|
|
26
|
+
...splitSchemas,
|
|
21
27
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split Payment Schemas
|
|
3
|
+
* @classytic/revenue
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Import first
|
|
7
|
+
import { splitItemSchema, splitsSchema } from './split.schema.js';
|
|
8
|
+
|
|
9
|
+
// Then re-export
|
|
10
|
+
export { splitItemSchema, splitsSchema };
|
|
11
|
+
|
|
12
|
+
// Now they're in scope for default export
|
|
13
|
+
export default {
|
|
14
|
+
splitItemSchema,
|
|
15
|
+
splitsSchema,
|
|
16
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split Payment Schema
|
|
3
|
+
* @classytic/revenue
|
|
4
|
+
*
|
|
5
|
+
* Schema for multi-party commission splits
|
|
6
|
+
* Spread into transaction schema when needed
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { SPLIT_TYPE, SPLIT_TYPE_VALUES, SPLIT_STATUS, SPLIT_STATUS_VALUES, PAYOUT_METHOD, PAYOUT_METHOD_VALUES } from '../../enums/split.enums.js';
|
|
10
|
+
|
|
11
|
+
export const splitItemSchema = {
|
|
12
|
+
type: {
|
|
13
|
+
type: String,
|
|
14
|
+
enum: SPLIT_TYPE_VALUES,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
recipientId: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
index: true,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
recipientType: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
rate: {
|
|
30
|
+
type: Number,
|
|
31
|
+
required: true,
|
|
32
|
+
min: 0,
|
|
33
|
+
max: 1,
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
grossAmount: {
|
|
37
|
+
type: Number,
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
gatewayFeeRate: {
|
|
42
|
+
type: Number,
|
|
43
|
+
default: 0,
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
gatewayFeeAmount: {
|
|
47
|
+
type: Number,
|
|
48
|
+
default: 0,
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
netAmount: {
|
|
52
|
+
type: Number,
|
|
53
|
+
required: true,
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
status: {
|
|
57
|
+
type: String,
|
|
58
|
+
enum: SPLIT_STATUS_VALUES,
|
|
59
|
+
default: SPLIT_STATUS.PENDING,
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
dueDate: Date,
|
|
63
|
+
paidDate: Date,
|
|
64
|
+
|
|
65
|
+
payoutMethod: {
|
|
66
|
+
type: String,
|
|
67
|
+
enum: PAYOUT_METHOD_VALUES,
|
|
68
|
+
required: false,
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
payoutTransactionId: String,
|
|
72
|
+
|
|
73
|
+
metadata: {
|
|
74
|
+
type: Object,
|
|
75
|
+
default: {},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const splitsSchema = {
|
|
80
|
+
splits: {
|
|
81
|
+
type: [splitItemSchema],
|
|
82
|
+
default: [],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default splitsSchema;
|