Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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