Skip to content

Commit 70616eb

Browse files
egor-romanovinian
authored andcommitted
feat: add generic parameter to invoke and make headers optional in constructor
1 parent 934492d commit 70616eb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export class FunctionsClient {
66
protected headers: { [key: string]: string }
77
protected fetch: Fetch
88

9-
constructor(url: string, headers: { [key: string]: string }, customFetch?: Fetch) {
9+
constructor(url: string, headers?: { [key: string]: string }, customFetch?: Fetch) {
1010
this.url = url
11-
this.headers = headers
11+
this.headers = headers ?? {}
1212

1313
this.fetch = resolveFetch(customFetch)
1414
}
@@ -29,10 +29,10 @@ export class FunctionsClient {
2929
* `body`: the body of the request
3030
* `responseType`: how the response should be parsed. The default is `json`
3131
*/
32-
async invoke(
32+
async invoke<T = string>(
3333
functionName: string,
3434
invokeOptions?: FunctionInvokeOptions
35-
): Promise<{ data: string | null; error: Error | null }> {
35+
): Promise<{ data: T | null; error: Error | null }> {
3636
try {
3737
const { headers, body } = invokeOptions ?? {}
3838
const response = await this.fetch(`${this.url}/${functionName}`, {

0 commit comments

Comments
 (0)