Skip to content

Commit 63e447c

Browse files
committed
feat: allow internal access to legacy stores
1 parent 8820cc8 commit 63e447c

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/main.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,56 @@ describe('get', () => {
163163

164164
expect(mockStore.fulfilled).toBeTruthy()
165165
})
166+
167+
test('Reads from a store with a legacy namespace', async () => {
168+
const mockStore = new MockFetch()
169+
.get({
170+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
171+
response: new Response(JSON.stringify({ url: signedURL })),
172+
url: `https://api.netlify.com/api/v1/blobs/${siteID}/oldie/${key}`,
173+
})
174+
.get({
175+
response: new Response(value),
176+
url: signedURL,
177+
})
178+
.get({
179+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
180+
response: new Response(JSON.stringify({ url: signedURL })),
181+
url: `https://api.netlify.com/api/v1/blobs/${siteID}/oldie/${key}`,
182+
})
183+
.get({
184+
response: new Response(value),
185+
url: signedURL,
186+
})
187+
.get({
188+
headers: { accept: 'application/json;type=signed-url', authorization: `Bearer ${apiToken}` },
189+
response: new Response(JSON.stringify({ url: signedURL })),
190+
url: `https://api.netlify.com/api/v1/blobs/${siteID}/oldie/${complexKey}`,
191+
})
192+
.get({
193+
response: new Response(value),
194+
url: signedURL,
195+
})
196+
197+
globalThis.fetch = mockStore.fetch
198+
199+
const blobs = getStore({
200+
name: 'netlify-internal/legacy-namespace/oldie',
201+
token: apiToken,
202+
siteID,
203+
})
204+
205+
const string = await blobs.get(key)
206+
expect(string).toBe(value)
207+
208+
const stream = await blobs.get(key, { type: 'stream' })
209+
expect(await streamToString(stream as unknown as NodeJS.ReadableStream)).toBe(value)
210+
211+
const string2 = await blobs.get(complexKey)
212+
expect(string2).toBe(value)
213+
214+
expect(mockStore.fulfilled).toBeTruthy()
215+
})
166216
})
167217

168218
describe('With edge credentials', () => {

src/store.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { BlobInput, HTTPMethod } from './types.ts'
88
import { BlobsInternalError, collectIterator } from './util.ts'
99

1010
export const DEPLOY_STORE_PREFIX = 'deploy:'
11+
export const LEGACY_STORE_INTERNAL_PREFIX = 'netlify-internal/legacy-namespace/'
1112
export const SITE_STORE_PREFIX = 'site:'
1213

1314
interface BaseStoreOptions {
@@ -76,6 +77,12 @@ export class Store {
7677
Store.validateDeployID(options.deployID)
7778

7879
this.name = DEPLOY_STORE_PREFIX + options.deployID
80+
} else if (options.name.startsWith(LEGACY_STORE_INTERNAL_PREFIX)) {
81+
const storeName = options.name.slice(LEGACY_STORE_INTERNAL_PREFIX.length)
82+
83+
Store.validateStoreName(storeName)
84+
85+
this.name = storeName
7986
} else {
8087
Store.validateStoreName(options.name)
8188

0 commit comments

Comments
 (0)