Skip to content

Commit

Permalink
feat!: add region parameter (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas authored Jul 3, 2024
1 parent 075b3a0 commit 03187bb
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 56 deletions.
5 changes: 5 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BlobsConsistencyError, ConsistencyMode } from './consistency.ts'
import { EnvironmentContext, getEnvironmentContext, MissingBlobsEnvironmentError } from './environment.ts'
import { encodeMetadata, Metadata, METADATA_HEADER_EXTERNAL, METADATA_HEADER_INTERNAL } from './metadata.ts'
import { InvalidBlobsRegionError, isValidRegion } from './region.ts'
import { fetchAndRetry } from './retry.ts'
import { BlobInput, Fetcher, HTTPMethod } from './types.ts'
import { BlobsInternalError } from './util.ts'
Expand Down Expand Up @@ -231,6 +232,10 @@ export const getClientOptions = (
throw new MissingBlobsEnvironmentError(['siteID', 'token'])
}

if (options.region !== undefined && !isValidRegion(options.region)) {
throw new InvalidBlobsRegionError(options.region)
}

const clientOptions: InternalClientOptions = {
apiURL: context.apiURL ?? options.apiURL,
consistency: options.consistency,
Expand Down
8 changes: 5 additions & 3 deletions src/consistency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('Consistency configuration', () => {
cool: true,
functions: ['edge', 'serverless'],
}
const mockRegion = 'us-east-1'
const headers = {
etag: '123456789',
'x-amz-meta-user': `b64;${base64Encode(mockMetadata)}`,
Expand All @@ -160,17 +161,17 @@ describe('Consistency configuration', () => {
.get({
headers: { authorization: `Bearer ${edgeToken}` },
response: new Response(value),
url: `${uncachedEdgeURL}/${siteID}/deploy:${deployID}/${key}`,
url: `${uncachedEdgeURL}/region:${mockRegion}/${siteID}/deploy:${deployID}/${key}`,
})
.head({
headers: { authorization: `Bearer ${edgeToken}` },
response: new Response(null, { headers }),
url: `${uncachedEdgeURL}/${siteID}/deploy:${deployID}/${key}`,
url: `${uncachedEdgeURL}/region:${mockRegion}/${siteID}/deploy:${deployID}/${key}`,
})
.get({
headers: { authorization: `Bearer ${edgeToken}` },
response: new Response(value, { headers }),
url: `${uncachedEdgeURL}/${siteID}/deploy:${deployID}/${key}`,
url: `${uncachedEdgeURL}/region:${mockRegion}/${siteID}/deploy:${deployID}/${key}`,
})

globalThis.fetch = mockStore.fetch
Expand All @@ -179,6 +180,7 @@ describe('Consistency configuration', () => {
consistency: 'strong',
edgeURL,
deployID,
region: mockRegion,
token: edgeToken,
siteID,
uncachedEdgeURL,
Expand Down
Loading

0 comments on commit 03187bb

Please sign in to comment.