@easy-cms/storage-netlify-blobs 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +33 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kanawoot K.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @easy-cms/storage-netlify-blobs
|
|
2
|
+
|
|
3
|
+
Netlify Blobs storage for Easy CMS uploads, for sites on Netlify (whose disk doesn't keep files). Part of [Easy CMS](https://github.com/maritonx/easy-cms), the embedded, code-first headless CMS for Nuxt and Next.js.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @easy-cms/storage-netlify-blobs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or `pnpm add`, `yarn add` or `bun add`.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
On Netlify, Blobs need no setup: the store is created on first use.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { netlifyBlobsStorage } from '@easy-cms/storage-netlify-blobs'
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
// …
|
|
22
|
+
upload: { storage: netlifyBlobsStorage() }, // files are served through /api/cms/media/file/…
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Outside Netlify's runtime (a script, another host), pass `siteID` and a personal access `token`.
|
|
27
|
+
|
|
28
|
+
## Links
|
|
29
|
+
|
|
30
|
+
[Uploads](https://maritonx.github.io/easy-cms/guide/uploads) · [One-click deploy](https://maritonx.github.io/easy-cms/guide/one-click-deploy) · [Documentation](https://maritonx.github.io/easy-cms/) ([ภาษาไทย](https://maritonx.github.io/easy-cms/th/)) · [GitHub](https://github.com/maritonx/easy-cms)
|
|
31
|
+
|
|
32
|
+
MIT License
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StorageAdapter } from '@easy-cms/core';
|
|
2
|
+
|
|
3
|
+
interface NetlifyBlobsStorageOptions {
|
|
4
|
+
/** The blob store's name. Default `easy-cms-uploads`. */
|
|
5
|
+
readonly name?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Outside Netlify's runtime (scripts, other hosts): the site and a personal access token.
|
|
8
|
+
* On Netlify they come from the environment.
|
|
9
|
+
*/
|
|
10
|
+
readonly siteID?: string;
|
|
11
|
+
readonly token?: string;
|
|
12
|
+
/** For tests: a local blobs server. */
|
|
13
|
+
readonly edgeURL?: string;
|
|
14
|
+
readonly uncachedEdgeURL?: string;
|
|
15
|
+
readonly apiURL?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Stores uploaded files in Netlify Blobs, for sites on Netlify (whose disk doesn't keep files).
|
|
19
|
+
* Files are served through the REST API (`<api>/media/file/<key>`).
|
|
20
|
+
*/
|
|
21
|
+
declare function netlifyBlobsStorage(options?: NetlifyBlobsStorageOptions): StorageAdapter;
|
|
22
|
+
|
|
23
|
+
export { type NetlifyBlobsStorageOptions, netlifyBlobsStorage };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { getStore } from "@netlify/blobs";
|
|
3
|
+
function netlifyBlobsStorage(options = {}) {
|
|
4
|
+
const open = () => getStore({
|
|
5
|
+
name: options.name ?? "easy-cms-uploads",
|
|
6
|
+
// Uploads are read right after they are written: strong consistency.
|
|
7
|
+
consistency: "strong",
|
|
8
|
+
...options.siteID ? { siteID: options.siteID } : {},
|
|
9
|
+
...options.token ? { token: options.token } : {},
|
|
10
|
+
...options.edgeURL ? { edgeURL: options.edgeURL } : {},
|
|
11
|
+
...options.uncachedEdgeURL ? { uncachedEdgeURL: options.uncachedEdgeURL } : {},
|
|
12
|
+
...options.apiURL ? { apiURL: options.apiURL } : {}
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
name: "netlify-blobs",
|
|
16
|
+
async put(key, data, { contentType }) {
|
|
17
|
+
const bytes = new Uint8Array(data);
|
|
18
|
+
await open().set(key, bytes.buffer, { metadata: { contentType } });
|
|
19
|
+
},
|
|
20
|
+
async get(key) {
|
|
21
|
+
const found = await open().get(key, { type: "arrayBuffer" });
|
|
22
|
+
if (found === null) return null;
|
|
23
|
+
const body = new Uint8Array(found);
|
|
24
|
+
return { body, size: body.byteLength };
|
|
25
|
+
},
|
|
26
|
+
async delete(key) {
|
|
27
|
+
await open().delete(key);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
netlifyBlobsStorage
|
|
33
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@easy-cms/storage-netlify-blobs",
|
|
3
|
+
"version": "0.36.0",
|
|
4
|
+
"description": "Netlify Blobs upload storage for Easy CMS",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@netlify/blobs": "^11.1.3"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@easy-cms/core": "^0.36.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@easy-cms/core": "^0.36.1"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.12"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/maritonx/easy-cms.git",
|
|
36
|
+
"directory": "packages/storage-netlify-blobs"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"easy-cms",
|
|
40
|
+
"storage",
|
|
41
|
+
"uploads",
|
|
42
|
+
"netlify",
|
|
43
|
+
"blobs"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"test": "vitest run"
|
|
49
|
+
}
|
|
50
|
+
}
|