Currently, @supabase/functions-js package automatically handles JSON/text/multipart-form/blob parsing. However, this is done simply by checking if Content-Type if one of three predefined options (see functions-js source code). In all other cases, response is converted to text.
Example
Supabase has defined following edge function:
// read-pdf-file
serve(async (req) => {
// read pdf file from S3 storage and return it as a response
const pdfFile: Blob = ...
return new Response(
pdfFile,
{
headers: {
// set correct content type
"Content-Type": "application/pdf",
},
},
);
});
When this function is invoked via Supabase client:
const { data } = await client.functions.invoke(f, { method: 'GET' });
// data is of type string, but should be Blob
As application/pdf is not one of three predefined content types, response is converted to text (in this line).
I know it is impossible to handle all possible content types, but defaulting to text might not be the best idea. Maybe you could add something like customResponseParser, which could be handled in a similar way to customFetch option already provided.
Bug report
Describe the bug
Currently,
@supabase/functions-js
package automatically handles JSON/text/multipart-form/blob parsing. However, this is done simply by checking ifContent-Type
if one of three predefined options (see functions-js source code). In all other cases, response is converted to text.Example
Supabase has defined following edge function:
When this function is invoked via Supabase client:
As
application/pdf
is not one of three predefined content types, response is converted to text (in this line).I know it is impossible to handle all possible content types, but defaulting to text might not be the best idea. Maybe you could add something like
customResponseParser
, which could be handled in a similar way tocustomFetch
option already provided.Does this make sense or am I missing something?