@beechcms/api 0.6.0-preview.2 → 0.6.0-preview.4
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/README.md +4 -4
- package/assets/dashboard/BeechLogo.svg +18 -18
- package/assets/dashboard/BeechLogoLIght.svg +48 -48
- package/assets/dashboard/assets/chart-BwlCt-IA.js +39 -0
- package/assets/dashboard/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/assets/dashboard/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/assets/dashboard/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/assets/dashboard/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/assets/dashboard/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/assets/dashboard/assets/index-BcVN-DNy.js +642 -0
- package/assets/dashboard/assets/index-Cf1yRCqG.css +1 -0
- package/assets/dashboard/assets/lora-cyrillic-ext-wght-normal-YcVxMP-u.woff2 +0 -0
- package/assets/dashboard/assets/lora-cyrillic-wght-normal-UWPuZLjM.woff2 +0 -0
- package/assets/dashboard/assets/lora-latin-ext-wght-normal-C2Wlntb9.woff2 +0 -0
- package/assets/dashboard/assets/lora-latin-wght-normal-BiLcIKcI.woff2 +0 -0
- package/assets/dashboard/assets/lora-math-wght-normal-sOy7rEfW.woff2 +0 -0
- package/assets/dashboard/assets/lora-symbols-wght-normal-DQ5VrUkH.woff2 +0 -0
- package/assets/dashboard/assets/lora-vietnamese-wght-normal-CfJ7gtf3.woff2 +0 -0
- package/assets/dashboard/assets/pie-chart-recharts-BMWpjFzf.js +1 -0
- package/assets/dashboard/assets/timeseries-chart-recharts-8_GwAFR0.js +1 -0
- package/assets/dashboard/beechLogoDark.svg +48 -48
- package/assets/dashboard/index.html +18 -18
- package/assets/dashboard/noResult.svg +42 -42
- package/assets/dashboard/sol.svg +3 -3
- package/assets/dashboard/undraw_enter_nwx3.svg +36 -36
- package/dist/auth/__fixtures__/in-memory-hash-provider.d.ts +5 -0
- package/dist/auth/__fixtures__/static-token-service.d.ts +6 -0
- package/dist/auth/bcrypt-hash-provider.d.ts +8 -0
- package/dist/auth/constants.d.ts +10 -0
- package/dist/auth/jose-token-service.d.ts +14 -0
- package/dist/auth/login.d.ts +32 -0
- package/dist/auth/refresh.d.ts +1 -0
- package/dist/factory.d.ts +45 -0
- package/dist/features/automations/action-executors/create-entry.executor.d.ts +7 -0
- package/dist/features/automations/action-executors/edit-field.executor.d.ts +7 -0
- package/dist/features/automations/action-executors/index.d.ts +13 -0
- package/dist/features/automations/action-executors/send-mail.executor.d.ts +7 -0
- package/dist/features/automations/action-executors/set-variable.executor.d.ts +15 -0
- package/dist/features/automations/action-executors/webhook.executor.d.ts +7 -0
- package/dist/features/automations/automation-runner.d.ts +13 -0
- package/dist/features/automations/automation-runner.utils.d.ts +3 -0
- package/dist/features/automations/automations.handler.d.ts +7 -0
- package/dist/features/automations/automations.schema.d.ts +191 -0
- package/dist/features/automations/context-resolver.d.ts +8 -0
- package/dist/features/automations/cron-runner.d.ts +9 -0
- package/dist/features/automations/cron-runner.utils.d.ts +1 -0
- package/dist/features/automations/filter-translation.d.ts +9 -0
- package/dist/features/automations/index.d.ts +7 -0
- package/dist/features/automations/template-grammar.d.ts +73 -0
- package/dist/features/automations/var-access-resolver.d.ts +6 -0
- package/dist/features/automations/when-evaluator.d.ts +3 -0
- package/dist/features/automations/when-pushdown.d.ts +2 -0
- package/dist/features/backrefs/backrefs.handler.d.ts +3 -0
- package/dist/features/backrefs/d1-backref.repository.d.ts +17 -0
- package/dist/features/backrefs/index.d.ts +1 -0
- package/dist/features/content/constants.d.ts +12 -0
- package/dist/features/content/handlers/bulk.handler.d.ts +3 -0
- package/dist/features/content/handlers/create.d.ts +3 -0
- package/dist/features/content/handlers/delete.d.ts +3 -0
- package/dist/features/content/handlers/facets.d.ts +3 -0
- package/dist/features/content/handlers/get.d.ts +4 -0
- package/dist/features/content/handlers/helpers.d.ts +12 -0
- package/dist/features/content/handlers/list.d.ts +3 -0
- package/dist/features/content/handlers/update.d.ts +3 -0
- package/dist/features/content/index.d.ts +4 -0
- package/dist/features/dashboard-layout/dashboard-layout.handler.d.ts +7 -0
- package/dist/features/dashboard-layout/index.d.ts +1 -0
- package/dist/features/draft/draft.handler.d.ts +4 -0
- package/dist/features/draft/draft.middleware.d.ts +9 -0
- package/dist/features/draft/index.d.ts +1 -0
- package/{src/features/email/email.provider.ts → dist/features/email/email.provider.d.ts} +19 -24
- package/dist/features/email/email.service.d.ts +13 -0
- package/dist/features/email/email.types.d.ts +94 -0
- package/{src/features/email/index.ts → dist/features/email/index.d.ts} +3 -16
- package/dist/features/email/providers/resend.d.ts +36 -0
- package/dist/features/email/providers/smtp.d.ts +11 -0
- package/dist/features/email/templates/automation-mail.d.ts +8 -0
- package/dist/features/email/templates/password-changed.d.ts +15 -0
- package/dist/features/email/templates/password-reset.d.ts +18 -0
- package/dist/features/email/templates/shell.d.ts +58 -0
- package/dist/features/notifications/index.d.ts +1 -0
- package/dist/features/notifications/notifications.handler.d.ts +15 -0
- package/dist/features/password-reset/index.d.ts +6 -0
- package/dist/features/password-reset/request.d.ts +10 -0
- package/dist/features/password-reset/reset.d.ts +9 -0
- package/dist/features/rotate-field/index.d.ts +1 -0
- package/dist/features/rotate-field/rotate-field.handler.d.ts +7 -0
- package/dist/features/rotate-field/rotate-field.schema.d.ts +11 -0
- package/dist/features/schema/schema.handler.d.ts +7 -0
- package/dist/features/seeds/index.d.ts +1 -0
- package/dist/features/seeds/seeds.handler.d.ts +6 -0
- package/dist/features/settings/settings.handler.d.ts +7 -0
- package/dist/features/setup/index.d.ts +7 -0
- package/dist/features/stats/index.d.ts +1 -0
- package/dist/features/stats/stats.handler.d.ts +7 -0
- package/dist/features/webhooks/index.d.ts +3 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +9732 -0
- package/dist/media-utils.d.ts +25 -0
- package/dist/middleware/auth-providers.middleware.d.ts +8 -0
- package/dist/middleware/observability.middleware.d.ts +20 -0
- package/dist/middleware/queue.middleware.d.ts +11 -0
- package/dist/middleware/rate-limit.middleware.d.ts +9 -0
- package/dist/middleware/repository.middleware.d.ts +34 -0
- package/dist/middleware/seed-registry.middleware.d.ts +10 -0
- package/dist/middleware/storage.middleware.d.ts +7 -0
- package/dist/middleware.d.ts +11 -0
- package/dist/public/access-policy.d.ts +12 -0
- package/dist/public/api-key-middleware.d.ts +6 -0
- package/dist/public/cache-utils.d.ts +10 -0
- package/dist/public/entry-projection.d.ts +2 -0
- package/dist/public/idempotency.d.ts +9 -0
- package/dist/public/index.d.ts +11 -0
- package/dist/public/problem-details.d.ts +31 -0
- package/dist/public/public-add.d.ts +3 -0
- package/dist/public/public-edit.d.ts +5 -0
- package/dist/public/public-errors.d.ts +13 -0
- package/dist/public/public-read.d.ts +3 -0
- package/dist/public/public-routes.d.ts +3 -0
- package/dist/public/query-builder.d.ts +28 -0
- package/dist/public/rate-limit-middleware.d.ts +3 -0
- package/dist/public/read-list.d.ts +26 -0
- package/dist/public/read-single.d.ts +22 -0
- package/dist/public/response-builder.d.ts +22 -0
- package/dist/public/sanitize.d.ts +23 -0
- package/{src/public/slug-utils.ts → dist/public/slug-utils.d.ts} +3 -10
- package/dist/rate-limit/cloudflare-rate-limiter.d.ts +6 -0
- package/dist/rate-limit/in-memory-rate-limiter.d.ts +7 -0
- package/dist/rate-limit/no-op-rate-limiter.d.ts +4 -0
- package/dist/search-utils.d.ts +54 -0
- package/dist/search.d.ts +6 -0
- package/dist/shared/apply-policies.d.ts +10 -0
- package/dist/shared/automations.repository.d1.d.ts +12 -0
- package/dist/shared/background-notification-service.d.ts +18 -0
- package/dist/shared/base.repository.d1.d.ts +18 -0
- package/dist/shared/cloudflare-queue-service.d.ts +11 -0
- package/dist/shared/content-utils.d.ts +21 -0
- package/dist/shared/content.repository.d1.d.ts +68 -0
- package/dist/shared/d1-activity-log.repository.d.ts +13 -0
- package/dist/shared/d1-activity-logger.d.ts +20 -0
- package/dist/shared/d1-analytics.repository.d.ts +20 -0
- package/dist/shared/d1-content-scan.repository.d.ts +7 -0
- package/dist/shared/d1-notification.repository.d.ts +17 -0
- package/dist/shared/d1-password-reset-token.repository.d.ts +10 -0
- package/dist/shared/d1-search.repository.d.ts +14 -0
- package/dist/shared/d1-session.repository.d.ts +12 -0
- package/dist/shared/d1-setup-checklist.repository.d.ts +12 -0
- package/dist/shared/d1-user.repository.d.ts +18 -0
- package/dist/shared/d1-widget.repository.d.ts +31 -0
- package/dist/shared/dashboard-layout.repository.d1.d.ts +9 -0
- package/dist/shared/demo-data-sql.d.ts +1 -0
- package/dist/shared/demo-data.repository.d1.d.ts +6 -0
- package/dist/shared/execution-context-scheduler.d.ts +6 -0
- package/dist/shared/fixed-clock.d.ts +13 -0
- package/dist/shared/fts-sync.d.ts +1 -0
- package/dist/shared/idempotency.repository.d1.d.ts +16 -0
- package/dist/shared/in-memory-activity-logger.d.ts +11 -0
- package/dist/shared/in-memory-notification-service.d.ts +11 -0
- package/dist/shared/in-memory-queue-service.d.ts +16 -0
- package/dist/shared/in-memory-seed.repository.d.ts +18 -0
- package/dist/shared/media.repository.d1.d.ts +35 -0
- package/dist/shared/qstash-notification-service.d.ts +18 -0
- package/dist/shared/query-utils.d.ts +36 -0
- package/dist/shared/queue-consumer.d.ts +9 -0
- package/dist/shared/request-utils.d.ts +13 -0
- package/dist/shared/schema-mutator.d1.d.ts +12 -0
- package/dist/shared/seed-layout.repository.d1.d.ts +9 -0
- package/dist/shared/seed-registry-cache.d.ts +12 -0
- package/dist/shared/seed.repository.d1.d.ts +13 -0
- package/dist/shared/sequential-id-generator.d.ts +13 -0
- package/dist/shared/site-settings.repository.d1.d.ts +7 -0
- package/dist/shared/storage/factory.d.ts +8 -0
- package/dist/shared/storage/s3-bucket.d.ts +43 -0
- package/dist/shared/storage-utils.d.ts +7 -0
- package/dist/shared/system-stats.repository.d1.d.ts +25 -0
- package/dist/types.d.ts +87 -0
- package/dist/upload.d.ts +16 -0
- package/dist/widget.d.ts +7 -0
- package/migrations/0000_v040_base.sql +265 -265
- package/migrations/0029_automations.sql +14 -14
- package/migrations/0030_test_seeds.sql +125 -125
- package/package.json +28 -18
- package/assets/dashboard/assets/chart-BrJFdsGZ.js +0 -39
- package/assets/dashboard/assets/index-CIaoMxuB.css +0 -1
- package/assets/dashboard/assets/index-wTKgygsg.js +0 -636
- package/assets/dashboard/assets/pie-chart-recharts-BEaE1FOE.js +0 -1
- package/assets/dashboard/assets/timeseries-chart-recharts-DmWM6imF.js +0 -1
- package/src/auth/__fixtures__/in-memory-hash-provider.ts +0 -17
- package/src/auth/__fixtures__/static-token-service.ts +0 -22
- package/src/auth/bcrypt-hash-provider.ts +0 -24
- package/src/auth/constants.ts +0 -14
- package/src/auth/generate-refresh-token.test.ts +0 -23
- package/src/auth/hash-provider.test.ts +0 -55
- package/src/auth/jose-token-service.ts +0 -62
- package/src/auth/jwt-claims-passthrough.test.ts +0 -87
- package/src/auth/login.test.ts +0 -100
- package/src/auth/login.ts +0 -78
- package/src/auth/refresh.ts +0 -11
- package/src/auth/token-service.test.ts +0 -90
- package/src/factory.ts +0 -370
- package/src/features/automations/__tests__/action-executors.test.ts +0 -255
- package/src/features/automations/__tests__/automation-runner.test.ts +0 -196
- package/src/features/automations/__tests__/automation-runner.utils.test.ts +0 -60
- package/src/features/automations/__tests__/automations.handler.test.ts +0 -264
- package/src/features/automations/__tests__/automations.repository.test.ts +0 -163
- package/src/features/automations/__tests__/automations.schema.test.ts +0 -224
- package/src/features/automations/__tests__/context-resolver.test.ts +0 -126
- package/src/features/automations/__tests__/cron-runner.test.ts +0 -267
- package/src/features/automations/__tests__/cron-runner.utils.test.ts +0 -144
- package/src/features/automations/__tests__/set-variable.executor.test.ts +0 -383
- package/src/features/automations/__tests__/template-grammar.test.ts +0 -308
- package/src/features/automations/__tests__/webhook.executor.test.ts +0 -142
- package/src/features/automations/__tests__/when-evaluator.test.ts +0 -274
- package/src/features/automations/__tests__/when-pushdown.test.ts +0 -281
- package/src/features/automations/action-executors/create-entry.executor.ts +0 -27
- package/src/features/automations/action-executors/edit-field.executor.ts +0 -26
- package/src/features/automations/action-executors/index.ts +0 -37
- package/src/features/automations/action-executors/send-mail.executor.ts +0 -53
- package/src/features/automations/action-executors/set-variable.executor.ts +0 -159
- package/src/features/automations/action-executors/webhook.executor.ts +0 -67
- package/src/features/automations/automation-runner.ts +0 -85
- package/src/features/automations/automation-runner.utils.ts +0 -47
- package/src/features/automations/automations.handler.ts +0 -197
- package/src/features/automations/automations.schema.ts +0 -177
- package/src/features/automations/context-resolver.ts +0 -152
- package/src/features/automations/cron-runner.ts +0 -140
- package/src/features/automations/cron-runner.utils.ts +0 -44
- package/src/features/automations/filter-translation.ts +0 -46
- package/src/features/automations/index.ts +0 -16
- package/src/features/automations/template-grammar.ts +0 -245
- package/src/features/automations/var-access-resolver.ts +0 -140
- package/src/features/automations/when-evaluator.ts +0 -87
- package/src/features/automations/when-pushdown.ts +0 -57
- package/src/features/backrefs/__tests__/backrefs.handler.test.ts +0 -359
- package/src/features/backrefs/backrefs.handler.ts +0 -168
- package/src/features/backrefs/d1-backref.repository.ts +0 -84
- package/src/features/backrefs/index.ts +0 -5
- package/src/features/content/constants.ts +0 -16
- package/src/features/content/handlers/bulk.handler.ts +0 -185
- package/src/features/content/handlers/create.ts +0 -129
- package/src/features/content/handlers/delete.ts +0 -62
- package/src/features/content/handlers/facets.ts +0 -49
- package/src/features/content/handlers/get.ts +0 -120
- package/src/features/content/handlers/helpers.test.ts +0 -180
- package/src/features/content/handlers/helpers.ts +0 -93
- package/src/features/content/handlers/list.ts +0 -174
- package/src/features/content/handlers/update.ts +0 -174
- package/src/features/content/index.ts +0 -26
- package/src/features/dashboard-layout/__tests__/dashboard-layout.handler.test.ts +0 -388
- package/src/features/dashboard-layout/dashboard-layout.handler.ts +0 -206
- package/src/features/dashboard-layout/index.ts +0 -5
- package/src/features/draft/draft.handler.ts +0 -195
- package/src/features/draft/draft.middleware.ts +0 -66
- package/src/features/draft/index.ts +0 -5
- package/src/features/email/email.service.ts +0 -98
- package/src/features/email/email.types.ts +0 -119
- package/src/features/email/providers/resend.ts +0 -67
- package/src/features/email/providers/smtp.ts +0 -55
- package/src/features/email/templates/automation-mail.ts +0 -19
- package/src/features/email/templates/password-changed.ts +0 -63
- package/src/features/email/templates/password-reset.ts +0 -68
- package/src/features/email/templates/shell.ts +0 -96
- package/src/features/notifications/index.ts +0 -5
- package/src/features/notifications/notifications.handler.ts +0 -105
- package/src/features/password-reset/index.ts +0 -19
- package/src/features/password-reset/request.ts +0 -92
- package/src/features/password-reset/reset.ts +0 -102
- package/src/features/rotate-field/index.ts +0 -5
- package/src/features/rotate-field/rotate-field.handler.ts +0 -132
- package/src/features/rotate-field/rotate-field.schema.ts +0 -17
- package/src/features/schema/schema.handler.ts +0 -131
- package/src/features/seeds/index.ts +0 -5
- package/src/features/seeds/seeds.handler.test.ts +0 -1199
- package/src/features/seeds/seeds.handler.ts +0 -558
- package/src/features/settings/__tests__/settings.handler.test.ts +0 -555
- package/src/features/settings/settings.handler.ts +0 -392
- package/src/features/setup/index.ts +0 -288
- package/src/features/stats/index.ts +0 -5
- package/src/features/stats/stats.handler.ts +0 -420
- package/src/features/webhooks/index.ts +0 -63
- package/src/index.ts +0 -65
- package/src/media-utils.ts +0 -82
- package/src/middleware/auth-providers.middleware.test.ts +0 -85
- package/src/middleware/auth-providers.middleware.ts +0 -45
- package/src/middleware/observability.middleware.test.ts +0 -93
- package/src/middleware/observability.middleware.ts +0 -70
- package/src/middleware/rate-limit.middleware.ts +0 -45
- package/src/middleware/repository.middleware.ts +0 -117
- package/src/middleware/seed-registry.middleware.test.ts +0 -97
- package/src/middleware/seed-registry.middleware.ts +0 -21
- package/src/middleware/storage.middleware.ts +0 -25
- package/src/middleware.ts +0 -45
- package/src/public/access-policy.ts +0 -27
- package/src/public/api-key-middleware.ts +0 -57
- package/src/public/cache-utils.ts +0 -38
- package/src/public/entry-projection.ts +0 -46
- package/src/public/idempotency.ts +0 -23
- package/src/public/index.ts +0 -16
- package/src/public/problem-details.ts +0 -124
- package/src/public/public-add.ts +0 -114
- package/src/public/public-edit.ts +0 -163
- package/src/public/public-errors.ts +0 -19
- package/src/public/public-read.ts +0 -63
- package/src/public/public-routes.ts +0 -88
- package/src/public/query-builder.test.ts +0 -224
- package/src/public/query-builder.ts +0 -156
- package/src/public/rate-limit-middleware.ts +0 -34
- package/src/public/read-list.ts +0 -54
- package/src/public/read-single.ts +0 -48
- package/src/public/response-builder.ts +0 -30
- package/src/public/sanitize.ts +0 -69
- package/src/rate-limit/cloudflare-rate-limiter.test.ts +0 -30
- package/src/rate-limit/cloudflare-rate-limiter.ts +0 -15
- package/src/rate-limit/in-memory-rate-limiter.test.ts +0 -37
- package/src/rate-limit/in-memory-rate-limiter.ts +0 -17
- package/src/rate-limit/no-op-rate-limiter.test.ts +0 -22
- package/src/rate-limit/no-op-rate-limiter.ts +0 -11
- package/src/search-utils.test.ts +0 -211
- package/src/search-utils.ts +0 -213
- package/src/search.ts +0 -65
- package/src/shared/apply-policies.test.ts +0 -81
- package/src/shared/apply-policies.ts +0 -67
- package/src/shared/automations.repository.d1.ts +0 -150
- package/src/shared/background-notification-service.test.ts +0 -62
- package/src/shared/background-notification-service.ts +0 -52
- package/src/shared/base.repository.d1.ts +0 -32
- package/src/shared/content-utils.test.ts +0 -165
- package/src/shared/content-utils.ts +0 -86
- package/src/shared/content.repository.d1.test.ts +0 -507
- package/src/shared/content.repository.d1.ts +0 -851
- package/src/shared/d1-activity-log.repository.test.ts +0 -140
- package/src/shared/d1-activity-log.repository.ts +0 -105
- package/src/shared/d1-activity-logger.test.ts +0 -86
- package/src/shared/d1-activity-logger.ts +0 -67
- package/src/shared/d1-analytics.repository.test.ts +0 -78
- package/src/shared/d1-analytics.repository.ts +0 -85
- package/src/shared/d1-content-scan.repository.test.ts +0 -80
- package/src/shared/d1-content-scan.repository.ts +0 -37
- package/src/shared/d1-notification.repository.test.ts +0 -128
- package/src/shared/d1-notification.repository.ts +0 -118
- package/src/shared/d1-password-reset-token.repository.test.ts +0 -81
- package/src/shared/d1-password-reset-token.repository.ts +0 -56
- package/src/shared/d1-search.repository.test.ts +0 -87
- package/src/shared/d1-search.repository.ts +0 -88
- package/src/shared/d1-session.repository.test.ts +0 -125
- package/src/shared/d1-session.repository.ts +0 -102
- package/src/shared/d1-setup-checklist.repository.ts +0 -36
- package/src/shared/d1-user.repository.test.ts +0 -151
- package/src/shared/d1-user.repository.ts +0 -119
- package/src/shared/d1-widget.repository.test.ts +0 -267
- package/src/shared/d1-widget.repository.ts +0 -385
- package/src/shared/dashboard-layout.repository.d1.test.ts +0 -135
- package/src/shared/dashboard-layout.repository.d1.ts +0 -58
- package/src/shared/demo-data-sql.ts +0 -216
- package/src/shared/demo-data.repository.d1.ts +0 -20
- package/src/shared/execution-context-scheduler.ts +0 -13
- package/src/shared/fixed-clock.ts +0 -25
- package/src/shared/fts-sync.ts +0 -8
- package/src/shared/idempotency.repository.d1.test.ts +0 -83
- package/src/shared/idempotency.repository.d1.ts +0 -60
- package/src/shared/in-memory-activity-logger.ts +0 -19
- package/src/shared/in-memory-notification-service.ts +0 -19
- package/src/shared/in-memory-seed.repository.ts +0 -58
- package/src/shared/media.repository.d1.test.ts +0 -107
- package/src/shared/media.repository.d1.ts +0 -68
- package/src/shared/qstash-notification-service.test.ts +0 -67
- package/src/shared/qstash-notification-service.ts +0 -55
- package/src/shared/query-utils.ts +0 -141
- package/src/shared/request-utils.ts +0 -26
- package/src/shared/schema-mutator.d1.test.ts +0 -142
- package/src/shared/schema-mutator.d1.ts +0 -64
- package/src/shared/seed-layout.repository.d1.test.ts +0 -114
- package/src/shared/seed-layout.repository.d1.ts +0 -62
- package/src/shared/seed-registry-cache.test.ts +0 -68
- package/src/shared/seed-registry-cache.ts +0 -49
- package/src/shared/seed.repository.d1.test.ts +0 -143
- package/src/shared/seed.repository.d1.ts +0 -98
- package/src/shared/sequential-id-generator.ts +0 -33
- package/src/shared/site-settings.repository.d1.ts +0 -53
- package/src/shared/storage/factory.ts +0 -41
- package/src/shared/storage/s3-bucket.ts +0 -195
- package/src/shared/storage-utils.ts +0 -40
- package/src/shared/system-stats.repository.d1.test.ts +0 -58
- package/src/shared/system-stats.repository.d1.ts +0 -48
- package/src/types.ts +0 -90
- package/src/upload.ts +0 -198
- package/src/widget.test.ts +0 -85
- package/src/widget.ts +0 -251
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
|
|
3
|
-
// See LICENSE in the repository root for license terms.
|
|
4
|
-
|
|
5
|
-
import { Hono } from 'hono'
|
|
6
|
-
import type { AppEnv } from '../types'
|
|
7
|
-
import { publicReadHandler } from './public-read'
|
|
8
|
-
import { publicAddHandler } from './public-add'
|
|
9
|
-
import { publicEditHandler } from './public-edit'
|
|
10
|
-
|
|
11
|
-
const publicApp = new Hono<AppEnv>()
|
|
12
|
-
|
|
13
|
-
publicApp.get('/health', (c) => {
|
|
14
|
-
return c.json({ ok: true, service: 'public-api' }, 200)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
/** Returns the public-facing schema: only seeds with public read or post enabled. */
|
|
18
|
-
publicApp.get('/schema', (c) => {
|
|
19
|
-
const registry = c.get('seedRegistry')
|
|
20
|
-
const publicSeeds = registry.all()
|
|
21
|
-
.filter(seed => seed.allowPublicRead === true || seed.allowPublicPost === true || seed.allowPublicEdit === true)
|
|
22
|
-
.map(seed => ({
|
|
23
|
-
slug: seed.slug,
|
|
24
|
-
label: seed.label,
|
|
25
|
-
labelPlural: seed.labelPlural,
|
|
26
|
-
allowPublicRead: seed.allowPublicRead ?? false,
|
|
27
|
-
allowPublicPost: seed.allowPublicPost ?? false,
|
|
28
|
-
allowPublicEdit: seed.allowPublicEdit ?? false,
|
|
29
|
-
branches: (seed.branches ?? []).map(branch => ({
|
|
30
|
-
alias: branch.alias,
|
|
31
|
-
type: branch.type,
|
|
32
|
-
label: branch.label,
|
|
33
|
-
requiredOnCreate: branch.requiredOnCreate ?? false,
|
|
34
|
-
policies: {
|
|
35
|
-
public: branch.policies?.public ?? true,
|
|
36
|
-
visibility: branch.policies?.visibility ?? 'full',
|
|
37
|
-
},
|
|
38
|
-
})),
|
|
39
|
-
}))
|
|
40
|
-
return c.json({ seeds: publicSeeds })
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
/** HTML render of the public schema for quick browser inspection. */
|
|
44
|
-
publicApp.get('/schema.html', (c) => {
|
|
45
|
-
const registry = c.get('seedRegistry')
|
|
46
|
-
const publicSeeds = registry.all()
|
|
47
|
-
.filter(seed => seed.allowPublicRead === true || seed.allowPublicPost === true || seed.allowPublicEdit === true)
|
|
48
|
-
|
|
49
|
-
const seedHtml = publicSeeds.map(seed => {
|
|
50
|
-
const ops = [
|
|
51
|
-
seed.allowPublicRead && 'GET /:seed',
|
|
52
|
-
seed.allowPublicPost && 'POST /:seed/add',
|
|
53
|
-
seed.allowPublicEdit && 'PUT /:seed/edit/:id',
|
|
54
|
-
].filter(Boolean).join(', ')
|
|
55
|
-
|
|
56
|
-
const branchRows = (seed.branches ?? []).map(b =>
|
|
57
|
-
`<tr><td>${b.alias}</td><td>${b.type}</td><td>${b.label}</td><td>${b.requiredOnCreate ? 'yes' : ''}</td><td>${(b.policies?.public ?? true) ? 'readable' : 'hidden'}</td></tr>`
|
|
58
|
-
).join('')
|
|
59
|
-
|
|
60
|
-
return `<section>
|
|
61
|
-
<h2>${seed.label} <code>${seed.slug}</code></h2>
|
|
62
|
-
<p><strong>Allowed operations:</strong> ${ops || 'none'}</p>
|
|
63
|
-
<table><thead><tr><th>alias</th><th>type</th><th>label</th><th>required</th><th>public access</th></tr></thead>
|
|
64
|
-
<tbody>${branchRows}</tbody></table>
|
|
65
|
-
</section>`
|
|
66
|
-
}).join('\n')
|
|
67
|
-
|
|
68
|
-
const html = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">
|
|
69
|
-
<title>BeechCMS Public Schema</title>
|
|
70
|
-
<style>body{font-family:system-ui,sans-serif;max-width:900px;margin:2rem auto;padding:0 1rem;color:#222}
|
|
71
|
-
code{background:#f3f4f6;padding:2px 6px;border-radius:4px}
|
|
72
|
-
table{border-collapse:collapse;width:100%}th,td{text-align:left;padding:6px 10px;border:1px solid #e5e7eb}
|
|
73
|
-
th{background:#f9fafb}h2{margin-top:2rem}section{margin-bottom:2rem}</style>
|
|
74
|
-
</head><body>
|
|
75
|
-
<h1>BeechCMS — Public API Schema</h1>
|
|
76
|
-
<p>Only content types with public access enabled are listed here.</p>
|
|
77
|
-
${seedHtml || '<p><em>No content types with public access configured.</em></p>'}
|
|
78
|
-
</body></html>`
|
|
79
|
-
|
|
80
|
-
return c.html(html)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
publicApp.get('/:seed', publicReadHandler)
|
|
84
|
-
publicApp.post('/:seed/add', publicAddHandler)
|
|
85
|
-
publicApp.put('/:seed/edit/:id', publicEditHandler)
|
|
86
|
-
|
|
87
|
-
export const publicRoutes = publicApp
|
|
88
|
-
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
|
|
3
|
-
// See LICENSE in the repository root for license terms.
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect } from 'vitest'
|
|
6
|
-
import {
|
|
7
|
-
parsePublicFilter,
|
|
8
|
-
toEngineFilters,
|
|
9
|
-
parsePublicPagination,
|
|
10
|
-
parseLatestCount,
|
|
11
|
-
} from './query-builder'
|
|
12
|
-
import type { Seed } from '@beechcms/core'
|
|
13
|
-
|
|
14
|
-
const SEED = {
|
|
15
|
-
slug: 'posts',
|
|
16
|
-
displayNameAlias: 'title',
|
|
17
|
-
branches: [
|
|
18
|
-
{ id: 'br_01', alias: 'title', type: 'text' },
|
|
19
|
-
{ id: 'br_02', alias: 'count', type: 'number' },
|
|
20
|
-
{ id: 'br_03', alias: 'active', type: 'boolean' },
|
|
21
|
-
{ id: 'br_04', alias: 'published_at', type: 'date' },
|
|
22
|
-
{ id: 'br_05', alias: 'tags', type: 'tags' },
|
|
23
|
-
{ id: 'br_06', alias: 'body', type: 'richtext' },
|
|
24
|
-
{ id: 'br_07', alias: 'attachment', type: 'file' },
|
|
25
|
-
{ id: 'br_08', alias: 'meta', type: 'json' },
|
|
26
|
-
],
|
|
27
|
-
} as unknown as Seed
|
|
28
|
-
|
|
29
|
-
// ─── parsePublicFilter ────────────────────────────────────────────────────────
|
|
30
|
-
|
|
31
|
-
describe('parsePublicFilter', () => {
|
|
32
|
-
it('returns null for undefined input', () => {
|
|
33
|
-
expect(parsePublicFilter(undefined)).toBeNull()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('returns null for empty string', () => {
|
|
37
|
-
expect(parsePublicFilter('')).toBeNull()
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('parses a valid filter with explicit AND logic', () => {
|
|
41
|
-
const raw = JSON.stringify({ logic: 'AND', where: [{ field: 'title', op: 'eq', value: 'Hello' }] })
|
|
42
|
-
const result = parsePublicFilter(raw)!
|
|
43
|
-
expect(result.logic).toBe('AND')
|
|
44
|
-
expect(result.where).toHaveLength(1)
|
|
45
|
-
expect(result.where[0]).toEqual({ field: 'title', op: 'eq', value: 'Hello' })
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('defaults logic to AND when omitted', () => {
|
|
49
|
-
const raw = JSON.stringify({ where: [{ field: 'title', op: 'contains', value: 'x' }] })
|
|
50
|
-
expect(parsePublicFilter(raw)!.logic).toBe('AND')
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('accepts case-insensitive logic value', () => {
|
|
54
|
-
const raw = JSON.stringify({ logic: 'or', where: [] })
|
|
55
|
-
expect(parsePublicFilter(raw)!.logic).toBe('OR')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('throws for malformed JSON', () => {
|
|
59
|
-
expect(() => parsePublicFilter('{not-json')).toThrow('malformed JSON')
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('throws when parsed value is not an object', () => {
|
|
63
|
-
expect(() => parsePublicFilter('"a string"')).toThrow('object expected')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('throws for an invalid logic value', () => {
|
|
67
|
-
const raw = JSON.stringify({ logic: 'BOTH', where: [] })
|
|
68
|
-
expect(() => parsePublicFilter(raw)).toThrow("'AND' or 'OR'")
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('throws for an unknown operator in a where condition', () => {
|
|
72
|
-
const raw = JSON.stringify({ where: [{ field: 'title', op: 'like', value: 'x' }] })
|
|
73
|
-
expect(() => parsePublicFilter(raw)).toThrow("unknown operator 'like'")
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('throws when where is not an array', () => {
|
|
77
|
-
const raw = JSON.stringify({ where: { field: 'title', op: 'eq' } })
|
|
78
|
-
expect(() => parsePublicFilter(raw)).toThrow("'where' must be an array")
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('filters out null conditions from where (missing field/op)', () => {
|
|
82
|
-
const raw = JSON.stringify({ where: [null, { field: 'title', op: 'eq', value: 'x' }] })
|
|
83
|
-
const result = parsePublicFilter(raw)!
|
|
84
|
-
expect(result.where).toHaveLength(1)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('accepts all valid operators without throwing', () => {
|
|
88
|
-
const operators = ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'contains', 'not_contains',
|
|
89
|
-
'starts_with', 'ends_with', 'is_empty', 'is_not_empty', 'in', 'not_in',
|
|
90
|
-
'has_tag', 'has_any_tag', 'has_all_tags']
|
|
91
|
-
for (const op of operators) {
|
|
92
|
-
const raw = JSON.stringify({ where: [{ field: 'title', op, value: 'x' }] })
|
|
93
|
-
expect(() => parsePublicFilter(raw)).not.toThrow()
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
// ─── toEngineFilters ──────────────────────────────────────────────────────────
|
|
99
|
-
|
|
100
|
-
describe('toEngineFilters', () => {
|
|
101
|
-
it('returns [] for null filter', () => {
|
|
102
|
-
expect(toEngineFilters(SEED, null)).toEqual([])
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('returns [] when where array is empty', () => {
|
|
106
|
-
expect(toEngineFilters(SEED, { where: [], logic: 'AND' })).toEqual([])
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('maps text branch to FilterType "text"', () => {
|
|
110
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'title', op: 'eq', value: 'Hi' }], logic: 'AND' })
|
|
111
|
-
expect(result[0].type).toBe('text')
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('maps number branch to FilterType "number"', () => {
|
|
115
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'count', op: 'gt', value: 5 }], logic: 'AND' })
|
|
116
|
-
expect(result[0].type).toBe('number')
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
it('maps boolean branch to FilterType "boolean"', () => {
|
|
120
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'active', op: 'eq', value: true }], logic: 'AND' })
|
|
121
|
-
expect(result[0].type).toBe('boolean')
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('maps date branch to FilterType "date"', () => {
|
|
125
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'published_at', op: 'gt', value: '2024-01-01' }], logic: 'AND' })
|
|
126
|
-
expect(result[0].type).toBe('date')
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('maps tags branch to FilterType "tags"', () => {
|
|
130
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'tags', op: 'has_tag', value: 'news' }], logic: 'AND' })
|
|
131
|
-
expect(result[0].type).toBe('tags')
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('maps richtext branch to FilterType "text"', () => {
|
|
135
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'body', op: 'contains', value: 'x' }], logic: 'AND' })
|
|
136
|
-
expect(result[0].type).toBe('text')
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
it('maps file branch to FilterType "text"', () => {
|
|
140
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'attachment', op: 'contains', value: 'url' }], logic: 'AND' })
|
|
141
|
-
expect(result[0].type).toBe('text')
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('maps json branch to FilterType "json"', () => {
|
|
145
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'meta', op: 'eq', value: '{}' }], logic: 'AND' })
|
|
146
|
-
expect(result[0].type).toBe('json')
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
it('maps system columns (id, slug, status) to FilterType "system"', () => {
|
|
150
|
-
for (const field of ['id', 'slug', 'status', 'created_at', 'updated_at']) {
|
|
151
|
-
const result = toEngineFilters(SEED, { where: [{ field, op: 'eq', value: 'x' }], logic: 'AND' })
|
|
152
|
-
expect(result[0].type).toBe('system')
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('maps unknown fields to FilterType "text"', () => {
|
|
157
|
-
const result = toEngineFilters(SEED, { where: [{ field: 'ghost_field', op: 'eq', value: 'x' }], logic: 'AND' })
|
|
158
|
-
expect(result[0].type).toBe('text')
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
it('produces one FilterGroup per condition', () => {
|
|
162
|
-
const filter = {
|
|
163
|
-
where: [
|
|
164
|
-
{ field: 'title', op: 'eq' as const, value: 'A' },
|
|
165
|
-
{ field: 'count', op: 'gt' as const, value: 5 },
|
|
166
|
-
],
|
|
167
|
-
logic: 'AND' as const,
|
|
168
|
-
}
|
|
169
|
-
expect(toEngineFilters(SEED, filter)).toHaveLength(2)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('includes column and conditions in each FilterGroup', () => {
|
|
173
|
-
const filter = { where: [{ field: 'title', op: 'contains' as const, value: 'hi' }], logic: 'AND' as const }
|
|
174
|
-
const [group] = toEngineFilters(SEED, filter)
|
|
175
|
-
expect(group.column).toBe('title')
|
|
176
|
-
expect(group.conditions[0].op).toBe('contains')
|
|
177
|
-
expect(group.conditions[0].value).toBe('hi')
|
|
178
|
-
})
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
// ─── parsePublicPagination ────────────────────────────────────────────────────
|
|
182
|
-
|
|
183
|
-
describe('parsePublicPagination', () => {
|
|
184
|
-
it('defaults to page=1 and limit=25 when input is empty', () => {
|
|
185
|
-
expect(parsePublicPagination({})).toEqual({ page: 1, limit: 25 })
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
it('parses valid page and limit values', () => {
|
|
189
|
-
expect(parsePublicPagination({ page: '3', limit: '10' })).toEqual({ page: 3, limit: 10 })
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
it('clamps limit to a maximum of 100', () => {
|
|
193
|
-
expect(parsePublicPagination({ limit: '500' }).limit).toBe(100)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
it('uses default for invalid (non-numeric) input', () => {
|
|
197
|
-
expect(parsePublicPagination({ page: 'abc', limit: 'xyz' })).toEqual({ page: 1, limit: 25 })
|
|
198
|
-
})
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
// ─── parseLatestCount ─────────────────────────────────────────────────────────
|
|
202
|
-
|
|
203
|
-
describe('parseLatestCount', () => {
|
|
204
|
-
it('returns 10 for undefined', () => {
|
|
205
|
-
expect(parseLatestCount(undefined)).toBe(10)
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
it('parses a valid integer string', () => {
|
|
209
|
-
expect(parseLatestCount('5')).toBe(5)
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
it('clamps to 1 for values below minimum', () => {
|
|
213
|
-
expect(parseLatestCount('0')).toBe(1)
|
|
214
|
-
expect(parseLatestCount('-5')).toBe(1)
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
it('clamps to 100 for values above maximum', () => {
|
|
218
|
-
expect(parseLatestCount('200')).toBe(100)
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
it('returns 10 for non-numeric input', () => {
|
|
222
|
-
expect(parseLatestCount('abc')).toBe(10)
|
|
223
|
-
})
|
|
224
|
-
})
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
|
|
3
|
-
// See LICENSE in the repository root for license terms.
|
|
4
|
-
|
|
5
|
-
import type { Seed, FilterGroup, FilterOperator, FilterType, BranchType } from '@beechcms/core'
|
|
6
|
-
import { parsePositiveInt } from '../shared/query-utils'
|
|
7
|
-
|
|
8
|
-
export type PublicQueryInput = {
|
|
9
|
-
page?: string
|
|
10
|
-
limit?: string
|
|
11
|
-
latest?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type PublicFilterLogic = 'AND' | 'OR'
|
|
15
|
-
export type PublicFilterOperator =
|
|
16
|
-
| 'eq'
|
|
17
|
-
| 'neq'
|
|
18
|
-
| 'gt'
|
|
19
|
-
| 'gte'
|
|
20
|
-
| 'lt'
|
|
21
|
-
| 'lte'
|
|
22
|
-
| 'contains'
|
|
23
|
-
| 'not_contains'
|
|
24
|
-
| 'starts_with'
|
|
25
|
-
| 'ends_with'
|
|
26
|
-
| 'is_empty'
|
|
27
|
-
| 'is_not_empty'
|
|
28
|
-
| 'in'
|
|
29
|
-
| 'not_in'
|
|
30
|
-
| 'has_tag'
|
|
31
|
-
| 'has_any_tag'
|
|
32
|
-
| 'has_all_tags'
|
|
33
|
-
|
|
34
|
-
export type PublicFilterCondition = {
|
|
35
|
-
field: string
|
|
36
|
-
op: PublicFilterOperator
|
|
37
|
-
value?: unknown
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type ParsedPublicFilter = {
|
|
41
|
-
where: PublicFilterCondition[]
|
|
42
|
-
logic: PublicFilterLogic
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const PUBLIC_FILTER_OPERATORS = new Set<PublicFilterOperator>([
|
|
46
|
-
'eq', 'neq', 'gt', 'gte', 'lt', 'lte',
|
|
47
|
-
'contains', 'not_contains', 'starts_with', 'ends_with',
|
|
48
|
-
'is_empty', 'is_not_empty', 'in', 'not_in',
|
|
49
|
-
'has_tag', 'has_any_tag', 'has_all_tags',
|
|
50
|
-
])
|
|
51
|
-
|
|
52
|
-
function asString(value: unknown): string | null {
|
|
53
|
-
return typeof value === 'string' && value.trim() ? value.trim() : null
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function validateLogic(logicRaw: unknown): PublicFilterLogic {
|
|
57
|
-
if (logicRaw === undefined) return 'AND'
|
|
58
|
-
if (typeof logicRaw !== 'string') throw new TypeError("Invalid filter: 'logic' must be 'AND' or 'OR'")
|
|
59
|
-
const normalized = logicRaw.toUpperCase()
|
|
60
|
-
if (normalized !== 'AND' && normalized !== 'OR') throw new TypeError("Invalid filter: 'logic' must be 'AND' or 'OR'")
|
|
61
|
-
return normalized
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function parseWhereCondition(raw: unknown): PublicFilterCondition | null {
|
|
65
|
-
if (!raw || typeof raw !== 'object') return null
|
|
66
|
-
const maybe = raw as Record<string, unknown>
|
|
67
|
-
const field = asString(maybe.field)
|
|
68
|
-
const opRaw = asString(maybe.op)
|
|
69
|
-
if (!field || !opRaw || !PUBLIC_FILTER_OPERATORS.has(opRaw as PublicFilterOperator)) {
|
|
70
|
-
throw new TypeError(`Invalid filter: unknown operator '${opRaw ?? 'undefined'}'`)
|
|
71
|
-
}
|
|
72
|
-
return { field, op: opRaw as PublicFilterOperator, value: maybe.value }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function parsePublicFilter(raw: string | undefined): ParsedPublicFilter | null {
|
|
76
|
-
if (!raw) return null
|
|
77
|
-
let parsed: unknown
|
|
78
|
-
try {
|
|
79
|
-
parsed = JSON.parse(raw)
|
|
80
|
-
} catch {
|
|
81
|
-
throw new TypeError('Invalid filter: malformed JSON')
|
|
82
|
-
}
|
|
83
|
-
if (!parsed || typeof parsed !== 'object') throw new TypeError('Invalid filter: object expected')
|
|
84
|
-
const filterObj = parsed as Record<string, unknown>
|
|
85
|
-
const logic = validateLogic(filterObj.logic)
|
|
86
|
-
if (!Array.isArray(filterObj.where)) throw new TypeError("Invalid filter: 'where' must be an array")
|
|
87
|
-
const where = filterObj.where
|
|
88
|
-
.map(parseWhereCondition)
|
|
89
|
-
.filter((item): item is PublicFilterCondition => item !== null)
|
|
90
|
-
return { where, logic }
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const SYSTEM_COLUMNS = new Set(['id', 'slug', 'status', 'created_at', 'updated_at'])
|
|
94
|
-
|
|
95
|
-
function mapBranchToFilterType(type: BranchType): FilterType {
|
|
96
|
-
switch (type) {
|
|
97
|
-
case 'richtext':
|
|
98
|
-
case 'file':
|
|
99
|
-
return 'text'
|
|
100
|
-
case 'json':
|
|
101
|
-
return 'json'
|
|
102
|
-
case 'tags':
|
|
103
|
-
return 'tags'
|
|
104
|
-
case 'number':
|
|
105
|
-
return 'number'
|
|
106
|
-
case 'boolean':
|
|
107
|
-
return 'boolean'
|
|
108
|
-
case 'date':
|
|
109
|
-
return 'date'
|
|
110
|
-
case 'text':
|
|
111
|
-
default:
|
|
112
|
-
return 'text'
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Trasforma il filtro pubblico in FilterGroup[] per il Repository.
|
|
118
|
-
* Zero SQL: la logica di generazione query risiede esclusivamente nel Repository/Engine core.
|
|
119
|
-
*/
|
|
120
|
-
export function toEngineFilters(seed: Seed, parsedFilter: ParsedPublicFilter | null): FilterGroup[] {
|
|
121
|
-
if (!parsedFilter || parsedFilter.where.length === 0) return []
|
|
122
|
-
|
|
123
|
-
// Note: Repository currently joins groups with AND.
|
|
124
|
-
// Public API supports logic: OR but the core engine currently defaults to AND for top-level groups.
|
|
125
|
-
// We map each condition to a group for maximum compatibility with the engine's buildFilterCondition.
|
|
126
|
-
return parsedFilter.where.map((cond) => {
|
|
127
|
-
const branch = seed.branches.find(b => b.alias === cond.field)
|
|
128
|
-
const type: FilterType = branch
|
|
129
|
-
? mapBranchToFilterType(branch.type)
|
|
130
|
-
: (SYSTEM_COLUMNS.has(cond.field) ? 'system' : 'text')
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
column: cond.field,
|
|
134
|
-
type,
|
|
135
|
-
conditions: [{
|
|
136
|
-
op: cond.op as FilterOperator,
|
|
137
|
-
value: cond.value as any
|
|
138
|
-
}]
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function parsePublicPagination(input: PublicQueryInput): { page: number; limit: number } {
|
|
144
|
-
const page = parsePositiveInt(input.page, 1)
|
|
145
|
-
const limit = Math.min(parsePositiveInt(input.limit, 25), 100)
|
|
146
|
-
return { page, limit }
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function parseLatestCount(latest: string | undefined): number {
|
|
150
|
-
if (!latest) return 10
|
|
151
|
-
const raw = Number.parseInt(latest, 10)
|
|
152
|
-
const parsed = Number.isNaN(raw) ? 10 : raw
|
|
153
|
-
if (parsed < 1) return 1
|
|
154
|
-
if (parsed > 100) return 100
|
|
155
|
-
return parsed
|
|
156
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
|
|
3
|
-
// See LICENSE in the repository root for license terms.
|
|
4
|
-
|
|
5
|
-
import type { Context, Next } from 'hono'
|
|
6
|
-
import type { AppEnv } from '../types'
|
|
7
|
-
import { publicProblem } from './problem-details'
|
|
8
|
-
import { getClientIp } from '../shared/request-utils'
|
|
9
|
-
|
|
10
|
-
function isReadMethod(method: string): boolean {
|
|
11
|
-
return method === 'GET' || method === 'HEAD' || method === 'OPTIONS'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function publicRateLimitMiddleware() {
|
|
15
|
-
return async (c: Context<AppEnv>, next: Next): Promise<Response | void> => {
|
|
16
|
-
const readMethod = isReadMethod(c.req.method)
|
|
17
|
-
const limiterName = readMethod ? ('publicApiRead' as const) : ('publicApiWrite' as const)
|
|
18
|
-
|
|
19
|
-
const seed = c.req.param('seed') ?? 'no-seed'
|
|
20
|
-
const key = `${getClientIp(c.req)}:${seed}:${limiterName}`
|
|
21
|
-
const result = await c.get('rateLimiters').getLimiter(limiterName).checkLimit(key)
|
|
22
|
-
|
|
23
|
-
if (!result.isAllowed) {
|
|
24
|
-
return publicProblem(c, {
|
|
25
|
-
type: 'rate-limit-exceeded',
|
|
26
|
-
title: 'Too Many Requests',
|
|
27
|
-
status: 429,
|
|
28
|
-
detail: 'Too many requests',
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await next()
|
|
33
|
-
}
|
|
34
|
-
}
|
package/src/public/read-list.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
|
|
3
|
-
// See LICENSE in the repository root for license terms.
|
|
4
|
-
|
|
5
|
-
import type { Seed, ContentRepository } from '@beechcms/core'
|
|
6
|
-
import { cleanStr } from '../shared/query-utils'
|
|
7
|
-
import { toFlatPublicEntry } from './entry-projection'
|
|
8
|
-
import { buildPublicListMeta } from './response-builder'
|
|
9
|
-
import { parsePublicFilter, parsePublicPagination, parseLatestCount, toEngineFilters } from './query-builder'
|
|
10
|
-
|
|
11
|
-
type ReadListInput = {
|
|
12
|
-
seed: Seed
|
|
13
|
-
seedSlug: string
|
|
14
|
-
repository: ContentRepository
|
|
15
|
-
query: Record<string, string | undefined>
|
|
16
|
-
publishedOnly: boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function readListEntries(input: ReadListInput) {
|
|
20
|
-
const { seed, seedSlug, repository, query, publishedOnly } = input
|
|
21
|
-
|
|
22
|
-
const parsedFilter = parsePublicFilter(query.filter)
|
|
23
|
-
const allMode = cleanStr(query.all)?.toLowerCase() === 'true'
|
|
24
|
-
const latestMode = cleanStr(query.latest) !== null
|
|
25
|
-
const latestCount = latestMode ? parseLatestCount(query.latest ?? '') : null
|
|
26
|
-
const pagination = allMode ? { page: 1, limit: 100 } : parsePublicPagination(query)
|
|
27
|
-
const offset = (pagination.page - 1) * pagination.limit
|
|
28
|
-
const search = cleanStr(query.search) ?? ''
|
|
29
|
-
const engineFilters = toEngineFilters(seed, parsedFilter)
|
|
30
|
-
const sortBy = cleanStr(query.orderBy) ?? 'created_at'
|
|
31
|
-
const sortDir = (cleanStr(query.orderDir) ?? 'desc').toLowerCase() === 'asc' ? 'ASC' : 'DESC'
|
|
32
|
-
|
|
33
|
-
const { items, total } = await repository.findMany(seed, {
|
|
34
|
-
filters: engineFilters,
|
|
35
|
-
search: search || undefined,
|
|
36
|
-
status: publishedOnly ? 'published' : null,
|
|
37
|
-
pagination: {
|
|
38
|
-
limit: latestMode ? (latestCount ?? 10) : pagination.limit,
|
|
39
|
-
offset: latestMode ? 0 : offset,
|
|
40
|
-
},
|
|
41
|
-
orderBy: latestMode ? { column: 'created_at', dir: 'DESC' } : { column: sortBy, dir: sortDir },
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const data = items.map(item => toFlatPublicEntry(item, seed, query.fields))
|
|
45
|
-
|
|
46
|
-
if (latestMode) {
|
|
47
|
-
return { data, meta: { total, returned: data.length, seed: seedSlug } }
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
data,
|
|
52
|
-
meta: buildPublicListMeta({ total, page: pagination.page, limit: pagination.limit, returned: data.length, seed: seedSlug }),
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
|
|
3
|
-
// See LICENSE in the repository root for license terms.
|
|
4
|
-
|
|
5
|
-
import { EntryNotFoundError } from '@beechcms/core'
|
|
6
|
-
import type { Seed, ContentRepository } from '@beechcms/core'
|
|
7
|
-
import { toFlatPublicEntry } from './entry-projection'
|
|
8
|
-
import { buildPublicSingleMeta } from './response-builder'
|
|
9
|
-
|
|
10
|
-
type ReadSingleInput = {
|
|
11
|
-
seed: Seed
|
|
12
|
-
seedSlug: string
|
|
13
|
-
repository: ContentRepository
|
|
14
|
-
id: string | null
|
|
15
|
-
slug: string | null
|
|
16
|
-
publishedOnly: boolean
|
|
17
|
-
fieldsParam?: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type ReadSingleResult =
|
|
21
|
-
| { ok: true; data: Record<string, unknown>; meta: { seed: string } }
|
|
22
|
-
| { ok: false; detail: string }
|
|
23
|
-
|
|
24
|
-
export async function readSingleEntry(input: ReadSingleInput): Promise<ReadSingleResult> {
|
|
25
|
-
const { seed, seedSlug, repository, id, slug, publishedOnly, fieldsParam } = input
|
|
26
|
-
const label = id ?? slug!
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const entry = id
|
|
30
|
-
? await repository.findById(seed, id)
|
|
31
|
-
: await repository.findBySlug(seed, slug!)
|
|
32
|
-
|
|
33
|
-
if (publishedOnly && entry.status !== 'published') {
|
|
34
|
-
return { ok: false, detail: `Entry '${label}' not found or not published.` }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
ok: true,
|
|
39
|
-
data: toFlatPublicEntry(entry, seed, fieldsParam),
|
|
40
|
-
meta: buildPublicSingleMeta(seedSlug),
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
if (error instanceof EntryNotFoundError) {
|
|
44
|
-
return { ok: false, detail: `Entry '${label}' not found for content type '${seedSlug}'.` }
|
|
45
|
-
}
|
|
46
|
-
throw error
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Copyright (c) 2024–2026 Flavio De Musso. All rights reserved.
|
|
3
|
-
// See LICENSE in the repository root for license terms.
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Helper meta per risposta lista Public API.
|
|
7
|
-
*/
|
|
8
|
-
export function buildPublicListMeta(input: {
|
|
9
|
-
total: number
|
|
10
|
-
page: number
|
|
11
|
-
limit: number
|
|
12
|
-
returned: number
|
|
13
|
-
seed: string
|
|
14
|
-
}) {
|
|
15
|
-
return {
|
|
16
|
-
total: input.total,
|
|
17
|
-
page: input.page,
|
|
18
|
-
limit: input.limit,
|
|
19
|
-
returned: input.returned,
|
|
20
|
-
seed: input.seed,
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Helper meta per risposta singolo elemento Public API.
|
|
26
|
-
*/
|
|
27
|
-
export function buildPublicSingleMeta(seed: string) {
|
|
28
|
-
return { seed }
|
|
29
|
-
}
|
|
30
|
-
|