diff --git a/docs/getting-valid-plan-ids.md b/docs/getting-valid-plan-ids.md index 2c1c307..798c713 100644 --- a/docs/getting-valid-plan-ids.md +++ b/docs/getting-valid-plan-ids.md @@ -10,7 +10,7 @@ Plan handle IDs must match the format used by your TimeSafari database. The plac ## Methods to Get Valid Plan Handle IDs -### Method 1: Create Projects in TimeSafari App +### Method 1: Create Projects in TimeSafari App (Recommended) 1. **Start TimeSafari app** (development or test app) 2. **Create a project** via the UI @@ -18,6 +18,7 @@ Plan handle IDs must match the format used by your TimeSafari database. The plac - Open browser DevTools (F12) - Check Network tab for API responses when creating/loading projects - Look for the `handleId` field in API responses + - Note: Plans are created via **POST `/api/v2/claim`** with a PlanAction JWT (see Method 6) - Or check localStorage/database for the plan record ### Method 2: Query Your Local Database @@ -60,6 +61,25 @@ cd /home/matthew/projects/timesafari/crowd-master # Check your local database or API for actual plan handle IDs ``` +### Method 6: Create Plans via PlanAction JWT Import + +Plans are created by importing JWT claims containing a `PlanAction`: + +**Route: POST `/api/v2/claim`** + +```json +{ + "jwtEncoded": "" +} +``` + +**Requirements**: +- JWT claim payload must include `@type: "PlanAction"` +- JWT must be signed with a valid DID key +- Response includes `handleId` and `planId` if creation succeeds + +**Note**: This method requires generating signed JWTs with DID keys, which is complex. **Method 1 (TimeSafari App UI) is recommended** for creating test plans. + ## Plan Handle ID Format Plan handle IDs **must be valid URIs** (RFC 3986 format). diff --git a/docs/localhost-testing-guide.md b/docs/localhost-testing-guide.md index 7704eb8..b8714d6 100644 --- a/docs/localhost-testing-guide.md +++ b/docs/localhost-testing-guide.md @@ -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": "" +} +``` + +**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 diff --git a/scripts/seed-test-projects.js b/scripts/seed-test-projects.js index 2eac605..03f5033 100755 --- a/scripts/seed-test-projects.js +++ b/scripts/seed-test-projects.js @@ -129,7 +129,15 @@ function generateAllTestProjects(projectIds = DEFAULT_TEST_PROJECT_IDS) { /** * Seed projects to localhost API server * - * Makes POST requests to create projects in your local API + * **IMPORTANT**: The TimeSafari API creates plans via POST `/api/v2/claim` with PlanAction JWTs. + * This function attempts to POST to `/api/test/seed-projects` if your API has a custom test seed endpoint. + * + * For real TimeSafari APIs: + * 1. Create plans via the TimeSafari app UI (recommended) + * 2. Import PlanAction JWTs via POST `/api/v2/claim` (requires DID signing) + * 3. Use direct database inserts (not recommended) + * + * This seed function is primarily for custom test endpoints or the test-api-server-with-seed.js */ function seedToLocalhost(apiUrl, projectIds = DEFAULT_TEST_PROJECT_IDS) { return new Promise((resolve, reject) => { @@ -140,6 +148,14 @@ function seedToLocalhost(apiUrl, projectIds = DEFAULT_TEST_PROJECT_IDS) { console.log(` ${index + 1}. ${project.planSummary.handleId} - ${project.planSummary.name}`); }); + console.log(''); + console.log('⚠️ NOTE: This attempts to POST to /api/test/seed-projects'); + console.log(' If your API doesn\'t have this endpoint, create plans via:'); + console.log(' 1. TimeSafari App UI (easiest)'); + console.log(' 2. POST /api/v2/claim with PlanAction JWT (requires DID signing)'); + console.log(' 3. Direct database inserts'); + console.log(''); + // If your API has a seed endpoint, use this: const seedUrl = `${apiUrl}/api/test/seed-projects`; const postData = JSON.stringify({ projects });