@bff-recipe/types 1.0.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 +99 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +2 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @bff-recipe/types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for [bff-recipe](https://tayyab23.github.io/bff) — a Backend For Frontend aggregation library for Spring Boot.
|
|
4
|
+
|
|
5
|
+
This package contains only type definitions. It adds **zero bytes** to your runtime bundle when used with `import type`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @bff-recipe/types --save-dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Define your API response types
|
|
16
|
+
|
|
17
|
+
These come from your backend — OpenAPI codegen, Smithy, or hand-written:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
interface Account {
|
|
21
|
+
accountId: string;
|
|
22
|
+
billingGroupId: string;
|
|
23
|
+
plan: 'FREE' | 'PRO' | 'ENTERPRISE';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface InvoiceList {
|
|
27
|
+
items: { id: string; amount: number; status: string }[];
|
|
28
|
+
total: number;
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Type your BFF request and response
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import type { RecipeRequest, RecipeResponse } from '@bff-recipe/types';
|
|
36
|
+
import axios from 'axios';
|
|
37
|
+
|
|
38
|
+
// Define what your recipe returns
|
|
39
|
+
type PaymentsPage = {
|
|
40
|
+
getAccount: Account;
|
|
41
|
+
getInvoices: InvoiceList;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Build the request — RecipeRequest gives you autocomplete on ingredients
|
|
45
|
+
const request: RecipeRequest = {
|
|
46
|
+
ingredients: [
|
|
47
|
+
{ id: 'getAccount', params: { accountId: 'acc-123' } },
|
|
48
|
+
{
|
|
49
|
+
id: 'getInvoices',
|
|
50
|
+
map: { query: { billingGroupId: 'getAccount::body::${billingGroupId}' } },
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Type the response — each ingredient's body is fully typed
|
|
56
|
+
const { data } = await axios.post<RecipeResponse<PaymentsPage>>(
|
|
57
|
+
'/bff/payments',
|
|
58
|
+
request
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
data.results.getAccount.body.plan; // ✓ 'FREE' | 'PRO' | 'ENTERPRISE'
|
|
62
|
+
data.results.getInvoices.body.items[0].amount; // ✓ number
|
|
63
|
+
data.results.getAccount.status; // ✓ number (HTTP status)
|
|
64
|
+
data.results.nonExistent; // ✗ compile error
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Works with any HTTP client
|
|
68
|
+
|
|
69
|
+
The types are framework-agnostic. Use them with whatever you already have:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
// fetch
|
|
73
|
+
const res = await fetch('/bff/payments', { method: 'POST', body: JSON.stringify(request) });
|
|
74
|
+
const data: RecipeResponse<PaymentsPage> = await res.json();
|
|
75
|
+
|
|
76
|
+
// ky
|
|
77
|
+
const data = await ky.post('/bff/payments', { json: request }).json<RecipeResponse<PaymentsPage>>();
|
|
78
|
+
|
|
79
|
+
// generated SDK
|
|
80
|
+
const data = await sdk.bff.execute<RecipeResponse<PaymentsPage>>(request);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Exported Types
|
|
84
|
+
|
|
85
|
+
| Type | Purpose |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `RecipeRequest` | The request body sent to `POST /bff/{recipe}` |
|
|
88
|
+
| `RecipeResponse<T>` | Typed response — maps ingredient IDs to their response bodies |
|
|
89
|
+
| `IngredientResult<T>` | Single ingredient result: `{ status, body }` |
|
|
90
|
+
| `IngredientInput` | Single ingredient in a request: `{ id, params, map, body, ... }` |
|
|
91
|
+
| `DebugInfo` | Debug details when `debug: true` is requested |
|
|
92
|
+
|
|
93
|
+
## Documentation
|
|
94
|
+
|
|
95
|
+
Full docs at [tayyab23.github.io/bff](https://tayyab23.github.io/bff)
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface IngredientResult<T> {
|
|
2
|
+
status: number;
|
|
3
|
+
body: T;
|
|
4
|
+
type?: string;
|
|
5
|
+
}
|
|
6
|
+
export type RecipeResponse<T extends Record<string, unknown>> = {
|
|
7
|
+
executionOrder: (string | string[])[];
|
|
8
|
+
results: {
|
|
9
|
+
[K in keyof T]: IngredientResult<T[K]>;
|
|
10
|
+
};
|
|
11
|
+
debug?: Record<string, DebugInfo>;
|
|
12
|
+
};
|
|
13
|
+
export interface DebugInfo {
|
|
14
|
+
resolvedRequest: {
|
|
15
|
+
method: string;
|
|
16
|
+
path: string;
|
|
17
|
+
headers: {
|
|
18
|
+
applied: Record<string, string>;
|
|
19
|
+
stripped: Record<string, string>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
resolvedResponse: {
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
durationMs: number;
|
|
26
|
+
}
|
|
27
|
+
export interface IngredientInput {
|
|
28
|
+
id: string;
|
|
29
|
+
params?: Record<string, unknown>;
|
|
30
|
+
body?: unknown;
|
|
31
|
+
map?: {
|
|
32
|
+
path?: Record<string, unknown>;
|
|
33
|
+
query?: Record<string, unknown>;
|
|
34
|
+
body?: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
dependsOn?: string[];
|
|
37
|
+
headers?: {
|
|
38
|
+
forward?: boolean;
|
|
39
|
+
forwardOnly?: string[];
|
|
40
|
+
custom?: Record<string, string>;
|
|
41
|
+
mappings?: Record<string, string>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface RecipeRequest {
|
|
45
|
+
ingredients: IngredientInput[];
|
|
46
|
+
debug?: boolean;
|
|
47
|
+
failFast?: boolean;
|
|
48
|
+
headers?: {
|
|
49
|
+
forward?: boolean;
|
|
50
|
+
forwardOnly?: string[];
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bff-recipe/types",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript type definitions for bff-recipe Spring Boot aggregator",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"typescript": "^5.0.0"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/tayyab23/bff.git",
|
|
18
|
+
"directory": "bff-client"
|
|
19
|
+
}
|
|
20
|
+
}
|