fareql 0.1.0 → 0.1.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.
- package/README.md +26 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# FareQL
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/fareql)
|
|
4
|
+
[](https://github.com/Bruce039/fareql/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/Bruce039/fareql/blob/main/LICENSE)
|
|
6
|
+
|
|
3
7
|
Charge for GraphQL operations over [MPP](https://mpp.dev) (HTTP 402), priced by what each operation selects.
|
|
4
8
|
|
|
5
9
|
A GraphQL API is one endpoint, so a flat price per route doesn't fit it: `{ hello }` and `{ users(first: 100) { edges { node { email } } } }` hit the same URL. FareQL works out the fare of every operation from your schema and charges it through [`mppx`](https://github.com/wevm/mppx) with Tempo, Stripe or any other MPP method.
|
|
@@ -15,6 +19,15 @@ A GraphQL API is one endpoint, so a flat price per route doesn't fit it: `{ hell
|
|
|
15
19
|
npm install fareql mppx graphql
|
|
16
20
|
```
|
|
17
21
|
|
|
22
|
+
## How it works
|
|
23
|
+
|
|
24
|
+
1. You mark what costs money in your schema: `@price(amount: "0.001")`.
|
|
25
|
+
2. A client sends a query. FareQL prices it from what it selects. Free operations run as usual.
|
|
26
|
+
3. A priced operation gets `402 Payment Required` with an MPP Challenge for that exact operation, plus the price and its breakdown.
|
|
27
|
+
4. The client (an app, the `mppx` CLI, an AI agent) pays, for example in stablecoins on Tempo, and resends the query with the Credential. FareQL verifies it through mppx, runs the operation, and returns the data with a `Payment-Receipt`.
|
|
28
|
+
|
|
29
|
+
Payments go straight to your own address. There is no account, API key or subscription for the client to set up.
|
|
30
|
+
|
|
18
31
|
## GraphQL Yoga
|
|
19
32
|
|
|
20
33
|
```ts
|
|
@@ -135,7 +148,15 @@ Content-Type: application/json; charset=utf-8
|
|
|
135
148
|
}
|
|
136
149
|
```
|
|
137
150
|
|
|
138
|
-
|
|
151
|
+
Clients need nothing from FareQL, only an MPP client. With the mppx CLI and a Tempo testnet wallet:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
npx mppx account create && npx mppx account fund
|
|
155
|
+
npx mppx https://api.example.com/graphql -X POST -H 'content-type: application/json' \
|
|
156
|
+
-d '{"query":"{ search(query: \"mpp\", first: 2) { snippet } }"}'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
In code, `mppx/client` wraps `fetch` so 402s are paid and retried automatically, and MPP-aware agents do the same. The paid response carries `Payment-Receipt` and `Cache-Control: private` (or `private, no-store`), so no shared cache or CDN stores paid content. Set `exposePrice: false` to leave the price out of every error body.
|
|
139
160
|
|
|
140
161
|
## Security model
|
|
141
162
|
|
|
@@ -143,7 +164,7 @@ Any MPP client (`mppx`'s fetch wrapper, `npx mppx`, agents) pays and retries. Th
|
|
|
143
164
|
- **Price what runs.** Yoga and Apollo are charged after the server's own parsing, validation and persisted-document lookup. `withPayment` refuses requests a handler could parse differently.
|
|
144
165
|
- **Fail closed.** Unreadable, unpriceable, over-limit or ambiguous requests are answered with an error and never executed. Batches can't hold more than one paid operation per Credential.
|
|
145
166
|
- **Bounded work.** Pricing is linear in the document, like graphql-js field collection. Token, length, depth, selection, body and batch limits keep it cheap.
|
|
146
|
-
- **Tested by attack.** `test/attacks-*.test.ts` hold the red-team suites: pricing tricks, parser differentials, cache and plugin-order bypasses, scope collisions and DoS. Each test asserts the secure behaviour.
|
|
167
|
+
- **Tested by attack.** [`test/attacks-*.test.ts`](https://github.com/Bruce039/fareql/tree/main/test) hold the red-team suites: pricing tricks, parser differentials, cache and plugin-order bypasses, scope collisions and DoS. Each test asserts the secure behaviour.
|
|
147
168
|
|
|
148
169
|
## Shared options
|
|
149
170
|
|
|
@@ -164,9 +185,9 @@ Any MPP client (`mppx`'s fetch wrapper, `npx mppx`, agents) pays and retries. Th
|
|
|
164
185
|
|
|
165
186
|
## Examples
|
|
166
187
|
|
|
167
|
-
- [`examples/yoga-tempo`](examples/yoga-tempo/server.ts): GraphQL Yoga on Tempo's Moderato testnet
|
|
168
|
-
- [`examples/apollo-tempo`](examples/apollo-tempo/server.ts): Apollo Server with a priced Relay-style connection
|
|
169
|
-
- [`examples/playground`](examples/playground/server.ts): a local page that walks through quote → Challenge → Credential → Receipt. It uses a settlement-free demo method by default (`npx tsx examples/playground/server.ts`, then open http://localhost:4000), and real Moderato Challenges when `RECIPIENT` and `MPP_SECRET_KEY` are set
|
|
188
|
+
- [`examples/yoga-tempo`](https://github.com/Bruce039/fareql/blob/main/examples/yoga-tempo/server.ts): GraphQL Yoga on Tempo's Moderato testnet
|
|
189
|
+
- [`examples/apollo-tempo`](https://github.com/Bruce039/fareql/blob/main/examples/apollo-tempo/server.ts): Apollo Server with a priced Relay-style connection
|
|
190
|
+
- [`examples/playground`](https://github.com/Bruce039/fareql/blob/main/examples/playground/server.ts): a local page that walks through quote → Challenge → Credential → Receipt. It uses a settlement-free demo method by default (`npx tsx examples/playground/server.ts`, then open http://localhost:4000), and real Moderato Challenges when `RECIPIENT` and `MPP_SECRET_KEY` are set
|
|
170
191
|
|
|
171
192
|
```bash
|
|
172
193
|
MPP_SECRET_KEY=$(openssl rand -hex 32) RECIPIENT=0x… npx tsx examples/yoga-tempo/server.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fareql",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Charge for GraphQL operations over MPP (HTTP 402), priced by what each operation selects. Plugins for GraphQL Yoga and Apollo Server, plus a wrapper for any Fetch handler.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|