docs(testing): document plan creation via PlanAction JWT route

Plans are created by importing JWT claims with @type: PlanAction via
POST /api/v2/claim, not through a dedicated plan creation endpoint.

Changes:
- Document POST /api/v2/claim route in localhost-testing-guide.md
- Add Method 6 (PlanAction JWT import) to getting-valid-plan-ids.md
- Update seed-test-projects.js with warnings about PlanAction JWT requirements
- Clarify that seed script cannot create plans (requires DID signing)

This reflects the actual TimeSafari API architecture where plans are
created as a side effect of importing PlanAction claims.
This commit is contained in:
Matthew Raymer
2025-10-29 12:32:12 +00:00
parent 848387b532
commit e5d539ed6b
3 changed files with 75 additions and 6 deletions

View File

@@ -38,14 +38,39 @@ node scripts/test-api-server-with-seed.js [port]
```
This server:
- ✅ Automatically seeds test projects on startup
-**Automatically creates plans in-memory on startup** (no fetch errors)
- ✅ Implements the `/api/v2/report/plansLastUpdatedBetween` endpoint
- ✅ Ready to use immediately with test-project-1, test_project_2, etc.
- ✅ Returns seeded projects when queried by `planIds`
- ✅ Ready to use immediately with auto-generated valid URI format IDs
- ✅ Provides debugging endpoints to view seeded projects
**Note**: Plans are stored in-memory only. When the server restarts, plans are re-seeded automatically.
#### Option B: Use Your Existing TimeSafari API Server
If you have your own localhost API server, seed test projects into it:
If you have your own localhost API server, you must create plans first. Plans are created by importing JWT claims containing a `PlanAction`:
**Route: POST `/api/v2/claim`**
```json
{
"jwtEncoded": "<signed JWT with PlanAction claim>"
}
```
**Requirements**:
- JWT must contain `@type: "PlanAction"` in the claim payload
- JWT must be signed with a valid DID key
- Response includes `handleId` and `planId` if creation succeeds
**Methods to Create Plans**:
1. **TimeSafari App UI** (easiest) - Create projects through the app UI and note `handleId` from API responses
2. **Import PlanAction JWT** - Generate a signed JWT with `PlanAction` claim and POST to `/api/v2/claim`
3. **Direct Database** - Insert plans directly into your database (not recommended for production data integrity)
**Note**: Creating PlanAction JWTs requires DID signing and proper claim structure, which is complex. For quick testing, **Option A (test API server) is recommended**.
Then verify your setup:
```bash
# Seed projects to your existing API server
@@ -186,7 +211,15 @@ Your localhost API server must implement:
## Seeding Test Projects
If your localhost API has no projects, you can seed test data using the included scripts:
### Using the Test API Server (Automatic)
If you're using `test-api-server-with-seed.js`, **projects are automatically created on startup** - no additional seeding needed. The server creates plans in-memory, so they're available immediately when the prefetch endpoint is called.
### Using Your Real TimeSafari API Server
If your localhost API has no projects, create them via **POST `/api/v2/claim`** with a PlanAction JWT (see "Option B" section above).
**Note**: The `seed-test-projects.js` script cannot directly create plans because it would require generating signed PlanAction JWTs with DID keys, which is complex. The seed script is designed for the test API server (Option A) or for verifying API responses after plans are created through other means.
### Generate Test Projects