// shareLink — turn a resource id into a short-lived share URL. // // Demonstrates: POST with a JSON body, schema-typed input/output, `ctx.env` // config, and runtime hints (memory / timeout / region). Pure compute — no // I/O — so it is trivially edge-safe and scales to zero. // // curl -X POST http://localhost:8910/ -d '{"resourceId":"doc-1","ttlMinutes":30}' import { Effect, Schema } from 'effect' import { defineServerless } from '@voltro/serverless' export default defineServerless({ name: 'share-link', method: 'POST', input: Schema.Struct({ resourceId: Schema.String.pipe(Schema.minLength(1)), ttlMinutes: Schema.Number.pipe(Schema.greaterThan(0)), }), output: Schema.Struct({ url: Schema.String, expiresAt: Schema.Number, }), runtime: { memoryMb: 128, timeoutSeconds: 10, region: 'fr-par' }, handler: ({ resourceId, ttlMinutes }, ctx) => Effect.sync(() => { const base = ctx.env.SHARE_BASE_URL ?? 'https://share.example' const expiresAt = Date.now() + ttlMinutes * 60_000 return { url: `${base}/s/${encodeURIComponent(resourceId)}?exp=${expiresAt}`, expiresAt } }), })