billfn 0.8.0 → 0.8.1

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