({
account,
memoryName
}: {
account: Account;
memoryName: string;
})
| 838 | } |
| 839 | |
| 840 | export async function listMemoryDocuments({ |
| 841 | account, |
| 842 | memoryName |
| 843 | }: { |
| 844 | account: Account; |
| 845 | memoryName: string; |
| 846 | }) { |
| 847 | const { listDocuments } = getMemoryApiUrls({ |
| 848 | memoryName: memoryName |
| 849 | }); |
| 850 | |
| 851 | // Wait 500 ms to avoid rate limiting |
| 852 | await new Promise(resolve => setTimeout(resolve, 500)); |
| 853 | const listResponse = await fetch(listDocuments, { |
| 854 | method: 'GET', |
| 855 | headers: { |
| 856 | 'Content-Type': 'application/json', |
| 857 | Authorization: `Bearer ${account.apiKey}` |
| 858 | } |
| 859 | }); |
| 860 | |
| 861 | if (!listResponse.ok) { |
| 862 | const errorData = (await listResponse.json()) as ErrorResponse; |
| 863 | |
| 864 | const errorMsg = errorData.error?.message; |
| 865 | |
| 866 | if (errorMsg?.includes('Invalid memory name.')) { |
| 867 | p.log.info(`Memory "${memoryName}" does not exist in production.`); |
| 868 | return []; |
| 869 | } |
| 870 | |
| 871 | throw new Error( |
| 872 | `HTTP error! status: ${listResponse.status}, message: ${errorMsg}` |
| 873 | ); |
| 874 | } |
| 875 | |
| 876 | const res = (await listResponse.json()) as { name: string }[]; |
| 877 | const documents = res.map((doc: { name: string }) => doc.name); |
| 878 | return documents; |
| 879 | } |
| 880 | |
| 881 | async function getSignedUploadUrl({ |
| 882 | documentName, |
no test coverage detected