diff --git a/lib/services/outline-service.ts b/lib/services/outline-service.ts index 3f9a8943..c5119eb2 100644 --- a/lib/services/outline-service.ts +++ b/lib/services/outline-service.ts @@ -30,12 +30,13 @@ export class OutlineService { try { // Create a collection in Outline based on the mission + // Note: According to Outline API, setting permission to "private" makes it private const payload = { name: collectionName, description: mission.description || 'Mission documentation', color: '#4f46e5', // Indigo color as default - permission: 'read_write', - private: true // Make the collection private + permission: "private", // This is the correct way to make it private + private: true // Keep this for backward compatibility }; console.log('Sending to Outline API:', JSON.stringify(payload, null, 2)); @@ -53,10 +54,18 @@ export class OutlineService { console.log('Outline API response:', JSON.stringify(response.data, null, 2)); - if (response.data && response.data.data && response.data.data.id) { - return response.data.data.id; - } else if (response.data && response.data.id) { - return response.data.id; + // Create a default document in the collection + if (response.data && (response.data.data?.id || response.data.id)) { + const collectionId = response.data.data?.id || response.data.id; + + try { + // Try to create a welcome document in the collection + await this.createWelcomeDocument(collectionId, collectionName); + } catch (docError) { + console.warn('Failed to create welcome document, but collection was created:', docError); + } + + return collectionId; } else { throw new Error('Failed to get collection ID from Outline API response'); } @@ -77,6 +86,31 @@ export class OutlineService { throw error; } } + + // Helper method to create a welcome document in a collection + private async createWelcomeDocument(collectionId: string, collectionName: string): Promise { + try { + const response = await axios.post( + `${this.apiUrl}/documents.create`, + { + title: `Welcome to ${collectionName}`, + text: `# Welcome to ${collectionName}\n\nThis is your new private collection in Outline. Here you can store and share documents related to this mission.\n\n## Getting Started\n\n- Use the + button to create new documents\n- Organize documents with headers and lists\n- Share this collection only with team members involved in this mission`, + collectionId: collectionId, + publish: true + }, + { + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.apiToken}` + } + } + ); + + console.log('Created welcome document with ID:', response.data?.data?.id || response.data?.id); + } catch (error) { + console.error('Failed to create welcome document:', error); + } + } async deleteCollection(collectionId: string): Promise { if (!this.apiToken) {