@paralect/hive 0.1.50-alpha.2 → 0.1.50
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/.claude/settings.local.json +13 -0
- package/cli/helpers/execCommand.js +10 -10
- package/cli/helpers/isProjectInit.js +3 -3
- package/cli/helpers/mergeDirs.js +1 -1
- package/cli/hive.js +105 -105
- package/{test-app → framework}/.cursor/commands/add-service.md +6 -6
- package/{test-app → framework}/.cursor/skills/hive-overview/SKILL.md +1 -1
- package/{test-app → framework}/.cursor/skills/hive-service/SKILL.md +2 -2
- package/framework/bin/start.sh +2 -0
- package/{.hive/bootstrap-hive.js → framework/bootstrap-hive.ts} +4 -4
- package/{.hive → framework}/package-lock.json +212 -156
- package/framework/package.json +42 -0
- package/{.hive/src/app.js → framework/src/app.ts} +1 -1
- package/{.hive/src/bullMqBus.js → framework/src/bullMqBus.ts} +1 -1
- package/{.hive/src/bullMqWrapper.js → framework/src/bullMqWrapper.ts} +1 -1
- package/{.hive/src/app-config/index.js → framework/src/config/index.ts} +7 -7
- package/{.hive/src/db.js → framework/src/db.ts} +21 -6
- package/framework/src/endpoint.ts +132 -0
- package/framework/src/helpers/generateDbTypes.ts +47 -0
- package/{.hive/src/helpers/getMiddlewares.js → framework/src/helpers/getMiddlewares.ts} +1 -1
- package/{.hive/src/helpers/getResourceEndpoints.js → framework/src/helpers/getResourceEndpoints.ts} +8 -8
- package/{.hive/src/helpers/getResources.js → framework/src/helpers/getResources.ts} +1 -1
- package/{.hive/src/helpers/getSchemas.js → framework/src/helpers/getSchemas.ts} +13 -13
- package/framework/src/index.ts +3 -0
- package/{.hive/src/ioEmitter.js → framework/src/ioEmitter.ts} +1 -1
- package/{.hive/src/lib/node-mongo/src/mongo-query-service.js → framework/src/lib/node-mongo/src/mongo-query-service.ts} +18 -7
- package/{.hive/src/lib/node-mongo/src/mongo-service.js → framework/src/lib/node-mongo/src/mongo-service.ts} +17 -9
- package/{starter/src/logger.js → framework/src/logger.ts} +4 -3
- package/{.hive/src/migrations/migrations-log/migration-log.schema.js → framework/src/migrations/migrations-log/migration-log.schema.ts} +1 -1
- package/{.hive/src/migrations/migrations-log/migration-log.service.js → framework/src/migrations/migrations-log/migration-log.service.ts} +1 -1
- package/{.hive/src/migrations/migrations.schema.js → framework/src/migrations/migrations.schema.ts} +1 -1
- package/{.hive/src/resources/_dev/endpoints/triggerSchedulerHandler.js → framework/src/resources/_dev/endpoints/triggerSchedulerHandler.ts} +2 -1
- package/framework/src/resources/health/endpoints/get.ts +14 -0
- package/{.hive/src/resources/schemaMappings/schemaMappings.schema.js → framework/src/resources/schemaMappings/schemaMappings.schema.ts} +1 -1
- package/{.hive/src/routes/index.js → framework/src/routes/index.ts} +23 -27
- package/framework/src/schema.ts +3 -0
- package/{.hive/src/services/emailService.js → framework/src/services/emailService.ts} +1 -1
- package/{.hive/src/socketIo.js → framework/src/socketIo.ts} +1 -1
- package/{.hive → framework}/tsconfig.json +17 -13
- package/package.json +43 -51
- package/starter/hive/autoMap/schemaMappings.json +1 -0
- package/starter/hive/config/.env.example +11 -0
- package/starter/hive/config/app.ts +19 -0
- package/{.hive/src/services/setCookie.js → starter/hive/helpers/setCookie.ts} +1 -2
- package/starter/hive/middlewares/_global.ts +9 -0
- package/{.hive/src/middlewares/attachUser.js → starter/hive/middlewares/attachUser.ts} +2 -2
- package/{.hive/src/middlewares/shouldExist.js → starter/hive/middlewares/shouldExist.ts} +1 -1
- package/{.hive/src/middlewares/shouldNotExist.js → starter/hive/middlewares/shouldNotExist.ts} +1 -1
- package/starter/hive/resources/files/endpoints/upload.ts +25 -0
- package/starter/hive/resources/files/files.schema.ts +20 -0
- package/{.hive/src/resources/tokens/methods/storeToken.js → starter/hive/resources/tokens/methods/storeToken.ts} +3 -3
- package/{.hive/src/resources/tokens/tokens.schema.js → starter/hive/resources/tokens/tokens.schema.ts} +1 -2
- package/starter/hive/resources/users/endpoints/getCurrentUser.ts +12 -0
- package/starter/hive/resources/users/endpoints/getUserProfile.ts +17 -0
- package/{.hive/src/resources/users/users.schema.js → starter/hive/resources/users/users.schema.ts} +1 -2
- package/starter/hive/services/cloudStorage.ts +102 -0
- package/starter/package.json +9 -97
- package/starter/tsconfig.json +16 -20
- package/.cursor/commands/deslop.md +0 -12
- package/.hive/.cursor/commands/add-service.md +0 -188
- package/.hive/.cursor/skills/hive-overview/SKILL.md +0 -50
- package/.hive/.cursor/skills/hive-service/SKILL.md +0 -90
- package/.hive/bin/start.sh +0 -2
- package/.hive/package.json +0 -98
- package/.hive/src/logger.js +0 -43
- package/.hive/src/middlewares/global/tryToAttachUser.js +0 -33
- package/.hive/src/resources/health/endpoints/get.js +0 -19
- package/.hive/src/resources/tokens/methods/setToken.js +0 -8
- package/.hive/src/resources/users/endpoints/getCurrentUser.js +0 -14
- package/.hive/src/resources/users/endpoints/getUserProfile.js +0 -19
- package/.hive/src/resources/users/methods/ensureUserCreated.js +0 -68
- package/.hive/src/security.util.js +0 -38
- package/.hive/src/services/globalTest.js +0 -0
- package/cli/helpers/docker.js +0 -59
- package/cli/helpers/envCheck.js +0 -127
- package/cli/helpers/findPort.js +0 -32
- package/starter/.babelrc +0 -3
- package/starter/.cursor/commands/add-endpoint.md +0 -262
- package/starter/.cursor/commands/add-handler.md +0 -137
- package/starter/.cursor/commands/add-middleware.md +0 -95
- package/starter/.cursor/commands/add-resource.md +0 -71
- package/starter/.cursor/commands/add-scheduler.md +0 -138
- package/starter/.cursor/commands/add-service.md +0 -188
- package/starter/.cursor/skills/hive-auth/SKILL.md +0 -134
- package/starter/.cursor/skills/hive-database/SKILL.md +0 -103
- package/starter/.cursor/skills/hive-endpoint/SKILL.md +0 -103
- package/starter/.cursor/skills/hive-handler/SKILL.md +0 -88
- package/starter/.cursor/skills/hive-mapping/SKILL.md +0 -85
- package/starter/.cursor/skills/hive-middleware/SKILL.md +0 -104
- package/starter/.cursor/skills/hive-overview/SKILL.md +0 -50
- package/starter/.cursor/skills/hive-scheduler/SKILL.md +0 -94
- package/starter/.cursor/skills/hive-schema/SKILL.md +0 -73
- package/starter/.cursor/skills/hive-service/SKILL.md +0 -90
- package/starter/.dockerignore +0 -1
- package/starter/Dockerfile +0 -22
- package/starter/Dockerfile.dev +0 -33
- package/starter/Dockerfile.prod +0 -29
- package/starter/README.md +0 -11
- package/starter/bin/deploy.sh +0 -5
- package/starter/bin/start.sh +0 -2
- package/starter/bootstrap-hive.js +0 -118
- package/starter/deploy/api/Chart.yaml +0 -6
- package/starter/deploy/api/staging.yaml +0 -3
- package/starter/deploy/api/templates/deployment.yaml +0 -44
- package/starter/deploy/api/templates/ingress.yaml +0 -26
- package/starter/deploy/api/templates/service.yaml +0 -14
- package/starter/deploy/script/Dockerfile +0 -39
- package/starter/deploy/script/package-lock.json +0 -1499
- package/starter/deploy/script/package.json +0 -12
- package/starter/deploy/script/src/config.js +0 -48
- package/starter/deploy/script/src/index.js +0 -108
- package/starter/deploy/script/src/util.js +0 -19
- package/starter/initial-data.json +0 -176
- package/starter/loader.mjs +0 -40
- package/starter/package-lock.json +0 -13492
- package/starter/register.mjs +0 -6
- package/starter/ship_logo.png +0 -0
- package/starter/src/app-config/app.js +0 -3
- package/starter/src/app-config/assertEnv.js +0 -15
- package/starter/src/app-config/index.js +0 -65
- package/starter/src/app.js +0 -65
- package/starter/src/assets/emails/components/header.mjml +0 -13
- package/starter/src/assets/emails/dist/.gitkeep +0 -0
- package/starter/src/assets/emails/signup-welcome.mjml +0 -34
- package/starter/src/assets/emails/styles/index.mjml +0 -77
- package/starter/src/autoMap/addHandlers.js +0 -142
- package/starter/src/autoMap/getDependentFields.js +0 -37
- package/starter/src/autoMap/mapSchema.js +0 -99
- package/starter/src/autoMap/schemaMappings.js +0 -13
- package/starter/src/autoMap/schemaMappings.json +0 -3
- package/starter/src/bullMqBus.js +0 -21
- package/starter/src/bullMqWrapper.js +0 -23
- package/starter/src/db.js +0 -53
- package/starter/src/emails/MyEmailComponent.jsx +0 -14
- package/starter/src/emails/compiled/MyEmailComponent.js +0 -18
- package/starter/src/emails/compiled/compiled/MyEmailComponent.js +0 -18
- package/starter/src/helpers/db/ifUpdated.js +0 -22
- package/starter/src/helpers/esm.js +0 -56
- package/starter/src/helpers/getMiddlewares.js +0 -41
- package/starter/src/helpers/getResourceEndpoints.js +0 -31
- package/starter/src/helpers/getResources.js +0 -35
- package/starter/src/helpers/getSchemas.js +0 -53
- package/starter/src/helpers/importHandlers.js +0 -20
- package/starter/src/helpers/isZodArray.js +0 -13
- package/starter/src/helpers/prettierFormat.js +0 -8
- package/starter/src/helpers/schema/db.schema.js +0 -9
- package/starter/src/helpers/schema/pagination.schema.js +0 -14
- package/starter/src/ioEmitter.js +0 -9
- package/starter/src/jsconfig.json +0 -5
- package/starter/src/lib/node-mongo/.github/workflows/npm-publish.yml +0 -32
- package/starter/src/lib/node-mongo/API.md +0 -654
- package/starter/src/lib/node-mongo/CHANGELOG.md +0 -98
- package/starter/src/lib/node-mongo/README.md +0 -97
- package/starter/src/lib/node-mongo/package-lock.json +0 -3682
- package/starter/src/lib/node-mongo/package.json +0 -74
- package/starter/src/lib/node-mongo/src/index.js +0 -64
- package/starter/src/lib/node-mongo/src/mongo-query-service.js +0 -78
- package/starter/src/lib/node-mongo/src/mongo-service-error.js +0 -15
- package/starter/src/lib/node-mongo/src/mongo-service.js +0 -303
- package/starter/src/middlewares/attachUser.js +0 -41
- package/starter/src/middlewares/global/extractUserTokens.js +0 -15
- package/starter/src/middlewares/global/tryToAttachUser.js +0 -33
- package/starter/src/middlewares/isAuthorized.js +0 -18
- package/starter/src/middlewares/shouldExist.js +0 -37
- package/starter/src/middlewares/shouldNotExist.js +0 -19
- package/starter/src/middlewares/uploadFile.js +0 -5
- package/starter/src/middlewares/validate.js +0 -32
- package/starter/src/migrations/migration.js +0 -8
- package/starter/src/migrations/migration.service.js +0 -76
- package/starter/src/migrations/migrations/1.js +0 -22
- package/starter/src/migrations/migrations-log/migration-log.schema.js +0 -13
- package/starter/src/migrations/migrations-log/migration-log.service.js +0 -50
- package/starter/src/migrations/migrations.schema.js +0 -6
- package/starter/src/migrations/migrator.js +0 -75
- package/starter/src/migrator.js +0 -3
- package/starter/src/resources/_dev/endpoints/triggerSchedulerHandler.js +0 -32
- package/starter/src/resources/health/endpoints/get.js +0 -19
- package/starter/src/resources/schemaMappings/schemaMappings.schema.js +0 -6
- package/starter/src/resources/tokens/methods/generateSecureToken.js +0 -9
- package/starter/src/resources/tokens/methods/setToken.js +0 -8
- package/starter/src/resources/tokens/methods/storeToken.js +0 -35
- package/starter/src/resources/tokens/tokens.schema.js +0 -11
- package/starter/src/resources/users/endpoints/getCurrentUser.js +0 -14
- package/starter/src/resources/users/endpoints/getUserProfile.js +0 -19
- package/starter/src/resources/users/handlers/test.js +0 -1
- package/starter/src/resources/users/methods/ensureUserCreated.js +0 -68
- package/starter/src/resources/users/users.schema.js +0 -16
- package/starter/src/routes/index.js +0 -172
- package/starter/src/routes/middlewares/attachCustomErrors.js +0 -28
- package/starter/src/routes/middlewares/routeErrorHandler.js +0 -27
- package/starter/src/scheduler.js +0 -35
- package/starter/src/security.util.js +0 -38
- package/starter/src/services/emailService.js +0 -15
- package/starter/src/services/globalTest.js +0 -0
- package/starter/src/services/setCookie.js +0 -21
- package/starter/src/socketIo.js +0 -99
- package/test-app/.cursor/commands/add-endpoint.md +0 -262
- package/test-app/.cursor/commands/add-handler.md +0 -137
- package/test-app/.cursor/commands/add-middleware.md +0 -95
- package/test-app/.cursor/commands/add-resource.md +0 -71
- package/test-app/.cursor/commands/add-scheduler.md +0 -138
- package/test-app/.cursor/skills/hive-auth/SKILL.md +0 -134
- package/test-app/.cursor/skills/hive-database/SKILL.md +0 -103
- package/test-app/.cursor/skills/hive-endpoint/SKILL.md +0 -103
- package/test-app/.cursor/skills/hive-handler/SKILL.md +0 -88
- package/test-app/.cursor/skills/hive-mapping/SKILL.md +0 -85
- package/test-app/.cursor/skills/hive-middleware/SKILL.md +0 -104
- package/test-app/.cursor/skills/hive-scheduler/SKILL.md +0 -94
- package/test-app/.cursor/skills/hive-schema/SKILL.md +0 -73
- package/test-app/package-lock.json +0 -462
- package/test-app/package.json +0 -21
- /package/{.hive → framework}/.babelrc +0 -0
- /package/{.hive → framework}/.cursor/commands/add-endpoint.md +0 -0
- /package/{.hive → framework}/.cursor/commands/add-handler.md +0 -0
- /package/{.hive → framework}/.cursor/commands/add-middleware.md +0 -0
- /package/{.hive → framework}/.cursor/commands/add-resource.md +0 -0
- /package/{.hive → framework}/.cursor/commands/add-scheduler.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-auth/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-database/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-endpoint/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-handler/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-mapping/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-middleware/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-scheduler/SKILL.md +0 -0
- /package/{.hive → framework}/.cursor/skills/hive-schema/SKILL.md +0 -0
- /package/{.hive → framework}/.dockerignore +0 -0
- /package/{.hive → framework}/Dockerfile +0 -0
- /package/{.hive → framework}/Dockerfile.dev +0 -0
- /package/{.hive → framework}/Dockerfile.prod +0 -0
- /package/{.hive → framework}/README.md +0 -0
- /package/{.hive → framework}/bin/deploy.sh +0 -0
- /package/{.hive → framework}/deploy/api/Chart.yaml +0 -0
- /package/{.hive → framework}/deploy/api/staging.yaml +0 -0
- /package/{.hive → framework}/deploy/api/templates/deployment.yaml +0 -0
- /package/{.hive → framework}/deploy/api/templates/ingress.yaml +0 -0
- /package/{.hive → framework}/deploy/api/templates/service.yaml +0 -0
- /package/{.hive → framework}/deploy/script/Dockerfile +0 -0
- /package/{.hive → framework}/deploy/script/package-lock.json +0 -0
- /package/{.hive → framework}/deploy/script/package.json +0 -0
- /package/{.hive/deploy/script/src/config.js → framework/deploy/script/src/config.ts} +0 -0
- /package/{.hive/deploy/script/src/index.js → framework/deploy/script/src/index.ts} +0 -0
- /package/{.hive/deploy/script/src/util.js → framework/deploy/script/src/util.ts} +0 -0
- /package/{.hive → framework}/initial-data.json +0 -0
- /package/{.hive → framework}/ship_logo.png +0 -0
- /package/{.hive → framework}/src/assets/emails/components/header.mjml +0 -0
- /package/{.hive → framework}/src/assets/emails/dist/.gitkeep +0 -0
- /package/{.hive → framework}/src/assets/emails/signup-welcome.mjml +0 -0
- /package/{.hive → framework}/src/assets/emails/styles/index.mjml +0 -0
- /package/{.hive/src/autoMap/addHandlers.js → framework/src/autoMap/addHandlers.ts} +0 -0
- /package/{.hive/src/autoMap/getDependentFields.js → framework/src/autoMap/getDependentFields.ts} +0 -0
- /package/{.hive/src/autoMap/mapSchema.js → framework/src/autoMap/mapSchema.ts} +0 -0
- /package/{.hive → framework}/src/autoMap/schemaMappings.json +0 -0
- /package/{.hive/src/autoMap/schemaMappings.js → framework/src/autoMap/schemaMappings.ts} +0 -0
- /package/{.hive/src/helpers/schema/db.schema.js → framework/src/common/schema/db.schema.ts} +0 -0
- /package/{.hive/src/helpers/schema/pagination.schema.js → framework/src/common/schema/pagination.schema.ts} +0 -0
- /package/{.hive/src/app-config/app.js → framework/src/config/app.ts} +0 -0
- /package/{.hive/src/app-config/assertEnv.js → framework/src/config/assertEnv.ts} +0 -0
- /package/{.hive/src/emails/MyEmailComponent.jsx → framework/src/emails/MyEmailComponent.tsx} +0 -0
- /package/{.hive/src/emails/compiled/MyEmailComponent.js → framework/src/emails/compiled/MyEmailComponent.ts} +0 -0
- /package/{.hive/src/emails/compiled/compiled/MyEmailComponent.js → framework/src/emails/compiled/compiled/MyEmailComponent.ts} +0 -0
- /package/{.hive/src/helpers/db/ifUpdated.js → framework/src/helpers/db/ifUpdated.ts} +0 -0
- /package/{.hive/src/helpers/importHandlers.js → framework/src/helpers/importHandlers.ts} +0 -0
- /package/{.hive/src/helpers/isZodArray.js → framework/src/helpers/isZodArray.ts} +0 -0
- /package/{.hive/src/helpers/prettierFormat.js → framework/src/helpers/prettierFormat.ts} +0 -0
- /package/{.hive → framework}/src/jsconfig.json +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/.github/workflows/npm-publish.yml +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/API.md +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/CHANGELOG.md +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/README.md +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/package-lock.json +0 -0
- /package/{.hive → framework}/src/lib/node-mongo/package.json +0 -0
- /package/{.hive/src/lib/node-mongo/src/index.js → framework/src/lib/node-mongo/src/index.ts} +0 -0
- /package/{.hive/src/lib/node-mongo/src/mongo-service-error.js → framework/src/lib/node-mongo/src/mongo-service-error.ts} +0 -0
- /package/{.hive/src/middlewares/allowNoAuth.js → framework/src/middlewares/allowNoAuth.ts} +0 -0
- /package/{.hive/src/middlewares/global/extractUserTokens.js → framework/src/middlewares/global/extractUserTokens.ts} +0 -0
- /package/{.hive/src/middlewares/validate.js → framework/src/middlewares/validate.ts} +0 -0
- /package/{.hive/src/migrations/migration.service.js → framework/src/migrations/migration.service.ts} +0 -0
- /package/{.hive/src/migrations/migration.js → framework/src/migrations/migration.ts} +0 -0
- /package/{.hive/src/migrations/migrations/1.js → framework/src/migrations/migrations/1.ts} +0 -0
- /package/{.hive/src/migrations/migrator.js → framework/src/migrations/migrator.ts} +0 -0
- /package/{.hive/src/migrator.js → framework/src/migrator.ts} +0 -0
- /package/{.hive/src/routes/middlewares/attachCustomErrors.js → framework/src/routes/middlewares/attachCustomErrors.ts} +0 -0
- /package/{.hive/src/routes/middlewares/routeErrorHandler.js → framework/src/routes/middlewares/routeErrorHandler.ts} +0 -0
- /package/{.hive/src/scheduler/handlers/sendDailyReport.example.js → framework/src/scheduler/handlers/sendDailyReport.example.ts} +0 -0
- /package/{.hive/src/scheduler.js → framework/src/scheduler.ts} +0 -0
- /package/starter/{src/middlewares/allowNoAuth.js → hive/middlewares/allowNoAuth.ts} +0 -0
- /package/{.hive/src/middlewares/isAuthorized.js → starter/hive/middlewares/isAuthorized.ts} +0 -0
- /package/{.hive/src/middlewares/uploadFile.js → starter/hive/middlewares/uploadFile.ts} +0 -0
- /package/{.hive/src/resources/tokens/methods/generateSecureToken.js → starter/hive/resources/tokens/methods/generateSecureToken.ts} +0 -0
- /package/{.hive/src/resources/users/handlers/test.js → starter/hive/resources/users/handlers/test.ts} +0 -0
- /package/starter/{src/scheduler/handlers/sendDailyReport.example.js → hive/scheduler/handlers/dailyExample.ts} +0 -0
|
@@ -6,11 +6,10 @@ import mount from "koa-mount";
|
|
|
6
6
|
import Router from "@koa/router";
|
|
7
7
|
import validate from "middlewares/validate";
|
|
8
8
|
import db from "db";
|
|
9
|
-
import
|
|
9
|
+
import extractUserTokens from "middlewares/global/extractUserTokens";
|
|
10
10
|
import attachCustomErrors from "./middlewares/attachCustomErrors";
|
|
11
11
|
import routeErrorHandler from "./middlewares/routeErrorHandler";
|
|
12
|
-
import
|
|
13
|
-
import config from 'app-config';
|
|
12
|
+
import config from 'config';
|
|
14
13
|
|
|
15
14
|
const requestLogService = db.createService("_request_logs");
|
|
16
15
|
|
|
@@ -67,19 +66,23 @@ export default async (app) => {
|
|
|
67
66
|
app.use(logRequestToMongo);
|
|
68
67
|
app.use(attachCustomErrors);
|
|
69
68
|
app.use(routeErrorHandler);
|
|
70
|
-
app.use(
|
|
69
|
+
app.use(extractUserTokens);
|
|
71
70
|
|
|
72
71
|
const [resources, allMiddlewares] = await Promise.all([getResources(), getMiddlewares()]);
|
|
73
72
|
|
|
74
73
|
await Promise.all(_.map(resources, async ({ name: resourceName }) => {
|
|
75
74
|
const resourceRouter = new Router();
|
|
76
75
|
const globalRouter = new Router();
|
|
77
|
-
const endpoints = await Promise.all((await getResourceEndpoints(resourceName))
|
|
76
|
+
const endpoints = (await Promise.all((await getResourceEndpoints(resourceName))
|
|
78
77
|
.map(async ({ file: endpointFile, name }) => {
|
|
79
78
|
let endpointDef = (await import(endpointFile));
|
|
80
79
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
80
|
+
if (endpointDef.default?.endpoint && endpointDef.default?.handler) {
|
|
81
|
+
endpointDef = endpointDef.default;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!endpointDef.endpoint || !endpointDef.handler) {
|
|
85
|
+
return null;
|
|
83
86
|
}
|
|
84
87
|
endpointDef.endpoint.name = name;
|
|
85
88
|
|
|
@@ -89,15 +92,13 @@ export default async (app) => {
|
|
|
89
92
|
middlewares: endpointDef.middlewares,
|
|
90
93
|
handler: endpointDef.handler,
|
|
91
94
|
};
|
|
92
|
-
})
|
|
93
|
-
.
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return -1;
|
|
100
|
-
}));
|
|
95
|
+
})))
|
|
96
|
+
.filter(Boolean)
|
|
97
|
+
.sort((a, b) => {
|
|
98
|
+
const urlA = a.endpoint.url || a.endpoint.absoluteUrl || '/';
|
|
99
|
+
const urlB = b.endpoint.url || b.endpoint.absoluteUrl || '/';
|
|
100
|
+
return urlA.includes('/:') ? 1 : urlB.includes('/:') ? -1 : 0;
|
|
101
|
+
});
|
|
101
102
|
|
|
102
103
|
endpoints.forEach(({ endpoint, requestSchema, middlewares = [], handler }) => {
|
|
103
104
|
let targetRouter;
|
|
@@ -114,7 +115,7 @@ export default async (app) => {
|
|
|
114
115
|
targetRouter = resourceRouter;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
const globalMiddleware = allMiddlewares.find(m => m.name === 'global');
|
|
118
|
+
const globalMiddleware = allMiddlewares.find(m => m.name === 'global') || allMiddlewares.find(m => m.name === '_global');
|
|
118
119
|
|
|
119
120
|
if (globalMiddleware) {
|
|
120
121
|
globalMiddleware.runOrder = 0;
|
|
@@ -141,20 +142,13 @@ export default async (app) => {
|
|
|
141
142
|
return middleware;
|
|
142
143
|
});
|
|
143
144
|
|
|
144
|
-
|
|
145
|
-
if (config._hive.isRequireAuthAllEndpoints) {
|
|
146
|
-
isAuthorized.runOrder = 0;
|
|
147
|
-
middlewares.unshift(isAuthorized);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
targetRouter[endpoint.method?.toLowerCase() || "get"](
|
|
151
|
-
url,
|
|
145
|
+
const routeMiddlewares = [
|
|
152
146
|
async (ctx, next) => {
|
|
153
147
|
ctx.state.resourceName = resourceName;
|
|
154
148
|
ctx.state.endpoint = endpoint;
|
|
155
149
|
await next();
|
|
156
150
|
},
|
|
157
|
-
validate(requestSchema),
|
|
151
|
+
...(requestSchema ? [validate(requestSchema)] : []),
|
|
158
152
|
..._.sortBy(middlewares, m => m.runOrder),
|
|
159
153
|
async ctx => {
|
|
160
154
|
const result = await handler(ctx);
|
|
@@ -163,7 +157,9 @@ export default async (app) => {
|
|
|
163
157
|
ctx.body = result || { isOk: true };
|
|
164
158
|
}
|
|
165
159
|
}
|
|
166
|
-
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
targetRouter[endpoint.method?.toLowerCase() || "get"](url, ...routeMiddlewares);
|
|
167
163
|
});
|
|
168
164
|
|
|
169
165
|
app.use(globalRouter.routes());
|
|
@@ -2,7 +2,7 @@ import db from 'db';
|
|
|
2
2
|
import { Server } from 'socket.io';
|
|
3
3
|
import { createClient } from 'redis';
|
|
4
4
|
import { createAdapter } from '@socket.io/redis-adapter';
|
|
5
|
-
import config from '
|
|
5
|
+
import config from 'config';
|
|
6
6
|
import logger from 'logger';
|
|
7
7
|
|
|
8
8
|
export default (server) => {
|
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
|
|
4
3
|
// Treat files as modules even if it doesn't use import/export
|
|
5
4
|
"moduleDetection": "force",
|
|
6
|
-
|
|
7
5
|
// Ignore module structure
|
|
8
6
|
"module": "Preserve",
|
|
9
|
-
|
|
10
7
|
// Allow JSON modules to be imported
|
|
11
8
|
"resolveJsonModule": true,
|
|
12
|
-
|
|
13
9
|
// Allow JS files to be imported from TS and vice versa
|
|
14
10
|
"allowJs": true,
|
|
15
|
-
|
|
16
11
|
// Use correct ESM import behavior
|
|
17
12
|
"esModuleInterop": true,
|
|
18
|
-
|
|
19
13
|
// Disallow features that require cross-file awareness
|
|
20
14
|
"isolatedModules": true,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
"baseUrl": ".",
|
|
16
|
+
"paths": {
|
|
17
|
+
"*": [
|
|
18
|
+
"src/*",
|
|
19
|
+
".hive/*",
|
|
20
|
+
"../hive/*"
|
|
21
|
+
],
|
|
22
|
+
"@hive": ["src/index"],
|
|
23
|
+
"@hive/*": ["src/*"],
|
|
24
|
+
"@/*": [
|
|
25
|
+
".hive/*",
|
|
26
|
+
"../hive/*"
|
|
27
|
+
],
|
|
28
|
+
}
|
|
26
29
|
},
|
|
27
|
-
|
|
30
|
+
"include": [
|
|
28
31
|
"src/**/*",
|
|
29
|
-
".hive/**/*"
|
|
32
|
+
".hive/**/*",
|
|
33
|
+
"../hive/**/*"
|
|
30
34
|
]
|
|
31
35
|
}
|
package/package.json
CHANGED
|
@@ -1,71 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paralect/hive",
|
|
3
|
-
"version": "0.1.50
|
|
3
|
+
"version": "0.1.50",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"hive": "cli/hive.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"test:init": "rm -rf test-app && node cli/hive.js init test-app --skip-install && cd test-app && npm pkg set 'dependencies.@paralect/hive=file:..' && npm install",
|
|
12
|
+
"test:dev": "cd test-app && npm run dev"
|
|
11
13
|
},
|
|
12
14
|
"dependencies": {
|
|
13
|
-
"@koa/cors": "
|
|
14
|
-
"@koa/multer": "
|
|
15
|
-
"@koa/router": "
|
|
16
|
-
"@
|
|
17
|
-
"@react-email/
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"@socket.io/redis-adapter": "7.1.0",
|
|
21
|
-
"@socket.io/redis-emitter": "4.1.1",
|
|
15
|
+
"@koa/cors": "5.0.0",
|
|
16
|
+
"@koa/multer": "4.0.0",
|
|
17
|
+
"@koa/router": "15.3.0",
|
|
18
|
+
"@react-email/components": "^1.0.7",
|
|
19
|
+
"@react-email/render": "^2.0.4",
|
|
20
|
+
"@socket.io/redis-adapter": "8.3.0",
|
|
21
|
+
"@socket.io/redis-emitter": "5.1.0",
|
|
22
22
|
"app-module-path": "2.2.0",
|
|
23
|
-
"aws-sdk": "2.
|
|
24
|
-
"axios": "^1.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"koa": "2.13.4",
|
|
36
|
-
"koa-bodyparser": "4.3.0",
|
|
37
|
-
"koa-helmet": "6.1.0",
|
|
38
|
-
"koa-logger": "3.2.1",
|
|
39
|
-
"koa-mount": "4.0.0",
|
|
23
|
+
"aws-sdk": "2.1693.0",
|
|
24
|
+
"axios": "^1.13.5",
|
|
25
|
+
"bullmq": "^5.69.1",
|
|
26
|
+
"commander": "^14.0.3",
|
|
27
|
+
"dotenv": "17.3.1",
|
|
28
|
+
"fs-extra": "^11.3.3",
|
|
29
|
+
"inquirer": "^13.2.2",
|
|
30
|
+
"koa": "3.1.1",
|
|
31
|
+
"koa-bodyparser": "4.4.1",
|
|
32
|
+
"koa-helmet": "9.0.0",
|
|
33
|
+
"koa-logger": "4.0.0",
|
|
34
|
+
"koa-mount": "4.2.0",
|
|
40
35
|
"koa-qs": "3.0.0",
|
|
41
|
-
"lodash": "4.17.
|
|
42
|
-
"mjml": "4.
|
|
43
|
-
"mkdirp": "
|
|
44
|
-
"moment": "2.
|
|
36
|
+
"lodash": "4.17.23",
|
|
37
|
+
"mjml": "4.18.0",
|
|
38
|
+
"mkdirp": "3.0.1",
|
|
39
|
+
"moment": "2.30.1",
|
|
45
40
|
"moment-duration-format": "2.3.2",
|
|
46
|
-
"
|
|
47
|
-
"node-schedule": "2.1.
|
|
48
|
-
"nodemailer": "^
|
|
49
|
-
"nodemon": "
|
|
50
|
-
"prettier": "
|
|
51
|
-
"psl": "1.
|
|
52
|
-
"redis": "
|
|
41
|
+
"monk": "^7.3.4",
|
|
42
|
+
"node-schedule": "2.1.1",
|
|
43
|
+
"nodemailer": "^8.0.1",
|
|
44
|
+
"nodemon": "3.1.11",
|
|
45
|
+
"prettier": "3.8.1",
|
|
46
|
+
"psl": "1.15.0",
|
|
47
|
+
"redis": "^5.10.0",
|
|
53
48
|
"require-dir": "1.2.0",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"typescript": "^5.5.4",
|
|
60
|
-
"winston": "3.6.0",
|
|
61
|
-
"zod": "^3.23.8"
|
|
49
|
+
"socket.io": "4.8.3",
|
|
50
|
+
"tsx": "^4.21.0",
|
|
51
|
+
"typescript": "^5.9.3",
|
|
52
|
+
"winston": "3.19.0",
|
|
53
|
+
"zod": "^4.3.6"
|
|
62
54
|
},
|
|
63
55
|
"devDependencies": {
|
|
64
|
-
"eslint": "
|
|
56
|
+
"eslint": "9.28.0",
|
|
65
57
|
"eslint-config-airbnb-base": "15.0.0",
|
|
66
|
-
"eslint-plugin-import": "2.
|
|
67
|
-
"husky": "
|
|
68
|
-
"lint-staged": "
|
|
58
|
+
"eslint-plugin-import": "2.32.0",
|
|
59
|
+
"husky": "9.1.7",
|
|
60
|
+
"lint-staged": "16.2.7"
|
|
69
61
|
},
|
|
70
62
|
"keywords": [],
|
|
71
63
|
"author": "",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
PORT=3001
|
|
2
|
+
|
|
3
|
+
WEB_URL=http://localhost:3002
|
|
4
|
+
|
|
5
|
+
MONGODB_URI=mongodb://root:root@localhost:27017/hive-dev?authSource=admin&replicaSet=rs&tls=false&directConnection=true
|
|
6
|
+
REDIS_URI=redis://:@localhost:6379
|
|
7
|
+
|
|
8
|
+
# STORAGE_ENDPOINT=https://fra1.digitaloceanspaces.com
|
|
9
|
+
# STORAGE_ACCESS_KEY_ID=youraccesskey
|
|
10
|
+
# STORAGE_SECRET=yoursecretkey
|
|
11
|
+
# STORAGE_BUCKET=yourbucket
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
_hive: {
|
|
3
|
+
authHeaderName: 'x-api-key',
|
|
4
|
+
},
|
|
5
|
+
|
|
6
|
+
webUrl: process.env.WEB_URL,
|
|
7
|
+
|
|
8
|
+
cloudStorage: {
|
|
9
|
+
endpoint: process.env.STORAGE_ENDPOINT,
|
|
10
|
+
accessKeyId: process.env.STORAGE_ACCESS_KEY_ID,
|
|
11
|
+
secretAccessKey: process.env.STORAGE_SECRET,
|
|
12
|
+
bucket: process.env.STORAGE_BUCKET
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
// google: {
|
|
16
|
+
// clientId: process.env.GOOGLE_CLIENT_ID,
|
|
17
|
+
// clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
18
|
+
// },
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { endpoint } from '@hive';
|
|
2
|
+
import uploadFile from '@/middlewares/uploadFile';
|
|
3
|
+
import cloudStorageService from '@/services/cloudStorage';
|
|
4
|
+
|
|
5
|
+
export default endpoint({
|
|
6
|
+
method: 'post',
|
|
7
|
+
url: '/',
|
|
8
|
+
middlewares: [uploadFile.single('file')],
|
|
9
|
+
|
|
10
|
+
handler: async (ctx) => {
|
|
11
|
+
const { file } = ctx.request;
|
|
12
|
+
const fileName = `${Date.now()}-${file.originalname}`;
|
|
13
|
+
|
|
14
|
+
const data = await cloudStorageService.uploadPublic(
|
|
15
|
+
`hive/${ctx.state.user._id}/${fileName}`,
|
|
16
|
+
file
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
let { Location: url } = data;
|
|
20
|
+
|
|
21
|
+
ctx.body = {
|
|
22
|
+
url,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z, dbSchema } from '@hive/schema';
|
|
2
|
+
|
|
3
|
+
const schema = dbSchema.extend({
|
|
4
|
+
url: z.coerce.string().nullable(),
|
|
5
|
+
|
|
6
|
+
user: z
|
|
7
|
+
.object({
|
|
8
|
+
_id: z.string(),
|
|
9
|
+
})
|
|
10
|
+
.passthrough()
|
|
11
|
+
.nullable()
|
|
12
|
+
.optional(),
|
|
13
|
+
|
|
14
|
+
name: z.coerce.string().nullable().optional(),
|
|
15
|
+
description: z.coerce.string().nullable().optional(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export default schema;
|
|
19
|
+
|
|
20
|
+
export const secureFields = [];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import db from 'db';
|
|
2
1
|
import crypto from 'crypto';
|
|
3
2
|
import util from 'util';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
import { db } from '@hive';
|
|
5
|
+
import setCookie from '@/services/setCookie';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const randomBytes = util.promisify(crypto.randomBytes, crypto);
|
|
8
8
|
|
|
9
9
|
const tokenService = db.services.tokens;
|
|
10
10
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { endpoint, z, db } from '@hive';
|
|
2
|
+
|
|
3
|
+
const userService = db.services.users;
|
|
4
|
+
|
|
5
|
+
export default endpoint({
|
|
6
|
+
method: 'get',
|
|
7
|
+
url: '/profile/:userId',
|
|
8
|
+
|
|
9
|
+
requestSchema: z.object({
|
|
10
|
+
userId: z.string(),
|
|
11
|
+
}),
|
|
12
|
+
|
|
13
|
+
handler: async (ctx) => {
|
|
14
|
+
const user = await userService.findOne({ _id: ctx.params.userId });
|
|
15
|
+
ctx.body = user;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import AWS from 'aws-sdk';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import config from '@/config/app';
|
|
4
|
+
|
|
5
|
+
const Bucket = config.cloudStorage.bucket;
|
|
6
|
+
const spacesEndpoint = config.cloudStorage.secretAccessKey ? new AWS.Endpoint(config.cloudStorage.endpoint) : null;
|
|
7
|
+
|
|
8
|
+
const storage = config.cloudStorage.secretAccessKey ? new AWS.S3({
|
|
9
|
+
endpoint: spacesEndpoint,
|
|
10
|
+
accessKeyId: config.cloudStorage.accessKeyId,
|
|
11
|
+
secretAccessKey: config.cloudStorage.secretAccessKey,
|
|
12
|
+
}) : null;
|
|
13
|
+
|
|
14
|
+
function getSignedUrl(fileName) {
|
|
15
|
+
const params = {
|
|
16
|
+
Bucket,
|
|
17
|
+
Key: fileName,
|
|
18
|
+
Expires: 1800,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return storage.getSignedUrl('getObject', params);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function upload(filePath, file) {
|
|
25
|
+
const params = {
|
|
26
|
+
Bucket,
|
|
27
|
+
ContentType: file.mimetype,
|
|
28
|
+
Body: file.buffer,
|
|
29
|
+
Key: filePath,
|
|
30
|
+
ACL: 'private',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return storage.upload(params).promise();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function uploadPublic(filePath, file) {
|
|
37
|
+
const params = {
|
|
38
|
+
Bucket,
|
|
39
|
+
ContentType: file.mimetype,
|
|
40
|
+
Body: file.buffer,
|
|
41
|
+
Key: filePath,
|
|
42
|
+
ACL: 'public-read',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return storage.upload(params).promise();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function uploadStream(filePath, stream, contentType, isPublic = false) {
|
|
49
|
+
const params = {
|
|
50
|
+
Bucket,
|
|
51
|
+
ContentType: contentType,
|
|
52
|
+
Body: stream,
|
|
53
|
+
Key: filePath,
|
|
54
|
+
ACL: isPublic ? 'public-read' : 'private',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return storage.upload(params).promise();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function uploadFromUrl(filePath, url, headers = {}, isPublic = false) {
|
|
61
|
+
console.log('getting image', filePath, url, headers);
|
|
62
|
+
const response = await axios({
|
|
63
|
+
method: 'get',
|
|
64
|
+
url: url,
|
|
65
|
+
headers: headers,
|
|
66
|
+
responseType: 'stream',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const contentType =
|
|
70
|
+
response.headers['content-type'] || 'application/octet-stream';
|
|
71
|
+
|
|
72
|
+
return uploadStream(filePath, response.data, contentType, isPublic);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function copy(filePath, copyFilePath) {
|
|
76
|
+
const params = {
|
|
77
|
+
Bucket,
|
|
78
|
+
CopySource: `${Bucket}/${copyFilePath}`,
|
|
79
|
+
Key: filePath,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return storage.copyObject(params).promise();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function remove(filePath) {
|
|
86
|
+
const params = {
|
|
87
|
+
Bucket,
|
|
88
|
+
Key: filePath,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return storage.deleteObject(params).promise();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default {
|
|
95
|
+
getSignedUrl,
|
|
96
|
+
copy,
|
|
97
|
+
upload,
|
|
98
|
+
uploadPublic,
|
|
99
|
+
remove,
|
|
100
|
+
uploadStream,
|
|
101
|
+
uploadFromUrl,
|
|
102
|
+
};
|