( input: GravityIndexInput, gravityApiKey: string | undefined, signal: AbortSignal, )
| 59 | } |
| 60 | |
| 61 | const buildGravityIndexRequest = ( |
| 62 | input: GravityIndexInput, |
| 63 | gravityApiKey: string | undefined, |
| 64 | signal: AbortSignal, |
| 65 | ): Parameters<typeof fetch> => { |
| 66 | switch (input.action) { |
| 67 | case 'search': { |
| 68 | const apiKey = requireGravityApiKey(gravityApiKey) |
| 69 | return [ |
| 70 | `${GRAVITY_INDEX_BASE_URL}/search`, |
| 71 | { |
| 72 | method: 'POST', |
| 73 | headers: { |
| 74 | 'Content-Type': 'application/json', |
| 75 | }, |
| 76 | body: JSON.stringify({ |
| 77 | query: input.query, |
| 78 | ...(input.search_id ? { search_id: input.search_id } : {}), |
| 79 | ...(input.context ? { context: input.context } : {}), |
| 80 | platform_api_key: apiKey, |
| 81 | }), |
| 82 | signal, |
| 83 | }, |
| 84 | ] |
| 85 | } |
| 86 | case 'browse': |
| 87 | return [ |
| 88 | `${GRAVITY_INDEX_BASE_URL}${withQuery('/services', { |
| 89 | category: input.category, |
| 90 | q: input.q, |
| 91 | })}`, |
| 92 | { signal }, |
| 93 | ] |
| 94 | case 'list_categories': |
| 95 | return [`${GRAVITY_INDEX_BASE_URL}/categories`, { signal }] |
| 96 | case 'get_service': |
| 97 | return [ |
| 98 | `${GRAVITY_INDEX_BASE_URL}/services/${encodeURIComponent(input.slug)}`, |
| 99 | { signal }, |
| 100 | ] |
| 101 | case 'report_integration': { |
| 102 | const apiKey = requireGravityApiKey(gravityApiKey) |
| 103 | return [ |
| 104 | `${GRAVITY_INDEX_BASE_URL}/integrations/report`, |
| 105 | { |
| 106 | method: 'POST', |
| 107 | headers: { |
| 108 | 'Content-Type': 'application/json', |
| 109 | }, |
| 110 | body: JSON.stringify({ |
| 111 | search_id: input.search_id, |
| 112 | integrated_slug: input.integrated_slug, |
| 113 | platform_api_key: apiKey, |
| 114 | }), |
| 115 | signal, |
| 116 | }, |
| 117 | ] |
| 118 | } |
no test coverage detected