@noy-db/as-aws-s3 0.2.0-pre.30 → 0.3.0-pre.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/package.json +6 -13
- package/dist/index.cjs +0 -127
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noy-db/as-aws-s3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-pre.1",
|
|
4
4
|
"description": "AWS S3 object projection for noy-db — serve blob bytes directly from S3/CDN (presigned or public), outside the encrypted store",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "vLannaAi <vicio@lanna.ai>",
|
|
@@ -17,17 +17,10 @@
|
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"default": "./dist/index.js"
|
|
23
|
-
},
|
|
24
|
-
"require": {
|
|
25
|
-
"types": "./dist/index.d.cts",
|
|
26
|
-
"default": "./dist/index.cjs"
|
|
27
|
-
}
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
28
22
|
}
|
|
29
23
|
},
|
|
30
|
-
"main": "./dist/index.cjs",
|
|
31
24
|
"module": "./dist/index.js",
|
|
32
25
|
"types": "./dist/index.d.ts",
|
|
33
26
|
"files": [
|
|
@@ -36,17 +29,17 @@
|
|
|
36
29
|
"LICENSE"
|
|
37
30
|
],
|
|
38
31
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
32
|
+
"node": ">=22.0.0"
|
|
40
33
|
},
|
|
41
34
|
"peerDependencies": {
|
|
42
35
|
"@aws-sdk/client-s3": "^3.0.0",
|
|
43
36
|
"@aws-sdk/s3-request-presigner": "^3.0.0",
|
|
44
|
-
"@noy-db/hub": "0.
|
|
37
|
+
"@noy-db/hub": "0.3.0-pre.1"
|
|
45
38
|
},
|
|
46
39
|
"devDependencies": {
|
|
47
40
|
"@aws-sdk/client-s3": "^3.0.0",
|
|
48
41
|
"@aws-sdk/s3-request-presigner": "^3.0.0",
|
|
49
|
-
"@noy-db/hub": "0.
|
|
42
|
+
"@noy-db/hub": "0.3.0-pre.1"
|
|
50
43
|
},
|
|
51
44
|
"keywords": [
|
|
52
45
|
"noy-db",
|
package/dist/index.cjs
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
asAwsS3: () => asAwsS3
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
27
|
-
var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
28
|
-
function isNotFound(err) {
|
|
29
|
-
const e = err;
|
|
30
|
-
return e?.name === "NotFound" || e?.name === "NoSuchKey" || e?.$metadata?.httpStatusCode === 404;
|
|
31
|
-
}
|
|
32
|
-
function asAwsS3(options) {
|
|
33
|
-
const { bucket } = options;
|
|
34
|
-
const prefix = options.prefix ? options.prefix.replace(/\/+$/, "") + "/" : "";
|
|
35
|
-
const region = options.region ?? "us-east-1";
|
|
36
|
-
const client = options.client ?? new import_client_s3.S3Client({ region });
|
|
37
|
-
const presignClient = client;
|
|
38
|
-
const defaultExpiry = options.defaultExpiresInSeconds ?? 900;
|
|
39
|
-
const publicBase = (options.baseUrl ?? `https://${bucket}.s3.${region}.amazonaws.com`).replace(/\/+$/, "");
|
|
40
|
-
const fullKey = (key) => `${prefix}${key}`;
|
|
41
|
-
return {
|
|
42
|
-
name: "aws-s3",
|
|
43
|
-
async putObject(key, bytes, opts) {
|
|
44
|
-
await client.send(
|
|
45
|
-
new import_client_s3.PutObjectCommand({
|
|
46
|
-
Bucket: bucket,
|
|
47
|
-
Key: fullKey(key),
|
|
48
|
-
Body: bytes,
|
|
49
|
-
ContentType: opts.contentType,
|
|
50
|
-
...opts.public ? { ACL: "public-read" } : {},
|
|
51
|
-
...opts.userMeta ? { Metadata: opts.userMeta } : {}
|
|
52
|
-
})
|
|
53
|
-
);
|
|
54
|
-
},
|
|
55
|
-
async getObject(key) {
|
|
56
|
-
try {
|
|
57
|
-
const r = await client.send(new import_client_s3.GetObjectCommand({ Bucket: bucket, Key: fullKey(key) }));
|
|
58
|
-
if (!r.Body) return null;
|
|
59
|
-
return await r.Body.transformToByteArray();
|
|
60
|
-
} catch (err) {
|
|
61
|
-
if (isNotFound(err)) return null;
|
|
62
|
-
throw err;
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
async deleteObject(key) {
|
|
66
|
-
await client.send(new import_client_s3.DeleteObjectCommand({ Bucket: bucket, Key: fullKey(key) }));
|
|
67
|
-
},
|
|
68
|
-
async headObject(key) {
|
|
69
|
-
try {
|
|
70
|
-
const r = await client.send(new import_client_s3.HeadObjectCommand({ Bucket: bucket, Key: fullKey(key) }));
|
|
71
|
-
return {
|
|
72
|
-
size: r.ContentLength ?? 0,
|
|
73
|
-
...r.ContentType ? { contentType: r.ContentType } : {},
|
|
74
|
-
...r.ETag ? { etag: r.ETag } : {},
|
|
75
|
-
...r.LastModified ? { lastModified: r.LastModified.toISOString() } : {},
|
|
76
|
-
...r.Metadata && Object.keys(r.Metadata).length ? { userMeta: r.Metadata } : {}
|
|
77
|
-
};
|
|
78
|
-
} catch (err) {
|
|
79
|
-
if (isNotFound(err)) return null;
|
|
80
|
-
throw err;
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
async objectUrl(key, opts) {
|
|
84
|
-
return await (0, import_s3_request_presigner.getSignedUrl)(presignClient, new import_client_s3.GetObjectCommand({ Bucket: bucket, Key: fullKey(key) }), {
|
|
85
|
-
expiresIn: opts?.expiresInSeconds ?? defaultExpiry
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
async putUrl(key, opts) {
|
|
89
|
-
return await (0, import_s3_request_presigner.getSignedUrl)(
|
|
90
|
-
presignClient,
|
|
91
|
-
new import_client_s3.PutObjectCommand({ Bucket: bucket, Key: fullKey(key), ContentType: opts.contentType }),
|
|
92
|
-
{ expiresIn: opts.expiresInSeconds ?? defaultExpiry }
|
|
93
|
-
);
|
|
94
|
-
},
|
|
95
|
-
async listPrefix(listPrefixArg) {
|
|
96
|
-
const out = [];
|
|
97
|
-
let token;
|
|
98
|
-
do {
|
|
99
|
-
const r = await client.send(
|
|
100
|
-
new import_client_s3.ListObjectsV2Command({ Bucket: bucket, Prefix: fullKey(listPrefixArg), ContinuationToken: token })
|
|
101
|
-
);
|
|
102
|
-
for (const obj of r.Contents ?? []) {
|
|
103
|
-
if (!obj.Key) continue;
|
|
104
|
-
const logicalKey = prefix && obj.Key.startsWith(prefix) ? obj.Key.slice(prefix.length) : obj.Key;
|
|
105
|
-
out.push({
|
|
106
|
-
key: logicalKey,
|
|
107
|
-
meta: {
|
|
108
|
-
size: obj.Size ?? 0,
|
|
109
|
-
...obj.ETag ? { etag: obj.ETag } : {},
|
|
110
|
-
...obj.LastModified ? { lastModified: obj.LastModified.toISOString() } : {}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
token = r.IsTruncated ? r.NextContinuationToken : void 0;
|
|
115
|
-
} while (token);
|
|
116
|
-
return out;
|
|
117
|
-
},
|
|
118
|
-
publicUrl(key) {
|
|
119
|
-
return `${publicBase}/${fullKey(key)}`;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
124
|
-
0 && (module.exports = {
|
|
125
|
-
asAwsS3
|
|
126
|
-
});
|
|
127
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@noy-db/as-aws-s3` — an {@link ObjectProjection} backed by AWS S3.\n *\n * Where `@noy-db/to-aws-s3` is a `to-*` store (ciphertext envelopes in/out, the\n * zero-knowledge backend), this is an `as-*` **projection**: it holds blob bytes\n * as **native, directly-consumable S3 objects** so they can be served straight\n * from S3/CDN — presigned (time-limited, private) or public — and processed by\n * AWS-native tooling. It sees **raw bytes** and lives **outside** the\n * zero-knowledge guarantee; wiring it to a blob field is a deliberate opt-in.\n *\n * @example\n * ```ts\n * import { asAwsS3 } from '@noy-db/as-aws-s3'\n * const objects = asAwsS3({ bucket: 'acme-public-assets', region: 'eu-west-1' })\n * await objects.putObject('logos/acme.png', bytes, { contentType: 'image/png', public: true })\n * const url = objects.publicUrl('logos/acme.png') // stable CDN/S3 URL\n * const dl = await objects.objectUrl('logos/acme.png') // presigned GET\n * const up = await objects.putUrl('videos/x.mp4', { contentType: 'video/mp4' }) // presigned PUT\n * ```\n */\nimport type {\n ObjectProjection,\n ObjectMeta,\n PutObjectOptions,\n ObjectUrlOptions,\n PutUrlOptions,\n} from '@noy-db/hub'\nimport {\n S3Client,\n PutObjectCommand,\n GetObjectCommand,\n DeleteObjectCommand,\n HeadObjectCommand,\n ListObjectsV2Command,\n} from '@aws-sdk/client-s3'\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner'\n\nexport interface AsAwsS3Options {\n /** Target bucket. */\n bucket: string\n /** Key prefix (folder). A trailing slash is added if missing. */\n prefix?: string\n /** AWS region. Default `us-east-1`. */\n region?: string\n /** Pre-built `S3Client` to share (overrides `region`). */\n client?: S3Client\n /**\n * Base URL for `publicUrl()` — a CDN origin or the bucket's website/vhost\n * URL. Defaults to the virtual-hosted S3 URL\n * (`https://{bucket}.s3.{region}.amazonaws.com`).\n */\n baseUrl?: string\n /** Default presigned-URL TTL (seconds). Default 900 (15 min). */\n defaultExpiresInSeconds?: number\n}\n\n/** The projection plus an S3-specific stable-public-URL helper. */\nexport type AsAwsS3Projection = ObjectProjection & {\n /** A stable, non-expiring URL for a **public** object (CDN/vhost). */\n publicUrl(key: string): string\n}\n\nfunction isNotFound(err: unknown): boolean {\n const e = err as { name?: string; $metadata?: { httpStatusCode?: number } }\n return e?.name === 'NotFound' || e?.name === 'NoSuchKey' || e?.$metadata?.httpStatusCode === 404\n}\n\nexport function asAwsS3(options: AsAwsS3Options): AsAwsS3Projection {\n const { bucket } = options\n const prefix = options.prefix ? options.prefix.replace(/\\/+$/, '') + '/' : ''\n const region = options.region ?? 'us-east-1'\n const client = options.client ?? new S3Client({ region })\n // getSignedUrl types its client against its own @smithy/types copy; when the\n // installed @aws-sdk/client-s3 and s3-request-presigner resolve to different\n // minor versions, S3Client and the expected Client diverge only on a private\n // `handlers` field. Runtime is identical — cast across the version skew.\n const presignClient = client as unknown as Parameters<typeof getSignedUrl>[0]\n const defaultExpiry = options.defaultExpiresInSeconds ?? 900\n const publicBase = (options.baseUrl ?? `https://${bucket}.s3.${region}.amazonaws.com`).replace(/\\/+$/, '')\n const fullKey = (key: string): string => `${prefix}${key}`\n\n return {\n name: 'aws-s3',\n\n async putObject(key: string, bytes: Uint8Array, opts: PutObjectOptions): Promise<void> {\n await client.send(\n new PutObjectCommand({\n Bucket: bucket,\n Key: fullKey(key),\n Body: bytes,\n ContentType: opts.contentType,\n ...(opts.public ? { ACL: 'public-read' as const } : {}),\n ...(opts.userMeta ? { Metadata: opts.userMeta } : {}),\n }),\n )\n },\n\n async getObject(key: string): Promise<Uint8Array | null> {\n try {\n const r = await client.send(new GetObjectCommand({ Bucket: bucket, Key: fullKey(key) }))\n if (!r.Body) return null\n return await r.Body.transformToByteArray()\n } catch (err) {\n if (isNotFound(err)) return null\n throw err\n }\n },\n\n async deleteObject(key: string): Promise<void> {\n await client.send(new DeleteObjectCommand({ Bucket: bucket, Key: fullKey(key) }))\n },\n\n async headObject(key: string): Promise<ObjectMeta | null> {\n try {\n const r = await client.send(new HeadObjectCommand({ Bucket: bucket, Key: fullKey(key) }))\n return {\n size: r.ContentLength ?? 0,\n ...(r.ContentType ? { contentType: r.ContentType } : {}),\n ...(r.ETag ? { etag: r.ETag } : {}),\n ...(r.LastModified ? { lastModified: r.LastModified.toISOString() } : {}),\n ...(r.Metadata && Object.keys(r.Metadata).length ? { userMeta: r.Metadata } : {}),\n }\n } catch (err) {\n if (isNotFound(err)) return null\n throw err\n }\n },\n\n async objectUrl(key: string, opts?: ObjectUrlOptions): Promise<string> {\n // Always a presigned GET — works for private and public objects alike.\n // For a stable public URL, use `publicUrl()`.\n return await getSignedUrl(presignClient, new GetObjectCommand({ Bucket: bucket, Key: fullKey(key) }), {\n expiresIn: opts?.expiresInSeconds ?? defaultExpiry,\n })\n },\n\n async putUrl(key: string, opts: PutUrlOptions): Promise<string> {\n return await getSignedUrl(\n presignClient,\n new PutObjectCommand({ Bucket: bucket, Key: fullKey(key), ContentType: opts.contentType }),\n { expiresIn: opts.expiresInSeconds ?? defaultExpiry },\n )\n },\n\n async listPrefix(listPrefixArg: string) {\n const out: Array<{ key: string; meta: ObjectMeta }> = []\n let token: string | undefined\n do {\n const r = await client.send(\n new ListObjectsV2Command({ Bucket: bucket, Prefix: fullKey(listPrefixArg), ContinuationToken: token }),\n )\n for (const obj of r.Contents ?? []) {\n if (!obj.Key) continue\n // Strip the configured prefix so callers see logical keys.\n const logicalKey = prefix && obj.Key.startsWith(prefix) ? obj.Key.slice(prefix.length) : obj.Key\n out.push({\n key: logicalKey,\n meta: {\n size: obj.Size ?? 0,\n ...(obj.ETag ? { etag: obj.ETag } : {}),\n ...(obj.LastModified ? { lastModified: obj.LastModified.toISOString() } : {}),\n },\n })\n }\n token = r.IsTruncated ? r.NextContinuationToken : undefined\n } while (token)\n return out\n },\n\n publicUrl(key: string): string {\n return `${publicBase}/${fullKey(key)}`\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,uBAOO;AACP,kCAA6B;AA2B7B,SAAS,WAAW,KAAuB;AACzC,QAAM,IAAI;AACV,SAAO,GAAG,SAAS,cAAc,GAAG,SAAS,eAAe,GAAG,WAAW,mBAAmB;AAC/F;AAEO,SAAS,QAAQ,SAA4C;AAClE,QAAM,EAAE,OAAO,IAAI;AACnB,QAAM,SAAS,QAAQ,SAAS,QAAQ,OAAO,QAAQ,QAAQ,EAAE,IAAI,MAAM;AAC3E,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,SAAS,QAAQ,UAAU,IAAI,0BAAS,EAAE,OAAO,CAAC;AAKxD,QAAM,gBAAgB;AACtB,QAAM,gBAAgB,QAAQ,2BAA2B;AACzD,QAAM,cAAc,QAAQ,WAAW,WAAW,MAAM,OAAO,MAAM,kBAAkB,QAAQ,QAAQ,EAAE;AACzG,QAAM,UAAU,CAAC,QAAwB,GAAG,MAAM,GAAG,GAAG;AAExD,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,MAAM,UAAU,KAAa,OAAmB,MAAuC;AACrF,YAAM,OAAO;AAAA,QACX,IAAI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AAwB;AAAA,MACpD,SAAS;AACT,aAAO;AAAA,IACT;AAAA,IAEA,UAAU,KAAqB;AAC7B,aAAO,GAAG,UAAU,IAAI,QAAQ,GAAG,CAAC;AAAA,IACtC;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ObjectProjection } from '@noy-db/hub';
|
|
2
|
-
import { S3Client } from '@aws-sdk/client-s3';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* `@noy-db/as-aws-s3` — an {@link ObjectProjection} backed by AWS S3.
|
|
6
|
-
*
|
|
7
|
-
* Where `@noy-db/to-aws-s3` is a `to-*` store (ciphertext envelopes in/out, the
|
|
8
|
-
* zero-knowledge backend), this is an `as-*` **projection**: it holds blob bytes
|
|
9
|
-
* as **native, directly-consumable S3 objects** so they can be served straight
|
|
10
|
-
* from S3/CDN — presigned (time-limited, private) or public — and processed by
|
|
11
|
-
* AWS-native tooling. It sees **raw bytes** and lives **outside** the
|
|
12
|
-
* zero-knowledge guarantee; wiring it to a blob field is a deliberate opt-in.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { asAwsS3 } from '@noy-db/as-aws-s3'
|
|
17
|
-
* const objects = asAwsS3({ bucket: 'acme-public-assets', region: 'eu-west-1' })
|
|
18
|
-
* await objects.putObject('logos/acme.png', bytes, { contentType: 'image/png', public: true })
|
|
19
|
-
* const url = objects.publicUrl('logos/acme.png') // stable CDN/S3 URL
|
|
20
|
-
* const dl = await objects.objectUrl('logos/acme.png') // presigned GET
|
|
21
|
-
* const up = await objects.putUrl('videos/x.mp4', { contentType: 'video/mp4' }) // presigned PUT
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
interface AsAwsS3Options {
|
|
26
|
-
/** Target bucket. */
|
|
27
|
-
bucket: string;
|
|
28
|
-
/** Key prefix (folder). A trailing slash is added if missing. */
|
|
29
|
-
prefix?: string;
|
|
30
|
-
/** AWS region. Default `us-east-1`. */
|
|
31
|
-
region?: string;
|
|
32
|
-
/** Pre-built `S3Client` to share (overrides `region`). */
|
|
33
|
-
client?: S3Client;
|
|
34
|
-
/**
|
|
35
|
-
* Base URL for `publicUrl()` — a CDN origin or the bucket's website/vhost
|
|
36
|
-
* URL. Defaults to the virtual-hosted S3 URL
|
|
37
|
-
* (`https://{bucket}.s3.{region}.amazonaws.com`).
|
|
38
|
-
*/
|
|
39
|
-
baseUrl?: string;
|
|
40
|
-
/** Default presigned-URL TTL (seconds). Default 900 (15 min). */
|
|
41
|
-
defaultExpiresInSeconds?: number;
|
|
42
|
-
}
|
|
43
|
-
/** The projection plus an S3-specific stable-public-URL helper. */
|
|
44
|
-
type AsAwsS3Projection = ObjectProjection & {
|
|
45
|
-
/** A stable, non-expiring URL for a **public** object (CDN/vhost). */
|
|
46
|
-
publicUrl(key: string): string;
|
|
47
|
-
};
|
|
48
|
-
declare function asAwsS3(options: AsAwsS3Options): AsAwsS3Projection;
|
|
49
|
-
|
|
50
|
-
export { type AsAwsS3Options, type AsAwsS3Projection, asAwsS3 };
|