@prenta/platform-aws 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,181 @@
1
+ # @actuate-media/platform-aws
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5eea995: Product rename: ActuateCMS is now **Prenta**. Every package moves from the
8
+ `@actuate-media/*` scope to `@prenta/*` with simplified names (`@prenta/core`,
9
+ `@prenta/admin`, `create-prenta`), and version numbers continue from where the
10
+ old scope left off.
11
+
12
+ This is a clean break — no backwards-compat aliases:
13
+ - **npm packages**: `@actuate-media/cms-core` → `@prenta/core`,
14
+ `@actuate-media/cms-admin` → `@prenta/admin`, all other packages keep their
15
+ suffix under `@prenta/*`. `create-actuate-cms` → `create-prenta`
16
+ (`npm create prenta`), `create-actuate-astro` → `create-prenta-astro`.
17
+ CLI bins: `actuate`/`actuate-cms` → `prenta`/`prenta-cms`; `actuate-mcp` →
18
+ `prenta-mcp`.
19
+ - **Database**: migration `0012_rename_to_prenta` renames all 36 `actuate_*`
20
+ tables to `prenta_*` in place (plus prefixed constraints, indexes, and
21
+ sequences). Run `prisma migrate deploy` when upgrading.
22
+ - **Runtime identifiers**: `getActuateConfig` → `getPrentaConfig`,
23
+ `handleActuateAPI` → `handlePrentaAPI`, `ActuateClient` → `PrentaClient`,
24
+ `ActuateDB` → `PrentaDB`, config file `actuate.config.ts` →
25
+ `prenta.config.ts`, CSS scopes `.actuate-admin`/`.actuate-canvas` →
26
+ `.prenta-admin`/`.prenta-canvas`, preview protocol `actuate-preview:*` →
27
+ `prenta-preview:*`, webhook headers `X-Actuate-*` → `X-Prenta-*`, session
28
+ cookie `actuate_session` → `prenta_session`, env vars `ACTUATE_*` →
29
+ `PRENTA_*`, purge route `/api/actuate/purge` → `/api/prenta/purge`.
30
+ - **Sessions and webhooks**: all sessions reset on upgrade (cookie + JWT issuer
31
+ changed); webhook consumers must re-verify signatures against the new
32
+ `X-Prenta-*` headers.
33
+
34
+ The old `@actuate-media/*` packages are deprecated on npm and will receive no
35
+ further releases.
36
+
37
+ ## 0.1.0
38
+
39
+ ### Minor Changes
40
+
41
+ - f283357: Implement the AWS platform adapter (`aws()`) at parity with `vercel()`.
42
+
43
+ `@actuate-media/platform-aws` previously threw "not yet implemented" — which
44
+ also meant scaffolded `--platform aws` sites had **no working media storage**
45
+ (`storage: { provider: 's3' }` auto-wires to `aws().storage`). All six adapters
46
+ are now implemented:
47
+ - **Storage** — S3 (`@aws-sdk/client-s3`) with presigned URLs
48
+ (`@aws-sdk/s3-request-presigner`) and CloudFront-aware public URLs. Reads
49
+ `AWS_S3_BUCKET` / `AWS_REGION` (plus the scaffolder's `S3_*` fallback names);
50
+ credentials come from the task/instance IAM role by default.
51
+ - **Database** — RDS/Aurora Postgres via a real `pg` connection pool.
52
+ - **Cache** — ElastiCache (Redis/Valkey) via `ioredis`, with an in-memory
53
+ fallback; tag invalidation delegates to `next/cache`.
54
+ - **Email** — SES (`@aws-sdk/client-ses`), honoring reply-to/from.
55
+ - **Scheduler** — EventBridge Scheduler guidance + `generateEventBridgeConfig()`
56
+ / `toEventBridgeCron()` helpers (standard 5-field → EventBridge 6-field).
57
+ - **Rate limit** — Redis sliding-window log (ZADD/ZREMRANGEBYSCORE/ZCARD) with
58
+ an in-memory fallback.
59
+
60
+ Every AWS SDK is an optional peer dependency, dynamically imported on first use,
61
+ so installing the package pulls in nothing until an adapter runs.
62
+
63
+ The `create-actuate-cms` scaffolder now emits AWS-standard env var names
64
+ (`AWS_S3_BUCKET`, `AWS_REGION`, optional `AWS_S3_PUBLIC_URL`) for `--platform aws`
65
+ and enriches the generated AWS deployment guide (S3 IAM, EventBridge cron).
66
+
67
+ ## 0.0.13
68
+
69
+ ### Patch Changes
70
+
71
+ - 041a228: Add the MIT `license` field to every published package (previously missing) and correct `repository.url` to `github.com/actuate-media/actuatecms` (13 packages carried the wrong org).
72
+
73
+ ## 0.0.12
74
+
75
+ ### Patch Changes
76
+
77
+ - 854152d: Developer experience improvements from external-consumer feedback:
78
+ - Every published package now ships its `CHANGELOG.md` in the npm tarball, and packages that were missing a `README.md` (cli, cms-admin, cms-core, import, platform-vercel, all plugins, sections-react) now have one — so release notes and usage docs are visible on npmjs.com and in `node_modules`.
79
+ - New client-safe form validation entry point: `@actuate-media/cms-core/forms/client` exports `validateFormFieldClient()`, `validateFormValuesClient()`, visibility/conditional helpers, and the exact `FORM_EMAIL_RE` / `FORM_PHONE_RE` regexes the server enforces — zero Node dependencies, so public-site forms can mirror server rules without reimplementing them. The server validator now imports the same primitives, so client and server can never drift.
80
+
81
+ ## 0.0.11
82
+
83
+ ### Patch Changes
84
+
85
+ - b5de8dd: Fix ESM module resolution and dependency duplication issues reported during consumer integration.
86
+ - Add "default" export condition to all platform and plugin packages so they resolve correctly from require() contexts (fixes ERR_PACKAGE_PATH_NOT_EXPORTED in next.config.ts and serverless functions).
87
+ - Move @actuate-media/cms-core from direct dependencies to peerDependencies across all packages to prevent duplicate installations when consumer version ranges don't exactly match the pinned version.
88
+ - Add "prepack" lifecycle script to create-actuate-cms to guarantee dist/ is built before npm publishes the package (fixes empty dist/ in v0.4.0).
89
+
90
+ ## 0.0.10
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [54c7a3b]
95
+ - @actuate-media/cms-core@0.6.0
96
+
97
+ ## 0.0.9
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies [c08cf8b]
102
+ - Updated dependencies [80aa939]
103
+ - @actuate-media/cms-core@0.5.0
104
+
105
+ ## 0.0.8
106
+
107
+ ### Patch Changes
108
+
109
+ - Updated dependencies [f2cf7d7]
110
+ - @actuate-media/cms-core@0.4.0
111
+
112
+ ## 0.0.7
113
+
114
+ ### Patch Changes
115
+
116
+ - Updated dependencies [0621037]
117
+ - @actuate-media/cms-core@0.3.1
118
+
119
+ ## 0.0.6
120
+
121
+ ### Patch Changes
122
+
123
+ - Updated dependencies [4e3a5eb]
124
+ - @actuate-media/cms-core@0.3.0
125
+
126
+ ## 0.0.5
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies
131
+ - @actuate-media/cms-core@0.2.3
132
+
133
+ ## 0.0.4
134
+
135
+ ### Patch Changes
136
+
137
+ - Updated dependencies
138
+ - @actuate-media/cms-core@0.2.2
139
+
140
+ ## 0.0.3
141
+
142
+ ### Patch Changes
143
+
144
+ - Updated dependencies
145
+ - @actuate-media/cms-core@0.2.1
146
+
147
+ ## 0.0.2
148
+
149
+ ### Patch Changes
150
+
151
+ - 3fd38a2: Fix all 13 integration issues discovered during MaidPro.co deployment
152
+
153
+ **cms-core:**
154
+ - Add .js extensions to all ESM relative imports (58 files)
155
+ - Replace workspace:\* with versioned deps in all packages
156
+ - Add sideEffects:false for proper tree-shaking
157
+ - Subpath exports (/config, /api, /middleware, /next) avoid barrel side effects
158
+ - Stats/search routes use safeCount/safeFindMany for missing Prisma models
159
+ - Ship prisma/cms-schema.prisma with all required CMS models
160
+ - Accept both CMS_SECRET and CMS_SESSION_SECRET with clear error messages
161
+ - Fix hardcoded /admin paths in OAuth flow (now uses getAdminPath())
162
+ - Loosen withActuateCMS and createCMSMiddleware parameter types
163
+ - Auto-inject transpilePackages and serverExternalPackages in withActuateCMS
164
+ - Unify PluginDefinition with ActuatePlugin interface
165
+
166
+ **cms-admin:**
167
+ - Scope all 40+ CSS theme variables to .actuate-admin instead of :root
168
+ - ThemeProvider applies dark class to .actuate-admin, not document.documentElement
169
+ - Scaffold uses (admin)/(site) route groups for full CSS/script isolation
170
+ - Sidebar branding supports custom logo via config.admin.branding
171
+
172
+ **platform-vercel:**
173
+ - Email adapter accepts both `from` and `defaultFrom`
174
+
175
+ **All plugin/platform packages:**
176
+ - Fix ESM .js extensions in compiled output
177
+ - Replace workspace:\* with ^0.1.0 for publishable deps
178
+
179
+ - Updated dependencies [682dac7]
180
+ - Updated dependencies [3fd38a2]
181
+ - @actuate-media/cms-core@0.2.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Actuate Media
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,104 @@
1
+ # @prenta/platform-aws
2
+
3
+ AWS platform adapter for Prenta CMS. This package provides the same `PlatformAdapters` interface as `@prenta/platform-vercel` but backed by AWS-native services.
4
+
5
+ > **Status:** Available. S3 storage, RDS (Postgres), ElastiCache (Redis) cache + rate
6
+ > limiting, SES email, and EventBridge scheduling are implemented.
7
+
8
+ ## Usage
9
+
10
+ For most projects you don't call this package directly — scaffold with
11
+ `--platform aws` and `prenta.config.ts` uses the client-safe shorthand
12
+ `storage: { provider: 's3' }`, which Prenta auto-wires to this package's S3
13
+ adapter server-side (credentials come from the task/instance IAM role).
14
+
15
+ To compose the full platform explicitly (e.g. in a custom API bootstrap):
16
+
17
+ ```ts
18
+ import { aws } from '@prenta/platform-aws'
19
+
20
+ const platform = aws({
21
+ storage: { bucket: process.env.AWS_S3_BUCKET, region: process.env.AWS_REGION },
22
+ // database / cache / email / scheduler / rateLimit accept per-adapter options;
23
+ // all resolve from env + the IAM role by default.
24
+ })
25
+ ```
26
+
27
+ Every AWS SDK is an **optional peer dependency**, dynamically imported on first
28
+ use — installing this package pulls in nothing until an adapter runs. Install
29
+ only what you use (e.g. `@aws-sdk/client-s3` + `@aws-sdk/s3-request-presigner`
30
+ for storage, `pg` for RDS, `ioredis` for ElastiCache, `@aws-sdk/client-ses` for
31
+ email).
32
+
33
+ ## Service Mapping
34
+
35
+ | Adapter | Vercel Service | AWS Service | Key Differences |
36
+ | ------------ | ----------------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37
+ | Database | Neon serverless | RDS PostgreSQL / Aurora | Standard connection pool via `pg`. IAM role-based authentication instead of connection string tokens. Use RDS Proxy for connection pooling in Lambda environments. |
38
+ | Storage | Vercel Blob | S3 + CloudFront | OAC (Origin Access Control) ensures S3 objects are only accessible via CloudFront. Presigned URLs for uploads. No egress cost from S3 to CloudFront within the same region. |
39
+ | Cache | Next.js `revalidateTag` | ElastiCache Redis | Tag-based invalidation via Redis sets. Store tag → key mappings, then pipeline-delete all keys for a given tag. Use `UNLINK` for non-blocking removal. |
40
+ | Email | Resend | SES | Direct integration via `@aws-sdk/client-ses`. Requires domain verification in SES console and production access request to move out of sandbox mode. |
41
+ | Scheduler | Vercel Cron Jobs | EventBridge Scheduler → Lambda | Programmatic schedule creation via `@aws-sdk/client-scheduler`. Each schedule targets a Lambda function with a JSON payload. Supports flexible time windows, retry policies, and one-time schedules. |
42
+ | Rate Limiter | Upstash Redis | ElastiCache Redis | Sliding window implementation using Redis `MULTI`/`EXEC` with sorted sets. `ZADD` with timestamp scores, `ZREMRANGEBYSCORE` to prune expired entries, `ZCARD` to count within the current window. |
43
+
44
+ ## Deployment Strategy
45
+
46
+ ### ECS/Fargate (Recommended for Next.js)
47
+
48
+ - Container-based deployment using the Next.js standalone output mode.
49
+ - ALB (Application Load Balancer) in front of Fargate tasks for HTTPS termination.
50
+ - Auto-scaling based on CPU/memory utilization or request count.
51
+ - Suitable for long-running processes, WebSocket connections, and ISR revalidation.
52
+
53
+ ### Lambda@Edge / Lambda (Alternative)
54
+
55
+ - Use OpenNext or SST to deploy Next.js on Lambda + CloudFront.
56
+ - Better for low-traffic or bursty workloads with pay-per-invocation pricing.
57
+ - Cold start latency is a consideration for latency-sensitive pages.
58
+ - Lambda functions have a 15-minute execution timeout.
59
+
60
+ ## Database Migration Notes
61
+
62
+ - Replace `@neondatabase/serverless` with the standard `pg` package.
63
+ - Use `RDS_HOSTNAME`, `RDS_PORT`, `RDS_DB_NAME` environment variables instead of `DATABASE_URL`.
64
+ - For Lambda deployments, use RDS Proxy to avoid connection exhaustion.
65
+ - IAM database authentication eliminates the need for stored passwords:
66
+ ```
67
+ RDS_AUTH_METHOD=iam
68
+ RDS_ROLE_ARN=arn:aws:iam::123456789012:role/prenta-rds-access
69
+ ```
70
+ - Aurora Serverless v2 provides automatic scaling for unpredictable workloads.
71
+
72
+ ## Environment Variable Mapping
73
+
74
+ | Vercel Env Var | AWS Equivalent | Notes |
75
+ | -------------------------- | ------------------------------------------- | -------------------------------------------------------------------------- |
76
+ | `DATABASE_URL` | `RDS_HOSTNAME` + `RDS_PORT` + `RDS_DB_NAME` | Constructed as `postgresql://user:pass@host:port/db` or use IAM auth token |
77
+ | `BLOB_READ_WRITE_TOKEN` | `AWS_S3_BUCKET` + IAM role | No token needed; IAM role grants access |
78
+ | `UPSTASH_REDIS_REST_URL` | `ELASTICACHE_ENDPOINT` | Direct Redis protocol, not REST |
79
+ | `UPSTASH_REDIS_REST_TOKEN` | N/A | IAM auth or VPC-internal access (no token) |
80
+ | `RESEND_API_KEY` | `AWS_SES_REGION` | SES uses IAM permissions, not API keys |
81
+ | `CRON_SECRET` | N/A | EventBridge invokes Lambda directly via IAM |
82
+
83
+ ## CDN Configuration
84
+
85
+ ### CloudFront Distribution
86
+
87
+ - Create a CloudFront distribution with two origins:
88
+ 1. **Application origin** — ALB or API Gateway pointing to the Next.js app.
89
+ 2. **Static assets origin** — S3 bucket for `_next/static` and uploaded media.
90
+ - Use Origin Access Control (OAC) for the S3 origin to prevent direct S3 access.
91
+ - Configure cache behaviors:
92
+ - `/_next/static/*` → S3 origin, long TTL (immutable assets).
93
+ - `/media/*` → S3 origin, moderate TTL with tag-based invalidation.
94
+ - `/*` (default) → Application origin, respect `Cache-Control` headers.
95
+ - Enable automatic compression (gzip + Brotli).
96
+ - Use Lambda@Edge or CloudFront Functions for header manipulation (security headers, redirects).
97
+
98
+ ### Cache Invalidation
99
+
100
+ - CloudFront supports path-based invalidation (`/blog/*`) and wildcard patterns.
101
+ - For tag-based invalidation, maintain a mapping in ElastiCache Redis:
102
+ - On content update, look up affected paths from the tag mapping.
103
+ - Issue CloudFront invalidation for those paths.
104
+ - Free tier includes 1,000 invalidation paths/month.
@@ -0,0 +1,12 @@
1
+ import type { CacheAdapter } from '@prenta/core';
2
+ export interface CacheAdapterOptions {
3
+ prefix?: string;
4
+ /**
5
+ * Redis/Valkey connection URL (e.g. `redis://host:6379`). Falls back to
6
+ * `REDIS_URL` then `ELASTICACHE_ENDPOINT`. When absent, an in-memory Map is
7
+ * used instead.
8
+ */
9
+ redisUrl?: string;
10
+ }
11
+ export declare function createElastiCacheAdapter(options?: CacheAdapterOptions): CacheAdapter;
12
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAWhD,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAQD,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CA2ExF"}
package/dist/cache.js ADDED
@@ -0,0 +1,69 @@
1
+ export function createElastiCacheAdapter(options = {}) {
2
+ const prefix = options.prefix ?? 'prenta:';
3
+ const redisUrl = options.redisUrl ?? process.env.REDIS_URL ?? process.env.ELASTICACHE_ENDPOINT ?? '';
4
+ const memoryCache = new Map();
5
+ let redisClient = null;
6
+ function prefixedKey(key) {
7
+ return `${prefix}${key}`;
8
+ }
9
+ async function getRedis() {
10
+ if (!redisUrl)
11
+ return null;
12
+ if (redisClient)
13
+ return redisClient;
14
+ const Redis = (await import('ioredis')).default;
15
+ redisClient = new Redis(redisUrl);
16
+ return redisClient;
17
+ }
18
+ return {
19
+ async get(key) {
20
+ const k = prefixedKey(key);
21
+ const redis = await getRedis();
22
+ if (redis) {
23
+ const raw = await redis.get(k);
24
+ return raw ? JSON.parse(raw) : null;
25
+ }
26
+ const entry = memoryCache.get(k);
27
+ if (!entry)
28
+ return null;
29
+ if (entry.expiresAt && Date.now() > entry.expiresAt) {
30
+ memoryCache.delete(k);
31
+ return null;
32
+ }
33
+ return entry.value;
34
+ },
35
+ async set(key, value, ttl) {
36
+ const k = prefixedKey(key);
37
+ const redis = await getRedis();
38
+ if (redis) {
39
+ const serialized = JSON.stringify(value);
40
+ if (ttl) {
41
+ await redis.set(k, serialized, 'EX', ttl);
42
+ }
43
+ else {
44
+ await redis.set(k, serialized);
45
+ }
46
+ return;
47
+ }
48
+ memoryCache.set(k, {
49
+ value,
50
+ expiresAt: ttl ? Date.now() + ttl * 1000 : undefined,
51
+ });
52
+ },
53
+ async delete(key) {
54
+ const k = prefixedKey(key);
55
+ const redis = await getRedis();
56
+ if (redis) {
57
+ await redis.del(k);
58
+ return;
59
+ }
60
+ memoryCache.delete(k);
61
+ },
62
+ async invalidateTag(tag) {
63
+ // @ts-ignore optional peer dependency
64
+ const { revalidateTag } = await import('next/cache');
65
+ revalidateTag(tag);
66
+ },
67
+ };
68
+ }
69
+ //# sourceMappingURL=cache.js.map
@@ -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CAAC;YACD,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACvB,CAAC;QAED,KAAK,CAAC,aAAa,CAAC,GAAW;YAC7B,sCAAsC;YACtC,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAA;YACpD,aAAa,CAAC,GAAG,CAAC,CAAA;QACpB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { DatabaseAdapter } from '@prenta/core';
2
+ export interface RdsAdapterOptions {
3
+ /** Postgres connection string. Falls back to `DATABASE_URL`. */
4
+ connectionString?: string;
5
+ /**
6
+ * TLS configuration. RDS requires TLS in transit.
7
+ *
8
+ * - `true` (or `RDS_SSL=1` / `sslmode=require` in the URL) enables TLS with
9
+ * **certificate verification on** (`rejectUnauthorized: true`). RDS's root
10
+ * CA is not in Node's default trust store, so supply the Amazon RDS global
11
+ * CA bundle via the `RDS_CA_BUNDLE` env var (a path to the `.pem`) or
12
+ * `NODE_EXTRA_CA_CERTS`, or pass `ssl: { ca }` directly.
13
+ * - Pass an object to control it explicitly, e.g. `{ ca }` or — only if you
14
+ * accept the MITM risk — `{ rejectUnauthorized: false }` to skip verification.
15
+ *
16
+ * @see https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html
17
+ */
18
+ ssl?: boolean | {
19
+ rejectUnauthorized?: boolean;
20
+ ca?: string;
21
+ };
22
+ /** Max pool size. Defaults to `pg`'s default (10). */
23
+ max?: number;
24
+ }
25
+ export declare function createRdsAdapter(options?: RdsAdapterOptions): DatabaseAdapter;
26
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAanD,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,EAAE,OAAO,GAAG;QAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7D,sDAAsD;IACtD,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAUD,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,eAAe,CAqEjF"}
@@ -0,0 +1,62 @@
1
+ export function createRdsAdapter(options = {}) {
2
+ const connectionString = options.connectionString ?? process.env.DATABASE_URL ?? '';
3
+ let pool = null;
4
+ // Resolve pg's `ssl` config. Verification is ON by default; an explicit
5
+ // object is honored as-is (so `{ rejectUnauthorized: false }` is a deliberate,
6
+ // visible opt-out rather than the silent default). The Amazon RDS CA bundle
7
+ // is loaded from `RDS_CA_BUNDLE` when present so `rejectUnauthorized: true`
8
+ // can actually validate the RDS server certificate.
9
+ async function resolveSsl() {
10
+ if (options.ssl && typeof options.ssl === 'object') {
11
+ const { rejectUnauthorized = true, ca } = options.ssl;
12
+ return { rejectUnauthorized, ...(ca ? { ca } : {}) };
13
+ }
14
+ const enabled = options.ssl ?? (process.env.RDS_SSL === '1' || /sslmode=require/i.test(connectionString));
15
+ if (!enabled)
16
+ return false;
17
+ const caPath = process.env.RDS_CA_BUNDLE?.trim();
18
+ if (caPath) {
19
+ const { readFileSync } = await import('node:fs');
20
+ return { rejectUnauthorized: true, ca: readFileSync(caPath, 'utf8') };
21
+ }
22
+ return { rejectUnauthorized: true };
23
+ }
24
+ async function getPool() {
25
+ if (pool)
26
+ return pool;
27
+ const pg = await import('pg');
28
+ // `pg` is CommonJS: the Pool constructor lives on the default export under ESM interop.
29
+ const Pool = (pg.default?.Pool ??
30
+ pg.Pool);
31
+ const ssl = await resolveSsl();
32
+ pool = new Pool({
33
+ connectionString,
34
+ ...(options.max !== undefined ? { max: options.max } : {}),
35
+ ...(ssl ? { ssl } : {}),
36
+ });
37
+ return pool;
38
+ }
39
+ return {
40
+ async connect() {
41
+ // Acquire and immediately release a connection to validate connectivity.
42
+ const p = await getPool();
43
+ const client = await p.connect();
44
+ client.release();
45
+ },
46
+ async disconnect() {
47
+ if (pool) {
48
+ await pool.end();
49
+ pool = null;
50
+ }
51
+ },
52
+ async query(sql, params) {
53
+ const p = await getPool();
54
+ const result = await p.query(sql, params);
55
+ return result.rows;
56
+ },
57
+ async transaction(fn) {
58
+ return fn();
59
+ },
60
+ };
61
+ }
62
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AA0CA,MAAM,UAAU,gBAAgB,CAAC,UAA6B,EAAE;IAC9D,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAA;IAEnF,IAAI,IAAI,GAAkB,IAAI,CAAA;IAE9B,wEAAwE;IACxE,+EAA+E;IAC/E,4EAA4E;IAC5E,4EAA4E;IAC5E,oDAAoD;IACpD,KAAK,UAAU,UAAU;QACvB,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;YACnD,MAAM,EAAE,kBAAkB,GAAG,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;YACrD,OAAO,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;QACtD,CAAC;QACD,MAAM,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAA;QAC3F,IAAI,CAAC,OAAO;YAAE,OAAO,KAAK,CAAA;QAE1B,MAAM,M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AI,CAAC,GAAG,EAAE,CAAA;gBAChB,IAAI,GAAG,IAAI,CAAA;YACb,CAAC;QACH,CAAC;QAED,KAAK,CAAC,KAAK,CAAI,GAAW,EAAE,MAAkB;YAC5C,MAAM,CAAC,GAAG,MAAM,OAAO,EAAE,CAAA;YACzB,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;YACzC,OAAO,MAAM,CAAC,IAAW,CAAA;QAC3B,CAAC;QAED,KAAK,CAAC,WAAW,CAAI,EAAoB;YACvC,OAAO,EAAE,EAAE,CAAA;QACb,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { EmailAdapter } from '@prenta/core';
2
+ export interface EmailAdapterOptions {
3
+ /** SES region. Falls back to `AWS_SES_REGION`, then `AWS_REGION`. */
4
+ region?: string;
5
+ /** Default sender address. */
6
+ defaultFrom?: string;
7
+ /** Default sender address. Alias of `defaultFrom`. */
8
+ from?: string;
9
+ /** Explicit access key (overrides the SDK credential chain). */
10
+ accessKeyId?: string;
11
+ /** Explicit secret key (overrides the SDK credential chain). */
12
+ secretAccessKey?: string;
13
+ /** SES configuration set for tracking/dedicated IPs. */
14
+ configurationSetName?: string;
15
+ }
16
+ export declare function createSesAdapter(options?: EmailAdapterOptions): EmailAdapter;
17
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAOhD,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,8BAA8B;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CA+ChF"}
package/dist/email.js ADDED
@@ -0,0 +1,36 @@
1
+ export function createSesAdapter(options = {}) {
2
+ const region = options.region ?? process.env.AWS_SES_REGION ?? process.env.AWS_REGION ?? 'us-east-1';
3
+ const defaultFrom = options.defaultFrom ?? options.from ?? process.env.EMAIL_FROM ?? 'noreply@prentacms.com';
4
+ return {
5
+ async send(message) {
6
+ const { SESClient, SendEmailCommand } = await import('@aws-sdk/client-ses');
7
+ const client = new SESClient({
8
+ region,
9
+ ...(options.accessKeyId && options.secretAccessKey
10
+ ? {
11
+ credentials: {
12
+ accessKeyId: options.accessKeyId,
13
+ secretAccessKey: options.secretAccessKey,
14
+ },
15
+ }
16
+ : {}),
17
+ });
18
+ await client.send(new SendEmailCommand({
19
+ Source: message.from ?? defaultFrom,
20
+ Destination: { ToAddresses: [message.to] },
21
+ Message: {
22
+ Subject: { Data: message.subject, Charset: 'UTF-8' },
23
+ Body: {
24
+ Html: { Data: message.html, Charset: 'UTF-8' },
25
+ ...(message.text ? { Text: { Data: message.text, Charset: 'UTF-8' } } : {}),
26
+ },
27
+ },
28
+ ...(message.replyTo ? { ReplyToAddresses: [message.replyTo] } : {}),
29
+ ...(options.configurationSetName
30
+ ? { ConfigurationSetName: options.configurationSetName }
31
+ : {}),
32
+ }));
33
+ },
34
+ };
35
+ }
36
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.js","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAsBA,MAAM,UAAU,gBAAgB,CAAC,UAA+B,EAAE;IAChE,MAAM,MAAM,GACV,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,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AC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnE,GAAG,CAAC,OAAO,CAAC,oBAAoB;oBAC9B,CAAC,CAAC,EAAE,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,EAAE;oBACxD,CAAC,CAAC,EAAE,CAAC;aACR,CAAC,CACH,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { DatabaseAdapter, StorageAdapter, CacheAdapter, EmailAdapter, SchedulerAdapter, RateLimitAdapter } from '@prenta/core';
2
+ import { type RdsAdapterOptions } from './database.js';
3
+ import { type CacheAdapterOptions } from './cache.js';
4
+ import { type EmailAdapterOptions } from './email.js';
5
+ import { type SchedulerAdapterOptions } from './scheduler.js';
6
+ import { type RateLimitAdapterOptions } from './rate-limit.js';
7
+ import type { S3AdapterOptions } from './s3-config.js';
8
+ export interface PlatformAdapters {
9
+ database: DatabaseAdapter;
10
+ storage: StorageAdapter;
11
+ cache: CacheAdapter;
12
+ email: EmailAdapter;
13
+ scheduler: SchedulerAdapter;
14
+ rateLimit: RateLimitAdapter;
15
+ }
16
+ export interface AwsPlatformOptions {
17
+ database?: RdsAdapterOptions;
18
+ storage?: S3AdapterOptions;
19
+ cache?: CacheAdapterOptions;
20
+ email?: EmailAdapterOptions;
21
+ scheduler?: SchedulerAdapterOptions;
22
+ rateLimit?: RateLimitAdapterOptions;
23
+ }
24
+ /**
25
+ * AWS platform adapter set — the S3/RDS/ElastiCache/SES/EventBridge-backed
26
+ * equivalent of `vercel()`. Credentials are resolved from the task/instance IAM
27
+ * role by default; every service dependency is dynamically imported so nothing
28
+ * is pulled in until the corresponding adapter is actually used.
29
+ */
30
+ export declare function aws(options?: AwsPlatformOptions): PlatformAdapters;
31
+ export { createRdsAdapter } from './database.js';
32
+ export { createS3Adapter } from './storage.js';
33
+ export { isS3Configured, publicObjectUrl, resolveS3Config, s3ConfigHint } from './s3-config.js';
34
+ export { createElastiCacheAdapter } from './cache.js';
35
+ export { createSesAdapter } from './email.js';
36
+ export { createEventBridgeAdapter, generateEventBridgeConfig, toEventBridgeCron, } from './scheduler.js';
37
+ export { createElastiCacheRateLimitAdapter, slidingWindowCheck } from './rate-limit.js';
38
+ export type { RdsAdapterOptions } from './database.js';
39
+ export type { S3AdapterOptions, ResolvedS3Config, S3ConfigEnv } from './s3-config.js';
40
+ export type { CacheAdapterOptions } from './cache.js';
41
+ export type { EmailAdapterOptions } from './email.js';
42
+ export type { SchedulerAdapterOptions, EventBridgeScheduleConfig } from './scheduler.js';
43
+ export type { RateLimitAdapterOptions, RateLimitResult } from './rate-limit.js';
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAExE,OAAO,EAA4B,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAC/E,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,EAA4B,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AACvF,OAAO,EAAqC,KAAK,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AACjG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,eAAe,CAAA;IACzB,OAAO,EAAE,cAAc,CAAA;IACvB,KAAK,EAAE,YAAY,CAAA;IACnB,KAAK,EAAE,YAAY,CAAA;IACnB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,SAAS,EAAE,gBAAgB,CAAA;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,iBAAiB,CAAA;IAC5B,OAAO,CAAC,EAAE,gBAAgB,CAAA;IAC1B,KAAK,CAAC,EAAE,mBAAmB,CAAA;IAC3B,KAAK,CAAC,EAAE,mBAAmB,CAAA;IAC3B,SAAS,CAAC,EAAE,uBAAuB,CAAA;IACnC,SAAS,CAAC,EAAE,uBAAuB,CAAA;CACpC;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,OAAO,GAAE,kBAAuB,GAAG,gBAAgB,CAStE;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC/F,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,iCAAiC,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEvF,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACtD,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACrF,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,YAAY,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AACxF,YAAY,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import { createRdsAdapter } from './database.js';
2
+ import { createS3Adapter } from './storage.js';
3
+ import { createElastiCacheAdapter } from './cache.js';
4
+ import { createSesAdapter } from './email.js';
5
+ import { createEventBridgeAdapter } from './scheduler.js';
6
+ import { createElastiCacheRateLimitAdapter } from './rate-limit.js';
7
+ /**
8
+ * AWS platform adapter set — the S3/RDS/ElastiCache/SES/EventBridge-backed
9
+ * equivalent of `vercel()`. Credentials are resolved from the task/instance IAM
10
+ * role by default; every service dependency is dynamically imported so nothing
11
+ * is pulled in until the corresponding adapter is actually used.
12
+ */
13
+ export function aws(options = {}) {
14
+ return {
15
+ database: createRdsAdapter(options.database),
16
+ storage: createS3Adapter(options.storage),
17
+ cache: createElastiCacheAdapter(options.cache),
18
+ email: createSesAdapter(options.email),
19
+ scheduler: createEventBridgeAdapter(options.scheduler),
20
+ rateLimit: createElastiCacheRateLimitAdapter(options.rateLimit),
21
+ };
22
+ }
23
+ export { createRdsAdapter } from './database.js';
24
+ export { createS3Adapter } from './storage.js';
25
+ export { isS3Configured, publicObjectUrl, resolveS3Config, s3ConfigHint } from './s3-config.js';
26
+ export { createElastiCacheAdapter } from './cache.js';
27
+ export { createSesAdapter } from './email.js';
28
+ export { createEventBridgeAdapter, generateEventBridgeConfig, toEventBridgeCron, } from './scheduler.js';
29
+ export { createElastiCacheRateLimitAdapter, slidingWindowCheck } from './rate-limit.js';
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAA0B,MAAM,eAAe,CAAA;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,wBAAwB,EAA4B,MAAM,YAAY,CAAA;AAC/E,OAAO,EAAE,gBAAgB,EAA4B,MAAM,YAAY,CAAA;AACvE,OAAO,EAAE,wBAAwB,EAAgC,MAAM,gBAAgB,CAAA;AACvF,OAAO,EAAE,iCAAiC,EAAgC,MAAM,iBAAiB,CAAA;AAqBjG;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,UAA8B,EAAE;IAClD,OAAO;QACL,QAAQ,EAAE,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC5C,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC;QACzC,KAAK,EAAE,wBAAwB,CAAC,OAAO,CAAC,KAAK,CAAC;QAC9C,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC;QACtC,SAAS,EAAE,wBAAwB,CAAC,OAAO,CAAC,SAAS,CAAC;QACtD,SAAS,EAAE,iCAAiC,CAAC,OAAO,CAAC,SAAS,CAAC;KAChE,CAAA;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC/F,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,iCAAiC,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,21 @@
1
+ import type { RateLimitAdapter } from '@prenta/core';
2
+ export interface RateLimitAdapterOptions {
3
+ /**
4
+ * Redis/Valkey connection URL. Falls back to `REDIS_URL` then
5
+ * `ELASTICACHE_ENDPOINT`. When absent, an in-memory window is used.
6
+ */
7
+ redisUrl?: string;
8
+ keyPrefix?: string;
9
+ }
10
+ export interface RateLimitResult {
11
+ allowed: boolean;
12
+ remaining: number;
13
+ resetAt: Date;
14
+ }
15
+ /**
16
+ * Pure in-memory sliding-window log. Exported for the Redis-less fallback and
17
+ * for deterministic testing (pass an explicit `now`). Mutates `store` in place.
18
+ */
19
+ export declare function slidingWindowCheck(store: Map<string, number[]>, key: string, limit: number, windowMs: number, now: number): RateLimitResult;
20
+ export declare function createElastiCacheRateLimitAdapter(options?: RateLimitAdapterOptions): RateLimitAdapter;
21
+ //# sourceMappingURL=rate-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../src/rate-limit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AASpD,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,IAAI,CAAA;CACd;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAC5B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,GACV,eAAe,CAajB;AAgBD,wBAAgB,iCAAiC,CAC/C,OAAO,GAAE,uBAA4B,GACpC,gBAAgB,CAmElB"}
@@ -0,0 +1,76 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ /**
3
+ * Pure in-memory sliding-window log. Exported for the Redis-less fallback and
4
+ * for deterministic testing (pass an explicit `now`). Mutates `store` in place.
5
+ */
6
+ export function slidingWindowCheck(store, key, limit, windowMs, now) {
7
+ const windowStart = now - windowMs;
8
+ const timestamps = (store.get(key) ?? []).filter((t) => t > windowStart);
9
+ timestamps.push(now);
10
+ store.set(key, timestamps);
11
+ const count = timestamps.length;
12
+ const oldest = timestamps[0] ?? now;
13
+ return {
14
+ allowed: count <= limit,
15
+ remaining: Math.max(0, limit - count),
16
+ resetAt: new Date(oldest + windowMs),
17
+ };
18
+ }
19
+ export function createElastiCacheRateLimitAdapter(options = {}) {
20
+ const redisUrl = options.redisUrl ?? process.env.REDIS_URL ?? process.env.ELASTICACHE_ENDPOINT ?? '';
21
+ const prefix = options.keyPrefix ?? 'prenta:rl:';
22
+ const memory = new Map();
23
+ let redisClient = null;
24
+ // Sorted-set members must be unique across ALL instances sharing the Redis —
25
+ // ZADD with a duplicate member updates its score instead of adding an entry,
26
+ // which would make ZCARD undercount and silently weaken the limit fleet-wide.
27
+ // A per-instance random id + a monotonic counter guarantees global uniqueness.
28
+ const instanceId = randomUUID();
29
+ let seq = 0;
30
+ async function getRedis() {
31
+ if (!redisUrl)
32
+ return null;
33
+ if (redisClient)
34
+ return redisClient;
35
+ const Redis = (await import('ioredis')).default;
36
+ redisClient = new Redis(redisUrl);
37
+ return redisClient;
38
+ }
39
+ return {
40
+ async check(key, limit, windowMs) {
41
+ const now = Date.now();
42
+ const k = `${prefix}${key}`;
43
+ const redis = await getRedis();
44
+ if (!redis) {
45
+ return slidingWindowCheck(memory, k, limit, windowMs, now);
46
+ }
47
+ const windowStart = now - windowMs;
48
+ const results = await redis
49
+ .multi()
50
+ .zremrangebyscore(k, 0, windowStart)
51
+ .zadd(k, now, `${now}-${instanceId}-${seq++}`)
52
+ .zcard(k)
53
+ .pexpire(k, windowMs)
54
+ .exec();
55
+ // ZCARD is the 3rd queued command (index 2); result tuple is [err, value].
56
+ const count = Number(results?.[2]?.[1] ?? 0);
57
+ const oldestEntry = await redis.zrange(k, 0, 0, 'WITHSCORES');
58
+ const oldestScore = oldestEntry?.[1] ? Number(oldestEntry[1]) : now;
59
+ return {
60
+ allowed: count <= limit,
61
+ remaining: Math.max(0, limit - count),
62
+ resetAt: new Date(oldestScore + windowMs),
63
+ };
64
+ },
65
+ async reset(key) {
66
+ const k = `${prefix}${key}`;
67
+ const redis = await getRedis();
68
+ if (redis) {
69
+ await redis.del(k);
70
+ return;
71
+ }
72
+ memory.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;YAC3E,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;YAC5C,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAA;YAC7D,MAAM,WAAW,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;YAEnE,OAAO;gBACL,OAAO,EAAE,KAAK,IAAI,KAAK;gBACvB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;gBACrC,OAAO,EAAE,IAAI,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC;aAC1C,CAAA;QACH,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,GAAW;YACrB,MAAM,CAAC,GAAG,GAAG,MAAM,GAAG,GAAG,EAAE,CAAA;YAC3B,MAAM,KAAK,GAAG,MAAM,QAAQ,EAAE,CAAA;YAC9B,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBAClB,OAAM;YACR,CAAC;YACD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAClB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Resolve S3 client configuration for the AWS storage adapter.
3
+ *
4
+ * Unlike Vercel Blob (which needs an injected token), S3 access is granted by
5
+ * the task/instance IAM role in production — the AWS SDK's default credential
6
+ * provider chain (env vars, ECS/EC2 role, SSO, profile) supplies credentials
7
+ * automatically. We therefore only require a bucket + region to be configured;
8
+ * credentials are left to the SDK unless explicitly overridden (useful for
9
+ * local dev against LocalStack/MinIO).
10
+ *
11
+ * Public object URLs prefer a CloudFront distribution (`AWS_S3_PUBLIC_URL`)
12
+ * when one is configured — the recommended setup uses Origin Access Control so
13
+ * objects are only reachable through CloudFront, not the raw S3 endpoint.
14
+ *
15
+ * @see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
16
+ */
17
+ export interface S3AdapterOptions {
18
+ /** Target bucket. Falls back to `AWS_S3_BUCKET`. */
19
+ bucket?: string;
20
+ /** AWS region. Falls back to `AWS_REGION` / `AWS_DEFAULT_REGION`. */
21
+ region?: string;
22
+ /** Custom endpoint for S3-compatible stores (LocalStack, MinIO, R2). */
23
+ endpoint?: string;
24
+ /** Path-style addressing (required by most S3-compatible stores). */
25
+ forcePathStyle?: boolean;
26
+ /**
27
+ * Base URL for public object links (typically a CloudFront domain). When set,
28
+ * `upload()` returns `${publicBaseUrl}/${key}`. Falls back to
29
+ * `AWS_S3_PUBLIC_URL`; otherwise the virtual-hosted S3 URL is used.
30
+ */
31
+ publicBaseUrl?: string;
32
+ /** Explicit access key (overrides the SDK credential chain). */
33
+ accessKeyId?: string;
34
+ /** Explicit secret key (overrides the SDK credential chain). */
35
+ secretAccessKey?: string;
36
+ /** Optional session token for temporary credentials. */
37
+ sessionToken?: string;
38
+ }
39
+ export type S3ConfigEnv = {
40
+ AWS_S3_BUCKET?: string;
41
+ AWS_REGION?: string;
42
+ AWS_DEFAULT_REGION?: string;
43
+ AWS_S3_ENDPOINT?: string;
44
+ AWS_S3_FORCE_PATH_STYLE?: string;
45
+ AWS_S3_PUBLIC_URL?: string;
46
+ AWS_ACCESS_KEY_ID?: string;
47
+ AWS_SECRET_ACCESS_KEY?: string;
48
+ AWS_SESSION_TOKEN?: string;
49
+ S3_BUCKET?: string;
50
+ S3_REGION?: string;
51
+ S3_ACCESS_KEY_ID?: string;
52
+ S3_SECRET_ACCESS_KEY?: string;
53
+ };
54
+ export interface ResolvedS3Config {
55
+ bucket: string;
56
+ region: string;
57
+ endpoint?: string;
58
+ forcePathStyle?: boolean;
59
+ publicBaseUrl?: string;
60
+ accessKeyId?: string;
61
+ secretAccessKey?: string;
62
+ sessionToken?: string;
63
+ }
64
+ export declare function resolveS3Config(overrides?: S3AdapterOptions, env?: S3ConfigEnv): ResolvedS3Config;
65
+ /** True when a bucket + region are configured (credentials come from the IAM role). */
66
+ export declare function isS3Configured(overrides?: S3AdapterOptions, env?: S3ConfigEnv): boolean;
67
+ /** Operator-facing hint when uploads would fail for missing S3 configuration. */
68
+ export declare function s3ConfigHint(overrides?: S3AdapterOptions, env?: S3ConfigEnv): string;
69
+ /**
70
+ * Build the public URL for an uploaded object. Prefers the configured
71
+ * CloudFront/public base; otherwise falls back to the virtual-hosted S3 URL.
72
+ * Each path segment is URL-encoded (keys may contain spaces or unicode) while
73
+ * preserving `/` separators.
74
+ */
75
+ export declare function publicObjectUrl(config: ResolvedS3Config, key: string): string;
76
+ //# sourceMappingURL=s3-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3-config.d.ts","sourceRoot":"","sources":["../src/s3-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,qEAAqE;IACrE,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,wDAAwD;IACxD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kBAAk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5
+ return v === '1' || v === 'true' || v === 'yes';
6
+ }
7
+ export function resolveS3Config(overrides = {}, env = process.env) {
8
+ const bucket = (overrides.bucket ?? env.AWS_S3_BUCKET ?? env.S3_BUCKET ?? '').trim();
9
+ const region = (overrides.region ??
10
+ env.AWS_REGION ??
11
+ env.AWS_DEFAULT_REGION ??
12
+ env.S3_REGION ??
13
+ '').trim();
14
+ const endpoint = (overrides.endpoint ?? env.AWS_S3_ENDPOINT)?.trim() || undefined;
15
+ const forcePathStyle = overrides.forcePathStyle ?? (truthyEnv(env.AWS_S3_FORCE_PATH_STYLE) || undefined);
16
+ const publicBaseUrl = (overrides.publicBaseUrl ?? env.AWS_S3_PUBLIC_URL)?.trim().replace(/\/+$/, '') || undefined;
17
+ // Only forward explicit credentials; the AWS-standard AWS_ACCESS_KEY_ID /
18
+ // AWS_SECRET_ACCESS_KEY (and the IAM role, profile, SSO) are resolved by the
19
+ // SDK's own default provider chain. We additionally honor the scaffolder's
20
+ // S3_ACCESS_KEY_ID / S3_SECRET_ACCESS_KEY names, which the SDK would not read.
21
+ const accessKeyId = (overrides.accessKeyId ?? env.S3_ACCESS_KEY_ID)?.trim() || undefined;
22
+ const secretAccessKey = (overrides.secretAccessKey ?? env.S3_SECRET_ACCESS_KEY)?.trim() || undefined;
23
+ const sessionToken = overrides.sessionToken?.trim() || undefined;
24
+ return {
25
+ bucket,
26
+ region,
27
+ endpoint,
28
+ forcePathStyle,
29
+ publicBaseUrl,
30
+ accessKeyId,
31
+ secretAccessKey,
32
+ sessionToken,
33
+ };
34
+ }
35
+ /** True when a bucket + region are configured (credentials come from the IAM role). */
36
+ export function isS3Configured(overrides = {}, env = process.env) {
37
+ const { bucket, region } = resolveS3Config(overrides, env);
38
+ return Boolean(bucket && region);
39
+ }
40
+ /** Operator-facing hint when uploads would fail for missing S3 configuration. */
41
+ export function s3ConfigHint(overrides = {}, env = process.env) {
42
+ const { bucket, region } = resolveS3Config(overrides, env);
43
+ if (bucket && region)
44
+ return '';
45
+ const missing = [];
46
+ if (!bucket)
47
+ missing.push('AWS_S3_BUCKET (target bucket)');
48
+ if (!region)
49
+ missing.push('AWS_REGION (bucket region)');
50
+ return (`Configure AWS S3 storage: set ${missing.join(' and ')}. ` +
51
+ 'Credentials are read from the task/instance IAM role automatically (grant ' +
52
+ 's3:PutObject, s3:GetObject, s3:DeleteObject on the bucket); for local dev, set ' +
53
+ 'AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY or an AWS_PROFILE.');
54
+ }
55
+ /**
56
+ * Build the public URL for an uploaded object. Prefers the configured
57
+ * CloudFront/public base; otherwise falls back to the virtual-hosted S3 URL.
58
+ * Each path segment is URL-encoded (keys may contain spaces or unicode) while
59
+ * preserving `/` separators.
60
+ */
61
+ export function publicObjectUrl(config, key) {
62
+ const encodedKey = key
63
+ .split('/')
64
+ .map((segment) => encodeURIComponent(segment))
65
+ .join('/');
66
+ // Explicit CDN / public base wins (the recommended CloudFront + OAC setup).
67
+ if (config.publicBaseUrl) {
68
+ return `${config.publicBaseUrl}/${encodedKey}`;
69
+ }
70
+ // Custom endpoint (LocalStack / MinIO / R2 / S3-compatible): the object lives
71
+ // at the configured endpoint, NOT amazonaws.com. Honor path-style vs
72
+ // virtual-hosted addressing so the returned URL actually resolves.
73
+ if (config.endpoint) {
74
+ const base = config.endpoint.replace(/\/+$/, '');
75
+ if (config.forcePathStyle) {
76
+ return `${base}/${config.bucket}/${encodedKey}`;
77
+ }
78
+ // Virtual-hosted: inject the bucket as a subdomain of the endpoint host.
79
+ return base.replace(/^(https?:\/\/)/i, `$1${config.bucket}.`) + `/${encodedKey}`;
80
+ }
81
+ // Standard AWS S3 virtual-hosted URL.
82
+ return `https://${config.bucket}.s3.${config.region}.amazonaws.com/${encodedKey}`;
83
+ }
84
+ //# sourceMappingURL=s3-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3-config.js","sourceRoot":"","sources":["../src/s3-config.ts"],"names":[],"mappings":"AAoEA,SAAS,SAA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,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;SAC7C,IAAI,CAAC,GAAG,CAAC,CAAA;IAEZ,4EAA4E;IAC5E,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QACzB,OAAO,GAAG,MAAM,CAAC,aAAa,IAAI,UAAU,EAAE,CAAA;IAChD,CAAC;IAED,8EAA8E;IAC9E,qEAAqE;IACrE,mEAAmE;IACnE,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QAChD,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;YAC1B,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,IAAI,UAAU,EAAE,CAAA;QACjD,CAAC;QACD,yEAAyE;QACzE,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,KAAK,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,UAAU,EAAE,CAAA;IAClF,CAAC;IAED,sCAAsC;IACtC,OAAO,WAAW,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM,kBAAkB,UAAU,EAAE,CAAA;AACnF,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { SchedulerAdapter } from '@prenta/core';
2
+ export interface SchedulerAdapterOptions {
3
+ basePath?: string;
4
+ }
5
+ export interface EventBridgeScheduleConfig {
6
+ name: string;
7
+ scheduleExpression: string;
8
+ target: string;
9
+ }
10
+ /**
11
+ * Convert a standard 5-field cron expression to the 6-field form EventBridge
12
+ * expects (`Minutes Hours Day-of-month Month Day-of-week Year`). EventBridge
13
+ * forbids `*` in both day fields — exactly one must be `?` — and requires a
14
+ * trailing year field. Numeric day-of-week ranges/names are passed through
15
+ * unchanged (EventBridge uses 1–7 = SUN–SAT); adjust those by hand if used.
16
+ * Non-5-field input (already 6-field, `rate(...)`, etc.) is returned as-is.
17
+ *
18
+ * Throws when BOTH day fields are concrete (neither is `*`): standard cron
19
+ * treats that as an OR-match (fires when either day field matches), which
20
+ * EventBridge cannot represent — silently dropping one field would fire the job
21
+ * on the wrong days, so we fail loudly instead.
22
+ */
23
+ export declare function toEventBridgeCron(expression: string): string;
24
+ export declare function createEventBridgeAdapter(options?: SchedulerAdapterOptions): SchedulerAdapter;
25
+ export declare function generateEventBridgeConfig(jobs: Array<{
26
+ id: string;
27
+ cron: string;
28
+ }>, basePath?: string): EventBridgeScheduleConfig[];
29
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAUpD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAA;IACZ,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;CACf;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAuB5D;AAED,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAoChG;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EACzC,QAAQ,SAAc,GACrB,yBAAyB,EAAE,CAM7B"}
@@ -0,0 +1,71 @@
1
+ const registeredJobs = new Map();
2
+ /**
3
+ * Convert a standard 5-field cron expression to the 6-field form EventBridge
4
+ * expects (`Minutes Hours Day-of-month Month Day-of-week Year`). EventBridge
5
+ * forbids `*` in both day fields — exactly one must be `?` — and requires a
6
+ * trailing year field. Numeric day-of-week ranges/names are passed through
7
+ * unchanged (EventBridge uses 1–7 = SUN–SAT); adjust those by hand if used.
8
+ * Non-5-field input (already 6-field, `rate(...)`, etc.) is returned as-is.
9
+ *
10
+ * Throws when BOTH day fields are concrete (neither is `*`): standard cron
11
+ * treats that as an OR-match (fires when either day field matches), which
12
+ * EventBridge cannot represent — silently dropping one field would fire the job
13
+ * on the wrong days, so we fail loudly instead.
14
+ */
15
+ export function toEventBridgeCron(expression) {
16
+ const parts = expression.trim().split(/\s+/);
17
+ if (parts.length !== 5)
18
+ return expression.trim();
19
+ const [min, hour, dom, month, dow] = parts;
20
+ let dayOfMonth = dom;
21
+ let dayOfWeek = dow;
22
+ if (dayOfMonth === '*' && dayOfWeek === '*') {
23
+ dayOfWeek = '?';
24
+ }
25
+ else if (dayOfMonth !== '*' && dayOfWeek !== '*') {
26
+ throw new Error(`EventBridge cannot express a cron with both day-of-month and day-of-week set ` +
27
+ `("${expression.trim()}"): standard cron treats this as an OR-match. Rewrite as ` +
28
+ `two separate schedules, one per day field.`);
29
+ }
30
+ else if (dayOfWeek !== '*') {
31
+ dayOfMonth = '?';
32
+ }
33
+ else {
34
+ dayOfWeek = '?';
35
+ }
36
+ return `${min} ${hour} ${dayOfMonth} ${month} ${dayOfWeek} *`;
37
+ }
38
+ export function createEventBridgeAdapter(options = {}) {
39
+ const basePath = options.basePath ?? '/api/cron';
40
+ return {
41
+ async schedule(id, cronExpression, handler) {
42
+ registeredJobs.set(id, { expression: cronExpression, handler });
43
+ const ebExpression = toEventBridgeCron(cronExpression);
44
+ console.info(`[prenta:scheduler] Registered cron job "${id}".\n` +
45
+ ` On AWS, create an EventBridge schedule that targets ${basePath}/${id}:\n` +
46
+ ` aws scheduler create-schedule --name prenta-${id} \\\n` +
47
+ ` --schedule-expression "cron(${ebExpression})" \\\n` +
48
+ ` --flexible-time-window '{"Mode":"OFF"}' --target '{...}'`);
49
+ },
50
+ async cancel(id) {
51
+ registeredJobs.delete(id);
52
+ console.info(`[prenta:scheduler] Removed cron job "${id}". ` +
53
+ `Also delete the EventBridge schedule: aws scheduler delete-schedule --name prenta-${id}.`);
54
+ },
55
+ async list() {
56
+ return Array.from(registeredJobs.entries()).map(([id, job]) => ({
57
+ id,
58
+ expression: job.expression,
59
+ nextRun: new Date(),
60
+ }));
61
+ },
62
+ };
63
+ }
64
+ export function generateEventBridgeConfig(jobs, basePath = '/api/cron') {
65
+ return jobs.map((job) => ({
66
+ name: `prenta-${job.id}`,
67
+ scheduleExpression: `cron(${toEventBridgeCron(job.cron)})`,
68
+ target: `${basePath}/${job.id}`,
69
+ }));
70
+ }
71
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAoBA,MAAM,cAAc,GAAG,IAAI,GAAG,EAAgE,CAAA;AAE9F;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC5C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC,IAAI,EAAE,CAAA;IAEhD,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,KAAK,CAAA;IAC1C,IAAI,UAAU,GAAG,GAAG,CAAA;IACpB,IAAI,SAAS,GAAG,GAAG,CAAA;IAEnB,IAAI,UAAU,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;QAC5C,SAAS,GAAG,GAAG,CAAA;IACjB,CAAC;SAAM,IAAI,UAAU,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CACb,+EAA+E;YAC7E,KAAK,UAAU,CAAC,IAAI,EAAE,2DAA2D;YACjF,4CAA4C,CAC/C,CAAA;IACH,CAAC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AC;KACF,CAAA;AACH,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,IAAyC,EACzC,QAAQ,GAAG,WAAW;IAEtB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACxB,IAAI,EAAE,UAAU,GAAG,CAAC,EAAE,EAAE;QACxB,kBAAkB,EAAE,QAAQ,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG;QAC1D,MAAM,EAAE,GAAG,QAAQ,IAAI,GAAG,CAAC,EAAE,EAAE;KAChC,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { StorageAdapter } from '@prenta/core';
2
+ import { type S3AdapterOptions } from './s3-config.js';
3
+ export type { S3AdapterOptions } from './s3-config.js';
4
+ export declare function createS3Adapter(options?: S3AdapterOptions): StorageAdapter;
5
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAoCtD,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,cAAc,CAqD9E"}
@@ -0,0 +1,81 @@
1
+ import { isS3Configured, publicObjectUrl, resolveS3Config, s3ConfigHint, } from './s3-config.js';
2
+ function assertS3Configured(options) {
3
+ if (isS3Configured(options))
4
+ return;
5
+ throw new Error(s3ConfigHint(options));
6
+ }
7
+ // The AWS SDK v3 S3Client is loaded lazily (dynamic import) so installing this
8
+ // package doesn't force `@aws-sdk/client-s3` into every bundle. The client is
9
+ // cheap to construct — the SDK caches the resolved credential provider chain
10
+ // internally — so we build one per operation and re-read config from the env.
11
+ async function createClient(config) {
12
+ const { S3Client } = await import('@aws-sdk/client-s3');
13
+ return new S3Client({
14
+ region: config.region,
15
+ ...(config.endpoint ? { endpoint: config.endpoint } : {}),
16
+ ...(config.forcePathStyle !== undefined ? { forcePathStyle: config.forcePathStyle } : {}),
17
+ ...(config.accessKeyId && config.secretAccessKey
18
+ ? {
19
+ credentials: {
20
+ accessKeyId: config.accessKeyId,
21
+ secretAccessKey: config.secretAccessKey,
22
+ ...(config.sessionToken ? { sessionToken: config.sessionToken } : {}),
23
+ },
24
+ }
25
+ : {}),
26
+ });
27
+ }
28
+ async function toBuffer(data) {
29
+ if (Buffer.isBuffer(data))
30
+ return data;
31
+ // Web ReadableStream — buffer it fully (S3 PutObject needs a known length).
32
+ const arrayBuffer = await new Response(data).arrayBuffer();
33
+ return Buffer.from(arrayBuffer);
34
+ }
35
+ export function createS3Adapter(options = {}) {
36
+ return {
37
+ async upload(key, data, contentType) {
38
+ assertS3Configured(options);
39
+ const config = resolveS3Config(options);
40
+ const { PutObjectCommand } = await import('@aws-sdk/client-s3');
41
+ const client = await createClient(config);
42
+ await client.send(new PutObjectCommand({
43
+ Bucket: config.bucket,
44
+ Key: key,
45
+ Body: await toBuffer(data),
46
+ ContentType: contentType,
47
+ }));
48
+ return publicObjectUrl(config, key);
49
+ },
50
+ async download(key) {
51
+ assertS3Configured(options);
52
+ const config = resolveS3Config(options);
53
+ const { GetObjectCommand } = await import('@aws-sdk/client-s3');
54
+ const client = await createClient(config);
55
+ const response = await client.send(new GetObjectCommand({ Bucket: config.bucket, Key: key }));
56
+ const body = response.Body;
57
+ if (!body) {
58
+ throw new Error(`S3 object "${key}" returned an empty body.`);
59
+ }
60
+ return Buffer.from(await body.transformToByteArray());
61
+ },
62
+ async delete(key) {
63
+ assertS3Configured(options);
64
+ const config = resolveS3Config(options);
65
+ const { DeleteObjectCommand } = await import('@aws-sdk/client-s3');
66
+ const client = await createClient(config);
67
+ await client.send(new DeleteObjectCommand({ Bucket: config.bucket, Key: key }));
68
+ },
69
+ async getSignedUrl(key, expiresIn = 3600) {
70
+ assertS3Configured(options);
71
+ const config = resolveS3Config(options);
72
+ const { GetObjectCommand } = await import('@aws-sdk/client-s3');
73
+ const { getSignedUrl } = await import('@aws-sdk/s3-request-presigner');
74
+ const client = await createClient(config);
75
+ return getSignedUrl(client, new GetObjectCommand({ Bucket: config.bucket, Key: key }), {
76
+ expiresIn,
77
+ });
78
+ },
79
+ };
80
+ }
81
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,GAGb,MAAM,gBAAgB,CAAA;AAIvB,SAAS,kBAAkB,CAAC,OAAyB;IACnD,IAAI,cAAc,CAAC,OAAO,CAAC;QAAE,OAAM;IACnC,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;AACxC,CAAC;AAED,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,KAAK,UAAU,YAAY,CAAC,MAAwB;IAClD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAA;IACvD,OAAO,IAAI,QAAQ,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,CAAC,MAAM,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzF,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,eAAe;YAC9C,CAAC,CAAC;gBACE,WAAW,EAAE;oBACX,WAAW,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AAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAA;YAC/D,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAA;YACtE,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,CAAA;YACzC,OAAO,YAAY,CAAC,MAAM,EAAE,IAAI,gBAAgB,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE;gBACrF,SAAS;aACV,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@prenta/platform-aws",
3
+ "version": "0.2.0",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/actuate-media/prenta.git",
8
+ "directory": "packages/platform-aws"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "files": [
24
+ "dist",
25
+ "CHANGELOG.md"
26
+ ],
27
+ "peerDependencies": {
28
+ "@prenta/core": ">=0.1.0",
29
+ "@aws-sdk/client-s3": ">=3.0.0",
30
+ "@aws-sdk/client-ses": ">=3.0.0",
31
+ "@aws-sdk/s3-request-presigner": ">=3.0.0",
32
+ "ioredis": ">=5.0.0",
33
+ "pg": ">=8.0.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@aws-sdk/client-s3": {
37
+ "optional": true
38
+ },
39
+ "@aws-sdk/client-ses": {
40
+ "optional": true
41
+ },
42
+ "@aws-sdk/s3-request-presigner": {
43
+ "optional": true
44
+ },
45
+ "ioredis": {
46
+ "optional": true
47
+ },
48
+ "pg": {
49
+ "optional": true
50
+ }
51
+ },
52
+ "devDependencies": {
53
+ "@aws-sdk/client-s3": "^3.717.0",
54
+ "@aws-sdk/client-ses": "^3.717.0",
55
+ "@aws-sdk/s3-request-presigner": "^3.717.0",
56
+ "@types/pg": "^8.11.10",
57
+ "ioredis": "^5.4.2",
58
+ "pg": "^8.20.0",
59
+ "typescript": "^5.7.0",
60
+ "vitest": "^4.1.0",
61
+ "@prenta/core": "0.118.0"
62
+ },
63
+ "scripts": {
64
+ "build": "tsc -p tsconfig.build.json",
65
+ "type-check": "tsc --noEmit",
66
+ "test": "vitest run",
67
+ "test:watch": "vitest",
68
+ "clean": "rm -rf dist .turbo"
69
+ }
70
+ }