@inbin/core
Advanced tools
+14
-1
@@ -72,3 +72,3 @@ "use strict"; | ||
| ...body !== void 0 ? { "content-type": "application/json" } : {}, | ||
| "user-agent": "inbin-core/0.1.0" | ||
| "user-agent": "inbin-core/0.2.0" | ||
| }, | ||
@@ -141,2 +141,15 @@ body: body !== void 0 ? JSON.stringify(body) : void 0, | ||
| }; | ||
| // ---- query ---- | ||
| /** | ||
| * POST /query — your inbox as a table. Filter, sort, project, | ||
| * flatten array records, group + aggregate over extracted events. | ||
| * | ||
| * await inbin.query({ | ||
| * flatten: "deals", | ||
| * where: [{ field: "price_usd", op: "lt", value: 300 }], | ||
| * group_by: "destination_city", | ||
| * aggregate: [{ fn: "avg", field: "price_usd", as: "avg_price" }], | ||
| * }); | ||
| */ | ||
| query = (q) => this.request("POST", "/query", q); | ||
| // ---- application ---- | ||
@@ -143,0 +156,0 @@ apps = { |
+41
-0
@@ -81,2 +81,31 @@ /** | ||
| } | ||
| export type QueryOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "contains" | "in" | "exists"; | ||
| export interface QueryInput { | ||
| /** Root array field to explode into records (e.g. "deals"). */ | ||
| flatten?: string; | ||
| where?: Array<{ | ||
| field: string; | ||
| op: QueryOp; | ||
| value?: unknown; | ||
| }>; | ||
| order_by?: { | ||
| field: string; | ||
| dir?: "asc" | "desc"; | ||
| }; | ||
| select?: string[]; | ||
| group_by?: string; | ||
| aggregate?: Array<{ | ||
| fn: "count" | "sum" | "avg" | "min" | "max"; | ||
| field?: string; | ||
| as?: string; | ||
| }>; | ||
| since?: string; | ||
| until?: string; | ||
| inbox_id?: string; | ||
| limit?: number; | ||
| } | ||
| export interface QueryResult { | ||
| rows: unknown[]; | ||
| row_count: number; | ||
| } | ||
| export interface RedeliverResult { | ||
@@ -144,2 +173,14 @@ event_id: string; | ||
| }; | ||
| /** | ||
| * POST /query — your inbox as a table. Filter, sort, project, | ||
| * flatten array records, group + aggregate over extracted events. | ||
| * | ||
| * await inbin.query({ | ||
| * flatten: "deals", | ||
| * where: [{ field: "price_usd", op: "lt", value: 300 }], | ||
| * group_by: "destination_city", | ||
| * aggregate: [{ fn: "avg", field: "price_usd", as: "avg_price" }], | ||
| * }); | ||
| */ | ||
| query: (q: QueryInput) => Promise<QueryResult>; | ||
| readonly apps: { | ||
@@ -146,0 +187,0 @@ /** GET /apps — the caller's application. */ |
+14
-1
@@ -46,3 +46,3 @@ // src/index.ts | ||
| ...body !== void 0 ? { "content-type": "application/json" } : {}, | ||
| "user-agent": "inbin-core/0.1.0" | ||
| "user-agent": "inbin-core/0.2.0" | ||
| }, | ||
@@ -115,2 +115,15 @@ body: body !== void 0 ? JSON.stringify(body) : void 0, | ||
| }; | ||
| // ---- query ---- | ||
| /** | ||
| * POST /query — your inbox as a table. Filter, sort, project, | ||
| * flatten array records, group + aggregate over extracted events. | ||
| * | ||
| * await inbin.query({ | ||
| * flatten: "deals", | ||
| * where: [{ field: "price_usd", op: "lt", value: 300 }], | ||
| * group_by: "destination_city", | ||
| * aggregate: [{ fn: "avg", field: "price_usd", as: "avg_price" }], | ||
| * }); | ||
| */ | ||
| query = (q) => this.request("POST", "/query", q); | ||
| // ---- application ---- | ||
@@ -117,0 +130,0 @@ apps = { |
+1
-1
| { | ||
| "name": "@inbin/core", | ||
| "version": "0.1.1", | ||
| "version": "0.2.0", | ||
| "description": "Official Inbin SDK: typed client for the Inbin REST API (email in, JSON out) plus webhook signature verification.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+21
-0
@@ -83,2 +83,3 @@ # @inbin/core | ||
| | `inbin.events.redeliver(id)` | `POST /v1/events/:id/redeliver` | | ||
| | `inbin.query(q)` | `POST /v1/query` | | ||
| | `inbin.apps.me()` | `GET /v1/apps` | | ||
@@ -89,2 +90,22 @@ | `inbin.apps.update({ name?, webhook_url? })` | `PATCH /v1/apps` | | ||
| ## Query | ||
| Your inbox as a table. Filter, sort, project, flatten array records, | ||
| group and aggregate over everything your schemas extracted. One | ||
| request, no database on your side. | ||
| ```ts | ||
| const { rows } = await inbin.query({ | ||
| flatten: "deals", | ||
| where: [{ field: "price_usd", op: "lt", value: 300 }], | ||
| group_by: "destination_city", | ||
| aggregate: [{ fn: "avg", field: "price_usd", as: "avg_price" }], | ||
| }); | ||
| // [{ destination_city: "Lisbon", avg_price: 274.5 }, ...] | ||
| ``` | ||
| Ops: `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `contains`, `in`, | ||
| `exists`. Aggregates: `count`, `sum`, `avg`, `min`, `max`. Limit | ||
| caps at 200. | ||
| ## MCP | ||
@@ -91,0 +112,0 @@ |
23944
13.14%574
13.21%118
21.65%