@tulip-systems/core 0.7.0 → 0.8.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/dist/auth/server.d.mts +3 -3
- package/dist/auth/server.mjs +3 -3
- package/dist/components/editor/components/editor.client.d.mts +4 -3
- package/dist/components/editor/components/editor.client.d.mts.map +1 -1
- package/dist/components/editor/components/editor.client.mjs +5 -2
- package/dist/components/editor/components/editor.client.mjs.map +1 -1
- package/dist/components/editor/extensions/file-handler/extension.d.mts +4 -4
- package/dist/components/editor/extensions/file-handler/extension.d.mts.map +1 -1
- package/dist/components/editor/extensions/file-handler/extension.mjs.map +1 -1
- package/dist/components/editor/extensions/file-handler/strategy.d.mts +4 -6
- package/dist/components/editor/extensions/file-handler/strategy.d.mts.map +1 -1
- package/dist/components/editor/extensions/file-handler/strategy.mjs +11 -11
- package/dist/components/editor/extensions/file-handler/strategy.mjs.map +1 -1
- package/dist/components/editor/extensions/file-handler/utils.mjs +1 -1
- package/dist/components/editor/extensions/file-handler/utils.mjs.map +1 -1
- package/dist/components/editor/extensions/image/extension.mjs +9 -9
- package/dist/components/editor/extensions/image/extension.mjs.map +1 -1
- package/dist/components/editor/lib/constants.d.mts +1 -1
- package/dist/components/editor/lib/constants.mjs +1 -1
- package/dist/components/editor/lib/extensions.d.mts +1 -1
- package/dist/components/editor/lib/helpers.d.mts +11 -3
- package/dist/components/editor/lib/helpers.d.mts.map +1 -1
- package/dist/components/editor/lib/helpers.mjs +27 -13
- package/dist/components/editor/lib/helpers.mjs.map +1 -1
- package/dist/components/ui/badge.d.mts +1 -1
- package/dist/components/ui/button-group.d.mts +1 -1
- package/dist/components/ui/button.d.mts +2 -2
- package/dist/components/ui/combobox-dropdown.client.mjs +1 -0
- package/dist/components/ui/combobox-dropdown.client.mjs.map +1 -1
- package/dist/components/ui/combobox.client.mjs +1 -1
- package/dist/components/ui/combobox.client.mjs.map +1 -1
- package/dist/components/ui/field.client.d.mts +1 -1
- package/dist/components/ui/item.d.mts +1 -1
- package/dist/components.d.mts +2 -2
- package/dist/components.mjs +2 -2
- package/dist/config/server.d.mts +1 -3
- package/dist/config/server.mjs +1 -4
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/data-tables/client.d.mts +2 -1
- package/dist/data-tables/client.mjs +2 -1
- package/dist/data-tables.d.mts +1 -1
- package/dist/database/client.d.mts +1 -0
- package/dist/database/client.mjs +1 -0
- package/dist/database/server.d.mts +2 -0
- package/dist/database/server.mjs +3 -0
- package/dist/database.d.mts +3 -0
- package/dist/database.mjs +3 -0
- package/dist/emails/client.d.mts +1 -0
- package/dist/emails/client.mjs +1 -0
- package/dist/emails/server.d.mts +2 -0
- package/dist/emails/server.mjs +3 -0
- package/dist/emails.d.mts +1 -0
- package/dist/emails.mjs +1 -0
- package/dist/lib/utils/markdown.d.mts +10 -0
- package/dist/lib/utils/markdown.d.mts.map +1 -0
- package/dist/lib/utils/markdown.mjs +15 -0
- package/dist/lib/utils/markdown.mjs.map +1 -0
- package/dist/lib/utils/url.mjs +2 -1
- package/dist/lib/utils/url.mjs.map +1 -1
- package/dist/lib/utils/user-agent.mjs +15 -0
- package/dist/lib/utils/user-agent.mjs.map +1 -1
- package/dist/lib.d.mts +2 -2
- package/dist/lib.mjs +2 -2
- package/dist/modules/auth/components/create-first-user-guard.server.d.mts +16 -0
- package/dist/modules/auth/components/create-first-user-guard.server.d.mts.map +1 -0
- package/dist/modules/auth/components/create-first-user-guard.server.mjs +16 -0
- package/dist/modules/auth/components/create-first-user-guard.server.mjs.map +1 -0
- package/dist/modules/auth/components/guard.server.d.mts +2 -2
- package/dist/modules/auth/components/guard.server.mjs +1 -1
- package/dist/modules/auth/components/guard.server.mjs.map +1 -1
- package/dist/modules/auth/db/schema.d.mts +1 -1
- package/dist/modules/auth/db/schema.mjs +2 -2
- package/dist/modules/auth/handler/create-client.client.d.mts +4838 -229
- package/dist/modules/auth/handler/create-client.client.d.mts.map +1 -1
- package/dist/modules/auth/handler/create-client.client.mjs.map +1 -1
- package/dist/modules/auth/handler/proxy.server.mjs +2 -2
- package/dist/modules/auth/handler/proxy.server.mjs.map +1 -1
- package/dist/modules/auth/handler/route.server.d.mts +2 -2
- package/dist/modules/auth/handler/route.server.d.mts.map +1 -1
- package/dist/modules/auth/handler/route.server.mjs.map +1 -1
- package/dist/modules/auth/handler/{init.d.mts → service.server.d.mts} +322 -90
- package/dist/modules/auth/handler/service.server.d.mts.map +1 -0
- package/dist/modules/auth/handler/{init.mjs → service.server.mjs} +19 -8
- package/dist/modules/auth/handler/service.server.mjs.map +1 -0
- package/dist/modules/auth/hooks/use-session.d.mts +9 -4
- package/dist/modules/auth/hooks/use-session.d.mts.map +1 -1
- package/dist/modules/auth/lib/helpers.server.d.mts +1 -1
- package/dist/modules/auth/lib/permissions.d.mts +1 -1
- package/dist/modules/auth/lib/validators.mjs +1 -1
- package/dist/modules/config/lib/context.d.mts +9 -10
- package/dist/modules/config/lib/context.d.mts.map +1 -1
- package/dist/modules/config/lib/context.mjs.map +1 -1
- package/dist/modules/data-tables/lib/converters/search.d.mts +1 -1
- package/dist/modules/data-tables/lib/converters/sorting.d.mts +1 -1
- package/dist/modules/data-tables/server/get-data.server.d.mts +3 -3
- package/dist/modules/data-tables/server/get-data.server.mjs +1 -1
- package/dist/modules/data-tables/server/get-data.server.mjs.map +1 -1
- package/dist/modules/data-tables/strategies/infinite/strategy.d.mts +1 -1
- package/dist/modules/data-tables/strategies/infinite/strategy.mjs +3 -0
- package/dist/modules/data-tables/strategies/infinite/strategy.mjs.map +1 -1
- package/dist/modules/data-tables/tables/data-table/components/row.mjs +5 -15
- package/dist/modules/data-tables/tables/data-table/components/row.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/body.mjs +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/body.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/row.client.mjs +13 -23
- package/dist/modules/data-tables/tables/inline-table/components/row.client.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/table.d.mts +1 -0
- package/dist/modules/data-tables/tables/inline-table/components/table.d.mts.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/table.mjs +2 -1
- package/dist/modules/data-tables/tables/inline-table/components/table.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.d.mts +5 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.d.mts.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.mjs +2 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.d.mts +30 -0
- package/dist/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.d.mts.map +1 -0
- package/dist/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.mjs +77 -9
- package/dist/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.mjs.map +1 -1
- package/dist/modules/{config/db → database/lib}/helpers.d.mts +2 -2
- package/dist/modules/database/lib/helpers.d.mts.map +1 -0
- package/dist/modules/{config/db → database/lib}/helpers.mjs +1 -1
- package/dist/modules/database/lib/helpers.mjs.map +1 -0
- package/dist/modules/database/lib/service.server.d.mts +34 -0
- package/dist/modules/database/lib/service.server.d.mts.map +1 -0
- package/dist/modules/database/lib/service.server.mjs +24 -0
- package/dist/modules/database/lib/service.server.mjs.map +1 -0
- package/dist/modules/{config/db → database/lib}/types.d.mts +1 -1
- package/dist/modules/database/lib/types.d.mts.map +1 -0
- package/dist/modules/emails/lib/service.server.d.mts +29 -0
- package/dist/modules/emails/lib/service.server.d.mts.map +1 -0
- package/dist/modules/emails/lib/service.server.mjs +21 -0
- package/dist/modules/emails/lib/service.server.mjs.map +1 -0
- package/dist/modules/inline-edit/components/date-input.client.mjs +1 -1
- package/dist/modules/inline-edit/components/date-input.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/date-picker.client.mjs +1 -0
- package/dist/modules/inline-edit/components/date-picker.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/date-time.client.mjs +1 -0
- package/dist/modules/inline-edit/components/date-time.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/editor.client.mjs +1 -0
- package/dist/modules/inline-edit/components/editor.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input-recipient.client.mjs +1 -0
- package/dist/modules/inline-edit/components/input-recipient.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input-toggle.client.mjs +1 -0
- package/dist/modules/inline-edit/components/input-toggle.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/input.client.mjs +3 -0
- package/dist/modules/inline-edit/components/input.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/select.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/select.client.mjs +1 -0
- package/dist/modules/inline-edit/components/select.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/switch.client.mjs +1 -0
- package/dist/modules/inline-edit/components/switch.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/toggle.client.mjs +1 -0
- package/dist/modules/inline-edit/components/toggle.client.mjs.map +1 -1
- package/dist/modules/inline-edit/lib/variants.d.mts +1 -1
- package/dist/modules/router/handler/context.server.d.mts +12 -10
- package/dist/modules/router/handler/context.server.d.mts.map +1 -1
- package/dist/modules/router/handler/init.server.d.mts +13 -11
- package/dist/modules/router/handler/init.server.d.mts.map +1 -1
- package/dist/modules/router/handler/init.server.mjs +2 -2
- package/dist/modules/router/handler/init.server.mjs.map +1 -1
- package/dist/modules/router/handler/route.server.d.mts +1 -1
- package/dist/modules/storage/components/dropzone.client.d.mts +2 -2
- package/dist/modules/storage/components/dropzone.client.d.mts.map +1 -1
- package/dist/modules/storage/components/dropzone.client.mjs.map +1 -1
- package/dist/modules/storage/components/image-grid.client.d.mts +3 -3
- package/dist/modules/storage/components/image-grid.client.d.mts.map +1 -1
- package/dist/modules/storage/components/image-grid.client.mjs +20 -22
- package/dist/modules/storage/components/image-grid.client.mjs.map +1 -1
- package/dist/modules/storage/components/image.client.d.mts +8 -0
- package/dist/modules/storage/components/image.client.d.mts.map +1 -0
- package/dist/modules/storage/components/image.client.mjs +17 -0
- package/dist/modules/storage/components/image.client.mjs.map +1 -0
- package/dist/modules/storage/components/upload-button.client.d.mts +12 -0
- package/dist/modules/storage/components/upload-button.client.d.mts.map +1 -0
- package/dist/modules/storage/components/upload-button.client.mjs +34 -0
- package/dist/modules/storage/components/upload-button.client.mjs.map +1 -0
- package/dist/modules/storage/components/upload-zone-context.client.d.mts +5 -5
- package/dist/modules/storage/components/upload-zone-context.client.d.mts.map +1 -1
- package/dist/modules/storage/components/upload-zone-context.client.mjs +2 -2
- package/dist/modules/storage/components/upload-zone-context.client.mjs.map +1 -1
- package/dist/modules/storage/components/upload-zone.client.d.mts +4 -4
- package/dist/modules/storage/components/upload-zone.client.d.mts.map +1 -1
- package/dist/modules/storage/components/upload-zone.client.mjs +16 -9
- package/dist/modules/storage/components/upload-zone.client.mjs.map +1 -1
- package/dist/modules/storage/lib/constants.d.mts +1 -5
- package/dist/modules/storage/lib/constants.d.mts.map +1 -1
- package/dist/modules/storage/lib/constants.mjs +1 -13
- package/dist/modules/storage/lib/constants.mjs.map +1 -1
- package/dist/modules/storage/lib/helpers.d.mts +14 -28
- package/dist/modules/storage/lib/helpers.d.mts.map +1 -1
- package/dist/modules/storage/lib/helpers.mjs +17 -75
- package/dist/modules/storage/lib/helpers.mjs.map +1 -1
- package/dist/modules/storage/lib/procedures.server.d.mts +1991 -0
- package/dist/modules/{auth/handler/init.d.mts.map → storage/lib/procedures.server.d.mts.map} +1 -1
- package/dist/modules/storage/lib/procedures.server.mjs +22 -0
- package/dist/modules/storage/lib/procedures.server.mjs.map +1 -0
- package/dist/modules/storage/lib/router-handlers.server.d.mts +41 -0
- package/dist/modules/storage/lib/router-handlers.server.d.mts.map +1 -0
- package/dist/modules/storage/lib/router-handlers.server.mjs +124 -0
- package/dist/modules/storage/lib/router-handlers.server.mjs.map +1 -0
- package/dist/modules/storage/lib/schema.d.mts +68 -958
- package/dist/modules/storage/lib/schema.d.mts.map +1 -1
- package/dist/modules/storage/lib/schema.mjs +28 -65
- package/dist/modules/storage/lib/schema.mjs.map +1 -1
- package/dist/modules/storage/lib/service.server.d.mts +2155 -141
- package/dist/modules/storage/lib/service.server.d.mts.map +1 -1
- package/dist/modules/storage/lib/service.server.mjs +453 -242
- package/dist/modules/storage/lib/service.server.mjs.map +1 -1
- package/dist/modules/storage/lib/upload.client.d.mts +58 -0
- package/dist/modules/storage/lib/upload.client.d.mts.map +1 -0
- package/dist/modules/storage/lib/upload.client.mjs +87 -0
- package/dist/modules/storage/lib/upload.client.mjs.map +1 -0
- package/dist/modules/storage/lib/validators.d.mts +297 -835
- package/dist/modules/storage/lib/validators.d.mts.map +1 -1
- package/dist/modules/storage/lib/validators.mjs +32 -76
- package/dist/modules/storage/lib/validators.mjs.map +1 -1
- package/dist/modules/storage/providers/adapters/s3.server.d.mts +19 -0
- package/dist/modules/storage/providers/adapters/s3.server.d.mts.map +1 -0
- package/dist/modules/storage/providers/adapters/s3.server.mjs +173 -0
- package/dist/modules/storage/providers/adapters/s3.server.mjs.map +1 -0
- package/dist/modules/storage/providers/lib/constants.d.mts +6 -0
- package/dist/modules/storage/providers/lib/constants.d.mts.map +1 -0
- package/dist/modules/storage/providers/lib/constants.mjs +6 -0
- package/dist/modules/storage/providers/lib/constants.mjs.map +1 -0
- package/dist/modules/storage/providers/lib/errors.d.mts +12 -0
- package/dist/modules/storage/providers/lib/errors.d.mts.map +1 -0
- package/dist/modules/storage/providers/lib/errors.mjs +13 -0
- package/dist/modules/storage/providers/lib/errors.mjs.map +1 -0
- package/dist/modules/storage/providers/lib/types.d.mts +21 -0
- package/dist/modules/storage/providers/lib/types.d.mts.map +1 -0
- package/dist/modules/storage/providers/lib/validators.d.mts +112 -0
- package/dist/modules/storage/providers/lib/validators.d.mts.map +1 -0
- package/dist/modules/storage/providers/lib/validators.mjs +75 -0
- package/dist/modules/storage/providers/lib/validators.mjs.map +1 -0
- package/dist/router/server.d.mts +1 -1
- package/dist/storage/client.d.mts +4 -2
- package/dist/storage/client.mjs +4 -2
- package/dist/storage/server.d.mts +5 -4
- package/dist/storage/server.mjs +5 -4
- package/dist/storage.d.mts +9 -6
- package/dist/storage.mjs +8 -6
- package/package.json +18 -5
- package/src/components/editor/components/editor.client.tsx +9 -1
- package/src/components/editor/extensions/file-handler/extension.ts +4 -4
- package/src/components/editor/extensions/file-handler/strategy.ts +15 -40
- package/src/components/editor/extensions/file-handler/utils.ts +1 -1
- package/src/components/editor/extensions/image/extension.ts +10 -10
- package/src/components/editor/lib/helpers.ts +28 -11
- package/src/components/ui/combobox-dropdown.client.tsx +1 -0
- package/src/components/ui/combobox.client.tsx +1 -1
- package/src/entry.ts +12 -51
- package/src/lib/entry.ts +1 -5
- package/src/lib/utils/markdown.ts +10 -0
- package/src/lib/utils/url.ts +2 -1
- package/src/lib/utils/user-agent.ts +15 -0
- package/src/modules/auth/components/{guard-first-user.server.tsx → create-first-user-guard.server.tsx} +8 -8
- package/src/modules/auth/components/guard.server.tsx +1 -1
- package/src/modules/auth/entry.server.ts +4 -5
- package/src/modules/auth/handler/create-client.client.ts +2 -2
- package/src/modules/auth/handler/proxy.server.ts +1 -1
- package/src/modules/auth/handler/route.server.ts +2 -2
- package/src/modules/auth/handler/{init.ts → service.server.ts} +30 -9
- package/src/modules/config/entry.server.ts +0 -9
- package/src/modules/config/entry.ts +2 -2
- package/src/modules/config/lib/context.ts +9 -9
- package/src/modules/data-tables/entry.client.ts +1 -0
- package/src/modules/data-tables/server/get-data.server.ts +1 -1
- package/src/modules/data-tables/strategies/infinite/strategy.ts +4 -1
- package/src/modules/data-tables/tables/data-table/components/row.tsx +12 -21
- package/src/modules/data-tables/tables/inline-table/components/body.tsx +1 -1
- package/src/modules/data-tables/tables/inline-table/components/row.client.tsx +24 -30
- package/src/modules/data-tables/tables/inline-table/components/table.tsx +6 -1
- package/src/modules/data-tables/tables/inline-table/hooks/context.client.tsx +5 -0
- package/src/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.ts +119 -91
- package/src/modules/database/entry.client.ts +0 -0
- package/src/modules/database/entry.server.ts +4 -0
- package/src/modules/database/entry.ts +5 -0
- package/src/modules/database/lib/service.server.ts +33 -0
- package/src/modules/emails/entry.client.ts +0 -0
- package/src/modules/emails/entry.server.ts +4 -0
- package/src/modules/emails/entry.ts +0 -0
- package/src/modules/emails/lib/service.server.ts +29 -0
- package/src/modules/inline-edit/components/date-input.client.tsx +1 -1
- package/src/modules/inline-edit/components/date-picker.client.tsx +1 -0
- package/src/modules/inline-edit/components/date-time.client.tsx +1 -0
- package/src/modules/inline-edit/components/editor.client.tsx +3 -0
- package/src/modules/inline-edit/components/input-recipient.client.tsx +1 -0
- package/src/modules/inline-edit/components/input-toggle.client.tsx +1 -0
- package/src/modules/inline-edit/components/input.client.tsx +3 -0
- package/src/modules/inline-edit/components/select.client.tsx +5 -1
- package/src/modules/inline-edit/components/switch.client.tsx +1 -0
- package/src/modules/inline-edit/components/toggle.client.tsx +1 -0
- package/src/modules/router/handler/init.server.ts +2 -2
- package/src/modules/storage/components/dropzone.client.tsx +1 -1
- package/src/modules/storage/components/image-grid.client.tsx +23 -20
- package/src/modules/storage/components/image.client.tsx +8 -0
- package/src/modules/storage/components/upload-zone-context.client.tsx +11 -8
- package/src/modules/storage/components/upload-zone.client.tsx +22 -16
- package/src/modules/storage/entry.client.ts +3 -1
- package/src/modules/storage/entry.server.ts +9 -3
- package/src/modules/storage/entry.ts +13 -1
- package/src/modules/storage/lib/constants.ts +0 -11
- package/src/modules/storage/lib/helpers.ts +18 -65
- package/src/modules/storage/lib/procedures.server.ts +60 -0
- package/src/modules/storage/lib/router-handlers.server.ts +178 -0
- package/src/modules/storage/lib/schema.ts +26 -97
- package/src/modules/storage/lib/service.server.ts +636 -374
- package/src/modules/storage/lib/upload.client.ts +156 -0
- package/src/modules/storage/lib/validators.ts +50 -111
- package/src/modules/storage/providers/adapters/s3.server.ts +281 -0
- package/src/modules/storage/providers/lib/constants.ts +3 -0
- package/src/modules/storage/providers/lib/errors.ts +21 -0
- package/src/modules/storage/providers/lib/types.ts +28 -0
- package/src/modules/storage/providers/lib/validators.ts +122 -0
- package/dist/lib/config/constants.d.mts +0 -5
- package/dist/lib/config/constants.d.mts.map +0 -1
- package/dist/lib/config/constants.mjs +0 -6
- package/dist/lib/config/constants.mjs.map +0 -1
- package/dist/modules/auth/components/guard-first-user.server.d.mts +0 -18
- package/dist/modules/auth/components/guard-first-user.server.d.mts.map +0 -1
- package/dist/modules/auth/components/guard-first-user.server.mjs +0 -16
- package/dist/modules/auth/components/guard-first-user.server.mjs.map +0 -1
- package/dist/modules/auth/handler/init.mjs.map +0 -1
- package/dist/modules/config/db/helpers.d.mts.map +0 -1
- package/dist/modules/config/db/helpers.mjs.map +0 -1
- package/dist/modules/config/db/init.d.mts +0 -20
- package/dist/modules/config/db/init.d.mts.map +0 -1
- package/dist/modules/config/db/init.mjs +0 -15
- package/dist/modules/config/db/init.mjs.map +0 -1
- package/dist/modules/config/db/types.d.mts.map +0 -1
- package/dist/modules/config/providers/email.d.mts +0 -12
- package/dist/modules/config/providers/email.d.mts.map +0 -1
- package/dist/modules/config/providers/email.mjs +0 -11
- package/dist/modules/config/providers/email.mjs.map +0 -1
- package/dist/modules/storage/config/filters.d.mts +0 -17
- package/dist/modules/storage/config/filters.d.mts.map +0 -1
- package/dist/modules/storage/config/filters.mjs +0 -17
- package/dist/modules/storage/config/filters.mjs.map +0 -1
- package/dist/modules/storage/lib/create-client.server.d.mts +0 -11
- package/dist/modules/storage/lib/create-client.server.d.mts.map +0 -1
- package/dist/modules/storage/lib/create-client.server.mjs +0 -11
- package/dist/modules/storage/lib/create-client.server.mjs.map +0 -1
- package/dist/modules/storage/lib/create-upload.client.d.mts +0 -56
- package/dist/modules/storage/lib/create-upload.client.d.mts.map +0 -1
- package/dist/modules/storage/lib/create-upload.client.mjs +0 -98
- package/dist/modules/storage/lib/create-upload.client.mjs.map +0 -1
- package/dist/modules/storage/lib/proxy.server.d.mts +0 -21
- package/dist/modules/storage/lib/proxy.server.d.mts.map +0 -1
- package/dist/modules/storage/lib/proxy.server.mjs +0 -46
- package/dist/modules/storage/lib/proxy.server.mjs.map +0 -1
- package/dist/modules/storage/lib/router.server.d.mts +0 -31002
- package/dist/modules/storage/lib/router.server.d.mts.map +0 -1
- package/dist/modules/storage/lib/router.server.mjs +0 -86
- package/dist/modules/storage/lib/router.server.mjs.map +0 -1
- package/src/lib/config/constants.ts +0 -1
- package/src/lib/utils/time-picker.ts +0 -139
- package/src/modules/config/db/init.ts +0 -21
- package/src/modules/config/providers/email.ts +0 -13
- package/src/modules/storage/config/filters.ts +0 -12
- package/src/modules/storage/lib/create-client.server.ts +0 -14
- package/src/modules/storage/lib/create-upload.client.ts +0 -134
- package/src/modules/storage/lib/proxy.server.ts +0 -63
- package/src/modules/storage/lib/router.server.ts +0 -182
- /package/src/modules/{config/db → database/lib}/helpers.ts +0 -0
- /package/src/modules/{config/db → database/lib}/types.ts +0 -0
package/dist/modules/{auth/handler/init.d.mts.map → storage/lib/procedures.server.d.mts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"procedures.server.d.mts","names":[],"sources":["../../../../src/modules/storage/lib/procedures.server.ts"],"mappings":";;;;;;;;;;iBAWgB,uBAAA,iBAAwC,eAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8C5C,aAAA,GAAgB,UAAA,QAAkB,uBAAA;AAAA,KAClC,oBAAA,GAAuB,kBAAA,CAAmB,aAAA;AAAA,KAC1C,mBAAA,GAAsB,iBAAA,CAAkB,aAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { confirmUploadInputSchema, presignUploadInputSchema, presignUploadOutputSchema, selectStorageAssetSchema } from "./validators.mjs";
|
|
2
|
+
import { initRPC } from "../../router/handler/init.server.mjs";
|
|
3
|
+
import { z as z$1 } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/modules/storage/lib/procedures.server.ts
|
|
6
|
+
function createStorageProcedures() {
|
|
7
|
+
const { protectedProcedure } = initRPC();
|
|
8
|
+
return {
|
|
9
|
+
presign: protectedProcedure.input(presignUploadInputSchema).output(presignUploadOutputSchema).handler(async ({ context, input }) => context.storage.presignUpload(input)),
|
|
10
|
+
confirm: protectedProcedure.input(confirmUploadInputSchema).output(selectStorageAssetSchema).handler(async ({ context, input }) => context.storage.confirmUpload(input)),
|
|
11
|
+
deleteAsset: protectedProcedure.input(z$1.uuid()).output(selectStorageAssetSchema.nullable()).handler(async ({ context, input }) => context.storage.deleteAsset(input)),
|
|
12
|
+
deleteAssets: protectedProcedure.input(z$1.string().array()).output(z$1.array(selectStorageAssetSchema)).handler(async ({ context, input }) => context.storage.deleteAssets(input)),
|
|
13
|
+
restoreAsset: protectedProcedure.input(z$1.uuid()).output(selectStorageAssetSchema.nullable()).handler(async ({ context, input }) => context.storage.restoreAsset(input)),
|
|
14
|
+
restoreAssets: protectedProcedure.input(z$1.string().array()).output(z$1.array(selectStorageAssetSchema)).handler(async ({ context, input }) => context.storage.restoreAssets(input)),
|
|
15
|
+
purgeAsset: protectedProcedure.input(z$1.uuid()).output(selectStorageAssetSchema.nullable()).handler(async ({ context, input }) => context.storage.purgeAsset(input)),
|
|
16
|
+
purgeAssets: protectedProcedure.input(z$1.string().array()).output(z$1.array(selectStorageAssetSchema)).handler(async ({ context, input }) => context.storage.purgeAssets(input))
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createStorageProcedures };
|
|
22
|
+
//# sourceMappingURL=procedures.server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedures.server.mjs","names":["z"],"sources":["../../../../src/modules/storage/lib/procedures.server.ts"],"sourcesContent":["import type { InferRouterInputs, InferRouterOutputs } from \"@orpc/server\";\nimport { z } from \"zod\";\nimport type { TDatabaseSchema } from \"@/modules/config/db/types\";\nimport { initRPC } from \"@/modules/router/handler/init.server\";\nimport {\n confirmUploadInputSchema,\n presignUploadInputSchema,\n presignUploadOutputSchema,\n selectStorageAssetSchema,\n} from \"./validators\";\n\nexport function createStorageProcedures<TSchema extends TDatabaseSchema>() {\n const { protectedProcedure } = initRPC<TSchema>();\n\n return {\n presign: protectedProcedure\n .input(presignUploadInputSchema)\n .output(presignUploadOutputSchema)\n .handler(async ({ context, input }) => context.storage.presignUpload(input)),\n\n confirm: protectedProcedure\n .input(confirmUploadInputSchema)\n .output(selectStorageAssetSchema)\n .handler(async ({ context, input }) => context.storage.confirmUpload(input)),\n\n deleteAsset: protectedProcedure\n .input(z.uuid())\n .output(selectStorageAssetSchema.nullable())\n .handler(async ({ context, input }) => context.storage.deleteAsset(input)),\n\n deleteAssets: protectedProcedure\n .input(z.string().array())\n .output(z.array(selectStorageAssetSchema))\n .handler(async ({ context, input }) => context.storage.deleteAssets(input)),\n\n restoreAsset: protectedProcedure\n .input(z.uuid())\n .output(selectStorageAssetSchema.nullable())\n .handler(async ({ context, input }) => context.storage.restoreAsset(input)),\n\n restoreAssets: protectedProcedure\n .input(z.string().array())\n .output(z.array(selectStorageAssetSchema))\n .handler(async ({ context, input }) => context.storage.restoreAssets(input)),\n\n purgeAsset: protectedProcedure\n .input(z.uuid())\n .output(selectStorageAssetSchema.nullable())\n .handler(async ({ context, input }) => context.storage.purgeAsset(input)),\n\n purgeAssets: protectedProcedure\n .input(z.string().array())\n .output(z.array(selectStorageAssetSchema))\n .handler(async ({ context, input }) => context.storage.purgeAssets(input)),\n };\n}\n\nexport type StorageRouter = ReturnType<typeof createStorageProcedures>;\nexport type StorageRouterOutputs = InferRouterOutputs<StorageRouter>;\nexport type StorageRouterInputs = InferRouterInputs<StorageRouter>;\n"],"mappings":";;;;;AAWA,SAAgB,0BAA2D;CACzE,MAAM,EAAE,uBAAuB,SAAkB;AAEjD,QAAO;EACL,SAAS,mBACN,MAAM,yBAAyB,CAC/B,OAAO,0BAA0B,C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equest } from "next/server";
|
|
3
|
+
import { TDatabaseSchema } from "@/modules/config/db/types";
|
|
4
|
+
|
|
5
|
+
//#region src/modules/storage/lib/router-handlers.server.d.ts
|
|
6
|
+
type RouteCtx = {
|
|
7
|
+
params: Promise<{
|
|
8
|
+
rest?: string[];
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
type CreateStorageRouteHandlerProps<TSchema extends TDatabaseSchema> = {
|
|
12
|
+
context: Pick<TulipContext<TSchema>, "auth" | "storage">;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Creates a catch-all storage route handler for `/api/storage/[[...rest]]`.
|
|
16
|
+
*
|
|
17
|
+
* Current support:
|
|
18
|
+
* - `GET /api/storage/files/:id`:
|
|
19
|
+
* resolves a storage asset, enforces visibility checks, and redirects
|
|
20
|
+
* to a short-lived signed read URL.
|
|
21
|
+
*
|
|
22
|
+
* Reserved for future extension:
|
|
23
|
+
* - `POST /api/storage/assets/presign`
|
|
24
|
+
* - `POST /api/storage/assets/confirm`
|
|
25
|
+
* - additional storage endpoints under the same catch-all route.
|
|
26
|
+
*
|
|
27
|
+
* @param props - Route handler dependencies (application context)
|
|
28
|
+
* @returns Next.js route handlers for GET, POST, PUT, PATCH, and DELETE
|
|
29
|
+
*/
|
|
30
|
+
declare function createStorageRouteHandler<TSchema extends TDatabaseSchema>({
|
|
31
|
+
context
|
|
32
|
+
}: CreateStorageRouteHandlerProps<TSchema>): {
|
|
33
|
+
GET: (request: NextRequest, ctx: RouteCtx) => Promise<Response>;
|
|
34
|
+
POST: () => Promise<Response>;
|
|
35
|
+
PUT: () => Promise<Response>;
|
|
36
|
+
PATCH: () => Promise<Response>;
|
|
37
|
+
DELETE: () => Promise<Response>;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { createStorageRouteHandler };
|
|
41
|
+
//# sourceMappingURL=router-handlers.server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-handlers.server.d.mts","names":[],"sources":["../../../../src/modules/storage/lib/router-handlers.server.ts"],"mappings":";;;;;KAQK,QAAA;EACH,MAAA,EAAQ,OAAA;IAAU,IAAA;EAAA;AAAA;AAAA,KAGf,8BAAA,iBAA+C,eAAA;EAClD,OAAA,EAAS,IAAA,CAAK,YAAA,CAAa,OAAA;AAAA;;;;AAJL;;;;;;;;;;;;;iBAwBR,yBAAA,iBAA0C,eAAA,CAAA,CAAA;EACxD;AAAA,GACC,8BAAA,CAA+B,OAAA;iBAUJ,WAAA,EAAW,GAAA,EAAO,QAAA,KAAQ,OAAA,CAAA,QAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ServerError } from "../../router/lib/error.server.mjs";
|
|
2
|
+
import { getAssetURLSchema } from "./validators.mjs";
|
|
3
|
+
import { getSession } from "../../auth/lib/helpers.server.mjs";
|
|
4
|
+
import z from "zod";
|
|
5
|
+
import { connection } from "next/server";
|
|
6
|
+
|
|
7
|
+
//#region src/modules/storage/lib/router-handlers.server.ts
|
|
8
|
+
/**
|
|
9
|
+
* Creates a catch-all storage route handler for `/api/storage/[[...rest]]`.
|
|
10
|
+
*
|
|
11
|
+
* Current support:
|
|
12
|
+
* - `GET /api/storage/files/:id`:
|
|
13
|
+
* resolves a storage asset, enforces visibility checks, and redirects
|
|
14
|
+
* to a short-lived signed read URL.
|
|
15
|
+
*
|
|
16
|
+
* Reserved for future extension:
|
|
17
|
+
* - `POST /api/storage/assets/presign`
|
|
18
|
+
* - `POST /api/storage/assets/confirm`
|
|
19
|
+
* - additional storage endpoints under the same catch-all route.
|
|
20
|
+
*
|
|
21
|
+
* @param props - Route handler dependencies (application context)
|
|
22
|
+
* @returns Next.js route handlers for GET, POST, PUT, PATCH, and DELETE
|
|
23
|
+
*/
|
|
24
|
+
function createStorageRouteHandler({ context }) {
|
|
25
|
+
/**
|
|
26
|
+
* GET /api/storage/[[...rest]]
|
|
27
|
+
*
|
|
28
|
+
* Current route support:
|
|
29
|
+
* - /api/storage/files/:id
|
|
30
|
+
*
|
|
31
|
+
* The file route resolves an asset by id, enforces visibility rules,
|
|
32
|
+
* and redirects to a short-lived signed object URL.
|
|
33
|
+
*/
|
|
34
|
+
async function GET(request, ctx) {
|
|
35
|
+
const { rest = [] } = await ctx.params;
|
|
36
|
+
/**
|
|
37
|
+
* Proxy file request
|
|
38
|
+
* GET /api/storage/files/:id
|
|
39
|
+
*/
|
|
40
|
+
if (rest[0] === "files") {
|
|
41
|
+
const id = rest[1];
|
|
42
|
+
if (!id) return Response.json({ error: {
|
|
43
|
+
code: "BAD_REQUEST",
|
|
44
|
+
message: "Missing id"
|
|
45
|
+
} }, { status: 400 });
|
|
46
|
+
console.info("Proxying file: ", id);
|
|
47
|
+
try {
|
|
48
|
+
const asset = await context.storage.getAssetById(id);
|
|
49
|
+
if (!asset) return Response.json({ error: {
|
|
50
|
+
code: "NOT_FOUND",
|
|
51
|
+
message: "Asset not found"
|
|
52
|
+
} }, { status: 404 });
|
|
53
|
+
if (asset.visibility === "private") {
|
|
54
|
+
if (!await getSession(context)) return Response.json({ error: {
|
|
55
|
+
code: "UNAUTHORIZED",
|
|
56
|
+
message: "Unauthorized"
|
|
57
|
+
} }, { status: 401 });
|
|
58
|
+
}
|
|
59
|
+
const disposition = request.nextUrl.searchParams.get("disposition") ?? void 0;
|
|
60
|
+
const options = getAssetURLSchema.parse({ disposition });
|
|
61
|
+
const url = await context.storage.getObjectURL(asset.id, options);
|
|
62
|
+
return Response.redirect(url, 307);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error instanceof z.ZodError) return Response.json({ error: {
|
|
65
|
+
code: "BAD_REQUEST",
|
|
66
|
+
message: "Invalid request input"
|
|
67
|
+
} }, { status: 400 });
|
|
68
|
+
if (error instanceof ServerError) {
|
|
69
|
+
const code = error.code;
|
|
70
|
+
if (code === "BAD_REQUEST") return Response.json({ error: {
|
|
71
|
+
code: "BAD_REQUEST",
|
|
72
|
+
message: error.message
|
|
73
|
+
} }, { status: 400 });
|
|
74
|
+
if (code === "NOT_FOUND") return Response.json({ error: {
|
|
75
|
+
code: "NOT_FOUND",
|
|
76
|
+
message: error.message
|
|
77
|
+
} }, { status: 404 });
|
|
78
|
+
if (code === "UNAUTHORIZED") return Response.json({ error: {
|
|
79
|
+
code: "UNAUTHORIZED",
|
|
80
|
+
message: error.message
|
|
81
|
+
} }, { status: 401 });
|
|
82
|
+
}
|
|
83
|
+
if (error instanceof Error && error.message === "Storage asset not found") return Response.json({ error: {
|
|
84
|
+
code: "NOT_FOUND",
|
|
85
|
+
message: "Asset not found"
|
|
86
|
+
} }, { status: 404 });
|
|
87
|
+
console.error("Storage route error", error);
|
|
88
|
+
return Response.json({ error: {
|
|
89
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
90
|
+
message: "Something went wrong"
|
|
91
|
+
} }, { status: 500 });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return Response.json({ error: {
|
|
95
|
+
code: "NOT_FOUND",
|
|
96
|
+
message: "Route not found"
|
|
97
|
+
} }, { status: 404 });
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* POST, PUT, PATCH, DELETE /api/storage/[[...rest]]
|
|
101
|
+
*
|
|
102
|
+
* Reserved for future extension, for example:
|
|
103
|
+
* - POST /api/storage/assets/presign
|
|
104
|
+
* - POST /api/storage/assets/confirm
|
|
105
|
+
*/
|
|
106
|
+
async function POST() {
|
|
107
|
+
await connection();
|
|
108
|
+
return Response.json({ error: {
|
|
109
|
+
code: "NOT_FOUND",
|
|
110
|
+
message: "Route not found"
|
|
111
|
+
} }, { status: 404 });
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
GET,
|
|
115
|
+
POST,
|
|
116
|
+
PUT: POST,
|
|
117
|
+
PATCH: POST,
|
|
118
|
+
DELETE: POST
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
export { createStorageRouteHandler };
|
|
124
|
+
//# sourceMappingURL=router-handlers.server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-handlers.server.mjs","names":[],"sources":["../../../../src/modules/storage/lib/router-handlers.server.ts"],"sourcesContent":["import { connection, type NextRequest } from \"next/server\";\nimport z from \"zod\";\nimport { getSession } from \"@/modules/auth/lib/helpers.server\";\nimport type { TDatabaseSchema } from \"@/modules/config/db/types\";\nimport type { TulipContext } from \"@/modules/config/lib/context\";\nimport { ServerError } from \"@/modules/router/lib/error.server\";\nimport { getAssetURLSchema } from \"../entry\";\n\ntype RouteCtx = {\n params: Promise<{ rest?: string[] }>;\n};\n\ntype CreateStorageRouteHandlerProps<TSchema extends TDatabaseSchema> = {\n context: Pick<TulipContext<TSchema>, \"auth\" | \"storage\">;\n};\n\n/**\n * Creates a catch-all storage route handler for `/api/storage/[[...rest]]`.\n *\n * Current support:\n * - `GET /api/storage/files/:id`:\n * resolves a storage asset, enforces visibility checks, and redirects\n * to a short-lived signed read URL.\n *\n * Reserved for future extension:\n * - `POST /api/storage/assets/presign`\n * - `POST /api/storage/assets/confirm`\n * - additional storage endpoints under the same catch-all route.\n *\n * @param props - Route handler dependencies (application context)\n * @returns Next.js route handlers for GET, POST, PUT, PATCH, and DELETE\n */\n\nexport function createStorageRouteHandler<TSchema extends TDatabaseSchema>({\n context,\n}: CreateStorageRouteHandlerProps<TSchema>) {\n /**\n * GET /api/storage/[[...rest]]\n *\n * Current route support:\n * - /api/storage/files/:id\n *\n * The file route resolves an asset by id, enforces visibility rules,\n * and redirects to a short-lived signed object URL.\n */\n async function GET(request: NextRequest, ctx: RouteCtx) {\n // Get the params\n const { rest = [] } = await ctx.params;\n const resource = rest[0];\n\n /**\n * Proxy file request\n * GET /api/storage/files/:id\n */\n if (resource === \"files\") {\n const id = rest[1];\n\n // Guard required path segment: /api/storage/files/:id\n if (!id) {\n return Response.json(\n { error: { code: \"BAD_REQUEST\", message: \"Missing id\" } },\n { status: 400 },\n );\n }\n\n console.info(\"Proxying file: \", id);\n\n try {\n // Resolve storage asset record by id\n const asset = await context.storage.getAssetById(id);\n\n if (!asset) {\n return Response.json(\n { error: { code: \"NOT_FOUND\", message: \"Asset not found\" } },\n { status: 404 },\n );\n }\n\n // Enforce private visibility with session auth\n if (asset.visibility === \"private\") {\n const session = await getSession(context);\n if (!session) {\n return Response.json(\n { error: { code: \"UNAUTHORIZED\", message: \"Unauthorized\" } },\n { status: 401 },\n );\n }\n }\n\n // Handle searchParams for disposition\n const searchParams = request.nextUrl.searchParams;\n const disposition = searchParams.get(\"disposition\") ?? undefined;\n\n // Parse the options\n const options = getAssetURLSchema.parse({ disposition });\n\n // Resolve signed read URL and redirect to object storage\n const url = await context.storage.getObjectURL(asset.id, options);\n\n // Return the file\n return Response.redirect(url, 307);\n } catch (error) {\n if (error instanceof z.ZodError) {\n return Response.json(\n { error: { code: \"BAD_REQUEST\", message: \"Invalid request input\" } },\n { status: 400 },\n );\n }\n\n if (error instanceof ServerError) {\n const code = error.code;\n\n if (code === \"BAD_REQUEST\") {\n return Response.json(\n { error: { code: \"BAD_REQUEST\", message: error.message } },\n { status: 400 },\n );\n }\n\n if (code === \"NOT_FOUND\") {\n return Response.json(\n { error: { code: \"NOT_FOUND\", message: error.message } },\n { status: 404 },\n );\n }\n\n if (code === \"UNAUTHORIZED\") {\n return Response.json(\n { error: { code: \"UNAUTHORIZED\", message: error.message } },\n { status: 401 },\n );\n }\n }\n\n if (error instanceof Error && error.message === \"Storage asset not found\") {\n return Response.json(\n { error: { code: \"NOT_FOUND\", message: \"Asset not found\" } },\n { status: 404 },\n );\n }\n\n console.error(\"Storage route error\", error);\n\n return Response.json(\n { error: { code: \"INTERNAL_SERVER_ERROR\", message: \"Something went wrong\" } },\n { status: 500 },\n );\n }\n }\n\n return Response.json(\n { error: { code: \"NOT_FOUND\", message: \"Route not found\" } },\n { status: 404 },\n );\n }\n\n /**\n * POST, PUT, PATCH, DELETE /api/storage/[[...rest]]\n *\n * Reserved for future extension, for example:\n * - POST /api/storage/assets/presign\n * - POST /api/storage/assets/confirm\n */\n async function POST() {\n // Make endpoint dynamic\n await connection();\n\n // future:\n // POST /api/storage/assets/presign\n // POST /api/storage/assets/confirm\n return Response.json(\n { error: { code: \"NOT_FOUND\", message: \"Route not found\" } },\n { status: 404 },\n );\n }\n\n return { GET, POST, PUT: POST, PATCH: POST, DELETE: POST };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,0BAA2D,EACzE,WAC0C;;;;;;;;;;CAU1C,eAAe,IAAI,SAAsB,KAAe;EAEtD,MAAM,EAAE,OAAO,EAAE,KAAK,MAAM,IAAI;;;;;AAOhC,MANiB,KAAK,OAML,SAAS;GACxB,MAAM,KAAK,KAAK;AAGhB,OAAI,CAAC,GACH,QAAO,SAAS,KACd,EAAE,OAAO;IAAE,MAAM;IAAe,SAAS;IAAc,EAAE,EACzD,EAAE,QAAQ,KAAK,CAChB;AAGH,WAAQ,KAAK,mBAAmB,GAAG;AAEnC,OAAI;IAEF,MAAM,QAAQ,MAAM,QAAQ,QAAQ,aAAa,GAAG;AAEpD,QAAI,CAAC,MACH,QAAO,SAAS,KACd,EAAE,OAAO;KAAE,MAAM;KAAa,SAAS;KAAmB,EAAE,EAC5D,EAAE,QAAQ,KAAK,CAChB;AAIH,QAAI,MAAM,eAAe,WAEvB;SAAI,CADY,MAAM,WAAW,QAAQ,CAEvC,QAAO,SAAS,KACd,EAAE,OAAO;MAAE,MAAM;MAAgB,SAAS;MAAgB,EAAE,EAC5D,EAAE,QAAQ,KAAK,CAChB;;IAML,MAAM,cADe,QAAQ,QAAQ,aACJ,IAAI,cAAc,IAAI;IAGvD,MAAM,UAAU,kBAAkB,MAAM,EAAE,aAAa,CAAC;IAGxD,MAAM,MAAM,MAAM,QAAQ,QAAQ,aAAa,MAAM,IAAI,QAAQ;AAGjE,WAAO,SAAS,SAAS,KAAK,IAAI;YAC3B,OAAO;AACd,QAAI,iBAAiB,EAAE,SACrB,Q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