Skip to content

Commit be7457f

Browse files
committed
feat: store context and normalize key
1 parent 6a30a31 commit be7457f

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/helpers/blobs.cts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1+
import { Buffer } from 'buffer'
2+
13
import { getStore } from '@netlify/blobs'
24

35
export const netliBlob = (token: string, deployID: string, siteID: string, apiURL?: string ) => {
4-
return getStore({
5-
deployID,
6-
siteID,
7-
token,
8-
apiURL
9-
})
6+
const storeAuth = {deployID, siteID, token, apiURL}
7+
// apiURL uses default on build so we only preserve context if apiURL is set within handler function
8+
if ( apiURL ){
9+
process.env.NETLIFY_BLOBS_CONTEXT = btoa(JSON.stringify(storeAuth))
10+
}
11+
return getStore(storeAuth)
1012
}
1113

12-
export const isBlobStorageAvailable = async (blob) => {
14+
export const isBlobStorageAvailable = async (blob: any) => {
1315
try {
1416
await blob.get('test-blob')
1517
return true
1618
} catch {
1719
return false
1820
}
1921
}
22+
23+
/**
24+
* @netlify/blobs ATM has some limitation to keys, so we need to normalize it for now (they will be resolved so we will be able to remove this code)
25+
*/
26+
export const getNormalizedBlobKey = (key: string): string => Buffer.from(key).toString('base64url')

src/helpers/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export const PLUGIN_DIR = resolve(`${MODULE_DIR}../..`)
66
export const TASK_DIR = process.cwd()
77

88
export const BUILD_DIR = `${TASK_DIR}/.netlify/.next`
9+
export const SERVER_APP_DIR = `${BUILD_DIR}/server/app`
10+
export const STANDALONE_BUILD_DIR = `${BUILD_DIR}/standalone`
11+
export const STANDALONE_APP_DIR = `${STANDALONE_BUILD_DIR}/.next/server/app`
912

1013
export const FUNCTIONS_DIR = `${TASK_DIR}/.netlify/functions-internal`
1114
export const EDGE_FUNCTIONS_DIR = `${TASK_DIR}/.netlify/edge-functions`

src/helpers/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NetlifyPluginOptions, NetlifyPluginConstants } from '@netlify/build'
2+
import type { NextConfigComplete } from 'next/dist/server/config-shared.js'
23

34

45
type NetlifyPluginOptionsWithFlags = NetlifyPluginOptions & { featureFlags?: Record<string, unknown> }
@@ -10,4 +11,13 @@ type EnhancedNetlifyPluginConstants = NetlifyPluginConstants & {
1011

1112
export type EnhancedNetlifyPluginOptions = NetlifyPluginOptions & { constants: EnhancedNetlifyPluginConstants } & {
1213
featureFlags?: Record<string, unknown>
14+
}
15+
16+
export interface RequiredServerFiles {
17+
version?: number
18+
relativeAppDir?: string
19+
config?: NextConfigComplete
20+
appDir?: string
21+
files?: string[]
22+
ignore?: string[]
1323
}

0 commit comments

Comments
 (0)