Skip to content

Commit aa53a36

Browse files
authored
Merge pull request #299 from commonknowledge/feature/sdk-publish-workflow
Feature/sdk publish workflow
2 parents 2cc736c + 1835e78 commit aa53a36

File tree

7 files changed

+1034
-0
lines changed

7 files changed

+1034
-0
lines changed

.github/workflows/publish-sdk.yml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: Publish SDK
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- "src/api/**"
8+
- "tsconfig.api.json"
9+
- ".github/workflows/publish-sdk.yml"
10+
workflow_dispatch:
11+
12+
jobs:
13+
publish-sdk:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 10
16+
steps:
17+
- name: Checkout ts-mapped
18+
uses: actions/checkout@v4
19+
with:
20+
path: ts-mapped
21+
22+
- name: Checkout ts-mapped-sdk
23+
uses: actions/checkout@v4
24+
with:
25+
repository: commonknowledge/ts-mapped-sdk
26+
token: ${{ secrets.SDK_REPO_TOKEN }}
27+
path: ts-mapped-sdk
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: 22
33+
34+
- name: Install dependencies
35+
working-directory: ts-mapped
36+
run: npm ci
37+
38+
- name: Build API types
39+
working-directory: ts-mapped
40+
run: npm run build:api
41+
42+
- name: Prepare SDK package
43+
run: |
44+
# Clear existing directories in SDK repo
45+
rm -rf ts-mapped-sdk/src
46+
rm -rf ts-mapped-sdk/dist
47+
48+
# Copy built types
49+
mkdir -p ts-mapped-sdk/dist
50+
cp -r ts-mapped/dist/api/* ts-mapped-sdk/dist/
51+
52+
# Copy source types (for reference/debugging)
53+
mkdir -p ts-mapped-sdk/src
54+
cp -r ts-mapped/src/api/* ts-mapped-sdk/src/
55+
56+
# Generate package.json for SDK
57+
cat > ts-mapped-sdk/package.json << 'EOF'
58+
{
59+
"name": "@commonknowledge/ts-mapped-sdk",
60+
"version": "0.0.0",
61+
"description": "TypeScript types for the ts-mapped REST API",
62+
"types": "./dist/index.d.ts",
63+
"exports": {
64+
".": {
65+
"types": "./dist/index.d.ts"
66+
}
67+
},
68+
"files": [
69+
"dist",
70+
"src"
71+
],
72+
"peerDependencies": {
73+
"typescript": "^5.0.0"
74+
},
75+
"dependencies": {
76+
"@types/geojson": "^7946.0.0"
77+
},
78+
"repository": {
79+
"type": "git",
80+
"url": "git+https://github.com/commonknowledge/ts-mapped-sdk.git"
81+
},
82+
"homepage": "https://github.com/commonknowledge/ts-mapped",
83+
"license": "MIT",
84+
"keywords": [
85+
"typescript",
86+
"types",
87+
"geojson",
88+
"api",
89+
"sdk",
90+
"mapped"
91+
]
92+
}
93+
EOF
94+
95+
# Generate README
96+
cat > ts-mapped-sdk/README.md << 'EOF'
97+
# ts-mapped SDK
98+
99+
TypeScript types for consuming the [ts-mapped](https://github.com/commonknowledge/ts-mapped) REST API.
100+
101+
> **Note:** This package is automatically generated from the ts-mapped repository. Do not edit directly.
102+
103+
## Installation
104+
105+
```bash
106+
npm install github:commonknowledge/ts-mapped-sdk
107+
# or if published to npm:
108+
npm install @commonknowledge/ts-mapped-sdk
109+
```
110+
111+
## Usage
112+
113+
```typescript
114+
import type {
115+
GeoJSONAPIResponse,
116+
GeoJSONAPIFeature,
117+
GeoJSONFeatureProperties,
118+
APIRecordFilter,
119+
APIRecordSort,
120+
APIFilterOperator,
121+
APIFilterType,
122+
} from '@commonknowledge/ts-mapped-sdk';
123+
124+
// Fetch data with proper typing
125+
async function fetchGeoJSON(dataSourceId: string): Promise<GeoJSONAPIResponse> {
126+
const response = await fetch(
127+
`https://your-instance.com/api/rest/data-sources/${dataSourceId}/geojson`,
128+
{
129+
headers: {
130+
'Authorization': `Basic ${btoa('email:password')}`,
131+
},
132+
}
133+
);
134+
return response.json();
135+
}
136+
```
137+
138+
## Available Types
139+
140+
- `GeoJSONAPIResponse` - Main response type from the GeoJSON endpoint
141+
- `GeoJSONAPIFeature` - Individual feature in the response
142+
- `GeoJSONFeatureProperties` - Properties object for each feature
143+
- `APIRecordFilter` - Filter configuration for querying
144+
- `APIRecordSort` - Sort configuration
145+
- `APIFilterOperator` - `AND` / `OR` operators
146+
- `APIFilterType` - `GEO` / `MULTI` / `TEXT` filter types
147+
- `APIPoint` - Geographic coordinates (lat/lng)
148+
- `APIGeocodeResult` - Geocoding metadata
149+
- `GeoJSONAPIErrorResponse` - Error response structure
150+
151+
## Documentation
152+
153+
For detailed usage examples, see the [API documentation](https://github.com/commonknowledge/ts-mapped/blob/main/src/api/README.md).
154+
155+
## License
156+
157+
MIT
158+
EOF
159+
160+
- name: Get commit info
161+
id: commit-info
162+
working-directory: ts-mapped
163+
run: |
164+
echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
165+
echo "message=$(git log -1 --pretty=%B | head -1)" >> $GITHUB_OUTPUT
166+
167+
- name: Update SDK version
168+
working-directory: ts-mapped-sdk
169+
run: |
170+
# Read current version from the committed SDK package.json (HEAD),
171+
# falling back to the working copy or 0.0.0 if necessary.
172+
if git show HEAD:package.json >/tmp/original_package.json 2>/dev/null; then
173+
CURRENT_VERSION=$(node -p "require('/tmp/original_package.json').version || '0.0.0'")
174+
elif [ -f package.json ]; then
175+
CURRENT_VERSION=$(node -p "require('./package.json').version || '0.0.0'")
176+
else
177+
CURRENT_VERSION="0.0.0"
178+
fi
179+
180+
# Bump patch version
181+
NEW_VERSION=$(echo "$CURRENT_VERSION" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
182+
183+
# Update package.json with new version
184+
node -e "
185+
const pkg = require('./package.json');
186+
pkg.version = '$NEW_VERSION';
187+
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
188+
"
189+
190+
echo "Updated version from $CURRENT_VERSION to $NEW_VERSION"
191+
192+
- name: Commit and push to SDK repo
193+
working-directory: ts-mapped-sdk
194+
run: |
195+
git config user.name "github-actions[bot]"
196+
git config user.email "github-actions[bot]@users.noreply.github.com"
197+
198+
git add -A
199+
200+
# Check if there are changes to commit
201+
if git diff --staged --quiet; then
202+
echo "No changes to commit"
203+
exit 0
204+
fi
205+
206+
git commit -m "chore: sync types from ts-mapped@${{ steps.commit-info.outputs.sha }}" \
207+
-m "Source commit: ${{ steps.commit-info.outputs.message }}" \
208+
-m "Generated from: https://github.com/commonknowledge/ts-mapped/commit/${{ github.sha }}"
209+
210+
git push

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# production
2121
/build
22+
/dist
2223

2324
# misc
2425
.DS_Store

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ npm run cmd -- upsertUser --email a@b.com --password 1234 --org "My Org"
4444

4545
## API Documentation
4646

47+
### TypeScript SDK
48+
49+
TypeScript types are available for consuming the REST API from external projects via a separate SDK package:
50+
51+
```bash
52+
npm install github:commonknowledge/ts-mapped-sdk
53+
```
54+
55+
```typescript
56+
import type { GeoJSONAPIResponse } from "@commonknowledge/ts-mapped-sdk";
57+
```
58+
59+
See [src/api/README.md](src/api/README.md) for detailed usage examples.
60+
4761
### GeoJSON REST API
4862

4963
The application provides a REST API endpoint to retrieve data source items as GeoJSON.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "next build",
7+
"build:api": "tsc -p tsconfig.api.json",
78
"cmd": "tsx --env-file=.env bin/cmd.ts",
89
"dev": "next dev --turbopack --experimental-https",
910
"emails": "email dev --port 3002 --dir src/server/emails",

0 commit comments

Comments
 (0)