@mars-stack/billing 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/chunk-AOHAQ4LF.js +49 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +16 -0
- package/dist/server/index.d.ts +64 -0
- package/dist/server/index.js +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/server/index.ts
|
|
2
|
+
function createSubscriptionService(delegate) {
|
|
3
|
+
return {
|
|
4
|
+
async findByUserId(userId) {
|
|
5
|
+
return delegate.findUnique({ where: { userId } });
|
|
6
|
+
},
|
|
7
|
+
async findByStripeCustomerId(stripeCustomerId) {
|
|
8
|
+
return delegate.findUnique({ where: { stripeCustomerId } });
|
|
9
|
+
},
|
|
10
|
+
async findByStripeSubscriptionId(stripeSubscriptionId) {
|
|
11
|
+
return delegate.findUnique({ where: { stripeSubscriptionId } });
|
|
12
|
+
},
|
|
13
|
+
async upsert(data) {
|
|
14
|
+
return delegate.upsert({
|
|
15
|
+
where: { userId: data.userId },
|
|
16
|
+
create: {
|
|
17
|
+
userId: data.userId,
|
|
18
|
+
stripeCustomerId: data.stripeCustomerId,
|
|
19
|
+
stripePriceId: data.stripePriceId ?? null,
|
|
20
|
+
stripeSubscriptionId: data.stripeSubscriptionId ?? null,
|
|
21
|
+
status: data.status,
|
|
22
|
+
currentPeriodEnd: data.currentPeriodEnd ?? null,
|
|
23
|
+
cancelAtPeriodEnd: data.cancelAtPeriodEnd ?? false
|
|
24
|
+
},
|
|
25
|
+
update: {
|
|
26
|
+
stripeCustomerId: data.stripeCustomerId,
|
|
27
|
+
stripePriceId: data.stripePriceId ?? void 0,
|
|
28
|
+
stripeSubscriptionId: data.stripeSubscriptionId ?? void 0,
|
|
29
|
+
status: data.status,
|
|
30
|
+
currentPeriodEnd: data.currentPeriodEnd ?? void 0,
|
|
31
|
+
cancelAtPeriodEnd: data.cancelAtPeriodEnd ?? void 0
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
async updateStatus(stripeSubscriptionId, data) {
|
|
36
|
+
return delegate.update({
|
|
37
|
+
where: { stripeSubscriptionId },
|
|
38
|
+
data: {
|
|
39
|
+
status: data.status,
|
|
40
|
+
...data.stripePriceId !== void 0 && { stripePriceId: data.stripePriceId },
|
|
41
|
+
...data.currentPeriodEnd !== void 0 && { currentPeriodEnd: data.currentPeriodEnd },
|
|
42
|
+
...data.cancelAtPeriodEnd !== void 0 && { cancelAtPeriodEnd: data.cancelAtPeriodEnd }
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { createSubscriptionService };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { S as SUBSCRIPTION_STATUS, a as SubscriptionDelegate, b as SubscriptionRecord, SubscriptionService, c as SubscriptionStatus, U as UpdateSubscriptionStatusData, d as UpsertSubscriptionData, createSubscriptionService } from './server/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { createSubscriptionService } from './chunk-AOHAQ4LF.js';
|
|
2
|
+
|
|
3
|
+
// src/types.ts
|
|
4
|
+
var SUBSCRIPTION_STATUS = {
|
|
5
|
+
active: "active",
|
|
6
|
+
canceled: "canceled",
|
|
7
|
+
incomplete: "incomplete",
|
|
8
|
+
incompleteExpired: "incomplete_expired",
|
|
9
|
+
pastDue: "past_due",
|
|
10
|
+
trialing: "trialing",
|
|
11
|
+
unpaid: "unpaid",
|
|
12
|
+
paused: "paused",
|
|
13
|
+
inactive: "inactive"
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { SUBSCRIPTION_STATUS };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
declare const SUBSCRIPTION_STATUS: {
|
|
2
|
+
readonly active: "active";
|
|
3
|
+
readonly canceled: "canceled";
|
|
4
|
+
readonly incomplete: "incomplete";
|
|
5
|
+
readonly incompleteExpired: "incomplete_expired";
|
|
6
|
+
readonly pastDue: "past_due";
|
|
7
|
+
readonly trialing: "trialing";
|
|
8
|
+
readonly unpaid: "unpaid";
|
|
9
|
+
readonly paused: "paused";
|
|
10
|
+
readonly inactive: "inactive";
|
|
11
|
+
};
|
|
12
|
+
type SubscriptionStatus = (typeof SUBSCRIPTION_STATUS)[keyof typeof SUBSCRIPTION_STATUS];
|
|
13
|
+
interface SubscriptionRecord {
|
|
14
|
+
id: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
stripeCustomerId: string;
|
|
17
|
+
stripePriceId: string | null;
|
|
18
|
+
stripeSubscriptionId: string | null;
|
|
19
|
+
status: string;
|
|
20
|
+
currentPeriodEnd: Date | null;
|
|
21
|
+
cancelAtPeriodEnd: boolean;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
updatedAt: Date;
|
|
24
|
+
}
|
|
25
|
+
interface UpsertSubscriptionData {
|
|
26
|
+
userId: string;
|
|
27
|
+
stripeCustomerId: string;
|
|
28
|
+
stripePriceId?: string;
|
|
29
|
+
stripeSubscriptionId?: string;
|
|
30
|
+
status: string;
|
|
31
|
+
currentPeriodEnd?: Date;
|
|
32
|
+
cancelAtPeriodEnd?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface UpdateSubscriptionStatusData {
|
|
35
|
+
status: string;
|
|
36
|
+
stripePriceId?: string;
|
|
37
|
+
currentPeriodEnd?: Date;
|
|
38
|
+
cancelAtPeriodEnd?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface SubscriptionDelegate {
|
|
41
|
+
findUnique(args: {
|
|
42
|
+
where: Record<string, unknown>;
|
|
43
|
+
}): Promise<SubscriptionRecord | null>;
|
|
44
|
+
upsert(args: {
|
|
45
|
+
where: Record<string, unknown>;
|
|
46
|
+
create: Record<string, unknown>;
|
|
47
|
+
update: Record<string, unknown>;
|
|
48
|
+
}): Promise<SubscriptionRecord>;
|
|
49
|
+
update(args: {
|
|
50
|
+
where: Record<string, unknown>;
|
|
51
|
+
data: Record<string, unknown>;
|
|
52
|
+
}): Promise<SubscriptionRecord>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare function createSubscriptionService(delegate: SubscriptionDelegate): {
|
|
56
|
+
findByUserId(userId: string): Promise<SubscriptionRecord | null>;
|
|
57
|
+
findByStripeCustomerId(stripeCustomerId: string): Promise<SubscriptionRecord | null>;
|
|
58
|
+
findByStripeSubscriptionId(stripeSubscriptionId: string): Promise<SubscriptionRecord | null>;
|
|
59
|
+
upsert(data: UpsertSubscriptionData): Promise<SubscriptionRecord>;
|
|
60
|
+
updateStatus(stripeSubscriptionId: string, data: UpdateSubscriptionStatusData): Promise<SubscriptionRecord>;
|
|
61
|
+
};
|
|
62
|
+
type SubscriptionService = ReturnType<typeof createSubscriptionService>;
|
|
63
|
+
|
|
64
|
+
export { SUBSCRIPTION_STATUS as S, type SubscriptionService, type UpdateSubscriptionStatusData as U, type SubscriptionDelegate as a, type SubscriptionRecord as b, type SubscriptionStatus as c, createSubscriptionService, type UpsertSubscriptionData as d };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createSubscriptionService } from '../chunk-AOHAQ4LF.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mars-stack/billing",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Billing module for MARS applications — subscription management, webhook handling, Stripe integration",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/greaveselliott/mars.git",
|
|
9
|
+
"directory": "packages/billing"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./server": {
|
|
18
|
+
"types": "./dist/server/index.d.ts",
|
|
19
|
+
"import": "./dist/server/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "restricted"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"test": "vitest run --passWithNoTests",
|
|
32
|
+
"prepublishOnly": "yarn build"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"zod": "^4.3.6"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@prisma/client": ">=5.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@prisma/client": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"tsup": "^8.0.0",
|
|
48
|
+
"typescript": "^5.7.0",
|
|
49
|
+
"vitest": "^3.0.0"
|
|
50
|
+
}
|
|
51
|
+
}
|