@venturekit-pro/billing 0.0.0-dev.20260323005827
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +93 -0
- package/dist/gating/feature-gate.d.ts +53 -0
- package/dist/gating/feature-gate.d.ts.map +1 -0
- package/dist/gating/feature-gate.js +92 -0
- package/dist/gating/feature-gate.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/invoices/generator.d.ts +70 -0
- package/dist/invoices/generator.d.ts.map +1 -0
- package/dist/invoices/generator.js +190 -0
- package/dist/invoices/generator.js.map +1 -0
- package/dist/plans/index.d.ts +124 -0
- package/dist/plans/index.d.ts.map +1 -0
- package/dist/plans/index.js +116 -0
- package/dist/plans/index.js.map +1 -0
- package/dist/subscriptions/manager.d.ts +98 -0
- package/dist/subscriptions/manager.d.ts.map +1 -0
- package/dist/subscriptions/manager.js +245 -0
- package/dist/subscriptions/manager.js.map +1 -0
- package/dist/types/config.d.ts +36 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +8 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/invoice.d.ts +78 -0
- package/dist/types/invoice.d.ts.map +1 -0
- package/dist/types/invoice.js +5 -0
- package/dist/types/invoice.js.map +1 -0
- package/dist/types/payment.d.ts +33 -0
- package/dist/types/payment.d.ts.map +1 -0
- package/dist/types/payment.js +8 -0
- package/dist/types/payment.js.map +1 -0
- package/dist/types/subscription.d.ts +87 -0
- package/dist/types/subscription.d.ts.map +1 -0
- package/dist/types/subscription.js +5 -0
- package/dist/types/subscription.js.map +1 -0
- package/dist/usage/tracker.d.ts +75 -0
- package/dist/usage/tracker.d.ts.map +1 -0
- package/dist/usage/tracker.js +91 -0
- package/dist/usage/tracker.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invoice Types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Invoice status
|
|
6
|
+
*/
|
|
7
|
+
export type InvoiceStatus = 'draft' | 'open' | 'paid' | 'void' | 'uncollectible';
|
|
8
|
+
/**
|
|
9
|
+
* Invoice line item
|
|
10
|
+
*/
|
|
11
|
+
export interface InvoiceLineItem {
|
|
12
|
+
/** Line item ID */
|
|
13
|
+
id: string;
|
|
14
|
+
/** Description */
|
|
15
|
+
description: string;
|
|
16
|
+
/** Quantity */
|
|
17
|
+
quantity: number;
|
|
18
|
+
/** Unit price in smallest currency unit */
|
|
19
|
+
unitPrice: number;
|
|
20
|
+
/** Total amount */
|
|
21
|
+
amount: number;
|
|
22
|
+
/** Tax rate (percentage) */
|
|
23
|
+
taxRate?: number;
|
|
24
|
+
/** Tax amount */
|
|
25
|
+
taxAmount?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Invoice
|
|
29
|
+
*/
|
|
30
|
+
export interface Invoice {
|
|
31
|
+
/** Invoice ID */
|
|
32
|
+
id: string;
|
|
33
|
+
/** Invoice number */
|
|
34
|
+
number: string;
|
|
35
|
+
/** Customer ID */
|
|
36
|
+
customerId: string;
|
|
37
|
+
/** Subscription ID (if subscription invoice) */
|
|
38
|
+
subscriptionId?: string;
|
|
39
|
+
/** Status */
|
|
40
|
+
status: InvoiceStatus;
|
|
41
|
+
/** Currency code */
|
|
42
|
+
currency: string;
|
|
43
|
+
/** Subtotal (before tax) */
|
|
44
|
+
subtotal: number;
|
|
45
|
+
/** Tax amount */
|
|
46
|
+
tax: number;
|
|
47
|
+
/** Total amount */
|
|
48
|
+
total: number;
|
|
49
|
+
/** Amount paid */
|
|
50
|
+
amountPaid: number;
|
|
51
|
+
/** Amount due */
|
|
52
|
+
amountDue: number;
|
|
53
|
+
/** Line items */
|
|
54
|
+
lineItems: InvoiceLineItem[];
|
|
55
|
+
/** Due date */
|
|
56
|
+
dueDate?: Date;
|
|
57
|
+
/** Paid at timestamp */
|
|
58
|
+
paidAt?: Date;
|
|
59
|
+
/** Invoice PDF URL */
|
|
60
|
+
pdfUrl?: string;
|
|
61
|
+
/** Created timestamp */
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
/** Updated timestamp */
|
|
64
|
+
updatedAt: Date;
|
|
65
|
+
/** Metadata */
|
|
66
|
+
metadata?: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Input for creating an invoice
|
|
70
|
+
*/
|
|
71
|
+
export interface CreateInvoiceInput {
|
|
72
|
+
customerId: string;
|
|
73
|
+
currency: string;
|
|
74
|
+
lineItems: Omit<InvoiceLineItem, 'id'>[];
|
|
75
|
+
dueDate?: Date;
|
|
76
|
+
metadata?: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=invoice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice.d.ts","sourceRoot":"","sources":["../../src/types/invoice.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,OAA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S,EAAE,IAAI,CAAC;IAEhB,eAAe;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,EAAE,CAAC;IACzC,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice.js","sourceRoot":"","sources":["../../src/types/invoice.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment-related types used by the invoicing system.
|
|
3
|
+
*
|
|
4
|
+
* This package does NOT implement payment processing.
|
|
5
|
+
* Integrate any payment provider separately.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Payment status (tracked on invoices)
|
|
9
|
+
*/
|
|
10
|
+
export type PaymentStatus = 'pending' | 'succeeded' | 'failed';
|
|
11
|
+
/**
|
|
12
|
+
* A payment record linked to an invoice.
|
|
13
|
+
* Created by external payment providers and stored for auditing.
|
|
14
|
+
*/
|
|
15
|
+
export interface PaymentRecord {
|
|
16
|
+
/** Payment ID (from your provider or internal) */
|
|
17
|
+
id: string;
|
|
18
|
+
/** Invoice ID this payment applies to */
|
|
19
|
+
invoiceId: string;
|
|
20
|
+
/** Amount in smallest currency unit */
|
|
21
|
+
amount: number;
|
|
22
|
+
/** Currency code (ISO 4217) */
|
|
23
|
+
currency: string;
|
|
24
|
+
/** Status */
|
|
25
|
+
status: PaymentStatus;
|
|
26
|
+
/** External reference from your payment provider */
|
|
27
|
+
externalRef?: string;
|
|
28
|
+
/** Created timestamp */
|
|
29
|
+
createdAt: Date;
|
|
30
|
+
/** Metadata */
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../src/types/payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,WAAW,GACX,QAAQ,CAAC;AAEb;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,EAAE,EAAE,MAAM,CAAC;IAEX,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAElB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IAEf,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IAEjB,aAAa;IACb,MAAM,EAAE,aAAa,CAAC;IAEtB,oDAAoD;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,wBAAwB;IACxB,SAAS,EAAE,IAAI,CAAC;IAEhB,eAAe;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../src/types/payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription Types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Subscription status
|
|
6
|
+
*/
|
|
7
|
+
export type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'unpaid' | 'trialing' | 'paused';
|
|
8
|
+
/**
|
|
9
|
+
* Billing interval
|
|
10
|
+
*/
|
|
11
|
+
export type BillingInterval = 'month' | 'year' | 'week' | 'day';
|
|
12
|
+
/**
|
|
13
|
+
* Subscription plan
|
|
14
|
+
*/
|
|
15
|
+
export interface SubscriptionPlan {
|
|
16
|
+
/** Plan ID */
|
|
17
|
+
id: string;
|
|
18
|
+
/** Plan name */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Plan description */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Price in smallest currency unit (cents) */
|
|
23
|
+
price: number;
|
|
24
|
+
/** Currency code (ISO 4217) */
|
|
25
|
+
currency: string;
|
|
26
|
+
/** Billing interval */
|
|
27
|
+
interval: BillingInterval;
|
|
28
|
+
/** Interval count (e.g., 3 for quarterly) */
|
|
29
|
+
intervalCount?: number;
|
|
30
|
+
/** Trial period in days */
|
|
31
|
+
trialDays?: number;
|
|
32
|
+
/** Features included */
|
|
33
|
+
features?: string[];
|
|
34
|
+
/** Is active/available */
|
|
35
|
+
active: boolean;
|
|
36
|
+
/** Metadata */
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Subscription
|
|
41
|
+
*/
|
|
42
|
+
export interface Subscription {
|
|
43
|
+
/** Subscription ID */
|
|
44
|
+
id: string;
|
|
45
|
+
/** Customer/tenant ID */
|
|
46
|
+
customerId: string;
|
|
47
|
+
/** Plan ID */
|
|
48
|
+
planId: string;
|
|
49
|
+
/** Status */
|
|
50
|
+
status: SubscriptionStatus;
|
|
51
|
+
/** Current period start */
|
|
52
|
+
currentPeriodStart: Date;
|
|
53
|
+
/** Current period end */
|
|
54
|
+
currentPeriodEnd: Date;
|
|
55
|
+
/** Cancel at period end */
|
|
56
|
+
cancelAtPeriodEnd: boolean;
|
|
57
|
+
/** Canceled at timestamp */
|
|
58
|
+
canceledAt?: Date;
|
|
59
|
+
/** Trial start */
|
|
60
|
+
trialStart?: Date;
|
|
61
|
+
/** Trial end */
|
|
62
|
+
trialEnd?: Date;
|
|
63
|
+
/** Created timestamp */
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
/** Updated timestamp */
|
|
66
|
+
updatedAt: Date;
|
|
67
|
+
/** Metadata */
|
|
68
|
+
metadata?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Input for creating a subscription
|
|
72
|
+
*/
|
|
73
|
+
export interface CreateSubscriptionInput {
|
|
74
|
+
customerId: string;
|
|
75
|
+
planId: string;
|
|
76
|
+
trialDays?: number;
|
|
77
|
+
metadata?: Record<string, unknown>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Input for updating a subscription
|
|
81
|
+
*/
|
|
82
|
+
export interface UpdateSubscriptionInput {
|
|
83
|
+
planId?: string;
|
|
84
|
+
cancelAtPeriodEnd?: boolean;
|
|
85
|
+
metadata?: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../src/types/subscription.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,GACR,UAAU,GACV,UAAU,GACV,QAAQ,GACR,UAAU,GACV,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,cAAc;IACd,EAAE,EAAE,MAAM,CAAC;IAEX,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IAEb,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IAEd,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IAEjB,uBAAuB;IACvB,QAAQ,EAAE,eAAe,CAAC;IAE1B,6CAA6C;IAC7C,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,wBAAwB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E,OAAO,CAAC,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../src/types/subscription.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VentureKit Usage Tracker
|
|
3
|
+
*
|
|
4
|
+
* Tracks metered usage for billing purposes — API calls, storage,
|
|
5
|
+
* seats, or any custom metric. Provides aggregation for invoice generation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Usage record
|
|
9
|
+
*/
|
|
10
|
+
export interface UsageRecord {
|
|
11
|
+
/** Customer/tenant ID */
|
|
12
|
+
customerId: string;
|
|
13
|
+
/** Feature key (e.g., 'api_calls', 'storage_gb', 'seats') */
|
|
14
|
+
featureKey: string;
|
|
15
|
+
/** Usage amount */
|
|
16
|
+
quantity: number;
|
|
17
|
+
/** Timestamp */
|
|
18
|
+
timestamp: number;
|
|
19
|
+
/** Optional metadata */
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Aggregated usage for a period
|
|
24
|
+
*/
|
|
25
|
+
export interface UsageSummary {
|
|
26
|
+
customerId: string;
|
|
27
|
+
featureKey: string;
|
|
28
|
+
/** Total usage in the period */
|
|
29
|
+
total: number;
|
|
30
|
+
/** Number of records in the period */
|
|
31
|
+
count: number;
|
|
32
|
+
/** Period start */
|
|
33
|
+
periodStart: number;
|
|
34
|
+
/** Period end */
|
|
35
|
+
periodEnd: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Usage store interface
|
|
39
|
+
*/
|
|
40
|
+
export interface UsageStore {
|
|
41
|
+
record(entry: UsageRecord): Promise<void>;
|
|
42
|
+
query(customerId: string, featureKey: string, from: number, to: number): Promise<UsageRecord[]>;
|
|
43
|
+
aggregate(customerId: string, from: number, to: number): Promise<UsageSummary[]>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a usage tracker
|
|
47
|
+
*/
|
|
48
|
+
export declare function createUsageTracker(store: UsageStore): {
|
|
49
|
+
/**
|
|
50
|
+
* Record a usage event
|
|
51
|
+
*/
|
|
52
|
+
record(customerId: string, featureKey: string, quantity?: number, metadata?: Record<string, unknown>): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Increment usage (alias for record with quantity=1)
|
|
55
|
+
*/
|
|
56
|
+
increment(customerId: string, featureKey: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Set absolute usage (e.g., current seat count)
|
|
59
|
+
*/
|
|
60
|
+
set(customerId: string, featureKey: string, quantity: number): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Get usage for a specific feature in a time range
|
|
63
|
+
*/
|
|
64
|
+
getUsage(customerId: string, featureKey: string, from: number, to: number): Promise<UsageRecord[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Get aggregated usage for all features in a period
|
|
67
|
+
* Returns a map of featureKey → total usage
|
|
68
|
+
*/
|
|
69
|
+
getSummary(customerId: string, from: number, to: number): Promise<Record<string, number>>;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* In-memory usage store (for dev/testing)
|
|
73
|
+
*/
|
|
74
|
+
export declare function createMemoryUsageStore(): UsageStore;
|
|
75
|
+
//# sourceMappingURL=tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/usage/tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,wBAAwB;IACxB,QAAQ,C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AM,EAAE,MAAM,CAAC,CAAC;EASrC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,UAAU,CAyCnD"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VentureKit Usage Tracker
|
|
3
|
+
*
|
|
4
|
+
* Tracks metered usage for billing purposes — API calls, storage,
|
|
5
|
+
* seats, or any custom metric. Provides aggregation for invoice generation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create a usage tracker
|
|
9
|
+
*/
|
|
10
|
+
export function createUsageTracker(store) {
|
|
11
|
+
return {
|
|
12
|
+
/**
|
|
13
|
+
* Record a usage event
|
|
14
|
+
*/
|
|
15
|
+
async record(customerId, featureKey, quantity = 1, metadata) {
|
|
16
|
+
await store.record({
|
|
17
|
+
customerId,
|
|
18
|
+
featureKey,
|
|
19
|
+
quantity,
|
|
20
|
+
timestamp: Date.now(),
|
|
21
|
+
metadata,
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Increment usage (alias for record with quantity=1)
|
|
26
|
+
*/
|
|
27
|
+
async increment(customerId, featureKey) {
|
|
28
|
+
return this.record(customerId, featureKey, 1);
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Set absolute usage (e.g., current seat count)
|
|
32
|
+
*/
|
|
33
|
+
async set(customerId, featureKey, quantity) {
|
|
34
|
+
return this.record(customerId, featureKey, quantity, { type: 'absolute' });
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Get usage for a specific feature in a time range
|
|
38
|
+
*/
|
|
39
|
+
async getUsage(customerId, featureKey, from, to) {
|
|
40
|
+
return store.query(customerId, featureKey, from, to);
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* Get aggregated usage for all features in a period
|
|
44
|
+
* Returns a map of featureKey → total usage
|
|
45
|
+
*/
|
|
46
|
+
async getSummary(customerId, from, to) {
|
|
47
|
+
const summaries = await store.aggregate(customerId, from, to);
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const s of summaries) {
|
|
50
|
+
result[s.featureKey] = s.total;
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* In-memory usage store (for dev/testing)
|
|
58
|
+
*/
|
|
59
|
+
export function createMemoryUsageStore() {
|
|
60
|
+
const records = [];
|
|
61
|
+
return {
|
|
62
|
+
async record(entry) {
|
|
63
|
+
records.push({ ...entry });
|
|
64
|
+
},
|
|
65
|
+
async query(customerId, featureKey, from, to) {
|
|
66
|
+
return records.filter(r => r.customerId === customerId &&
|
|
67
|
+
r.featureKey === featureKey &&
|
|
68
|
+
r.timestamp >= from &&
|
|
69
|
+
r.timestamp <= to);
|
|
70
|
+
},
|
|
71
|
+
async aggregate(customerId, from, to) {
|
|
72
|
+
const filtered = records.filter(r => r.customerId === customerId && r.timestamp >= from && r.timestamp <= to);
|
|
73
|
+
const byFeature = new Map();
|
|
74
|
+
for (const r of filtered) {
|
|
75
|
+
const existing = byFeature.get(r.featureKey) ?? { total: 0, count: 0 };
|
|
76
|
+
existing.total += r.quantity;
|
|
77
|
+
existing.count++;
|
|
78
|
+
byFeature.set(r.featureKey, existing);
|
|
79
|
+
}
|
|
80
|
+
return Array.from(byFeature.entries()).map(([featureKey, data]) => ({
|
|
81
|
+
customerId,
|
|
82
|
+
featureKey,
|
|
83
|
+
total: data.total,
|
|
84
|
+
count: data.count,
|
|
85
|
+
periodStart: from,
|
|
86
|
+
periodEnd: to,
|
|
87
|
+
}));
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/usage/tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2CH;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,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,CAAC,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;gBAClE,UAAU;gBACV,UAAU;gBACV,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,WAAW,EAAE,IAAI;gBACjB,SAAS,EAAE,EAAE;aACd,CAAC,CAAC,CAAC;QACN,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@venturekit-pro/billing",
|
|
3
|
+
"version": "0.0.0-dev.20260323005827",
|
|
4
|
+
"description": "Invoicing, plans, usage tracking, and feature gating for VentureKit",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/venturekit-dev/venturekit-pro.git",
|
|
14
|
+
"directory": "packages/billing"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"registry": "https://registry.npmjs.org",
|
|
18
|
+
"access": "restricted"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@venturekit/core": "0.0.0-dev.20260312012510"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^20.10.0",
|
|
32
|
+
"typescript": "^5.3.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"dev": "tsc --watch",
|
|
37
|
+
"clean": "rm -rf dist"
|
|
38
|
+
}
|
|
39
|
+
}
|