@superwall/server 0.1.2 → 0.1.3
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 +53 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @superwall/server
|
|
2
|
+
|
|
3
|
+
Server-side entitlement enforcement for the Superwall web SDK. The browser's
|
|
4
|
+
subscription status is editable from devtools — this package gates real routes
|
|
5
|
+
server-to-server against Superwall's `/entitlements` endpoint, with caching.
|
|
6
|
+
|
|
7
|
+
Works on any runtime with `fetch` (Node 18+, Bun, Deno, Workers).
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
bun add @superwall/server # or npm / pnpm / yarn
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Superwall } from "@superwall/server";
|
|
17
|
+
|
|
18
|
+
const sw = Superwall({
|
|
19
|
+
apiKey: process.env.SUPERWALL_API_KEY!, // required
|
|
20
|
+
userId: (req) => req.session?.userId ?? null, // how to read the user per request
|
|
21
|
+
// environment: "release",
|
|
22
|
+
// cache: { ttlMs: 60_000, maxEntries: 10_000 },
|
|
23
|
+
// timeoutMs: 5_000,
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Gate a route (Express-style middleware)
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
app.get("/api/export", sw.requires("pro"), exportHandler);
|
|
31
|
+
// 403 if the user lacks the "pro" entitlement; calls next() if they have it.
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`requires(entitlement, options?)` returns `(req, res, next)`. Pass a per-call
|
|
35
|
+
`userId` extractor in `options` to override the default.
|
|
36
|
+
|
|
37
|
+
## Check imperatively
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
if (await sw.userHas(userId, "pro")) {
|
|
41
|
+
// grant access
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Offline verification
|
|
46
|
+
|
|
47
|
+
For per-request checks without a network round-trip, verify the signed
|
|
48
|
+
entitlements token the client holds (`sw.entitlementsToken` on the browser
|
|
49
|
+
SDK) with [`@superwall/verify`](https://www.npmjs.com/package/@superwall/verify).
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superwall/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"clean": "rm -rf node_modules .turbo *.tsbuildinfo"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@superwall/core": "0.1.
|
|
24
|
-
"@superwall/verify": "0.1.
|
|
23
|
+
"@superwall/core": "^0.1.3",
|
|
24
|
+
"@superwall/verify": "^0.1.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/bun": "latest",
|