@sssb/cdk 0.3.0 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sssb/cdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,11 +26,11 @@
26
26
  "peerDependencies": {
27
27
  "aws-cdk-lib": "^2.274.0",
28
28
  "constructs": "^10.8.1",
29
- "@sssb/tools": "0.3.0"
29
+ "@sssb/tools": "0.4.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "aws-cdk-lib": "^2.274.0",
33
33
  "constructs": "^10.8.1",
34
- "@sssb/tools": "0.3.0"
34
+ "@sssb/tools": "0.4.0"
35
35
  }
36
36
  }
package/src/index.d.ts CHANGED
@@ -14,16 +14,19 @@ export type DatabaseTransport = 'pg' | 'data-api'
14
14
 
15
15
  /**
16
16
  * Which of SSSB's optional ports the app uses: the app's `params.ports`. The construct sets each one given as the
17
- * server's switch (`LLM_PROVIDER`, `EMAIL_PROVIDER`, `INBOUND_EMAIL_PROVIDER`, `JOBS_RUNNER`); a port left out keeps
18
- * the framework's default (the first choice of each). `none` makes the port absent: its settings are not required, and
19
- * a call through it fails naming the switch. `jobs: 'in-process'` runs each job's handler in the server, with no
20
- * CodeBuild project.
17
+ * server's switch (`LLM_PROVIDER`, `EMAIL_PROVIDER`, `INBOUND_EMAIL_PROVIDER`, `JOBS_RUNNER`, `STORAGE_PROVIDER`); a
18
+ * port left out keeps the framework's default (the first choice of each). `none` makes the port absent: its settings
19
+ * are not required, and a call through it fails naming the switch. `jobs: 'in-process'` runs each job's handler in the
20
+ * server, with no CodeBuild project. `storage: 's3'` (or left out) builds the storage bucket; `'s3-compatible'` (Cloudflare R2,
21
+ * MinIO, Backblaze B2) and `'none'` build none and grant no S3 access: the deployment sets the compatible store's
22
+ * `STORAGE_*` settings on the server itself (`app.server`).
21
23
  */
22
24
  export interface OptionalPorts {
23
25
  readonly llm?: 'anthropic' | 'none'
24
26
  readonly email?: 'mailgun' | 'none'
25
27
  readonly inboundEmail?: 'mailgun' | 'none'
26
28
  readonly jobs?: 'codebuild' | 'in-process' | 'none'
29
+ readonly storage?: 's3' | 's3-compatible' | 'none'
27
30
  }
28
31
 
29
32
  /** The scheduled tick: what runs the app's scheduled work (its cron route) in the deployment. */
@@ -107,7 +110,8 @@ export declare class SssbApp extends Construct {
107
110
  */
108
111
  readonly responseHeadersPolicy: cdk.interfaces.aws_cloudfront.IResponseHeadersPolicyRef
109
112
  readonly assetsBucket: cdk.aws_s3.Bucket
110
- readonly storageBucket: cdk.aws_s3.Bucket
113
+ /** The app's object storage, the `storage` port's bucket: none unless `params.ports.storage` is `s3` or left out. */
114
+ readonly storageBucket: cdk.aws_s3.Bucket | undefined
111
115
  readonly databaseTransport: DatabaseTransport
112
116
  /** The scheduled tick's function, when `scheduledTick` is given. */
113
117
  readonly scheduledTick: cdk.aws_lambda.Function | undefined
@@ -11,6 +11,7 @@ export const PORT_SWITCHES = {
11
11
  email: { variable: 'EMAIL_PROVIDER', choices: ['mailgun', 'none'] },
12
12
  inboundEmail: { variable: 'INBOUND_EMAIL_PROVIDER', choices: ['mailgun', 'none'] },
13
13
  jobs: { variable: 'JOBS_RUNNER', choices: ['codebuild', 'in-process', 'none'] },
14
+ storage: { variable: 'STORAGE_PROVIDER', choices: ['s3', 's3-compatible', 'none'] },
14
15
  }
15
16
 
16
17
  /**
package/src/sssb-app.js CHANGED
@@ -369,6 +369,9 @@ export class SssbApp extends Construct {
369
369
  }
370
370
  // The optional ports' switches (LLM_PROVIDER, …), from `params.ports`: validated here, before anything is built.
371
371
  const portsEnv = portsEnvironment(props.params?.ports)
372
+ // Storage left out is the framework's default, `s3`: the bucket below exists for `s3` alone. `s3-compatible`
373
+ // keeps its objects in a store this stack does not own (R2, MinIO, B2), and `none` stores nothing.
374
+ const storesObjects = (portsEnv['STORAGE_PROVIDER'] ?? 's3') === 's3'
372
375
  const scheduledTick = props.scheduledTick
373
376
  // Duck-typed: an imported secret (`Secret.fromSecretCompleteArn`) is no `Secret` instance.
374
377
  const tickSecret = /** @type {{ secretArn?: unknown, grantRead?: unknown } | undefined} */ (
@@ -453,14 +456,19 @@ export class SssbApp extends Construct {
453
456
  })
454
457
  // App object storage (StoragePort) — private, NEVER behind CloudFront: sharing the CDN
455
458
  // bucket would make app-stored objects publicly fetchable and let the app overwrite
456
- // served JS.
457
- const storageBucket = new aws_s3.Bucket(this, 'StorageBucket', {
458
- blockPublicAccess: aws_s3.BlockPublicAccess.BLOCK_ALL,
459
- enforceSSL: true,
460
- encryption: aws_s3.BucketEncryption.S3_MANAGED,
461
- removalPolicy,
462
- autoDeleteObjects: !isProd,
463
- })
459
+ // served JS. Only for an app on the `s3` choice (`params.ports.storage` `s3`, or left out). Its construct id, and so
460
+ // its logical id, is the same whenever it exists (the stateful logical ids snapshot). Switching an existing
461
+ // deployment to `none` or `s3-compatible` removes it from the stack: in production its removal policy retains it, orphaned with
462
+ // its objects; elsewhere it is emptied and deleted, as on the stack's own deletion.
463
+ const storageBucket = storesObjects
464
+ ? new aws_s3.Bucket(this, 'StorageBucket', {
465
+ blockPublicAccess: aws_s3.BlockPublicAccess.BLOCK_ALL,
466
+ enforceSSL: true,
467
+ encryption: aws_s3.BucketEncryption.S3_MANAGED,
468
+ removalPolicy,
469
+ autoDeleteObjects: !isProd,
470
+ })
471
+ : undefined
464
472
 
465
473
  // The database half of each Lambda's environment (the framework's real adapters read it at boot).
466
474
  // data-api builds no DATABASE_URL at all: the credential stays in Secrets Manager, where the Data
@@ -529,12 +537,12 @@ export class SssbApp extends Construct {
529
537
  APP_MODE: 'real',
530
538
  NEXT_TELEMETRY_DISABLED: '1',
531
539
  ...databaseEnv,
532
- STORAGE_BUCKET: storageBucket.bucketName,
540
+ ...(storageBucket && { STORAGE_BUCKET: storageBucket.bucketName }),
533
541
  ...portsEnv,
534
542
  },
535
543
  })
536
544
  grantDatabase(server)
537
- storageBucket.grantReadWrite(server)
545
+ storageBucket?.grantReadWrite(server)
538
546
 
539
547
  // AWS_IAM, not NONE. A Function URL with NONE answers anyone on the internet who has the URL,
540
548
  // and putting CloudFront in front of it does not change that — the origin stays directly