billfn 0.8.0 → 0.9.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 +116 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,8 +1,119 @@
|
|
|
1
|
+
<!-- Generated by scripts/bare-readme.mjs from front-door.template.md and the READMEs it includes; edit those and run `npm run readmes:bare`. -->
|
|
2
|
+
|
|
1
3
|
# billfn
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
BillFn is a self-hostable billing and entitlement layer for product builders. It gives you billing accounts, checkout
|
|
6
|
+
flows, subscription state, entitlement snapshots, usage metering and webhook ingestion behind one normalized interface,
|
|
7
|
+
so your product can ask a simpler question: what is this account allowed to do right now?
|
|
8
|
+
|
|
9
|
+
The core design is entitlement-first:
|
|
10
|
+
|
|
11
|
+
- providers are the source of truth for money movement
|
|
12
|
+
- `billfn` is the internal source of truth for entitlement state
|
|
13
|
+
- downstream consumers should read entitlements and quotas, not provider payloads
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install billfn @billfn/provider-dodo @superfunctions/db
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`import ... from "billfn"` gives `@billfn/core` at the same version. Add a provider adapter (`@billfn/provider-dodo`,
|
|
22
|
+
`@billfn/provider-apple`) and, for the browser, `@billfn/client` or `@billfn/svelte`.
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { createBillFn, type BillFnCatalog } from "billfn";
|
|
28
|
+
import { createDodoProvider } from "@billfn/provider-dodo";
|
|
29
|
+
import { memoryAdapter } from "@superfunctions/db/adapters/memory";
|
|
30
|
+
|
|
31
|
+
const catalog: BillFnCatalog = {
|
|
32
|
+
plans: [
|
|
33
|
+
{
|
|
34
|
+
productKey: "nucleus",
|
|
35
|
+
planKey: "pro",
|
|
36
|
+
displayName: "Pro",
|
|
37
|
+
features: { sync: true, analytics: true },
|
|
38
|
+
limits: { storage: 1_000 },
|
|
39
|
+
prices: [
|
|
40
|
+
{
|
|
41
|
+
priceId: "price_pro_dodo_month",
|
|
42
|
+
provider: "dodo",
|
|
43
|
+
providerProductId: "pdt_pro_month",
|
|
44
|
+
currency: "USD",
|
|
45
|
+
amount: 12,
|
|
46
|
+
kind: "subscription",
|
|
47
|
+
interval: "month",
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const billfn = createBillFn({
|
|
55
|
+
db: memoryAdapter({ debug: false }), // in-memory, for trying it out; use a durable adapter in production
|
|
56
|
+
catalog,
|
|
57
|
+
providers: {
|
|
58
|
+
dodo: createDodoProvider({
|
|
59
|
+
apiKey: process.env.DODO_API_KEY!,
|
|
60
|
+
webhookSecret: process.env.DODO_WEBHOOK_SECRET!,
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This example targets Dodo's test mode, the adapter's default: use a test mode key (`dodo_test_...`). Production sets
|
|
67
|
+
`environment: "live_mode"` with a live key; see [server setup](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/server/setup.mdx).
|
|
68
|
+
|
|
69
|
+
`createBillFn()` returns a service instance with:
|
|
70
|
+
|
|
71
|
+
- `router`, the HTTP routes under `basePath` (default `/billfn`): status, catalog, entitlements, usage, checkouts,
|
|
72
|
+
subscription cancel and sync, purchase restore, and `POST /billfn/webhooks/:provider`;
|
|
73
|
+
- `getSchema()`, the database schema for migrations;
|
|
74
|
+
- direct methods such as `createCheckout()` and `verifyCheckout()`;
|
|
75
|
+
- `subscriptionProvider` and `quotaProvider`, for the rest of your app to read entitlements and quotas.
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
If you do not override them, `namespace` defaults to `"billfn"`, `basePath` to `"/billfn"`, ids come from the built-in
|
|
80
|
+
`defaultIdFactory()`, and billing accounts come from the default resolver: `organizationId` or `tenantId` becomes an
|
|
81
|
+
organization billing account, otherwise `principalId` or `actorId` becomes a user billing account, and a request with
|
|
82
|
+
none of them fails.
|
|
83
|
+
|
|
84
|
+
The router needs `auth.resolveSubject` to know who a request acts for; a `subject` in the request body or query string
|
|
85
|
+
is ignored when it is set. Without a resolver the account routes answer 401, unless you set
|
|
86
|
+
`auth.allowClientSubject: true` for trusted server-to-server callers. See
|
|
87
|
+
[getting started](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/getting-started.mdx) and [routes](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/server/routes.mdx).
|
|
88
|
+
|
|
89
|
+
## Documentation
|
|
90
|
+
|
|
91
|
+
- [Overview](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/index.mdx) and [getting started](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/getting-started.mdx)
|
|
92
|
+
- [Architecture](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/architecture.mdx)
|
|
93
|
+
- [Server setup](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/server/setup.mdx), [routes](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/server/routes.mdx),
|
|
94
|
+
[entitlements and quotas](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/server/entitlements-and-quotas.mdx) and
|
|
95
|
+
[administration](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/server/administration.mdx)
|
|
96
|
+
- Providers: [overview](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/providers/overview.mdx), [Dodo](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/providers/dodo.mdx),
|
|
97
|
+
[Apple](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/providers/apple.mdx)
|
|
98
|
+
- Clients: [TypeScript](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/clients/typescript.mdx), [Svelte](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/clients/svelte.mdx),
|
|
99
|
+
[Swift](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/clients/swift.mdx), [Python](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/clients/python.mdx)
|
|
100
|
+
- [Production readiness](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/production-readiness.mdx) and
|
|
101
|
+
[troubleshooting](https://github.com/21nCo/superfunctions/blob/dev/billfn/docs/content/docs/troubleshooting.mdx)
|
|
102
|
+
|
|
103
|
+
## Packages
|
|
104
|
+
|
|
105
|
+
`billfn` is the front door; the scoped packages remain for installing one part.
|
|
106
|
+
|
|
107
|
+
| Package | What it is |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| `billfn` | The core as `import "billfn"` |
|
|
110
|
+
| `@billfn/core` | Billing domain, service, router, schema helpers, entitlement and quota providers; `billfn` re-exports it at the same version |
|
|
111
|
+
| `@billfn/client` | Typed HTTP client for browser or server consumers |
|
|
112
|
+
| `@billfn/svelte` | Svelte context and entitlement store helpers |
|
|
113
|
+
| `@billfn/admin` | Super Console administration capability backed by the configured BillFn instance |
|
|
114
|
+
| `@billfn/provider-dodo` | Dodo adapter: checkout, verification, sync, restore, refunds and webhooks |
|
|
115
|
+
| `@billfn/provider-apple` | Apple adapter: StoreKit verification, sync, restore and App Store Server Notifications |
|
|
116
|
+
| `@billfn/swift-bridge` | JavaScript bridge protocol for native-backed embedded web apps |
|
|
6
117
|
|
|
7
|
-
The
|
|
8
|
-
[
|
|
118
|
+
The Swift client (`BillFnSwift`) and the Python SDK (`billfn` on PyPI) live in [billfn/swift](https://github.com/21nCo/superfunctions/tree/dev/billfn/swift) and
|
|
119
|
+
[billfn/python](https://github.com/21nCo/superfunctions/tree/dev/billfn/python).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "billfn",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "BillFn: import \"billfn\" for @billfn/core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"test": "node --test test/front-door.test.mjs"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@billfn/core": "0.
|
|
23
|
+
"@billfn/core": "0.9.0"
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"repository": {
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "fd55fa86d402e9f15a065825539e3fc18444b88d"
|
|
39
39
|
}
|