Skip to content

Commit 03187bb

Browse files
feat!: add region parameter (#183)
1 parent 075b3a0 commit 03187bb

File tree

6 files changed

+213
-56
lines changed

6 files changed

+213
-56
lines changed

src/client.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BlobsConsistencyError, ConsistencyMode } from './consistency.ts'
22
import { EnvironmentContext, getEnvironmentContext, MissingBlobsEnvironmentError } from './environment.ts'
33
import { encodeMetadata, Metadata, METADATA_HEADER_EXTERNAL, METADATA_HEADER_INTERNAL } from './metadata.ts'
4+
import { InvalidBlobsRegionError, isValidRegion } from './region.ts'
45
import { fetchAndRetry } from './retry.ts'
56
import { BlobInput, Fetcher, HTTPMethod } from './types.ts'
67
import { BlobsInternalError } from './util.ts'
@@ -231,6 +232,10 @@ export const getClientOptions = (
231232
throw new MissingBlobsEnvironmentError(['siteID', 'token'])
232233
}
233234

235+
if (options.region !== undefined && !isValidRegion(options.region)) {
236+
throw new InvalidBlobsRegionError(options.region)
237+
}
238+
234239
const clientOptions: InternalClientOptions = {
235240
apiURL: context.apiURL ?? options.apiURL,
236241
consistency: options.consistency,

src/consistency.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ describe('Consistency configuration', () => {
152152
cool: true,
153153
functions: ['edge', 'serverless'],
154154
}
155+
const mockRegion = 'us-east-1'
155156
const headers = {
156157
etag: '123456789',
157158
'x-amz-meta-user': `b64;${base64Encode(mockMetadata)}`,
@@ -160,17 +161,17 @@ describe('Consistency configuration', () => {
160161
.get({
161162
headers: { authorization: `Bearer ${edgeToken}` },
162163
response: new Response(value),
163-
url: `${uncachedEdgeURL}/${siteID}/deploy:${deployID}/${key}`,
164+
url: `${uncachedEdgeURL}/region:${mockRegion}/${siteID}/deploy:${deployID}/${key}`,
164165
})
165166
.head({
166167
headers: { authorization: `Bearer ${edgeToken}` },
167168
response: new Response(null, { headers }),
168-
url: `${uncachedEdgeURL}/${siteID}/deploy:${deployID}/${key}`,
169+
url: `${uncachedEdgeURL}/region:${mockRegion}/${siteID}/deploy:${deployID}/${key}`,
169170
})
170171
.get({
171172
headers: { authorization: `Bearer ${edgeToken}` },
172173
response: new Response(value, { headers }),
173-
url: `${uncachedEdgeURL}/${siteID}/deploy:${deployID}/${key}`,
174+
url: `${uncachedEdgeURL}/region:${mockRegion}/${siteID}/deploy:${deployID}/${key}`,
174175
})
175176

176177
globalThis.fetch = mockStore.fetch
@@ -179,6 +180,7 @@ describe('Consistency configuration', () => {
179180
consistency: 'strong',
180181
edgeURL,
181182
deployID,
183+
region: mockRegion,
182184
token: edgeToken,
183185
siteID,
184186
uncachedEdgeURL,

0 commit comments

Comments
 (0)