@pfdev/api-types 3.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 +110 -0
- package/index.ts +2 -0
- package/package.json +25 -0
- package/v3.ts +80 -0
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @pfdev/api-types
|
|
2
|
+
|
|
3
|
+
TypeScript types for PF API V3, directly exported from TypeBox schemas.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @pfdev/api-types
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Use in React/React Native
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import type { components, paths } from '@pfdev/api-types';
|
|
17
|
+
|
|
18
|
+
// Type your API responses
|
|
19
|
+
type SetListResponse = components['schemas']['SetListResponse'];
|
|
20
|
+
type SetDetail = components['schemas']['SetDetail'];
|
|
21
|
+
|
|
22
|
+
// Type your API calls
|
|
23
|
+
const getSets = async (): Promise<SetListResponse> => {
|
|
24
|
+
const res = await fetch('/api/v3/sets');
|
|
25
|
+
return res.json();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const getSet = async (setid: string): Promise<SetDetail> => {
|
|
29
|
+
const res = await fetch(`/api/v3/sets/${setid}`);
|
|
30
|
+
return res.json();
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
✅ **Fully Typed** - All API endpoints have TypeScript types
|
|
37
|
+
✅ **Auto-Generated** - Types come directly from API schemas
|
|
38
|
+
✅ **Zero Manual Maintenance** - Regenerate when API changes
|
|
39
|
+
✅ **OpenAPI Standard** - Compatible with any OpenAPI tooling
|
|
40
|
+
✅ **Free to Publish** - No paid npm account needed
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
### Add/Update Types
|
|
45
|
+
|
|
46
|
+
When you add new V3 endpoints:
|
|
47
|
+
|
|
48
|
+
1. Create schemas in `../pfapi-fs/src/routes/v3/{resource}/schemas.ts`
|
|
49
|
+
2. Export the TypeBox schemas
|
|
50
|
+
3. Copy the types to `v3.ts` in this package
|
|
51
|
+
4. Commit and publish
|
|
52
|
+
|
|
53
|
+
Example workflow:
|
|
54
|
+
```bash
|
|
55
|
+
# Backend: Create new endpoint with TypeBox schemas
|
|
56
|
+
# pfapi-fs/src/routes/v3/cards/schemas.ts
|
|
57
|
+
export const CardSchema = Type.Object({ ... })
|
|
58
|
+
export type Card = Static<typeof CardSchema>
|
|
59
|
+
|
|
60
|
+
# Types package: Re-export in v3.ts
|
|
61
|
+
# pfapi-types/v3.ts
|
|
62
|
+
export { CardSchema, type Card } from '...'
|
|
63
|
+
|
|
64
|
+
# Publish
|
|
65
|
+
npm version patch
|
|
66
|
+
npm publish
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Publishing
|
|
70
|
+
|
|
71
|
+
### First Time Only
|
|
72
|
+
|
|
73
|
+
1. Create free npm account: https://www.npmjs.com/signup
|
|
74
|
+
2. Login locally: `npm login`
|
|
75
|
+
3. Publish: `npm publish`
|
|
76
|
+
|
|
77
|
+
### Update Existing Package
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Regenerate types from updated API
|
|
81
|
+
npm run generate
|
|
82
|
+
|
|
83
|
+
# Bump version
|
|
84
|
+
npm version patch # or minor/major
|
|
85
|
+
|
|
86
|
+
# Publish
|
|
87
|
+
npm publish
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Version Mapping
|
|
91
|
+
|
|
92
|
+
- **V3.x.x** - API V3 types
|
|
93
|
+
- **V2.x.x** - (future) API V2 types
|
|
94
|
+
|
|
95
|
+
## Files
|
|
96
|
+
|
|
97
|
+
- `index.ts` - Main entry point (re-exports v3.ts)
|
|
98
|
+
- `v3.ts` - Auto-generated types (run `npm run generate`)
|
|
99
|
+
- `package.json` - npm metadata
|
|
100
|
+
- `SETUP.md` - Detailed setup guide
|
|
101
|
+
|
|
102
|
+
## No Cost
|
|
103
|
+
|
|
104
|
+
- ✅ npm account: FREE (forever)
|
|
105
|
+
- ✅ Publish to npm: FREE (unlimited public packages)
|
|
106
|
+
- ✅ Type generation: FREE (openapi-typescript is open source)
|
|
107
|
+
|
|
108
|
+
## Support
|
|
109
|
+
|
|
110
|
+
See `SETUP.md` for troubleshooting and CI/CD setup.
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pfdev/api-types",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "TypeScript types for PF API V3",
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"types": "index.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.ts",
|
|
9
|
+
"v3.ts"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"verify": "tsc --noEmit v3.ts"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"api",
|
|
16
|
+
"types",
|
|
17
|
+
"typescript"
|
|
18
|
+
],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@sinclair/typebox": "^0.34.52",
|
|
23
|
+
"typescript": "^7.0.2"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/v3.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// V3 API Types
|
|
2
|
+
// Manually exported from backend TypeBox schemas
|
|
3
|
+
// Update this as new V3 endpoints are added
|
|
4
|
+
|
|
5
|
+
import { Static, Type } from '@sinclair/typebox';
|
|
6
|
+
|
|
7
|
+
// ============= SETS =============
|
|
8
|
+
|
|
9
|
+
export const SetListItemSchema = Type.Object({
|
|
10
|
+
setid: Type.String({ description: 'Unique set identifier' }),
|
|
11
|
+
name: Type.String({ description: 'Set name' }),
|
|
12
|
+
series: Type.String({ description: 'Pokemon series' }),
|
|
13
|
+
releaseddate: Type.String({ format: 'date', description: 'Release date' }),
|
|
14
|
+
imgsymbol: Type.String({ format: 'uri', description: 'Symbol image URL' }),
|
|
15
|
+
imglogo: Type.String({ format: 'uri', description: 'Logo image URL' }),
|
|
16
|
+
printedtotal: Type.Number({ description: 'Total cards in set' }),
|
|
17
|
+
current_price: Type.Optional(Type.Number({ description: 'Current market price' })),
|
|
18
|
+
change_7d: Type.Optional(Type.Number({ description: '7-day price change %' })),
|
|
19
|
+
slug: Type.String({ description: 'URL-friendly slug' })
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export type SetListItem = Static<typeof SetListItemSchema>;
|
|
23
|
+
|
|
24
|
+
export const SetListResponseSchema = Type.Object({
|
|
25
|
+
data: Type.Array(SetListItemSchema),
|
|
26
|
+
total: Type.Number({ description: 'Total number of sets' }),
|
|
27
|
+
count: Type.Number({ description: 'Number of sets returned' })
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type SetListResponse = Static<typeof SetListResponseSchema>;
|
|
31
|
+
|
|
32
|
+
export const RarityCountSchema = Type.Object({
|
|
33
|
+
rarity: Type.String(),
|
|
34
|
+
count: Type.Number()
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export type RarityCount = Static<typeof RarityCountSchema>;
|
|
38
|
+
|
|
39
|
+
export const SetDetailSchema = Type.Object({
|
|
40
|
+
setid: Type.String(),
|
|
41
|
+
name: Type.String(),
|
|
42
|
+
printedtotal: Type.Number(),
|
|
43
|
+
total: Type.Number(),
|
|
44
|
+
series: Type.String(),
|
|
45
|
+
releaseddate: Type.String({ format: 'date' }),
|
|
46
|
+
updatedat: Type.String({ format: 'date-time' }),
|
|
47
|
+
imgsymbol: Type.String({ format: 'uri' }),
|
|
48
|
+
imglogo: Type.String({ format: 'uri' }),
|
|
49
|
+
slug: Type.String(),
|
|
50
|
+
ptcgocode: Type.Optional(Type.String()),
|
|
51
|
+
legalities: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
52
|
+
current_price: Type.Optional(Type.Number()),
|
|
53
|
+
change_1d: Type.Optional(Type.Number()),
|
|
54
|
+
change_7d: Type.Optional(Type.Number()),
|
|
55
|
+
change_1m: Type.Optional(Type.Number()),
|
|
56
|
+
change_3m: Type.Optional(Type.Number()),
|
|
57
|
+
change_6m: Type.Optional(Type.Number()),
|
|
58
|
+
change_1y: Type.Optional(Type.Number()),
|
|
59
|
+
rarities: Type.Array(RarityCountSchema)
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export type SetDetail = Static<typeof SetDetailSchema>;
|
|
63
|
+
|
|
64
|
+
// ============= QUERY/PARAMS =============
|
|
65
|
+
|
|
66
|
+
export const SetListQuerySchema = Type.Object({
|
|
67
|
+
search: Type.Optional(Type.String({ description: 'Search by set name' })),
|
|
68
|
+
series: Type.Optional(Type.String({ description: 'Filter by series' })),
|
|
69
|
+
limit: Type.Optional(Type.Number({ minimum: 1, maximum: 100, default: 20 })),
|
|
70
|
+
offset: Type.Optional(Type.Number({ minimum: 0, default: 0 }))
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export type SetListQuery = Static<typeof SetListQuerySchema>;
|
|
74
|
+
|
|
75
|
+
export const SetDetailParamSchema = Type.Object({
|
|
76
|
+
setid: Type.String({ description: 'Set ID or slug' })
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export type SetDetailParam = Static<typeof SetDetailParamSchema>;
|
|
80
|
+
|