@mostajs/subscriptions-plan 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/dist/api/plans.route.d.ts +17 -0
- package/dist/api/plans.route.d.ts.map +1 -0
- package/dist/api/plans.route.js +66 -0
- package/dist/api/plans.route.js.map +1 -0
- package/dist/api/subscriptions.route.d.ts +10 -0
- package/dist/api/subscriptions.route.d.ts.map +1 -0
- package/dist/api/subscriptions.route.js +65 -0
- package/dist/api/subscriptions.route.js.map +1 -0
- package/dist/api/usage.route.d.ts +10 -0
- package/dist/api/usage.route.d.ts.map +1 -0
- package/dist/api/usage.route.js +47 -0
- package/dist/api/usage.route.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/module-info.d.ts +10 -0
- package/dist/lib/module-info.d.ts.map +1 -0
- package/dist/lib/module-info.js +17 -0
- package/dist/lib/module-info.js.map +1 -0
- package/dist/lib/plan-factory.d.ts +9 -0
- package/dist/lib/plan-factory.d.ts.map +1 -0
- package/dist/lib/plan-factory.js +38 -0
- package/dist/lib/plan-factory.js.map +1 -0
- package/dist/lib/quota-check.d.ts +43 -0
- package/dist/lib/quota-check.d.ts.map +1 -0
- package/dist/lib/quota-check.js +171 -0
- package/dist/lib/quota-check.js.map +1 -0
- package/dist/lib/stripe-billing.d.ts +51 -0
- package/dist/lib/stripe-billing.d.ts.map +1 -0
- package/dist/lib/stripe-billing.js +150 -0
- package/dist/lib/stripe-billing.js.map +1 -0
- package/dist/register.d.ts +10 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +12 -0
- package/dist/register.js.map +1 -0
- package/dist/schemas/invoice.schema.d.ts +3 -0
- package/dist/schemas/invoice.schema.d.ts.map +1 -0
- package/dist/schemas/invoice.schema.js +27 -0
- package/dist/schemas/invoice.schema.js.map +1 -0
- package/dist/schemas/plan.schema.d.ts +3 -0
- package/dist/schemas/plan.schema.d.ts.map +1 -0
- package/dist/schemas/plan.schema.js +25 -0
- package/dist/schemas/plan.schema.js.map +1 -0
- package/dist/schemas/subscription.schema.d.ts +3 -0
- package/dist/schemas/subscription.schema.d.ts.map +1 -0
- package/dist/schemas/subscription.schema.js +24 -0
- package/dist/schemas/subscription.schema.js.map +1 -0
- package/dist/schemas/usage-log.schema.d.ts +3 -0
- package/dist/schemas/usage-log.schema.d.ts.map +1 -0
- package/dist/schemas/usage-log.schema.js +24 -0
- package/dist/schemas/usage-log.schema.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +17 -0
- package/dist/server.js.map +1 -0
- package/dist/types/index.d.ts +83 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type Stripe from 'stripe';
|
|
2
|
+
import type { BillingConfig } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create a Stripe Checkout session for subscription billing.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createBillingSession(stripe: Stripe, config: BillingConfig, params: {
|
|
7
|
+
customerId: string;
|
|
8
|
+
priceId: string;
|
|
9
|
+
successUrl?: string;
|
|
10
|
+
cancelUrl?: string;
|
|
11
|
+
trialDays?: number;
|
|
12
|
+
metadata?: Record<string, string>;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
url: string | null;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a Stripe Customer Portal session (manage card, invoices, cancel).
|
|
19
|
+
*/
|
|
20
|
+
export declare function createPortalSession(stripe: Stripe, config: BillingConfig, customerId: string): Promise<{
|
|
21
|
+
url: string;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a Stripe customer for a new account.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createStripeCustomer(stripe: Stripe, params: {
|
|
27
|
+
email: string;
|
|
28
|
+
name: string;
|
|
29
|
+
metadata?: Record<string, string>;
|
|
30
|
+
}): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Cancel a Stripe subscription (at period end by default).
|
|
33
|
+
*/
|
|
34
|
+
export declare function cancelSubscription(stripe: Stripe, stripeSubId: string, immediate?: boolean): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Change subscription plan (upgrade/downgrade).
|
|
37
|
+
*/
|
|
38
|
+
export declare function changeSubscriptionPlan(stripe: Stripe, stripeSubId: string, newPriceId: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Verify and parse a Stripe webhook event.
|
|
41
|
+
*/
|
|
42
|
+
export declare function verifyWebhookEvent(stripe: Stripe, body: string | Buffer, signature: string, secret: string): Stripe.Event;
|
|
43
|
+
/**
|
|
44
|
+
* Handle billing webhook events.
|
|
45
|
+
* Returns the action taken for logging/auditing.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseBillingEvent(event: Stripe.Event): {
|
|
48
|
+
type: 'subscription_created' | 'subscription_updated' | 'subscription_deleted' | 'invoice_paid' | 'invoice_failed' | 'checkout_completed' | 'unknown';
|
|
49
|
+
data: Record<string, unknown>;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=stripe-billing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-billing.d.ts","sourceRoot":"","sources":["../../src/lib/stripe-billing.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE;IACN,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAA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AAE,sBAAsB,GAAG,sBAAsB,GAAG,sBAAsB,GACxE,cAAc,GAAG,gBAAgB,GAAG,oBAAoB,GAAG,SAAS,CAAA;IAC1E,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,CA4EA"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// @mostajs/subscriptions-plan — Stripe Billing integration
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
/**
|
|
4
|
+
* Create a Stripe Checkout session for subscription billing.
|
|
5
|
+
*/
|
|
6
|
+
export async function createBillingSession(stripe, config, params) {
|
|
7
|
+
const session = await stripe.checkout.sessions.create({
|
|
8
|
+
customer: params.customerId,
|
|
9
|
+
mode: 'subscription',
|
|
10
|
+
line_items: [{ price: params.priceId, quantity: 1 }],
|
|
11
|
+
success_url: params.successUrl ?? config.successUrl,
|
|
12
|
+
cancel_url: params.cancelUrl ?? config.cancelUrl,
|
|
13
|
+
subscription_data: {
|
|
14
|
+
trial_period_days: params.trialDays,
|
|
15
|
+
metadata: params.metadata,
|
|
16
|
+
},
|
|
17
|
+
metadata: params.metadata,
|
|
18
|
+
});
|
|
19
|
+
return { url: session.url, sessionId: session.id };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a Stripe Customer Portal session (manage card, invoices, cancel).
|
|
23
|
+
*/
|
|
24
|
+
export async function createPortalSession(stripe, config, customerId) {
|
|
25
|
+
const session = await stripe.billingPortal.sessions.create({
|
|
26
|
+
customer: customerId,
|
|
27
|
+
return_url: config.portalReturnUrl,
|
|
28
|
+
});
|
|
29
|
+
return { url: session.url };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a Stripe customer for a new account.
|
|
33
|
+
*/
|
|
34
|
+
export async function createStripeCustomer(stripe, params) {
|
|
35
|
+
const customer = await stripe.customers.create({
|
|
36
|
+
email: params.email,
|
|
37
|
+
name: params.name,
|
|
38
|
+
metadata: params.metadata,
|
|
39
|
+
});
|
|
40
|
+
return customer.id;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cancel a Stripe subscription (at period end by default).
|
|
44
|
+
*/
|
|
45
|
+
export async function cancelSubscription(stripe, stripeSubId, immediate = false) {
|
|
46
|
+
if (immediate) {
|
|
47
|
+
await stripe.subscriptions.cancel(stripeSubId);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
await stripe.subscriptions.update(stripeSubId, {
|
|
51
|
+
cancel_at_period_end: true,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Change subscription plan (upgrade/downgrade).
|
|
57
|
+
*/
|
|
58
|
+
export async function changeSubscriptionPlan(stripe, stripeSubId, newPriceId) {
|
|
59
|
+
const sub = await stripe.subscriptions.retrieve(stripeSubId);
|
|
60
|
+
await stripe.subscriptions.update(stripeSubId, {
|
|
61
|
+
items: [{
|
|
62
|
+
id: sub.items.data[0].id,
|
|
63
|
+
price: newPriceId,
|
|
64
|
+
}],
|
|
65
|
+
proration_behavior: 'always_invoice',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Verify and parse a Stripe webhook event.
|
|
70
|
+
*/
|
|
71
|
+
export function verifyWebhookEvent(stripe, body, signature, secret) {
|
|
72
|
+
return stripe.webhooks.constructEvent(body, signature, secret);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Handle billing webhook events.
|
|
76
|
+
* Returns the action taken for logging/auditing.
|
|
77
|
+
*/
|
|
78
|
+
export function parseBillingEvent(event) {
|
|
79
|
+
switch (event.type) {
|
|
80
|
+
case 'checkout.session.completed': {
|
|
81
|
+
const session = event.data.object;
|
|
82
|
+
return {
|
|
83
|
+
type: 'checkout_completed',
|
|
84
|
+
data: {
|
|
85
|
+
customerId: session.customer,
|
|
86
|
+
subscriptionId: session.subscription,
|
|
87
|
+
metadata: session.metadata,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
case 'customer.subscription.created':
|
|
92
|
+
case 'customer.subscription.updated': {
|
|
93
|
+
const sub = event.data.object;
|
|
94
|
+
return {
|
|
95
|
+
type: event.type === 'customer.subscription.created' ? 'subscription_created' : 'subscription_updated',
|
|
96
|
+
data: {
|
|
97
|
+
stripeSubId: sub.id,
|
|
98
|
+
customerId: sub.customer,
|
|
99
|
+
status: sub.status,
|
|
100
|
+
priceId: sub.items.data[0]?.price?.id,
|
|
101
|
+
currentPeriodStart: new Date(sub.current_period_start * 1000).toISOString(),
|
|
102
|
+
currentPeriodEnd: new Date(sub.current_period_end * 1000).toISOString(),
|
|
103
|
+
cancelAt: sub.cancel_at ? new Date(sub.cancel_at * 1000).toISOString() : null,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
case 'customer.subscription.deleted': {
|
|
108
|
+
const sub = event.data.object;
|
|
109
|
+
return {
|
|
110
|
+
type: 'subscription_deleted',
|
|
111
|
+
data: {
|
|
112
|
+
stripeSubId: sub.id,
|
|
113
|
+
customerId: sub.customer,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
case 'invoice.paid': {
|
|
118
|
+
const invoice = event.data.object;
|
|
119
|
+
return {
|
|
120
|
+
type: 'invoice_paid',
|
|
121
|
+
data: {
|
|
122
|
+
stripeInvoiceId: invoice.id,
|
|
123
|
+
customerId: invoice.customer,
|
|
124
|
+
subscriptionId: invoice.subscription,
|
|
125
|
+
amount: invoice.amount_paid,
|
|
126
|
+
currency: invoice.currency,
|
|
127
|
+
pdfUrl: invoice.invoice_pdf,
|
|
128
|
+
hostedUrl: invoice.hosted_invoice_url,
|
|
129
|
+
periodStart: invoice.period_start ? new Date(invoice.period_start * 1000).toISOString() : null,
|
|
130
|
+
periodEnd: invoice.period_end ? new Date(invoice.period_end * 1000).toISOString() : null,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
case 'invoice.payment_failed': {
|
|
135
|
+
const invoice = event.data.object;
|
|
136
|
+
return {
|
|
137
|
+
type: 'invoice_failed',
|
|
138
|
+
data: {
|
|
139
|
+
stripeInvoiceId: invoice.id,
|
|
140
|
+
customerId: invoice.customer,
|
|
141
|
+
subscriptionId: invoice.subscription,
|
|
142
|
+
amount: invoice.amount_due,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
default:
|
|
147
|
+
return { type: 'unknown', data: { eventType: event.type } };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=stripe-billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-billing.js","sourceRoot":"","sources":["../../src/lib/stripe-billing.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,wCAAwC;AAKxC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,MAAqB,EACrB,MAOC;IAED,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;QACpD,QAAQ,EAAE,MAAM,CAAC,UAAU;QAC3B,IAAI,EAAE,cAAc;QACpB,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;QACpD,WAAW,EAAE,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU;QACnD,UAAU,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS;QAChD,iBAAiB,EAAE;YACjB,iBAAiB,EAAE,MAAM,CAAC,SAAS;YACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B;QACD,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC,CAAA;IAEF,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE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AC,CAAC,IAAI;oBAC9F,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;iBACzF;aACF,CAAA;QACH,CAAC;QAED,KAAK,wBAAwB,CAAC,CAAC,CAAC;YAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,MAAwB,CAAA;YACnD,OAAO;gBACL,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE;oBACJ,eAAe,EAAE,OAAO,CAAC,EAAE;oBAC3B,UAAU,EAAE,OAAO,CAAC,QAAQ;oBAC5B,cAAc,EAAE,OAAO,CAAC,YAAY;oBACpC,MAAM,EAAE,OAAO,CAAC,UAAU;iBAC3B;aACF,CAAA;QACH,CAAC;QAED;YACE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,CAAA;IAC/D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getSchemas } from './lib/module-info.js';
|
|
2
|
+
export declare const subscriptionPlanRegistration: {
|
|
3
|
+
name: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description: string;
|
|
6
|
+
version: string;
|
|
7
|
+
priority: number;
|
|
8
|
+
getSchemas: typeof getSchemas;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAE7D,eAAO,MAAM,4BAA4B;;;;;;;CAOxC,CAAA"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @mostajs/subscriptions-plan — Module registration
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
import { moduleInfo, getSchemas } from './lib/module-info.js';
|
|
4
|
+
export const subscriptionPlanRegistration = {
|
|
5
|
+
name: moduleInfo.name,
|
|
6
|
+
label: moduleInfo.label,
|
|
7
|
+
description: moduleInfo.description,
|
|
8
|
+
version: moduleInfo.version,
|
|
9
|
+
priority: 40,
|
|
10
|
+
getSchemas,
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,wCAAwC;AAExC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAE7D,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,IAAI,EAAE,UAAU,CAAC,IAAI;IACrB,KAAK,EAAE,UAAU,CAAC,KAAK;IACvB,WAAW,EAAE,UAAU,CAAC,WAAW;IACnC,OAAO,EAAE,UAAU,CAAC,OAAO;IAC3B,QAAQ,EAAE,EAAE;IACZ,UAAU;CACX,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/invoice.schema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD,eAAO,MAAM,aAAa,EAAE,YA0B3B,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @mostajs/subscriptions-plan — Invoice Schema
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
export const InvoiceSchema = {
|
|
4
|
+
name: 'Invoice',
|
|
5
|
+
collection: 'invoices',
|
|
6
|
+
timestamps: true,
|
|
7
|
+
fields: {
|
|
8
|
+
stripeInvoiceId: { type: 'string' },
|
|
9
|
+
amount: { type: 'number', required: true }, // centimes
|
|
10
|
+
currency: { type: 'string', default: 'usd' },
|
|
11
|
+
status: { type: 'string', required: true, default: 'open' },
|
|
12
|
+
paidAt: { type: 'date' },
|
|
13
|
+
periodStart: { type: 'date' },
|
|
14
|
+
periodEnd: { type: 'date' },
|
|
15
|
+
pdfUrl: { type: 'string' },
|
|
16
|
+
hostedUrl: { type: 'string' },
|
|
17
|
+
},
|
|
18
|
+
relations: {
|
|
19
|
+
account: { type: 'many-to-one', target: 'Account', required: true },
|
|
20
|
+
subscription: { type: 'many-to-one', target: 'Subscription' },
|
|
21
|
+
},
|
|
22
|
+
indexes: [
|
|
23
|
+
{ fields: { status: 'asc' } },
|
|
24
|
+
{ fields: { stripeInvoiceId: 'asc' }, unique: true },
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=invoice.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice.schema.js","sourceRoot":"","sources":["../../src/schemas/invoice.schema.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,wCAAwC;AAIxC,MAAM,CAAC,MAAM,aAAa,GAAiB;IACzC,IAAI,EAAE,SAAS;IACf,UAAU,EAAE,UAAU;IACtB,UAAU,EAAE,IAAI;IAEhB,MAAM,EAAE;QACN,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACnC,MAAM,EAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAK,WAAW;QACnE,QAAQ,EAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE;QACnD,MAAM,EAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE;QACpE,MAAM,EAAW,EAAE,IAAI,EAAE,MAAM,EAAE;QACjC,WAAW,EAAM,EAAE,IAAI,EAAE,MAAM,EAAE;QACjC,SAAS,EAAQ,EAAE,IAAI,EAAE,MAAM,EAAE;QACjC,MAAM,EAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;QACnC,SAAS,EAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;KACpC;IAED,SAAS,EAAE;QACT,OAAO,EAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;QACxE,YAAY,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE;KAC9D;IAED,OAAO,EAAE;QACP,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;QAC7B,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;KACrD;CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/plan.schema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD,eAAO,MAAM,UAAU,EAAE,YAwBxB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @mostajs/subscriptions-plan — Plan Schema
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
export const PlanSchema = {
|
|
4
|
+
name: 'Plan',
|
|
5
|
+
collection: 'plans',
|
|
6
|
+
timestamps: true,
|
|
7
|
+
fields: {
|
|
8
|
+
name: { type: 'string', required: true },
|
|
9
|
+
slug: { type: 'string', required: true },
|
|
10
|
+
price: { type: 'number', required: true }, // centimes (2900 = $29)
|
|
11
|
+
currency: { type: 'string', default: 'usd' },
|
|
12
|
+
interval: { type: 'string', default: 'month' }, // month | year
|
|
13
|
+
stripePriceId: { type: 'string' },
|
|
14
|
+
limits: { type: 'json', required: true },
|
|
15
|
+
features: { type: 'json' },
|
|
16
|
+
active: { type: 'boolean', default: true },
|
|
17
|
+
sortOrder: { type: 'number', default: 0 },
|
|
18
|
+
},
|
|
19
|
+
relations: {},
|
|
20
|
+
indexes: [
|
|
21
|
+
{ fields: { slug: 'asc' }, unique: true },
|
|
22
|
+
{ fields: { active: 'asc', sortOrder: 'asc' } },
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=plan.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.schema.js","sourceRoot":"","sources":["../../src/schemas/plan.schema.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,wCAAwC;AAIxC,MAAM,CAAC,MAAM,UAAU,GAAiB;IACtC,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,OAAO;IACnB,UAAU,EAAE,IAAI;IAEhB,MAAM,EAAE;QACN,IAAI,EAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;QACjD,IAAI,EAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;QACjD,KAAK,EAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAM,wBAAwB;QAC/E,QAAQ,EAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE;QACjD,QAAQ,EAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAI,eAAe;QACtE,aAAa,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACjC,MAAM,EAAS,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC/C,QAAQ,EAAO,EAAE,IAAI,EAAE,MAAM,EAAE;QAC/B,MAAM,EAAS,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;QACjD,SAAS,EAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;KAC9C;IAED,SAAS,EAAE,EAAE;IAEb,OAAO,EAAE;QACP,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;QACzC,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE;KAChD;CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/subscription.schema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD,eAAO,MAAM,kBAAkB,EAAE,YAuBhC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @mostajs/subscriptions-plan — Subscription Schema
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
export const SubscriptionSchema = {
|
|
4
|
+
name: 'Subscription',
|
|
5
|
+
collection: 'subscriptions',
|
|
6
|
+
timestamps: true,
|
|
7
|
+
fields: {
|
|
8
|
+
status: { type: 'string', required: true, default: 'active' },
|
|
9
|
+
stripeSubId: { type: 'string' },
|
|
10
|
+
currentPeriodStart: { type: 'date' },
|
|
11
|
+
currentPeriodEnd: { type: 'date' },
|
|
12
|
+
cancelAt: { type: 'date' },
|
|
13
|
+
trialEnd: { type: 'date' },
|
|
14
|
+
},
|
|
15
|
+
relations: {
|
|
16
|
+
account: { type: 'many-to-one', target: 'Account', required: true },
|
|
17
|
+
plan: { type: 'many-to-one', target: 'Plan', required: true },
|
|
18
|
+
},
|
|
19
|
+
indexes: [
|
|
20
|
+
{ fields: { status: 'asc' } },
|
|
21
|
+
{ fields: { stripeSubId: 'asc' }, unique: true },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=subscription.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.schema.js","sourceRoot":"","sources":["../../src/schemas/subscription.schema.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,wCAAwC;AAIxC,MAAM,CAAC,MAAM,kBAAkB,GAAiB;IAC9C,IAAI,EAAE,cAAc;IACpB,UAAU,EAAE,eAAe;IAC3B,UAAU,EAAE,IAAI;IAEhB,MAAM,EAAE;QACN,MAAM,EAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE;QACzE,WAAW,EAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;QACtC,kBAAkB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QACpC,gBAAgB,EAAI,EAAE,IAAI,EAAE,MAAM,EAAE;QACpC,QAAQ,EAAY,EAAE,IAAI,EAAE,MAAM,EAAE;QACpC,QAAQ,EAAY,EAAE,IAAI,EAAE,MAAM,EAAE;KACrC;IAED,SAAS,EAAE;QACT,OAAO,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;QACnE,IAAI,EAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;KACjE;IAED,OAAO,EAAE;QACP,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;QAC7B,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;KACjD;CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-log.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/usage-log.schema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD,eAAO,MAAM,cAAc,EAAE,YAuB5B,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @mostajs/subscriptions-plan — UsageLog Schema
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
export const UsageLogSchema = {
|
|
4
|
+
name: 'UsageLog',
|
|
5
|
+
collection: 'usage_logs',
|
|
6
|
+
timestamps: true,
|
|
7
|
+
fields: {
|
|
8
|
+
date: { type: 'string', required: true }, // YYYY-MM-DD
|
|
9
|
+
requests: { type: 'number', default: 0 },
|
|
10
|
+
reads: { type: 'number', default: 0 },
|
|
11
|
+
writes: { type: 'number', default: 0 },
|
|
12
|
+
errors: { type: 'number', default: 0 },
|
|
13
|
+
bandwidth: { type: 'number', default: 0 }, // bytes
|
|
14
|
+
},
|
|
15
|
+
relations: {
|
|
16
|
+
account: { type: 'many-to-one', target: 'Account', required: true },
|
|
17
|
+
project: { type: 'many-to-one', target: 'Project' },
|
|
18
|
+
},
|
|
19
|
+
indexes: [
|
|
20
|
+
{ fields: { date: 'desc' } },
|
|
21
|
+
{ fields: { date: 'asc', account: 'asc' } },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=usage-log.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-log.schema.js","sourceRoot":"","sources":["../../src/schemas/usage-log.schema.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,wCAAwC;AAIxC,MAAM,CAAC,MAAM,cAAc,GAAiB;IAC1C,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,IAAI;IAEhB,MAAM,EAAE;QACN,IAAI,EAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAK,aAAa;QAC/D,QAAQ,EAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;QACzC,KAAK,EAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;QACzC,MAAM,EAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;QACzC,MAAM,EAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;QACzC,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE,EAAS,QAAQ;KAC3D;IAED,SAAS,EAAE;QACT,OAAO,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;QACnE,OAAO,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE;KACpD;IAED,OAAO,EAAE;QACP,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;QAC5B,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;KAC5C;CACF,CAAA"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { getPlanRepo, getSubscriptionRepo, getInvoiceRepo, getUsageLogRepo, resetRepos, } from './lib/plan-factory.js';
|
|
2
|
+
export { checkQuota, isDialectAllowed, isTransportAllowed, getUsageSummary, incrementUsage, DEFAULT_PLANS, } from './lib/quota-check.js';
|
|
3
|
+
export { createBillingSession, createPortalSession, createStripeCustomer, cancelSubscription, changeSubscriptionPlan, verifyWebhookEvent, parseBillingEvent, } from './lib/stripe-billing.js';
|
|
4
|
+
export { createPlanHandlers } from './api/plans.route.js';
|
|
5
|
+
export { createSubscriptionHandlers } from './api/subscriptions.route.js';
|
|
6
|
+
export { createUsageHandlers } from './api/usage.route.js';
|
|
7
|
+
export { getSchemas, moduleInfo } from './lib/module-info.js';
|
|
8
|
+
export { subscriptionPlanRegistration } from './register.js';
|
|
9
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAG1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAG7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @mostajs/subscriptions-plan — Server-side exports (ORM + Stripe dependent)
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
// Repositories
|
|
4
|
+
export { getPlanRepo, getSubscriptionRepo, getInvoiceRepo, getUsageLogRepo, resetRepos, } from './lib/plan-factory.js';
|
|
5
|
+
// Quota enforcement
|
|
6
|
+
export { checkQuota, isDialectAllowed, isTransportAllowed, getUsageSummary, incrementUsage, DEFAULT_PLANS, } from './lib/quota-check.js';
|
|
7
|
+
// Stripe Billing
|
|
8
|
+
export { createBillingSession, createPortalSession, createStripeCustomer, cancelSubscription, changeSubscriptionPlan, verifyWebhookEvent, parseBillingEvent, } from './lib/stripe-billing.js';
|
|
9
|
+
// API handlers
|
|
10
|
+
export { createPlanHandlers } from './api/plans.route.js';
|
|
11
|
+
export { createSubscriptionHandlers } from './api/subscriptions.route.js';
|
|
12
|
+
export { createUsageHandlers } from './api/usage.route.js';
|
|
13
|
+
// Module info & schemas
|
|
14
|
+
export { getSchemas, moduleInfo } from './lib/module-info.js';
|
|
15
|
+
// Registration
|
|
16
|
+
export { subscriptionPlanRegistration } from './register.js';
|
|
17
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wCAAwC;AAExC,eAAe;AACf,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAA;AAE9B,oBAAoB;AACpB,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAA;AAE7B,iBAAiB;AACjB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,yBAAyB,CAAA;AAEhC,eAAe;AACf,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAE1D,wBAAwB;AACxB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAE7D,eAAe;AACf,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export interface PlanLimits {
|
|
2
|
+
maxProjects: number;
|
|
3
|
+
maxApiKeys: number;
|
|
4
|
+
requestsPerDay: number;
|
|
5
|
+
maxPoolSize: number;
|
|
6
|
+
dialects: string[] | '*';
|
|
7
|
+
transports: string[] | '*';
|
|
8
|
+
replication: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface PlanDTO {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
slug: string;
|
|
14
|
+
price: number;
|
|
15
|
+
currency: string;
|
|
16
|
+
interval: 'month' | 'year';
|
|
17
|
+
stripePriceId?: string;
|
|
18
|
+
limits: PlanLimits;
|
|
19
|
+
features: string[];
|
|
20
|
+
active: boolean;
|
|
21
|
+
sortOrder: number;
|
|
22
|
+
createdAt?: string;
|
|
23
|
+
updatedAt?: string;
|
|
24
|
+
}
|
|
25
|
+
export type SubscriptionStatus = 'active' | 'trialing' | 'past_due' | 'canceled' | 'unpaid';
|
|
26
|
+
export interface SubscriptionDTO {
|
|
27
|
+
id: string;
|
|
28
|
+
accountId: string;
|
|
29
|
+
planId: string;
|
|
30
|
+
status: SubscriptionStatus;
|
|
31
|
+
stripeSubId?: string;
|
|
32
|
+
currentPeriodStart?: string;
|
|
33
|
+
currentPeriodEnd?: string;
|
|
34
|
+
cancelAt?: string;
|
|
35
|
+
trialEnd?: string;
|
|
36
|
+
createdAt?: string;
|
|
37
|
+
updatedAt?: string;
|
|
38
|
+
}
|
|
39
|
+
export type InvoiceStatus = 'open' | 'paid' | 'void' | 'uncollectible';
|
|
40
|
+
export interface InvoiceDTO {
|
|
41
|
+
id: string;
|
|
42
|
+
accountId: string;
|
|
43
|
+
subscriptionId?: string;
|
|
44
|
+
stripeInvoiceId?: string;
|
|
45
|
+
amount: number;
|
|
46
|
+
currency: string;
|
|
47
|
+
status: InvoiceStatus;
|
|
48
|
+
paidAt?: string;
|
|
49
|
+
periodStart?: string;
|
|
50
|
+
periodEnd?: string;
|
|
51
|
+
pdfUrl?: string;
|
|
52
|
+
hostedUrl?: string;
|
|
53
|
+
createdAt?: string;
|
|
54
|
+
updatedAt?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface UsageLogDTO {
|
|
57
|
+
id: string;
|
|
58
|
+
accountId: string;
|
|
59
|
+
projectId?: string;
|
|
60
|
+
date: string;
|
|
61
|
+
requests: number;
|
|
62
|
+
reads: number;
|
|
63
|
+
writes: number;
|
|
64
|
+
errors: number;
|
|
65
|
+
bandwidth: number;
|
|
66
|
+
createdAt?: string;
|
|
67
|
+
updatedAt?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface BillingConfig {
|
|
70
|
+
stripeSecretKey: string;
|
|
71
|
+
stripeWebhookSecret: string;
|
|
72
|
+
successUrl: string;
|
|
73
|
+
cancelUrl: string;
|
|
74
|
+
portalReturnUrl: string;
|
|
75
|
+
}
|
|
76
|
+
export interface QuotaCheckResult {
|
|
77
|
+
allowed: boolean;
|
|
78
|
+
reason?: string;
|
|
79
|
+
current: number;
|
|
80
|
+
limit: number;
|
|
81
|
+
resource: string;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;IACxB,UAAU,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;IAC1B,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAA;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,UAAU,CAAA;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,MAAM,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W,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAMD,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAA;IACvB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;CACxB;AAMD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,wCAAwC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mostajs/subscriptions-plan",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Subscription plans, billing, invoices and usage tracking for @mostajs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./server": {
|
|
15
|
+
"types": "./dist/server.d.ts",
|
|
16
|
+
"import": "./dist/server.js",
|
|
17
|
+
"default": "./dist/server.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"dev": "tsc --watch",
|
|
23
|
+
"test": "tsx test-scripts/test-unit.ts",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"author": "Dr Hamid MADANI <drmdh@msn.com>",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"stripe": "^17.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@mostajs/orm": "^1.8.0",
|
|
37
|
+
"next": ">=14.0.0",
|
|
38
|
+
"react": ">=18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.0.0",
|
|
42
|
+
"better-sqlite3": "^12.0.0",
|
|
43
|
+
"tsx": "^4.0.0",
|
|
44
|
+
"typescript": "^5.7.0"
|
|
45
|
+
}
|
|
46
|
+
}
|