Skip to content

Commit

Permalink
feat: add regional calls in the functions library
Browse files Browse the repository at this point in the history
  • Loading branch information
mansueli committed Dec 19, 2023
1 parent 1470363 commit ffbc4b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/FunctionsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
export class FunctionsClient {
protected url: string
protected headers: Record<string, string>
protected region: string
protected fetch: Fetch

constructor(
Expand All @@ -25,6 +26,7 @@ export class FunctionsClient {
) {
this.url = url
this.headers = headers
this.region = 'any'
this.fetch = resolveFetch(customFetch)
}

Expand All @@ -47,8 +49,10 @@ export class FunctionsClient {
): Promise<FunctionsResponse<T>> {
try {
const { headers, method, body: functionArgs } = options

let _headers: Record<string, string> = {}
if (this.region !== 'any') {
_headers['x-region'] = this.region
}
let body: any
if (
functionArgs &&
Expand Down
18 changes: 18 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ export type FunctionInvokeOptions = {
* The HTTP verb of the request
*/
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE'
/**
* The Region to invoke the function in.
*/
region?: 'any'
| 'ap-northeast-1'
| 'ap-northeast-2'
| 'ap-south-1'
| 'ap-southeast-1'
| 'ap-southeast-2'
| 'ca-central-1'
| 'eu-central-1'
| 'eu-west-1'
| 'eu-west-2'
| 'eu-west-3'
| 'sa-east-1'
| 'us-east-1'
| 'us-west-1'
| 'us-west-2'
/**
* The body of the request.
*/
Expand Down

0 comments on commit ffbc4b6

Please sign in to comment.