@valencets/plugin-cloud-storage 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 valencets
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.
@@ -0,0 +1,10 @@
1
+ import type { CmsConfig } from '@valencets/cms';
2
+ import type { CloudStorageAdapter } from './storage-adapter.js';
3
+ export interface CloudStoragePluginOptions {
4
+ readonly adapter: CloudStorageAdapter;
5
+ }
6
+ export interface CmsConfigWithStorage extends CmsConfig {
7
+ readonly storageAdapter: CloudStorageAdapter;
8
+ }
9
+ export declare function cloudStoragePlugin(opts: CloudStoragePluginOptions): (config: CmsConfig) => CmsConfigWithStorage;
10
+ //# sourceMappingURL=cloud-storage-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-storage-plugin.d.ts","sourceRoot":"","sources":["../src/cloud-storage-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAE/D,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAA;CACtC;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,QAAQ,CAAC,cAAc,EAAE,mBAAmB,CAAA;CAC7C;AAED,wBAAgB,kBAAkB,CAAE,IAAI,EAAE,yBAAyB,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,oBAAoB,CAKhH"}
@@ -0,0 +1,7 @@
1
+ export function cloudStoragePlugin(opts) {
2
+ return (config) => ({
3
+ ...config,
4
+ storageAdapter: opts.adapter
5
+ });
6
+ }
7
+ //# sourceMappingURL=cloud-storage-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-storage-plugin.js","sourceRoot":"","sources":["../src/cloud-storage-plugin.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,kBAAkB,CAAE,IAA+B;IACjE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAClB,GAAG,MAAM;QACT,cAAc,EAAE,IAAI,CAAC,OAAO;KAC7B,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { createS3Adapter } from './s3-adapter.js';
2
+ export type { S3AdapterOptions, S3Credentials } from './s3-adapter.js';
3
+ export { cloudStoragePlugin } from './cloud-storage-plugin.js';
4
+ export type { CloudStoragePluginOptions, CmsConfigWithStorage } from './cloud-storage-plugin.js';
5
+ export type { CloudStorageAdapter, StorageError } from './storage-adapter.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,YAAY,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChG,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ // @valencets/plugin-cloud-storage — S3-compatible cloud storage adapter for Valence CMS
2
+ export { createS3Adapter } from './s3-adapter.js';
3
+ export { cloudStoragePlugin } from './cloud-storage-plugin.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wFAAwF;AAExF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA"}
@@ -0,0 +1,14 @@
1
+ import type { CloudStorageAdapter } from './storage-adapter.js';
2
+ export interface S3Credentials {
3
+ readonly accessKeyId: string;
4
+ readonly secretAccessKey: string;
5
+ }
6
+ export interface S3AdapterOptions {
7
+ readonly bucket: string;
8
+ readonly region: string;
9
+ readonly credentials: S3Credentials;
10
+ readonly prefix?: string | undefined;
11
+ readonly publicUrl?: string | undefined;
12
+ }
13
+ export declare function createS3Adapter(opts: S3AdapterOptions): CloudStorageAdapter;
14
+ //# sourceMappingURL=s3-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3-adapter.d.ts","sourceRoot":"","sources":["../src/s3-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,sBAAsB,CAAA;AAE7E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;CACjC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAA;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACxC;AAiBD,wBAAgB,eAAe,CAAE,IAAI,EAAE,gBAAgB,GAAG,mBAAmB,CAgD5E"}
@@ -0,0 +1,55 @@
1
+ import { ResultAsync } from '@valencets/resultkit';
2
+ import { S3Client, PutObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3';
3
+ function buildKey(key, prefix) {
4
+ const segments = key.split('/').filter(s => s !== '..' && s !== '.');
5
+ const sanitized = segments.join('/');
6
+ return prefix !== undefined && prefix !== '' ? `${prefix}/${sanitized}` : sanitized;
7
+ }
8
+ function buildDefaultUrl(key, bucket, region) {
9
+ return `https://${bucket}.s3.${region}.amazonaws.com/${key}`;
10
+ }
11
+ function buildPublicUrl(key, publicUrl) {
12
+ const base = publicUrl.replace(/\/$/, '');
13
+ return `${base}/${key}`;
14
+ }
15
+ export function createS3Adapter(opts) {
16
+ const client = new S3Client({
17
+ region: opts.region,
18
+ credentials: {
19
+ accessKeyId: opts.credentials.accessKeyId,
20
+ secretAccessKey: opts.credentials.secretAccessKey
21
+ }
22
+ });
23
+ return {
24
+ upload(key, buffer, contentType) {
25
+ const fullKey = buildKey(key, opts.prefix);
26
+ const command = new PutObjectCommand({
27
+ Bucket: opts.bucket,
28
+ Key: fullKey,
29
+ Body: buffer,
30
+ ContentType: contentType
31
+ });
32
+ return ResultAsync.fromPromise(client.send(command).then(() => fullKey), (e) => ({
33
+ message: e instanceof Error ? e.message : 'Upload failed'
34
+ }));
35
+ },
36
+ delete(key) {
37
+ const fullKey = buildKey(key, opts.prefix);
38
+ const command = new DeleteObjectCommand({
39
+ Bucket: opts.bucket,
40
+ Key: fullKey
41
+ });
42
+ return ResultAsync.fromPromise(client.send(command).then(() => undefined), (e) => ({
43
+ message: e instanceof Error ? e.message : 'Delete failed'
44
+ }));
45
+ },
46
+ getUrl(key) {
47
+ const fullKey = buildKey(key, opts.prefix);
48
+ if (opts.publicUrl !== undefined && opts.publicUrl !== '') {
49
+ return buildPublicUrl(fullKey, opts.publicUrl);
50
+ }
51
+ return buildDefaultUrl(fullKey, opts.bucket, opts.region);
52
+ }
53
+ };
54
+ }
55
+ //# sourceMappingURL=s3-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3-adapter.js","sourceRoot":"","sources":["../src/s3-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAgBpF,SAAS,QAAQ,CAAE,GAAW,EAAE,MAA0B;IACxD,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;IACpE,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACpC,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACrF,CAAC;AAED,SAAS,eAAe,CAAE,GAAW,EAAE,MAAc,EAAE,MAAc;IACnE,OAAO,WAAW,MAAM,OAAO,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAC9D,CAAC;AAED,SAAS,cAAc,CAAE,GAAW,EAAE,SAAiB;IACrD,MAAM,IAAI,G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AC,WAAW,CAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAiB,CAAC,EAClD,CAAC,CAAU,EAAgB,EAAE,CAAC,CAAC;gBAC7B,OAAO,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAC1D,CAAC,CACH,CAAA;QACH,CAAC;QAED,MAAM,CAAE,GAAW;YACjB,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;YAC1C,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,EAAE,EAAE,CAAC;gBAC1D,OAAO,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;YAChD,CAAC;YACD,OAAO,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QAC3D,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ResultAsync } from '@valencets/resultkit';
2
+ export interface StorageError {
3
+ readonly message: string;
4
+ }
5
+ export interface CloudStorageAdapter {
6
+ upload(key: string, buffer: Buffer, contentType?: string): ResultAsync<string, StorageError>;
7
+ delete(key: string): ResultAsync<void, StorageError>;
8
+ getUrl(key: string): string;
9
+ }
10
+ //# sourceMappingURL=storage-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-adapter.d.ts","sourceRoot":"","sources":["../src/storage-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IAC5F,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;IACpD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAC5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=storage-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-adapter.js","sourceRoot":"","sources":["../src/storage-adapter.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@valencets/plugin-cloud-storage",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "peerDependencies": {
14
+ "@valencets/cms": "0.12.0"
15
+ },
16
+ "dependencies": {
17
+ "@aws-sdk/client-s3": "^3.782.0",
18
+ "@valencets/resultkit": "^0.2.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^25.4.0",
22
+ "typescript": "^5.9.3",
23
+ "vitest": "^4.0.18",
24
+ "@valencets/cms": "0.12.0"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "engines": {
30
+ "node": ">=22"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "test": "vitest run"
35
+ }
36
+ }