@gettersethya/mira 0.1.0-alpha.10
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/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/src/app/app.d.ts +100 -0
- package/dist/src/app/app.d.ts.map +1 -0
- package/dist/src/app/app.js +176 -0
- package/dist/src/app/app.js.map +1 -0
- package/dist/src/app/builder.d.ts +106 -0
- package/dist/src/app/builder.d.ts.map +1 -0
- package/dist/src/app/builder.js +122 -0
- package/dist/src/app/builder.js.map +1 -0
- package/dist/src/app/index.d.ts +33 -0
- package/dist/src/app/index.d.ts.map +1 -0
- package/dist/src/app/index.js +30 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/plugin.d.ts +60 -0
- package/dist/src/app/plugin.d.ts.map +1 -0
- package/dist/src/app/plugin.js +20 -0
- package/dist/src/app/plugin.js.map +1 -0
- package/dist/src/app/types.d.ts +55 -0
- package/dist/src/app/types.d.ts.map +1 -0
- package/dist/src/app/types.js +2 -0
- package/dist/src/app/types.js.map +1 -0
- package/dist/src/cache/cached-collection.d.ts +30 -0
- package/dist/src/cache/cached-collection.d.ts.map +1 -0
- package/dist/src/cache/cached-collection.js +107 -0
- package/dist/src/cache/cached-collection.js.map +1 -0
- package/dist/src/cache/collection-cache.d.ts +17 -0
- package/dist/src/cache/collection-cache.d.ts.map +1 -0
- package/dist/src/cache/collection-cache.js +37 -0
- package/dist/src/cache/collection-cache.js.map +1 -0
- package/dist/src/cache/index.d.ts +4 -0
- package/dist/src/cache/index.d.ts.map +1 -0
- package/dist/src/cache/index.js +3 -0
- package/dist/src/cache/index.js.map +1 -0
- package/dist/src/cache/types.d.ts +12 -0
- package/dist/src/cache/types.d.ts.map +1 -0
- package/dist/src/cache/types.js +2 -0
- package/dist/src/cache/types.js.map +1 -0
- package/dist/src/collection-service/collection-service.d.ts +62 -0
- package/dist/src/collection-service/collection-service.d.ts.map +1 -0
- package/dist/src/collection-service/collection-service.js +289 -0
- package/dist/src/collection-service/collection-service.js.map +1 -0
- package/dist/src/collection-service/context.d.ts +19 -0
- package/dist/src/collection-service/context.d.ts.map +1 -0
- package/dist/src/collection-service/context.js +2 -0
- package/dist/src/collection-service/context.js.map +1 -0
- package/dist/src/collection-service/decode.d.ts +6 -0
- package/dist/src/collection-service/decode.d.ts.map +1 -0
- package/dist/src/collection-service/decode.js +26 -0
- package/dist/src/collection-service/decode.js.map +1 -0
- package/dist/src/collection-service/errors.d.ts +67 -0
- package/dist/src/collection-service/errors.d.ts.map +1 -0
- package/dist/src/collection-service/errors.js +43 -0
- package/dist/src/collection-service/errors.js.map +1 -0
- package/dist/src/collection-service/index.d.ts +5 -0
- package/dist/src/collection-service/index.d.ts.map +1 -0
- package/dist/src/collection-service/index.js +3 -0
- package/dist/src/collection-service/index.js.map +1 -0
- package/dist/src/collection-service/input-schema.d.ts +10 -0
- package/dist/src/collection-service/input-schema.d.ts.map +1 -0
- package/dist/src/collection-service/input-schema.js +123 -0
- package/dist/src/collection-service/input-schema.js.map +1 -0
- package/dist/src/collection-service/where.d.ts +35 -0
- package/dist/src/collection-service/where.d.ts.map +1 -0
- package/dist/src/collection-service/where.js +91 -0
- package/dist/src/collection-service/where.js.map +1 -0
- package/dist/src/config/config.d.ts +44 -0
- package/dist/src/config/config.d.ts.map +1 -0
- package/dist/src/config/config.js +89 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/index.d.ts +3 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +2 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/config/types.d.ts +29 -0
- package/dist/src/config/types.d.ts.map +1 -0
- package/dist/src/config/types.js +2 -0
- package/dist/src/config/types.js.map +1 -0
- package/dist/src/crypto/crypto.d.ts +11 -0
- package/dist/src/crypto/crypto.d.ts.map +1 -0
- package/dist/src/crypto/crypto.js +4 -0
- package/dist/src/crypto/crypto.js.map +1 -0
- package/dist/src/crypto/index.d.ts +3 -0
- package/dist/src/crypto/index.d.ts.map +1 -0
- package/dist/src/crypto/index.js +3 -0
- package/dist/src/crypto/index.js.map +1 -0
- package/dist/src/crypto/node.d.ts +4 -0
- package/dist/src/crypto/node.d.ts.map +1 -0
- package/dist/src/crypto/node.js +9 -0
- package/dist/src/crypto/node.js.map +1 -0
- package/dist/src/databases/index.d.ts +2 -0
- package/dist/src/databases/index.d.ts.map +1 -0
- package/dist/src/databases/index.js +2 -0
- package/dist/src/databases/index.js.map +1 -0
- package/dist/src/databases/sqlite.d.ts +24 -0
- package/dist/src/databases/sqlite.d.ts.map +1 -0
- package/dist/src/databases/sqlite.js +27 -0
- package/dist/src/databases/sqlite.js.map +1 -0
- package/dist/src/hooks/hook-collection.d.ts +5 -0
- package/dist/src/hooks/hook-collection.d.ts.map +1 -0
- package/dist/src/hooks/hook-collection.js +77 -0
- package/dist/src/hooks/hook-collection.js.map +1 -0
- package/dist/src/hooks/hook-service.d.ts +33 -0
- package/dist/src/hooks/hook-service.d.ts.map +1 -0
- package/dist/src/hooks/hook-service.js +118 -0
- package/dist/src/hooks/hook-service.js.map +1 -0
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +3 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/types.d.ts +52 -0
- package/dist/src/hooks/types.d.ts.map +1 -0
- package/dist/src/hooks/types.js +2 -0
- package/dist/src/hooks/types.js.map +1 -0
- package/dist/src/http/auth-node.d.ts +4 -0
- package/dist/src/http/auth-node.d.ts.map +1 -0
- package/dist/src/http/auth-node.js +34 -0
- package/dist/src/http/auth-node.js.map +1 -0
- package/dist/src/http/auth.d.ts +40 -0
- package/dist/src/http/auth.d.ts.map +1 -0
- package/dist/src/http/auth.js +76 -0
- package/dist/src/http/auth.js.map +1 -0
- package/dist/src/http/errors.d.ts +31 -0
- package/dist/src/http/errors.d.ts.map +1 -0
- package/dist/src/http/errors.js +36 -0
- package/dist/src/http/errors.js.map +1 -0
- package/dist/src/http/file-serve.d.ts +10 -0
- package/dist/src/http/file-serve.d.ts.map +1 -0
- package/dist/src/http/file-serve.js +159 -0
- package/dist/src/http/file-serve.js.map +1 -0
- package/dist/src/http/file-token.d.ts +7 -0
- package/dist/src/http/file-token.d.ts.map +1 -0
- package/dist/src/http/file-token.js +57 -0
- package/dist/src/http/file-token.js.map +1 -0
- package/dist/src/http/files.d.ts +11 -0
- package/dist/src/http/files.d.ts.map +1 -0
- package/dist/src/http/files.js +85 -0
- package/dist/src/http/files.js.map +1 -0
- package/dist/src/http/index.d.ts +11 -0
- package/dist/src/http/index.d.ts.map +1 -0
- package/dist/src/http/index.js +9 -0
- package/dist/src/http/index.js.map +1 -0
- package/dist/src/http/ip-middleware.d.ts +4 -0
- package/dist/src/http/ip-middleware.d.ts.map +1 -0
- package/dist/src/http/ip-middleware.js +24 -0
- package/dist/src/http/ip-middleware.js.map +1 -0
- package/dist/src/http/params.d.ts +15 -0
- package/dist/src/http/params.d.ts.map +1 -0
- package/dist/src/http/params.js +48 -0
- package/dist/src/http/params.js.map +1 -0
- package/dist/src/http/router.d.ts +11 -0
- package/dist/src/http/router.d.ts.map +1 -0
- package/dist/src/http/router.js +300 -0
- package/dist/src/http/router.js.map +1 -0
- package/dist/src/http/schema.d.ts +5 -0
- package/dist/src/http/schema.d.ts.map +1 -0
- package/dist/src/http/schema.js +17 -0
- package/dist/src/http/schema.js.map +1 -0
- package/dist/src/http/server-factory-node.d.ts +4 -0
- package/dist/src/http/server-factory-node.d.ts.map +1 -0
- package/dist/src/http/server-factory-node.js +8 -0
- package/dist/src/http/server-factory-node.js.map +1 -0
- package/dist/src/http/server-factory.d.ts +11 -0
- package/dist/src/http/server-factory.d.ts.map +1 -0
- package/dist/src/http/server-factory.js +4 -0
- package/dist/src/http/server-factory.js.map +1 -0
- package/dist/src/http/telemetry-routes.d.ts +5 -0
- package/dist/src/http/telemetry-routes.d.ts.map +1 -0
- package/dist/src/http/telemetry-routes.js +156 -0
- package/dist/src/http/telemetry-routes.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +22 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/migrator/dialect-sqlite.d.ts +9 -0
- package/dist/src/migrator/dialect-sqlite.d.ts.map +1 -0
- package/dist/src/migrator/dialect-sqlite.js +102 -0
- package/dist/src/migrator/dialect-sqlite.js.map +1 -0
- package/dist/src/migrator/dialect.d.ts +24 -0
- package/dist/src/migrator/dialect.d.ts.map +1 -0
- package/dist/src/migrator/dialect.js +5 -0
- package/dist/src/migrator/dialect.js.map +1 -0
- package/dist/src/migrator/index.d.ts +8 -0
- package/dist/src/migrator/index.d.ts.map +1 -0
- package/dist/src/migrator/index.js +6 -0
- package/dist/src/migrator/index.js.map +1 -0
- package/dist/src/migrator/migrator.d.ts +36 -0
- package/dist/src/migrator/migrator.d.ts.map +1 -0
- package/dist/src/migrator/migrator.js +200 -0
- package/dist/src/migrator/migrator.js.map +1 -0
- package/dist/src/migrator/schema-diff.d.ts +25 -0
- package/dist/src/migrator/schema-diff.d.ts.map +1 -0
- package/dist/src/migrator/schema-diff.js +157 -0
- package/dist/src/migrator/schema-diff.js.map +1 -0
- package/dist/src/migrator/types.d.ts +91 -0
- package/dist/src/migrator/types.d.ts.map +1 -0
- package/dist/src/migrator/types.js +13 -0
- package/dist/src/migrator/types.js.map +1 -0
- package/dist/src/platforms/node.d.ts +40 -0
- package/dist/src/platforms/node.d.ts.map +1 -0
- package/dist/src/platforms/node.js +45 -0
- package/dist/src/platforms/node.js.map +1 -0
- package/dist/src/repository/id.d.ts +5 -0
- package/dist/src/repository/id.d.ts.map +1 -0
- package/dist/src/repository/id.js +9 -0
- package/dist/src/repository/id.js.map +1 -0
- package/dist/src/repository/index.d.ts +3 -0
- package/dist/src/repository/index.d.ts.map +1 -0
- package/dist/src/repository/index.js +2 -0
- package/dist/src/repository/index.js.map +1 -0
- package/dist/src/repository/repository.d.ts +53 -0
- package/dist/src/repository/repository.d.ts.map +1 -0
- package/dist/src/repository/repository.js +150 -0
- package/dist/src/repository/repository.js.map +1 -0
- package/dist/src/repository/types.d.ts +42 -0
- package/dist/src/repository/types.d.ts.map +1 -0
- package/dist/src/repository/types.js +2 -0
- package/dist/src/repository/types.js.map +1 -0
- package/dist/src/rule/compiler.d.ts +52 -0
- package/dist/src/rule/compiler.d.ts.map +1 -0
- package/dist/src/rule/compiler.js +115 -0
- package/dist/src/rule/compiler.js.map +1 -0
- package/dist/src/rule/enforcer.d.ts +47 -0
- package/dist/src/rule/enforcer.d.ts.map +1 -0
- package/dist/src/rule/enforcer.js +60 -0
- package/dist/src/rule/enforcer.js.map +1 -0
- package/dist/src/rule/index.d.ts +3 -0
- package/dist/src/rule/index.d.ts.map +1 -0
- package/dist/src/rule/index.js +3 -0
- package/dist/src/rule/index.js.map +1 -0
- package/dist/src/storage/index.d.ts +3 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +3 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/local-preset.d.ts +21 -0
- package/dist/src/storage/local-preset.d.ts.map +1 -0
- package/dist/src/storage/local-preset.js +21 -0
- package/dist/src/storage/local-preset.js.map +1 -0
- package/dist/src/storage/storage.d.ts +83 -0
- package/dist/src/storage/storage.d.ts.map +1 -0
- package/dist/src/storage/storage.js +120 -0
- package/dist/src/storage/storage.js.map +1 -0
- package/dist/src/telemetry/collections.d.ts +4 -0
- package/dist/src/telemetry/collections.d.ts.map +1 -0
- package/dist/src/telemetry/collections.js +19 -0
- package/dist/src/telemetry/collections.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +9 -0
- package/dist/src/telemetry/index.d.ts.map +1 -0
- package/dist/src/telemetry/index.js +9 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/logger.d.ts +4 -0
- package/dist/src/telemetry/logger.d.ts.map +1 -0
- package/dist/src/telemetry/logger.js +27 -0
- package/dist/src/telemetry/logger.js.map +1 -0
- package/dist/src/telemetry/sqlite-logger.d.ts +24 -0
- package/dist/src/telemetry/sqlite-logger.d.ts.map +1 -0
- package/dist/src/telemetry/sqlite-logger.js +152 -0
- package/dist/src/telemetry/sqlite-logger.js.map +1 -0
- package/dist/src/telemetry/telemetry-sql-client.d.ts +11 -0
- package/dist/src/telemetry/telemetry-sql-client.d.ts.map +1 -0
- package/dist/src/telemetry/telemetry-sql-client.js +8 -0
- package/dist/src/telemetry/telemetry-sql-client.js.map +1 -0
- package/dist/src/telemetry/tracer.d.ts +16 -0
- package/dist/src/telemetry/tracer.d.ts.map +1 -0
- package/dist/src/telemetry/tracer.js +106 -0
- package/dist/src/telemetry/tracer.js.map +1 -0
- package/dist/src/thumbnail/index.d.ts +4 -0
- package/dist/src/thumbnail/index.d.ts.map +1 -0
- package/dist/src/thumbnail/index.js +3 -0
- package/dist/src/thumbnail/index.js.map +1 -0
- package/dist/src/thumbnail/photon.d.ts +9 -0
- package/dist/src/thumbnail/photon.d.ts.map +1 -0
- package/dist/src/thumbnail/photon.js +73 -0
- package/dist/src/thumbnail/photon.js.map +1 -0
- package/dist/src/thumbnail/types.d.ts +23 -0
- package/dist/src/thumbnail/types.d.ts.map +1 -0
- package/dist/src/thumbnail/types.js +22 -0
- package/dist/src/thumbnail/types.js.map +1 -0
- package/dist/tests/app/app.test.d.ts +2 -0
- package/dist/tests/app/app.test.d.ts.map +1 -0
- package/dist/tests/app/app.test.js +125 -0
- package/dist/tests/app/app.test.js.map +1 -0
- package/dist/tests/app/builder.test.d.ts +2 -0
- package/dist/tests/app/builder.test.d.ts.map +1 -0
- package/dist/tests/app/builder.test.js +70 -0
- package/dist/tests/app/builder.test.js.map +1 -0
- package/dist/tests/cache/cached-collection.test.d.ts +2 -0
- package/dist/tests/cache/cached-collection.test.d.ts.map +1 -0
- package/dist/tests/cache/cached-collection.test.js +244 -0
- package/dist/tests/cache/cached-collection.test.js.map +1 -0
- package/dist/tests/cache/collection-cache.test.d.ts +2 -0
- package/dist/tests/cache/collection-cache.test.d.ts.map +1 -0
- package/dist/tests/cache/collection-cache.test.js +73 -0
- package/dist/tests/cache/collection-cache.test.js.map +1 -0
- package/dist/tests/collection-service/collection-service.test.d.ts +2 -0
- package/dist/tests/collection-service/collection-service.test.d.ts.map +1 -0
- package/dist/tests/collection-service/collection-service.test.js +938 -0
- package/dist/tests/collection-service/collection-service.test.js.map +1 -0
- package/dist/tests/collection-service/input-schema.test.d.ts +2 -0
- package/dist/tests/collection-service/input-schema.test.d.ts.map +1 -0
- package/dist/tests/collection-service/input-schema.test.js +327 -0
- package/dist/tests/collection-service/input-schema.test.js.map +1 -0
- package/dist/tests/config/config.test.d.ts +2 -0
- package/dist/tests/config/config.test.d.ts.map +1 -0
- package/dist/tests/config/config.test.js +84 -0
- package/dist/tests/config/config.test.js.map +1 -0
- package/dist/tests/crypto/crypto.test.d.ts +2 -0
- package/dist/tests/crypto/crypto.test.d.ts.map +1 -0
- package/dist/tests/crypto/crypto.test.js +56 -0
- package/dist/tests/crypto/crypto.test.js.map +1 -0
- package/dist/tests/hooks/hook-collection.test.d.ts +2 -0
- package/dist/tests/hooks/hook-collection.test.d.ts.map +1 -0
- package/dist/tests/hooks/hook-collection.test.js +103 -0
- package/dist/tests/hooks/hook-collection.test.js.map +1 -0
- package/dist/tests/hooks/hook-service.test.d.ts +2 -0
- package/dist/tests/hooks/hook-service.test.d.ts.map +1 -0
- package/dist/tests/hooks/hook-service.test.js +216 -0
- package/dist/tests/hooks/hook-service.test.js.map +1 -0
- package/dist/tests/http/file-serve.test.d.ts +2 -0
- package/dist/tests/http/file-serve.test.d.ts.map +1 -0
- package/dist/tests/http/file-serve.test.js +210 -0
- package/dist/tests/http/file-serve.test.js.map +1 -0
- package/dist/tests/http/file-token.test.d.ts +2 -0
- package/dist/tests/http/file-token.test.d.ts.map +1 -0
- package/dist/tests/http/file-token.test.js +165 -0
- package/dist/tests/http/file-token.test.js.map +1 -0
- package/dist/tests/http/ip-middleware.test.d.ts +2 -0
- package/dist/tests/http/ip-middleware.test.d.ts.map +1 -0
- package/dist/tests/http/ip-middleware.test.js +58 -0
- package/dist/tests/http/ip-middleware.test.js.map +1 -0
- package/dist/tests/http/router.test.d.ts +2 -0
- package/dist/tests/http/router.test.d.ts.map +1 -0
- package/dist/tests/http/router.test.js +312 -0
- package/dist/tests/http/router.test.js.map +1 -0
- package/dist/tests/migrator/dialect-sqlite.test.d.ts +2 -0
- package/dist/tests/migrator/dialect-sqlite.test.d.ts.map +1 -0
- package/dist/tests/migrator/dialect-sqlite.test.js +90 -0
- package/dist/tests/migrator/dialect-sqlite.test.js.map +1 -0
- package/dist/tests/migrator/integration.test.d.ts +2 -0
- package/dist/tests/migrator/integration.test.d.ts.map +1 -0
- package/dist/tests/migrator/integration.test.js +180 -0
- package/dist/tests/migrator/integration.test.js.map +1 -0
- package/dist/tests/migrator/migrator.test.d.ts +2 -0
- package/dist/tests/migrator/migrator.test.d.ts.map +1 -0
- package/dist/tests/migrator/migrator.test.js +225 -0
- package/dist/tests/migrator/migrator.test.js.map +1 -0
- package/dist/tests/migrator/schema-diff.test.d.ts +2 -0
- package/dist/tests/migrator/schema-diff.test.d.ts.map +1 -0
- package/dist/tests/migrator/schema-diff.test.js +323 -0
- package/dist/tests/migrator/schema-diff.test.js.map +1 -0
- package/dist/tests/repository/repository.test.d.ts +2 -0
- package/dist/tests/repository/repository.test.d.ts.map +1 -0
- package/dist/tests/repository/repository.test.js +255 -0
- package/dist/tests/repository/repository.test.js.map +1 -0
- package/dist/tests/rule/compiler.test.d.ts +2 -0
- package/dist/tests/rule/compiler.test.d.ts.map +1 -0
- package/dist/tests/rule/compiler.test.js +226 -0
- package/dist/tests/rule/compiler.test.js.map +1 -0
- package/dist/tests/rule/enforcer.test.d.ts +2 -0
- package/dist/tests/rule/enforcer.test.d.ts.map +1 -0
- package/dist/tests/rule/enforcer.test.js +190 -0
- package/dist/tests/rule/enforcer.test.js.map +1 -0
- package/dist/tests/storage/storage.test.d.ts +2 -0
- package/dist/tests/storage/storage.test.d.ts.map +1 -0
- package/dist/tests/storage/storage.test.js +76 -0
- package/dist/tests/storage/storage.test.js.map +1 -0
- package/dist/tests/telemetry/collections.test.d.ts +2 -0
- package/dist/tests/telemetry/collections.test.d.ts.map +1 -0
- package/dist/tests/telemetry/collections.test.js +67 -0
- package/dist/tests/telemetry/collections.test.js.map +1 -0
- package/dist/tests/telemetry/instrumentation.test.d.ts +2 -0
- package/dist/tests/telemetry/instrumentation.test.d.ts.map +1 -0
- package/dist/tests/telemetry/instrumentation.test.js +226 -0
- package/dist/tests/telemetry/instrumentation.test.js.map +1 -0
- package/dist/tests/telemetry/logger.test.d.ts +2 -0
- package/dist/tests/telemetry/logger.test.d.ts.map +1 -0
- package/dist/tests/telemetry/logger.test.js +56 -0
- package/dist/tests/telemetry/logger.test.js.map +1 -0
- package/dist/tests/telemetry/sqlite-logger.test.d.ts +2 -0
- package/dist/tests/telemetry/sqlite-logger.test.d.ts.map +1 -0
- package/dist/tests/telemetry/sqlite-logger.test.js +218 -0
- package/dist/tests/telemetry/sqlite-logger.test.js.map +1 -0
- package/dist/tests/telemetry/telemetry-routes.test.d.ts +2 -0
- package/dist/tests/telemetry/telemetry-routes.test.d.ts.map +1 -0
- package/dist/tests/telemetry/telemetry-routes.test.js +133 -0
- package/dist/tests/telemetry/telemetry-routes.test.js.map +1 -0
- package/dist/tests/telemetry/tracer.test.d.ts +2 -0
- package/dist/tests/telemetry/tracer.test.d.ts.map +1 -0
- package/dist/tests/telemetry/tracer.test.js +63 -0
- package/dist/tests/telemetry/tracer.test.js.map +1 -0
- package/dist/tests/thumbnail/photon.test.d.ts +2 -0
- package/dist/tests/thumbnail/photon.test.d.ts.map +1 -0
- package/dist/tests/thumbnail/photon.test.js +478 -0
- package/dist/tests/thumbnail/photon.test.js.map +1 -0
- package/dist/tests/thumbnail/thumbnail.test.d.ts +2 -0
- package/dist/tests/thumbnail/thumbnail.test.d.ts.map +1 -0
- package/dist/tests/thumbnail/thumbnail.test.js +35 -0
- package/dist/tests/thumbnail/thumbnail.test.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-serve.test.js","sourceRoot":"","sources":["../../../tests/http/file-serve.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAe,MAAM,gBAAgB,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE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,CAAC,CAAC,CACnC,CAAA;IAED,EAAE,CAAC,MAAM,CAAC,6DAA6D,EAAE,GAAG,EAAE,CAC5E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,KAAK,CAAC,CAAC,WAAW,CAAA;QAClB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA;QAC3D,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,aAAa,EAAE,YAAY,EAAE,aAAa,CAAC,CAAA;QACxE,KAAK,CAAC,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAA;QAC3E,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,aAAa,CACpC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,EACrD,UAAU,CACX,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACpB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,CAC/B,0BAA0B,EAAE,IAAI,aAAa,UAAU,SAAS,EAAE,CACnE,CAAA;QACD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACrC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CACnC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-token.test.d.ts","sourceRoot":"","sources":["../../../tests/http/file-token.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Cookies, HttpClient, HttpClientRequest, HttpServer } from "@effect/platform";
|
|
2
|
+
import { NodeHttpServer } from "@effect/platform-node";
|
|
3
|
+
import { SqlClient } from "@effect/sql";
|
|
4
|
+
import { SqliteClient } from "@effect/sql-sqlite-node";
|
|
5
|
+
import { Effect, Layer, Option, Redacted, Schema } from "effect";
|
|
6
|
+
import { assert, describe, it } from "@effect/vitest";
|
|
7
|
+
import { AuthCollection } from "@gettersethya/mira-client";
|
|
8
|
+
import { BaseCollection } from "@gettersethya/mira-client";
|
|
9
|
+
import { Field } from "@gettersethya/mira-client";
|
|
10
|
+
import { makeCollectionServiceLayer } from "../../src/collection-service/collection-service.js";
|
|
11
|
+
import { Repository, RepositoryLive } from "../../src/repository/repository.js";
|
|
12
|
+
import { FileStorage, FileStorageNotFound } from "../../src/storage/storage.js";
|
|
13
|
+
import { ThumbnailServiceNoopLive } from "../../src/thumbnail/index.js";
|
|
14
|
+
import { hashPassword } from "../../src/http/auth.js";
|
|
15
|
+
import { makeCollectionRouter } from "../../src/http/router.js";
|
|
16
|
+
import { AppConfig } from "../../src/config/index.js";
|
|
17
|
+
import { NodeCryptoLayer } from "../../src/crypto/node.js";
|
|
18
|
+
import { NodeAuthServiceLayer } from "../../src/http/auth-node.js";
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Collections
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
const Users = AuthCollection.define("users", {}).rules((R) => ({
|
|
23
|
+
list: R.public(),
|
|
24
|
+
view: R.public(),
|
|
25
|
+
create: R.public(),
|
|
26
|
+
update: R.public(),
|
|
27
|
+
delete: R.public(),
|
|
28
|
+
}));
|
|
29
|
+
const Docs = BaseCollection.define("docs", {
|
|
30
|
+
title: Field.text(),
|
|
31
|
+
attachment: Field.file({ required: false }),
|
|
32
|
+
}).rules((R) => ({
|
|
33
|
+
list: R.public(),
|
|
34
|
+
view: R.public(),
|
|
35
|
+
create: R.public(),
|
|
36
|
+
update: R.public(),
|
|
37
|
+
delete: R.public(),
|
|
38
|
+
}));
|
|
39
|
+
const JWT_SECRET = "test-file-token-secret";
|
|
40
|
+
const ALL_COLLECTIONS = [Users, Docs];
|
|
41
|
+
const AppConfigTest = Layer.succeed(AppConfig, AppConfig.of({
|
|
42
|
+
appName: "test",
|
|
43
|
+
port: 8080,
|
|
44
|
+
applicationUrl: "http://localhost:8080",
|
|
45
|
+
jwtSecret: Redacted.make(JWT_SECRET),
|
|
46
|
+
useS3: false,
|
|
47
|
+
s3Config: Option.none(),
|
|
48
|
+
}));
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Test layer
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
const FileStorageTest = Layer.succeed(FileStorage, FileStorage.of({
|
|
53
|
+
upload: (key) => Effect.succeed(key),
|
|
54
|
+
delete: () => Effect.void,
|
|
55
|
+
url: (key) => `/files/${key}`,
|
|
56
|
+
read: (key) => Effect.fail(new FileStorageNotFound({ key })),
|
|
57
|
+
exists: () => Effect.succeed(false),
|
|
58
|
+
list: () => Effect.succeed([])
|
|
59
|
+
}));
|
|
60
|
+
const sqliteLayer = SqliteClient.layer({ filename: ":memory:" });
|
|
61
|
+
const repoWithSql = RepositoryLive.pipe(Layer.provide(sqliteLayer), Layer.provide(NodeCryptoLayer));
|
|
62
|
+
const collectionServiceWithDeps = makeCollectionServiceLayer(ALL_COLLECTIONS).pipe(Layer.provide(repoWithSql), Layer.provide(FileStorageTest), Layer.provide(sqliteLayer));
|
|
63
|
+
const testLayer = Layer.mergeAll(collectionServiceWithDeps, repoWithSql, FileStorageTest, sqliteLayer, ThumbnailServiceNoopLive, NodeHttpServer.layerTest, AppConfigTest, NodeCryptoLayer, NodeAuthServiceLayer);
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Setup helpers
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
const setupTables = Effect.gen(function* () {
|
|
68
|
+
const sql = yield* SqlClient.SqlClient;
|
|
69
|
+
yield* sql.unsafe(`
|
|
70
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
71
|
+
"seqId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
72
|
+
"id" TEXT NOT NULL UNIQUE,
|
|
73
|
+
"email" TEXT NOT NULL UNIQUE,
|
|
74
|
+
"password" TEXT NOT NULL,
|
|
75
|
+
"emailVerified" INTEGER NOT NULL DEFAULT 0,
|
|
76
|
+
"created" TEXT NOT NULL,
|
|
77
|
+
"updated" TEXT NOT NULL
|
|
78
|
+
)
|
|
79
|
+
`);
|
|
80
|
+
yield* sql `DELETE FROM ${sql("users")}`;
|
|
81
|
+
yield* sql.unsafe(`
|
|
82
|
+
CREATE TABLE IF NOT EXISTS "docs" (
|
|
83
|
+
"seqId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
84
|
+
"id" TEXT NOT NULL UNIQUE,
|
|
85
|
+
"title" TEXT NOT NULL DEFAULT '',
|
|
86
|
+
"attachment" TEXT,
|
|
87
|
+
"created" TEXT NOT NULL,
|
|
88
|
+
"updated" TEXT NOT NULL
|
|
89
|
+
)
|
|
90
|
+
`);
|
|
91
|
+
yield* sql `DELETE FROM ${sql("docs")}`;
|
|
92
|
+
});
|
|
93
|
+
function seedUser(email, plain) {
|
|
94
|
+
return Effect.gen(function* () {
|
|
95
|
+
const repo = yield* Repository;
|
|
96
|
+
const hash = yield* hashPassword(plain);
|
|
97
|
+
const raw = yield* repo.create("users", { email, password: hash }).pipe(Effect.orDie);
|
|
98
|
+
const { id } = yield* Schema.decodeUnknown(Schema.Struct({ id: Schema.String }))(raw).pipe(Effect.orDie);
|
|
99
|
+
return id;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function login(email, password) {
|
|
103
|
+
return Effect.gen(function* () {
|
|
104
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email, password })));
|
|
105
|
+
const body = yield* res.json;
|
|
106
|
+
const { token } = yield* Schema.decodeUnknown(Schema.Struct({ token: Schema.String }))(body).pipe(Effect.orDie);
|
|
107
|
+
return token;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Tests
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
describe("POST /api/files/token", () => {
|
|
114
|
+
it.scoped("returns 401 when no auth token is provided", () => Effect.gen(function* () {
|
|
115
|
+
yield* setupTables;
|
|
116
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
117
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/files/token").pipe(HttpClientRequest.bodyUnsafeJson({ collection: "docs" })));
|
|
118
|
+
assert.strictEqual(res.status, 401);
|
|
119
|
+
}).pipe(Effect.provide(testLayer)));
|
|
120
|
+
it.scoped("returns 401 when Bearer token is invalid", () => Effect.gen(function* () {
|
|
121
|
+
yield* setupTables;
|
|
122
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
123
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/files/token").pipe(HttpClientRequest.setHeader("Authorization", "Bearer not-a-valid-jwt"), HttpClientRequest.bodyUnsafeJson({ collection: "docs" })));
|
|
124
|
+
assert.strictEqual(res.status, 401);
|
|
125
|
+
}).pipe(Effect.provide(testLayer)));
|
|
126
|
+
it.scoped("returns 422 when body is missing collection field", () => Effect.gen(function* () {
|
|
127
|
+
yield* setupTables;
|
|
128
|
+
yield* seedUser("alice@example.com", "pass123");
|
|
129
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
130
|
+
const token = yield* login("alice@example.com", "pass123");
|
|
131
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/files/token").pipe(HttpClientRequest.setHeader("Authorization", `Bearer ${token}`), HttpClientRequest.bodyUnsafeJson({})));
|
|
132
|
+
assert.strictEqual(res.status, 422);
|
|
133
|
+
}).pipe(Effect.provide(testLayer)));
|
|
134
|
+
it.scoped("returns 404 for an unknown collection", () => Effect.gen(function* () {
|
|
135
|
+
yield* setupTables;
|
|
136
|
+
yield* seedUser("bob@example.com", "pass456");
|
|
137
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
138
|
+
const token = yield* login("bob@example.com", "pass456");
|
|
139
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/files/token").pipe(HttpClientRequest.setHeader("Authorization", `Bearer ${token}`), HttpClientRequest.bodyUnsafeJson({ collection: "nonexistent" })));
|
|
140
|
+
assert.strictEqual(res.status, 404);
|
|
141
|
+
}).pipe(Effect.provide(testLayer)));
|
|
142
|
+
it.scoped("returns 200 with token and expiresAt for valid request", () => Effect.gen(function* () {
|
|
143
|
+
yield* setupTables;
|
|
144
|
+
yield* seedUser("carol@example.com", "pass789");
|
|
145
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
146
|
+
const token = yield* login("carol@example.com", "pass789");
|
|
147
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/files/token").pipe(HttpClientRequest.setHeader("Authorization", `Bearer ${token}`), HttpClientRequest.bodyUnsafeJson({ collection: "docs" })));
|
|
148
|
+
assert.strictEqual(res.status, 200);
|
|
149
|
+
const body = yield* res.json;
|
|
150
|
+
const parsed = yield* Schema.decodeUnknown(Schema.Struct({ token: Schema.String, expiresAt: Schema.Number }))(body).pipe(Effect.orDie);
|
|
151
|
+
assert.ok(parsed.token.length > 0);
|
|
152
|
+
assert.ok(parsed.expiresAt > Date.now());
|
|
153
|
+
}).pipe(Effect.provide(testLayer)));
|
|
154
|
+
it.scoped("returns 200 with valid mira_token cookie and no Bearer header", () => Effect.gen(function* () {
|
|
155
|
+
yield* setupTables;
|
|
156
|
+
yield* seedUser("cookiefile@example.com", "pass101");
|
|
157
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
158
|
+
const loginRes = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "cookiefile@example.com", password: "pass101" })));
|
|
159
|
+
assert.strictEqual(loginRes.status, 200);
|
|
160
|
+
const cookieToken = Option.getOrThrow(Cookies.getValue(loginRes.cookies, "mira_token"));
|
|
161
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/files/token").pipe(HttpClientRequest.setHeader("Cookie", `mira_token=${cookieToken}`), HttpClientRequest.bodyUnsafeJson({ collection: "docs" })));
|
|
162
|
+
assert.strictEqual(res.status, 200);
|
|
163
|
+
}).pipe(Effect.provide(testLayer)));
|
|
164
|
+
});
|
|
165
|
+
//# sourceMappingURL=file-token.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-token.test.js","sourceRoot":"","sources":["../../../tests/http/file-token.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAmB,iBAAiB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACtG,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAChE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,mBAAmB,E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CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAC7C,iBAAiB,CAAC,SAAS,CAAC,QAAQ,EAAE,cAAc,WAAW,EAAE,CAAC,EAClE,iBAAiB,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CACzD,CACF,CAAA;QACD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACrC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CACnC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip-middleware.test.d.ts","sourceRoot":"","sources":["../../../tests/http/ip-middleware.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { HttpClient, HttpClientRequest, HttpServer, HttpServerResponse } from "@effect/platform";
|
|
2
|
+
import { NodeHttpServer } from "@effect/platform-node";
|
|
3
|
+
import { Chunk, Effect, Layer, Queue } from "effect";
|
|
4
|
+
import { randomBytes } from "node:crypto";
|
|
5
|
+
import { describe, it } from "@effect/vitest";
|
|
6
|
+
import { expect } from "vitest";
|
|
7
|
+
import { makeConsoleTracer } from "../../src/telemetry/tracer.js";
|
|
8
|
+
import { ipAnnotationMiddleware } from "../../src/http/ip-middleware.js";
|
|
9
|
+
const testApp = ipAnnotationMiddleware(Effect.succeed(HttpServerResponse.text("ok")));
|
|
10
|
+
function makeIpTestLayer(queue) {
|
|
11
|
+
return Layer.mergeAll(NodeHttpServer.layerTest, Layer.setTracer(makeConsoleTracer(queue, (size) => randomBytes(size))));
|
|
12
|
+
}
|
|
13
|
+
function findSpanWithIp(spans) {
|
|
14
|
+
return spans.find((s) => "http.client_ip" in s.attributes);
|
|
15
|
+
}
|
|
16
|
+
describe("ipAnnotationMiddleware", () => {
|
|
17
|
+
it.scoped("x-forwarded-for — single IP annotates span", () => Effect.gen(function* () {
|
|
18
|
+
const queue = yield* Queue.unbounded();
|
|
19
|
+
yield* Effect.gen(function* () {
|
|
20
|
+
yield* testApp.pipe(HttpServer.serveEffect());
|
|
21
|
+
yield* HttpClientRequest.get("/").pipe(HttpClientRequest.setHeader("x-forwarded-for", "1.2.3.4"), HttpClient.execute);
|
|
22
|
+
}).pipe(Effect.provide(makeIpTestLayer(queue)));
|
|
23
|
+
const spans = Chunk.toArray(yield* Queue.takeAll(queue));
|
|
24
|
+
const span = findSpanWithIp(spans);
|
|
25
|
+
expect(span?.attributes["http.client_ip"]).toBe("1.2.3.4");
|
|
26
|
+
}));
|
|
27
|
+
it.scoped("x-forwarded-for — multiple IPs uses first entry", () => Effect.gen(function* () {
|
|
28
|
+
const queue = yield* Queue.unbounded();
|
|
29
|
+
yield* Effect.gen(function* () {
|
|
30
|
+
yield* testApp.pipe(HttpServer.serveEffect());
|
|
31
|
+
yield* HttpClientRequest.get("/").pipe(HttpClientRequest.setHeader("x-forwarded-for", "1.2.3.4, 5.6.7.8, 9.0.0.1"), HttpClient.execute);
|
|
32
|
+
}).pipe(Effect.provide(makeIpTestLayer(queue)));
|
|
33
|
+
const spans = Chunk.toArray(yield* Queue.takeAll(queue));
|
|
34
|
+
const span = findSpanWithIp(spans);
|
|
35
|
+
expect(span?.attributes["http.client_ip"]).toBe("1.2.3.4");
|
|
36
|
+
}));
|
|
37
|
+
it.scoped("x-real-ip fallback when no x-forwarded-for", () => Effect.gen(function* () {
|
|
38
|
+
const queue = yield* Queue.unbounded();
|
|
39
|
+
yield* Effect.gen(function* () {
|
|
40
|
+
yield* testApp.pipe(HttpServer.serveEffect());
|
|
41
|
+
yield* HttpClientRequest.get("/").pipe(HttpClientRequest.setHeader("x-real-ip", "2.3.4.5"), HttpClient.execute);
|
|
42
|
+
}).pipe(Effect.provide(makeIpTestLayer(queue)));
|
|
43
|
+
const spans = Chunk.toArray(yield* Queue.takeAll(queue));
|
|
44
|
+
const span = findSpanWithIp(spans);
|
|
45
|
+
expect(span?.attributes["http.client_ip"]).toBe("2.3.4.5");
|
|
46
|
+
}));
|
|
47
|
+
it.scoped("no IP headers — http.client_ip attribute absent", () => Effect.gen(function* () {
|
|
48
|
+
const queue = yield* Queue.unbounded();
|
|
49
|
+
yield* Effect.gen(function* () {
|
|
50
|
+
yield* testApp.pipe(HttpServer.serveEffect());
|
|
51
|
+
yield* HttpClient.get("/");
|
|
52
|
+
}).pipe(Effect.provide(makeIpTestLayer(queue)));
|
|
53
|
+
const spans = Chunk.toArray(yield* Queue.takeAll(queue));
|
|
54
|
+
const span = findSpanWithIp(spans);
|
|
55
|
+
expect(span).toBeUndefined();
|
|
56
|
+
}));
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=ip-middleware.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip-middleware.test.js","sourceRoot":"","sources":["../../../tests/http/ip-middleware.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAEhE,MAAM,OAAO,GAAG,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAErF,SAAS,eAAe,C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IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QAClC,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAA;IAC9B,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.test.d.ts","sourceRoot":"","sources":["../../../tests/http/router.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { Cookies, HttpClient, HttpClientRequest, HttpServer } from "@effect/platform";
|
|
2
|
+
import { NodeHttpServer } from "@effect/platform-node";
|
|
3
|
+
import { SqlClient } from "@effect/sql";
|
|
4
|
+
import { SqliteClient } from "@effect/sql-sqlite-node";
|
|
5
|
+
import { Effect, Layer, Option, Redacted } from "effect";
|
|
6
|
+
import { assert, describe, it } from "@effect/vitest";
|
|
7
|
+
import { AuthCollection } from "@gettersethya/mira-client";
|
|
8
|
+
import { BaseCollection } from "@gettersethya/mira-client";
|
|
9
|
+
import { Field } from "@gettersethya/mira-client";
|
|
10
|
+
import { makeCollectionServiceLayer } from "../../src/collection-service/collection-service.js";
|
|
11
|
+
import { Repository, RepositoryLive } from "../../src/repository/repository.js";
|
|
12
|
+
import { FileStorage, FileStorageNotFound } from "../../src/storage/storage.js";
|
|
13
|
+
import { ThumbnailServiceNoopLive } from "../../src/thumbnail/index.js";
|
|
14
|
+
import { hashPassword } from "../../src/http/auth.js";
|
|
15
|
+
import { makeCollectionRouter } from "../../src/http/router.js";
|
|
16
|
+
import { AppConfig } from "../../src/config/index.js";
|
|
17
|
+
import { NodeCryptoLayer } from "../../src/crypto/node.js";
|
|
18
|
+
import { NodeAuthServiceLayer } from "../../src/http/auth-node.js";
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Collection definitions
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
const Posts = BaseCollection.define("posts", {
|
|
23
|
+
title: Field.text(),
|
|
24
|
+
content: Field.text({ required: false }),
|
|
25
|
+
}).rules((R) => ({
|
|
26
|
+
list: R.public(),
|
|
27
|
+
view: R.public(),
|
|
28
|
+
create: R.public(),
|
|
29
|
+
update: R.public(),
|
|
30
|
+
delete: R.public(),
|
|
31
|
+
}));
|
|
32
|
+
const Restricted = BaseCollection.define("restricted", {
|
|
33
|
+
name: Field.text(),
|
|
34
|
+
});
|
|
35
|
+
const Users = AuthCollection.define("users", {}).rules((R) => ({
|
|
36
|
+
list: R.public(),
|
|
37
|
+
view: R.public(),
|
|
38
|
+
create: R.public(),
|
|
39
|
+
update: R.public(),
|
|
40
|
+
delete: R.public(),
|
|
41
|
+
}));
|
|
42
|
+
const JWT_SECRET = "test-jwt-secret";
|
|
43
|
+
const ALL_COLLECTIONS = [Posts, Restricted, Users];
|
|
44
|
+
const AppConfigTest = Layer.succeed(AppConfig, AppConfig.of({
|
|
45
|
+
appName: "test",
|
|
46
|
+
port: 8080,
|
|
47
|
+
applicationUrl: "http://localhost:8080",
|
|
48
|
+
jwtSecret: Redacted.make(JWT_SECRET),
|
|
49
|
+
useS3: false,
|
|
50
|
+
s3Config: Option.none(),
|
|
51
|
+
}));
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Test layer
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
const FileStorageTest = Layer.succeed(FileStorage, FileStorage.of({
|
|
56
|
+
upload: (key) => Effect.succeed(key),
|
|
57
|
+
delete: () => Effect.void,
|
|
58
|
+
url: (key) => `/files/${key}`,
|
|
59
|
+
read: (key) => Effect.fail(new FileStorageNotFound({ key })),
|
|
60
|
+
exists: () => Effect.succeed(false),
|
|
61
|
+
list: () => Effect.succeed([])
|
|
62
|
+
}));
|
|
63
|
+
const sqliteLayer = SqliteClient.layer({ filename: ":memory:" });
|
|
64
|
+
// Repository wired to the shared sqlite connection
|
|
65
|
+
const repoWithSql = RepositoryLive.pipe(Layer.provide(sqliteLayer), Layer.provide(NodeCryptoLayer));
|
|
66
|
+
// CollectionService wired to all its dependencies
|
|
67
|
+
const collectionServiceWithDeps = makeCollectionServiceLayer(ALL_COLLECTIONS).pipe(Layer.provide(repoWithSql), Layer.provide(FileStorageTest), Layer.provide(sqliteLayer));
|
|
68
|
+
// Merge everything needed by the router handlers + table setup into one test layer
|
|
69
|
+
const testLayer = Layer.mergeAll(collectionServiceWithDeps, repoWithSql, FileStorageTest, sqliteLayer, ThumbnailServiceNoopLive, NodeHttpServer.layerTest, AppConfigTest, NodeCryptoLayer, NodeAuthServiceLayer);
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// Table setup helper
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
const setupTables = Effect.gen(function* () {
|
|
74
|
+
const sql = yield* SqlClient.SqlClient;
|
|
75
|
+
yield* sql.unsafe(`
|
|
76
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
77
|
+
"seqId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
78
|
+
"id" TEXT NOT NULL UNIQUE,
|
|
79
|
+
"title" TEXT NOT NULL DEFAULT '',
|
|
80
|
+
"content" TEXT,
|
|
81
|
+
"created" TEXT NOT NULL,
|
|
82
|
+
"updated" TEXT NOT NULL
|
|
83
|
+
)
|
|
84
|
+
`);
|
|
85
|
+
yield* sql.unsafe(`DELETE FROM "posts"`);
|
|
86
|
+
yield* sql.unsafe(`
|
|
87
|
+
CREATE TABLE IF NOT EXISTS "restricted" (
|
|
88
|
+
"seqId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
89
|
+
"id" TEXT NOT NULL UNIQUE,
|
|
90
|
+
"name" TEXT NOT NULL DEFAULT '',
|
|
91
|
+
"created" TEXT NOT NULL,
|
|
92
|
+
"updated" TEXT NOT NULL
|
|
93
|
+
)
|
|
94
|
+
`);
|
|
95
|
+
yield* sql.unsafe(`DELETE FROM "restricted"`);
|
|
96
|
+
yield* sql.unsafe(`
|
|
97
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
98
|
+
"seqId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
99
|
+
"id" TEXT NOT NULL UNIQUE,
|
|
100
|
+
"email" TEXT NOT NULL UNIQUE,
|
|
101
|
+
"password" TEXT NOT NULL,
|
|
102
|
+
"emailVerified" INTEGER NOT NULL DEFAULT 0,
|
|
103
|
+
"created" TEXT NOT NULL,
|
|
104
|
+
"updated" TEXT NOT NULL
|
|
105
|
+
)
|
|
106
|
+
`);
|
|
107
|
+
yield* sql.unsafe(`DELETE FROM "users"`);
|
|
108
|
+
});
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// Helper: seed a user with hashed password, bypassing system-field validation
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
function seedUser(email, plainPassword) {
|
|
113
|
+
return Effect.gen(function* () {
|
|
114
|
+
const repo = yield* Repository;
|
|
115
|
+
const hash = yield* hashPassword(plainPassword);
|
|
116
|
+
const record = yield* repo.create("users", { email, password: hash }).pipe(Effect.orDie);
|
|
117
|
+
return record["id"];
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// Integration tests
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
describe("makeCollectionRouter", () => {
|
|
124
|
+
it.scoped("GET /api/collections/:name — list returns empty result on empty table", () => Effect.gen(function* () {
|
|
125
|
+
yield* setupTables;
|
|
126
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
127
|
+
const res = yield* HttpClient.get("/api/collections/posts");
|
|
128
|
+
assert.strictEqual(res.status, 200);
|
|
129
|
+
const body = yield* res.json;
|
|
130
|
+
assert.ok(typeof body === "object" && body !== null);
|
|
131
|
+
const items = body.items;
|
|
132
|
+
assert.ok(Array.isArray(items));
|
|
133
|
+
assert.strictEqual(items.length, 0);
|
|
134
|
+
}).pipe(Effect.provide(testLayer)));
|
|
135
|
+
it.scoped("GET /api/collections/:name — list returns 404 for unknown collection", () => Effect.gen(function* () {
|
|
136
|
+
yield* setupTables;
|
|
137
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
138
|
+
const res = yield* HttpClient.get("/api/collections/no_such_collection");
|
|
139
|
+
assert.strictEqual(res.status, 404);
|
|
140
|
+
}).pipe(Effect.provide(testLayer)));
|
|
141
|
+
it.scoped("POST /api/collections/:name — create returns 201 with record", () => Effect.gen(function* () {
|
|
142
|
+
yield* setupTables;
|
|
143
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
144
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/posts").pipe(HttpClientRequest.bodyUnsafeJson({ title: "Hello World", content: "body text" })));
|
|
145
|
+
assert.strictEqual(res.status, 201);
|
|
146
|
+
const body = yield* res.json;
|
|
147
|
+
const record = body;
|
|
148
|
+
assert.strictEqual(record["title"], "Hello World");
|
|
149
|
+
assert.strictEqual(record["content"], "body text");
|
|
150
|
+
assert.ok(typeof record["id"] === "string");
|
|
151
|
+
}).pipe(Effect.provide(testLayer)));
|
|
152
|
+
it.scoped("POST /api/collections/:name — create returns 403 when rules deny", () => Effect.gen(function* () {
|
|
153
|
+
yield* setupTables;
|
|
154
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
155
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/restricted").pipe(HttpClientRequest.bodyUnsafeJson({ name: "secret" })));
|
|
156
|
+
assert.strictEqual(res.status, 403);
|
|
157
|
+
}).pipe(Effect.provide(testLayer)));
|
|
158
|
+
it.scoped("GET /api/collections/:name/:id — view returns 200 with record", () => Effect.gen(function* () {
|
|
159
|
+
yield* setupTables;
|
|
160
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
161
|
+
const createRes = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/posts").pipe(HttpClientRequest.bodyUnsafeJson({ title: "Test Post" })));
|
|
162
|
+
assert.strictEqual(createRes.status, 201);
|
|
163
|
+
const created = (yield* createRes.json);
|
|
164
|
+
const id = created["id"];
|
|
165
|
+
const res = yield* HttpClient.get(`/api/collections/posts/${id}`);
|
|
166
|
+
assert.strictEqual(res.status, 200);
|
|
167
|
+
const body = (yield* res.json);
|
|
168
|
+
assert.strictEqual(body["id"], id);
|
|
169
|
+
assert.strictEqual(body["title"], "Test Post");
|
|
170
|
+
}).pipe(Effect.provide(testLayer)));
|
|
171
|
+
it.scoped("GET /api/collections/:name/:id — view returns 404 for unknown id", () => Effect.gen(function* () {
|
|
172
|
+
yield* setupTables;
|
|
173
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
174
|
+
const res = yield* HttpClient.get("/api/collections/posts/nonexistent-id");
|
|
175
|
+
assert.strictEqual(res.status, 404);
|
|
176
|
+
}).pipe(Effect.provide(testLayer)));
|
|
177
|
+
it.scoped("PATCH /api/collections/:name/:id — update returns 200 with updated record", () => Effect.gen(function* () {
|
|
178
|
+
yield* setupTables;
|
|
179
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
180
|
+
const createRes = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/posts").pipe(HttpClientRequest.bodyUnsafeJson({ title: "Original" })));
|
|
181
|
+
const created = (yield* createRes.json);
|
|
182
|
+
const id = created["id"];
|
|
183
|
+
const res = yield* HttpClient.execute(HttpClientRequest.patch(`/api/collections/posts/${id}`).pipe(HttpClientRequest.bodyUnsafeJson({ title: "Updated" })));
|
|
184
|
+
assert.strictEqual(res.status, 200);
|
|
185
|
+
const body = (yield* res.json);
|
|
186
|
+
assert.strictEqual(body["title"], "Updated");
|
|
187
|
+
}).pipe(Effect.provide(testLayer)));
|
|
188
|
+
it.scoped("DELETE /api/collections/:name/:id — delete returns 204 with empty body", () => Effect.gen(function* () {
|
|
189
|
+
yield* setupTables;
|
|
190
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
191
|
+
const createRes = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/posts").pipe(HttpClientRequest.bodyUnsafeJson({ title: "To Delete" })));
|
|
192
|
+
const created = (yield* createRes.json);
|
|
193
|
+
const id = created["id"];
|
|
194
|
+
const res = yield* HttpClient.execute(HttpClientRequest.del(`/api/collections/posts/${id}`));
|
|
195
|
+
assert.strictEqual(res.status, 204);
|
|
196
|
+
const text = yield* res.text;
|
|
197
|
+
assert.strictEqual(text, "");
|
|
198
|
+
}).pipe(Effect.provide(testLayer)));
|
|
199
|
+
it.scoped("DELETE /api/collections/:name/:id — delete returns 404 for unknown id", () => Effect.gen(function* () {
|
|
200
|
+
yield* setupTables;
|
|
201
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
202
|
+
const res = yield* HttpClient.execute(HttpClientRequest.del("/api/collections/posts/no-such-id"));
|
|
203
|
+
assert.strictEqual(res.status, 404);
|
|
204
|
+
}).pipe(Effect.provide(testLayer)));
|
|
205
|
+
it.scoped("POST auth-with-password — valid credentials return token and stripped record", () => Effect.gen(function* () {
|
|
206
|
+
yield* setupTables;
|
|
207
|
+
yield* seedUser("alice@example.com", "password123");
|
|
208
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
209
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "alice@example.com", password: "password123" })));
|
|
210
|
+
assert.strictEqual(res.status, 200);
|
|
211
|
+
const body = (yield* res.json);
|
|
212
|
+
assert.ok(typeof body["token"] === "string" && body["token"].length > 0);
|
|
213
|
+
assert.ok(typeof body["record"] === "object" && body["record"] !== null);
|
|
214
|
+
const user = body["record"];
|
|
215
|
+
assert.strictEqual(user["email"], "alice@example.com");
|
|
216
|
+
assert.ok(!("password" in user), "password must not appear in auth response");
|
|
217
|
+
}).pipe(Effect.provide(testLayer)));
|
|
218
|
+
it.scoped("POST auth-with-password — wrong password returns 403", () => Effect.gen(function* () {
|
|
219
|
+
yield* setupTables;
|
|
220
|
+
yield* seedUser("bob@example.com", "correctpass");
|
|
221
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
222
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "bob@example.com", password: "wrongpass" })));
|
|
223
|
+
assert.strictEqual(res.status, 403);
|
|
224
|
+
}).pipe(Effect.provide(testLayer)));
|
|
225
|
+
it.scoped("POST auth-with-password — non-auth collection returns 405", () => Effect.gen(function* () {
|
|
226
|
+
yield* setupTables;
|
|
227
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
228
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/posts/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "x@x.com", password: "pass" })));
|
|
229
|
+
assert.strictEqual(res.status, 405);
|
|
230
|
+
}).pipe(Effect.provide(testLayer)));
|
|
231
|
+
it.scoped("POST auth-with-password — missing fields returns 422", () => Effect.gen(function* () {
|
|
232
|
+
yield* setupTables;
|
|
233
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
234
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "only@example.com" })));
|
|
235
|
+
assert.strictEqual(res.status, 422);
|
|
236
|
+
}).pipe(Effect.provide(testLayer)));
|
|
237
|
+
it.scoped("JWT bearer token resolves auth context for subsequent requests", () => Effect.gen(function* () {
|
|
238
|
+
yield* setupTables;
|
|
239
|
+
yield* seedUser("carol@example.com", "secret");
|
|
240
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
241
|
+
const loginRes = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "carol@example.com", password: "secret" })));
|
|
242
|
+
assert.strictEqual(loginRes.status, 200);
|
|
243
|
+
const loginBody = (yield* loginRes.json);
|
|
244
|
+
const token = loginBody["token"];
|
|
245
|
+
// Authenticated request — router resolves the auth context from the JWT
|
|
246
|
+
const authedRes = yield* HttpClient.get("/api/collections/posts", {
|
|
247
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
248
|
+
});
|
|
249
|
+
assert.strictEqual(authedRes.status, 200);
|
|
250
|
+
}).pipe(Effect.provide(testLayer)));
|
|
251
|
+
it.scoped("POST auth-with-password — response sets HttpOnly mira_token cookie", () => Effect.gen(function* () {
|
|
252
|
+
yield* setupTables;
|
|
253
|
+
yield* seedUser("cookieuser@example.com", "secret");
|
|
254
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
255
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "cookieuser@example.com", password: "secret" })));
|
|
256
|
+
assert.strictEqual(res.status, 200);
|
|
257
|
+
const cookieOpt = Cookies.get(res.cookies, "mira_token");
|
|
258
|
+
assert.ok(Option.isSome(cookieOpt));
|
|
259
|
+
assert.strictEqual(cookieOpt.value.options?.httpOnly, true);
|
|
260
|
+
}).pipe(Effect.provide(testLayer)));
|
|
261
|
+
it.scoped("GET /api/collections/:name — cookie auth returns 200 without Bearer header", () => Effect.gen(function* () {
|
|
262
|
+
yield* setupTables;
|
|
263
|
+
yield* seedUser("cookieauth@example.com", "secret");
|
|
264
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
265
|
+
const loginRes = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "cookieauth@example.com", password: "secret" })));
|
|
266
|
+
assert.strictEqual(loginRes.status, 200);
|
|
267
|
+
const cookieToken = Option.getOrThrow(Cookies.getValue(loginRes.cookies, "mira_token"));
|
|
268
|
+
const res = yield* HttpClient.get("/api/collections/posts", {
|
|
269
|
+
headers: { Cookie: `mira_token=${cookieToken}` }
|
|
270
|
+
});
|
|
271
|
+
assert.strictEqual(res.status, 200);
|
|
272
|
+
}).pipe(Effect.provide(testLayer)));
|
|
273
|
+
it.scoped("GET /api/collections/:name — invalid cookie is treated as anonymous, returns 200 for public route", () => Effect.gen(function* () {
|
|
274
|
+
yield* setupTables;
|
|
275
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
276
|
+
const res = yield* HttpClient.get("/api/collections/posts", {
|
|
277
|
+
headers: { Cookie: "mira_token=not-a-valid-jwt" }
|
|
278
|
+
});
|
|
279
|
+
assert.strictEqual(res.status, 200);
|
|
280
|
+
}).pipe(Effect.provide(testLayer)));
|
|
281
|
+
it.scoped("POST /api/auth/logout — response clears mira_token cookie with Max-Age=0", () => Effect.gen(function* () {
|
|
282
|
+
yield* setupTables;
|
|
283
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
284
|
+
const res = yield* HttpClient.execute(HttpClientRequest.post("/api/auth/logout"));
|
|
285
|
+
assert.strictEqual(res.status, 204);
|
|
286
|
+
const cookieOpt = Cookies.get(res.cookies, "mira_token");
|
|
287
|
+
assert.ok(Option.isSome(cookieOpt));
|
|
288
|
+
assert.ok(cookieOpt.value.options?.maxAge !== undefined);
|
|
289
|
+
}).pipe(Effect.provide(testLayer)));
|
|
290
|
+
it.scoped("GET /api/auth/me — valid cookie returns 200 with collection and record", () => Effect.gen(function* () {
|
|
291
|
+
yield* setupTables;
|
|
292
|
+
yield* seedUser("meuser@example.com", "secret");
|
|
293
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
294
|
+
const loginRes = yield* HttpClient.execute(HttpClientRequest.post("/api/collections/users/auth-with-password").pipe(HttpClientRequest.bodyUnsafeJson({ email: "meuser@example.com", password: "secret" })));
|
|
295
|
+
assert.strictEqual(loginRes.status, 200);
|
|
296
|
+
const cookieToken = Option.getOrThrow(Cookies.getValue(loginRes.cookies, "mira_token"));
|
|
297
|
+
const res = yield* HttpClient.get("/api/auth/me", {
|
|
298
|
+
headers: { Cookie: `mira_token=${cookieToken}` }
|
|
299
|
+
});
|
|
300
|
+
assert.strictEqual(res.status, 200);
|
|
301
|
+
const body = (yield* res.json);
|
|
302
|
+
assert.strictEqual(body["collection"], "users");
|
|
303
|
+
assert.ok(typeof body["record"] === "object" && body["record"] !== null);
|
|
304
|
+
}).pipe(Effect.provide(testLayer)));
|
|
305
|
+
it.scoped("GET /api/auth/me — no token returns 401", () => Effect.gen(function* () {
|
|
306
|
+
yield* setupTables;
|
|
307
|
+
yield* makeCollectionRouter(ALL_COLLECTIONS).pipe(HttpServer.serveEffect());
|
|
308
|
+
const res = yield* HttpClient.get("/api/auth/me");
|
|
309
|
+
assert.strictEqual(res.status, 401);
|
|
310
|
+
}).pipe(Effect.provide(testLayer)));
|
|
311
|
+
});
|
|
312
|
+
//# sourceMappingURL=router.test.js.map
|