@auth-gate/billing 0.9.2 → 0.10.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 +113 -0
- package/icon.png +0 -0
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="icon.png" alt="AuthGate" width="120" height="120" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @auth-gate/billing
|
|
6
|
+
|
|
7
|
+
Billing as code for [AuthGate](https://www.authgate.dev) — define plans, prices, and features in TypeScript and sync them to AuthGate + Stripe with a single CLI command.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @auth-gate/billing
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Optional peer dependency:** `stripe >= 14` (required for Stripe sync)
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### 1. Generate a starter config
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx @auth-gate/billing init
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 2. Define your billing config
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// authgate.billing.ts
|
|
29
|
+
import { defineBilling } from "@auth-gate/billing";
|
|
30
|
+
|
|
31
|
+
export const billing = defineBilling({
|
|
32
|
+
features: {
|
|
33
|
+
api_calls: { type: "metered" },
|
|
34
|
+
analytics: { type: "boolean" },
|
|
35
|
+
seats: { type: "metered" },
|
|
36
|
+
},
|
|
37
|
+
plans: {
|
|
38
|
+
free: {
|
|
39
|
+
name: "Free",
|
|
40
|
+
prices: [{ amount: 0, interval: "monthly" }],
|
|
41
|
+
entitlements: {
|
|
42
|
+
api_calls: { limit: 1000 },
|
|
43
|
+
analytics: false,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
pro: {
|
|
47
|
+
name: "Pro",
|
|
48
|
+
prices: [
|
|
49
|
+
{ amount: 2900, interval: "monthly" },
|
|
50
|
+
{ amount: 29000, interval: "yearly" },
|
|
51
|
+
],
|
|
52
|
+
entitlements: {
|
|
53
|
+
api_calls: { limit: 100000 },
|
|
54
|
+
analytics: true,
|
|
55
|
+
seats: { limit: 10 },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 3. Sync to AuthGate + Stripe
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
export AUTHGATE_API_KEY=ag_...
|
|
66
|
+
export AUTHGATE_BASE_URL=https://www.authgate.dev
|
|
67
|
+
|
|
68
|
+
npx @auth-gate/billing diff # Preview changes
|
|
69
|
+
npx @auth-gate/billing sync # Apply changes
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Type Safety
|
|
73
|
+
|
|
74
|
+
`defineBilling()` infers plan and feature keys as literal types for full IDE autocomplete.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
billing.plans.pro.key // "pro" (literal type)
|
|
78
|
+
billing.plans.pro.name // "Pro"
|
|
79
|
+
billing.plans.pro.entitlements // { api_calls: { limit: 100000 }, ... }
|
|
80
|
+
billing.features.api_calls.key // "api_calls"
|
|
81
|
+
billing.features.api_calls.type // "metered"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## CLI Commands
|
|
85
|
+
|
|
86
|
+
| Command | Description |
|
|
87
|
+
|---------|-------------|
|
|
88
|
+
| `npx @auth-gate/billing init` | Generate a starter config file |
|
|
89
|
+
| `npx @auth-gate/billing diff` | Preview changes without applying |
|
|
90
|
+
| `npx @auth-gate/billing sync` | Apply changes to AuthGate and Stripe |
|
|
91
|
+
| `npx @auth-gate/billing pull` | Pull server state into a local config |
|
|
92
|
+
| `npx @auth-gate/billing sync --json` | Output JSON for CI/CD integration |
|
|
93
|
+
|
|
94
|
+
## Features
|
|
95
|
+
|
|
96
|
+
- **Type-safe plans** — plan and feature keys are literal types
|
|
97
|
+
- **Multiple price models** — recurring, per-seat, metered, and tiered pricing
|
|
98
|
+
- **Feature entitlements** — boolean and metered feature gates per plan
|
|
99
|
+
- **Diff before sync** — preview all plan and price changes before applying
|
|
100
|
+
- **Revenue impact** — see estimated revenue impact of plan changes
|
|
101
|
+
- **Rename migrations** — rename plans without losing subscribers via `renamedFrom`
|
|
102
|
+
- **Grandfathering** — configure how existing subscribers are handled on plan changes
|
|
103
|
+
- **Pull workflow** — import existing Stripe products as a local config
|
|
104
|
+
- **Coexists with dashboard** — plans created in the dashboard are preserved
|
|
105
|
+
|
|
106
|
+
## Related Packages
|
|
107
|
+
|
|
108
|
+
- [`@auth-gate/testing/billing`](https://www.npmjs.com/package/@auth-gate/testing) — test utilities with in-memory store and simulated time (via `@auth-gate/testing`)
|
|
109
|
+
- [`@auth-gate/billing-action`](https://github.com/authgate/authgate/tree/main/packages/billing-action) — GitHub Action for CI/CD billing sync
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
package/icon.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth-gate/billing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
"module": "./dist/index.mjs",
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"files": [
|
|
19
|
-
"dist"
|
|
19
|
+
"dist",
|
|
20
|
+
"icon.png"
|
|
20
21
|
],
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"chalk": "^5.4.0",
|
|
23
24
|
"dotenv": "^17.2.4",
|
|
24
25
|
"jiti": "^2.4.0",
|
|
25
|
-
"@auth-gate/core": "0.
|
|
26
|
+
"@auth-gate/core": "0.10.0"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"stripe": ">=14"
|