get_hook_reference
Retrieve hook reference tables for OCAPI or SCAPI endpoints and extension points. Use this tool to identify available hooks, understand their signatures, and select the correct hook for extending SFCC APIs.
Instructions
Get comprehensive hook reference tables showing all available OCAPI or SCAPI hook endpoints and extension points. Use this when implementing hooks to see all available extension points, understand hook signatures, and ensure you're using the correct hook for your use case. Essential reference when extending SFCC APIs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guideName | Yes | The hook guide name |
Implementation Reference
- Core handler logic that parses the specified best practice guide (OCAPI or SCAPI hooks) markdown content to extract hook reference tables, categorizing hooks by API type and parsing table rows for endpoints, hook points, and optional signatures. Uses caching for performance.async getHookReference(guideName: string): Promise<Array<{ category: string; hooks: Array<{endpoint: string; hookPoints: string[]; signature?: string}>; }>> { if (!guideName.includes('hooks')) {return [];} const cacheKey = `best-practices:hook-reference:${guideName}`; const cached = this.cache.getSearchResults(cacheKey); if (cached) {return cached;} const guide = await this.getBestPracticeGuide(guideName); if (!guide) {return [];} const reference = []; const lines = guide.content.split('\n'); let currentCategory = ''; let inTable = false; let hooks: Array<{endpoint: string; hookPoints: string[]; signature?: string}> = []; for (const line of lines) { // Look for hook reference sections if (line.match(/^###?\s+(Shop API Hooks|Data API Hooks|Shopper.*Hooks|.*API Hooks)/i)) { if (currentCategory && hooks.length > 0) { reference.push({ category: currentCategory, hooks: [...hooks] }); } currentCategory = line.replace(/^#+\s*/, ''); hooks = []; inTable = false; } // Detect table headers if (line.includes('API Endpoint') && line.includes('Hook')) { inTable = true; continue; } // Skip separator line if (line.match(/^\|[\s\-|]+\|$/)) { continue; } // Parse table rows if (inTable && line.startsWith('|') && !line.includes('**')) { const parts = line.split('|').map(p => p.trim()).filter(p => p); if (parts.length >= 2) { const endpoint = parts[0].replace(/`/g, ''); const hookPoints = parts[1].split(',').map(h => h.replace(/`/g, '').trim()); const signature = parts[2] ? parts[2].replace(/`/g, '') : undefined; if (endpoint && hookPoints.length > 0) { hooks.push({ endpoint, hookPoints, signature }); } } } // End table when we hit a new section if (inTable && line.startsWith('#')) { inTable = false; } } // Add last category if (currentCategory && hooks.length > 0) { reference.push({ category: currentCategory, hooks }); } this.cache.setSearchResults(cacheKey, reference); return reference; }
- src/tool-configs/best-practices-tool-config.ts:57-67 (registration)Tool registration configuration defining defaults, input validation (requires guideName), execution handler that delegates to SFCCBestPracticesClient.getHookReference, and log message.get_hook_reference: { defaults: (args: ToolArguments) => args, validate: (args: ToolArguments, toolName: string) => { ValidationHelpers.validateArguments(args, CommonValidations.requiredString('guideName'), toolName); }, exec: async (args: ToolArguments, context: ToolExecutionContext) => { const client = context.bestPracticesClient as SFCCBestPracticesClient; return client.getHookReference(args.guideName as string); }, logMessage: (args: ToolArguments) => `Hook reference ${args.guideName}`, },
- src/core/tool-definitions.ts:147-161 (schema)Tool schema definition including name, description, and input schema requiring 'guideName' parameter limited to 'ocapi_hooks' or 'scapi_hooks'.{ name: 'get_hook_reference', description: "Get comprehensive hook reference tables showing all available OCAPI or SCAPI hook endpoints and extension points. Use this when implementing hooks to see all available extension points, understand hook signatures, and ensure you're using the correct hook for your use case. Essential reference when extending SFCC APIs.", inputSchema: { type: 'object', properties: { guideName: { type: 'string', description: 'The hook guide name', enum: ['ocapi_hooks', 'scapi_hooks'], }, }, required: ['guideName'], }, },