Skip to content

Commit 28eda05

Browse files
committed
feat: update blob
1 parent de028c6 commit 28eda05

File tree

6 files changed

+81
-146
lines changed

6 files changed

+81
-146
lines changed

package-lock.json

Lines changed: 32 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"homepage": "https://github.com/netlify/next-runtime-minimal#readme",
3636
"dependencies": {
3737
"@fastly/http-compute-js": "github:orinokai/http-compute-js",
38-
"@netlify/blobs": "^1.6.0",
38+
"@netlify/blobs": "^2.2.0",
3939
"@netlify/build": "^29.20.6",
4040
"@netlify/functions": "^2.0.1",
4141
"@vercel/nft": "^0.24.3",

src/helpers/blobs.cts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// eslint-disable-next-line n/no-missing-import
2+
import { Blobs } from '@netlify/blobs'
3+
4+
type BlobsInit = ConstructorParameters<typeof Blobs>[0]
5+
let blobsInit: BlobsInit;
6+
7+
// eslint-disable-next-line max-params
8+
export const netliBlob = ( token: string, context: string, siteID: string, contextURL?: string, apiURL?: string ) => {
9+
blobsInit = {authentication: ({apiURL, token} || {contextURL, token}), context, siteID}
10+
return new Blobs(blobsInit)
11+
}
12+
13+
export const getBlobInit = () => blobsInit
14+
15+
export const isBlobStorageAvailable = async (blob: Blobs) => {
16+
try {
17+
await blob.get('test')
18+
return true
19+
} catch {
20+
return false
21+
}
22+
}

src/helpers/blobs.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/helpers/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { NetlifyPluginOptions, NetlifyPluginConstants } from '@netlify/build'
2+
3+
4+
type NetlifyPluginOptionsWithFlags = NetlifyPluginOptions & { featureFlags?: Record<string, unknown> }
5+
6+
type EnhancedNetlifyPluginConstants = NetlifyPluginConstants & {
7+
NETLIFY_API_HOST: string
8+
NETLIFY_API_TOKEN: string
9+
}
10+
11+
export type EnhancedNetlifyPluginOptions = NetlifyPluginOptions & { constants: EnhancedNetlifyPluginConstants } & {
12+
featureFlags?: Record<string, unknown>
13+
}

src/index.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
import type { NetlifyPluginOptions, NetlifyPluginConstants } from '@netlify/build'
2-
1+
import { netliBlob, isBlobStorageAvailable } from './helpers/blobs.cjs'
32
import { setBuildConfig } from './helpers/config.js'
43
import { publishStaticAssets, stashBuildOutput, storePrerenderedContent } from './helpers/files.js'
54
import { createEdgeHandler, createServerHandler } from './helpers/functions.js'
6-
7-
type NetlifyPluginOptionsWithFlags = NetlifyPluginOptions & {
8-
featureFlags?: Record<string, unknown>
9-
}
5+
import { EnhancedNetlifyPluginOptions } from './helpers/types.js'
106

117
export const onPreBuild = () => {
128
setBuildConfig()
139
}
1410

15-
export const onBuild = async ({ constants }: NetlifyPluginOptionsWithFlags) => {
11+
export const onBuild = async ({ constants }: EnhancedNetlifyPluginOptions) => {
12+
const testingDeployId = ''
13+
const context = testingDeployId || `deploy:${process.env.DEPLOY_ID}`
14+
const { NETLIFY_API_HOST, NETLIFY_API_TOKEN, SITE_ID } = constants
15+
16+
const testBlobStorage = await netliBlob(NETLIFY_API_TOKEN, context, SITE_ID, NETLIFY_API_HOST)
17+
// const blob = testBlobStorage && (await isBlobStorageAvailable(testBlobStorage)) ? testBlobStorage : undefined
18+
19+
console.log('get blob storage', { testBlobStorage, available: await isBlobStorageAvailable(testBlobStorage) })
20+
1621
await stashBuildOutput(constants)
1722

1823
return Promise.all([
1924
publishStaticAssets(constants),
25+
2026
storePrerenderedContent(),
2127
createServerHandler(),
2228
createEdgeHandler(),

0 commit comments

Comments
 (0)