Browse Source

Merge pull request #5686 from nocodb/develop

pull/5687/head 0.107.1
github-actions[bot] 2 years ago committed by GitHub
parent
commit
cc05b6fed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      packages/nc-gui/package-lock.json
  2. 2
      packages/nc-gui/package.json
  3. 4
      packages/nocodb-sdk/package-lock.json
  4. 30
      packages/nocodb/package-lock.json
  5. 4
      packages/nocodb/package.json
  6. 69
      packages/nocodb/src/Noco.ts
  7. 51
      packages/nocodb/src/app.module.ts
  8. 20
      packages/nocodb/src/modules/global/global.module.ts
  9. 19
      packages/nocodb/src/services/app-init.service.spec.ts
  10. 68
      packages/nocodb/src/services/app-init.service.ts
  11. 10
      packages/nocodb/src/utils/NcConfigFactory.ts
  12. 14
      tests/playwright/pages/Dashboard/common/Cell/SelectOptionCell.ts
  13. 1
      tests/playwright/pages/Dashboard/common/Toolbar/index.ts
  14. 4
      tests/playwright/tests/db/undo-redo.spec.ts

52
packages/nc-gui/package-lock.json generated

@ -30,7 +30,7 @@
"leaflet.markercluster": "^1.5.3", "leaflet.markercluster": "^1.5.3",
"locale-codes": "^1.3.1", "locale-codes": "^1.3.1",
"monaco-editor": "^0.33.0", "monaco-editor": "^0.33.0",
"nocodb-sdk": "0.107.0", "nocodb-sdk": "file:../nocodb-sdk",
"papaparse": "^5.3.2", "papaparse": "^5.3.2",
"pinia": "^2.0.33", "pinia": "^2.0.33",
"qrcode": "^1.5.1", "qrcode": "^1.5.1",
@ -111,7 +111,6 @@
}, },
"../nocodb-sdk": { "../nocodb-sdk": {
"version": "0.107.0", "version": "0.107.0",
"extraneous": true,
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.21.1",
@ -8776,6 +8775,7 @@
"version": "1.15.1", "version": "1.15.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
"integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==",
"devOptional": true,
"funding": [ "funding": [
{ {
"type": "individual", "type": "individual",
@ -12294,21 +12294,8 @@
} }
}, },
"node_modules/nocodb-sdk": { "node_modules/nocodb-sdk": {
"version": "0.107.0", "resolved": "../nocodb-sdk",
"resolved": "https://registry.npmjs.org/nocodb-sdk/-/nocodb-sdk-0.107.0.tgz", "link": true
"integrity": "sha512-g/+oIwUY3T3e6RHGxmKKW7AShIfFeYnzxedFXiZVGKFUwKX2PAuKuaq+zdfirKyuEuSZYQq2fAzcdDOWTNUU/w==",
"dependencies": {
"axios": "^0.21.1",
"jsep": "^1.3.6"
}
},
"node_modules/nocodb-sdk/node_modules/axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"dependencies": {
"follow-redirects": "^1.14.0"
}
}, },
"node_modules/node-abi": { "node_modules/node-abi": {
"version": "3.23.0", "version": "3.23.0",
@ -24810,7 +24797,8 @@
"follow-redirects": { "follow-redirects": {
"version": "1.15.1", "version": "1.15.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
"integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==" "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==",
"devOptional": true
}, },
"form-data": { "form-data": {
"version": "4.0.0", "version": "4.0.0",
@ -27360,22 +27348,22 @@
} }
}, },
"nocodb-sdk": { "nocodb-sdk": {
"version": "0.107.0", "version": "file:../nocodb-sdk",
"resolved": "https://registry.npmjs.org/nocodb-sdk/-/nocodb-sdk-0.107.0.tgz",
"integrity": "sha512-g/+oIwUY3T3e6RHGxmKKW7AShIfFeYnzxedFXiZVGKFUwKX2PAuKuaq+zdfirKyuEuSZYQq2fAzcdDOWTNUU/w==",
"requires": { "requires": {
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"jsep": "^1.3.6" "cspell": "^4.1.0",
}, "eslint": "^7.8.0",
"dependencies": { "eslint-config-prettier": "^6.11.0",
"axios": { "eslint-plugin-eslint-comments": "^3.2.0",
"version": "0.21.4", "eslint-plugin-functional": "^3.0.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", "eslint-plugin-import": "^2.22.0",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", "eslint-plugin-prettier": "^4.0.0",
"requires": { "jsep": "^1.3.6",
"follow-redirects": "^1.14.0" "npm-run-all": "^4.1.5",
} "prettier": "^2.1.1",
} "typescript": "^4.0.2"
} }
}, },
"node-abi": { "node-abi": {

2
packages/nc-gui/package.json

@ -54,7 +54,7 @@
"leaflet.markercluster": "^1.5.3", "leaflet.markercluster": "^1.5.3",
"locale-codes": "^1.3.1", "locale-codes": "^1.3.1",
"monaco-editor": "^0.33.0", "monaco-editor": "^0.33.0",
"nocodb-sdk": "0.107.0", "nocodb-sdk": "file:../nocodb-sdk",
"papaparse": "^5.3.2", "papaparse": "^5.3.2",
"pinia": "^2.0.33", "pinia": "^2.0.33",
"qrcode": "^1.5.1", "qrcode": "^1.5.1",

4
packages/nocodb-sdk/package-lock.json generated

@ -1,12 +1,12 @@
{ {
"name": "nocodb-sdk", "name": "nocodb-sdk",
"version": "0.107.0-beta.1", "version": "0.107.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "nocodb-sdk", "name": "nocodb-sdk",
"version": "0.107.0-beta.1", "version": "0.107.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.21.1",

30
packages/nocodb/package-lock.json generated

@ -83,7 +83,7 @@
"nc-lib-gui": "0.107.0", "nc-lib-gui": "0.107.0",
"nc-plugin": "^0.1.3", "nc-plugin": "^0.1.3",
"ncp": "^2.0.0", "ncp": "^2.0.0",
"nocodb-sdk": "0.107.0", "nocodb-sdk": "file:../nocodb-sdk",
"nodemailer": "^6.4.10", "nodemailer": "^6.4.10",
"object-hash": "^3.0.0", "object-hash": "^3.0.0",
"os-locale": "^6.0.2", "os-locale": "^6.0.2",
@ -191,7 +191,6 @@
}, },
"../nocodb-sdk": { "../nocodb-sdk": {
"version": "0.107.0", "version": "0.107.0",
"extraneous": true,
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.21.1",
@ -13207,13 +13206,8 @@
} }
}, },
"node_modules/nocodb-sdk": { "node_modules/nocodb-sdk": {
"version": "0.107.0", "resolved": "../nocodb-sdk",
"resolved": "https://registry.npmjs.org/nocodb-sdk/-/nocodb-sdk-0.107.0.tgz", "link": true
"integrity": "sha512-g/+oIwUY3T3e6RHGxmKKW7AShIfFeYnzxedFXiZVGKFUwKX2PAuKuaq+zdfirKyuEuSZYQq2fAzcdDOWTNUU/w==",
"dependencies": {
"axios": "^0.21.1",
"jsep": "^1.3.6"
}
}, },
"node_modules/node-abort-controller": { "node_modules/node-abort-controller": {
"version": "3.1.1", "version": "3.1.1",
@ -28485,12 +28479,22 @@
"integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg==" "integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg=="
}, },
"nocodb-sdk": { "nocodb-sdk": {
"version": "0.107.0", "version": "file:../nocodb-sdk",
"resolved": "https://registry.npmjs.org/nocodb-sdk/-/nocodb-sdk-0.107.0.tgz",
"integrity": "sha512-g/+oIwUY3T3e6RHGxmKKW7AShIfFeYnzxedFXiZVGKFUwKX2PAuKuaq+zdfirKyuEuSZYQq2fAzcdDOWTNUU/w==",
"requires": { "requires": {
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"jsep": "^1.3.6" "cspell": "^4.1.0",
"eslint": "^7.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^4.0.0",
"jsep": "^1.3.6",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.1",
"typescript": "^4.0.2"
} }
}, },
"node-abort-controller": { "node-abort-controller": {

4
packages/nocodb/package.json

@ -114,7 +114,7 @@
"nc-lib-gui": "0.107.0", "nc-lib-gui": "0.107.0",
"nc-plugin": "^0.1.3", "nc-plugin": "^0.1.3",
"ncp": "^2.0.0", "ncp": "^2.0.0",
"nocodb-sdk": "0.107.0", "nocodb-sdk": "file:../nocodb-sdk",
"nodemailer": "^6.4.10", "nodemailer": "^6.4.10",
"object-hash": "^3.0.0", "object-hash": "^3.0.0",
"os-locale": "^6.0.2", "os-locale": "^6.0.2",
@ -201,4 +201,4 @@
"coverageDirectory": "../coverage", "coverageDirectory": "../coverage",
"testEnvironment": "node" "testEnvironment": "node"
} }
} }

69
packages/nocodb/src/Noco.ts

@ -1,4 +1,5 @@
// import * as Sentry from '@sentry/node'; import Sentry, { Handlers } from '@sentry/node';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import clear from 'clear'; import clear from 'clear';
import * as express from 'express'; import * as express from 'express';
@ -6,20 +7,26 @@ import NcToolGui from 'nc-lib-gui';
import { IoAdapter } from '@nestjs/platform-socket.io'; import { IoAdapter } from '@nestjs/platform-socket.io';
import requestIp from 'request-ip'; import requestIp from 'request-ip';
import cookieParser from 'cookie-parser'; import cookieParser from 'cookie-parser';
import { T } from 'nc-help';
import { v4 as uuidv4 } from 'uuid';
import dotenv from 'dotenv';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
import { NC_LICENSE_KEY } from './constants'; import { NC_LICENSE_KEY } from './constants';
import Store from './models/Store'; import Store from './models/Store';
import { MetaTable } from './utils/globals';
import type { IEventEmitter } from './modules/event-emitter/event-emitter.interface'; import type { IEventEmitter } from './modules/event-emitter/event-emitter.interface';
import type { Express } from 'express'; import type { Express } from 'express';
import type * as http from 'http'; import type * as http from 'http';
dotenv.config();
export default class Noco { export default class Noco {
private static _this: Noco; private static _this: Noco;
private static ee: boolean; private static ee: boolean;
public static readonly env: string = '_noco'; public static readonly env: string = '_noco';
private static _httpServer: http.Server; private static _httpServer: http.Server;
private static _server: Express; private static _server: Express;
private static logger = new Logger(Noco.name);
public static get dashboardUrl(): string { public static get dashboardUrl(): string {
let siteUrl = `http://localhost:${process.env.PORT || 8080}`; let siteUrl = `http://localhost:${process.env.PORT || 8080}`;
@ -42,7 +49,6 @@ export default class Noco {
public readonly metaMgrv2: any; public readonly metaMgrv2: any;
public env: string; public env: string;
private ncToolApi;
private config: any; private config: any;
private requestContext: any; private requestContext: any;
@ -102,6 +108,8 @@ export default class Noco {
const nestApp = await NestFactory.create(AppModule); const nestApp = await NestFactory.create(AppModule);
this.initSentry(nestApp);
nestApp.useWebSocketAdapter(new IoAdapter(httpServer)); nestApp.useWebSocketAdapter(new IoAdapter(httpServer));
nestApp.use(requestIp.mw()); nestApp.use(requestIp.mw());
@ -115,6 +123,9 @@ export default class Noco {
const dashboardPath = process.env.NC_DASHBOARD_URL || '/dashboard'; const dashboardPath = process.env.NC_DASHBOARD_URL || '/dashboard';
server.use(NcToolGui.expressMiddleware(dashboardPath)); server.use(NcToolGui.expressMiddleware(dashboardPath));
server.get('/', (_req, res) => res.redirect(dashboardPath)); server.get('/', (_req, res) => res.redirect(dashboardPath));
this.initSentryErrorHandler(server);
return nestApp.getHttpAdapter().getInstance(); return nestApp.getHttpAdapter().getInstance();
} }
@ -125,4 +136,56 @@ export default class Noco {
public static get server(): Express { public static get server(): Express {
return Noco._server; return Noco._server;
} }
public static async initJwt(): Promise<any> {
if (this.config?.auth?.jwt) {
if (!this.config.auth.jwt.secret) {
let secret = (
await Noco._ncMeta.metaGet('', '', MetaTable.STORE, {
key: 'nc_auth_jwt_secret',
})
)?.value;
if (!secret) {
await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, {
key: 'nc_auth_jwt_secret',
value: (secret = uuidv4()),
});
}
this.config.auth.jwt.secret = secret;
}
this.config.auth.jwt.options = this.config.auth.jwt.options || {};
if (!this.config.auth.jwt.options?.expiresIn) {
this.config.auth.jwt.options.expiresIn =
process.env.NC_JWT_EXPIRES_IN ?? '10h';
}
}
let serverId = (
await Noco._ncMeta.metaGet('', '', MetaTable.STORE, {
key: 'nc_server_id',
})
)?.value;
if (!serverId) {
await Noco._ncMeta.metaInsert('', '', MetaTable.STORE, {
key: 'nc_server_id',
value: (serverId = T.id),
});
}
process.env.NC_SERVER_UUID = serverId;
}
private static initSentryErrorHandler(router) {
if (process.env.NC_SENTRY_DSN) {
router.use(Handlers.errorHandler());
}
}
private static initSentry(router) {
if (process.env.NC_SENTRY_DSN) {
Sentry.init({ dsn: process.env.NC_SENTRY_DSN });
// The request handler must be the first middleware on the app
router.use(Handlers.requestHandler());
}
}
} }

51
packages/nocodb/src/app.module.ts

@ -1,35 +1,25 @@
import { Inject, Module, RequestMethod } from '@nestjs/common'; import { Module, RequestMethod } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core'; import { APP_FILTER } from '@nestjs/core';
import { BullModule } from '@nestjs/bull'; import { BullModule } from '@nestjs/bull';
import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter'; import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter';
import { Connection } from './connection/connection';
import { GlobalExceptionFilter } from './filters/global-exception/global-exception.filter'; import { GlobalExceptionFilter } from './filters/global-exception/global-exception.filter';
import NcPluginMgrv2 from './helpers/NcPluginMgrv2';
import { GlobalMiddleware } from './middlewares/global/global.middleware'; import { GlobalMiddleware } from './middlewares/global/global.middleware';
import { GuiMiddleware } from './middlewares/gui/gui.middleware'; import { GuiMiddleware } from './middlewares/gui/gui.middleware';
import { PublicMiddleware } from './middlewares/public/public.middleware'; import { PublicMiddleware } from './middlewares/public/public.middleware';
import { DatasModule } from './modules/datas/datas.module'; import { DatasModule } from './modules/datas/datas.module';
import { IEventEmitter } from './modules/event-emitter/event-emitter.interface';
import { EventEmitterModule } from './modules/event-emitter/event-emitter.module'; import { EventEmitterModule } from './modules/event-emitter/event-emitter.module';
import { AuthService } from './services/auth.service'; import { AuthService } from './services/auth.service';
import { UsersModule } from './modules/users/users.module'; import { UsersModule } from './modules/users/users.module';
import { MetaService } from './meta/meta.service';
import Noco from './Noco';
import { TestModule } from './modules/test/test.module'; import { TestModule } from './modules/test/test.module';
import { GlobalModule } from './modules/global/global.module'; import { GlobalModule } from './modules/global/global.module';
import { HookHandlerService } from './services/hook-handler.service'; import { HookHandlerService } from './services/hook-handler.service';
import { LocalStrategy } from './strategies/local.strategy'; import { LocalStrategy } from './strategies/local.strategy';
import { AuthTokenStrategy } from './strategies/authtoken.strategy/authtoken.strategy'; import { AuthTokenStrategy } from './strategies/authtoken.strategy/authtoken.strategy';
import { BaseViewStrategy } from './strategies/base-view.strategy/base-view.strategy'; import { BaseViewStrategy } from './strategies/base-view.strategy/base-view.strategy';
import NcConfigFactory from './utils/NcConfigFactory';
import NcUpgrader from './version-upgrader/NcUpgrader';
import { MetasModule } from './modules/metas/metas.module'; import { MetasModule } from './modules/metas/metas.module';
import NocoCache from './cache/NocoCache';
import { JobsModule } from './modules/jobs/jobs.module'; import { JobsModule } from './modules/jobs/jobs.module';
import type { import { AppInitService } from './services/app-init.service';
MiddlewareConsumer, import type { MiddlewareConsumer } from '@nestjs/common';
OnApplicationBootstrap,
} from '@nestjs/common';
@Module({ @Module({
imports: [ imports: [
@ -60,15 +50,10 @@ import type {
AuthTokenStrategy, AuthTokenStrategy,
BaseViewStrategy, BaseViewStrategy,
HookHandlerService, HookHandlerService,
AppInitService,
], ],
}) })
export class AppModule implements OnApplicationBootstrap { export class AppModule {
constructor(
private readonly connection: Connection,
private readonly metaService: MetaService,
@Inject('IEventEmitter') private readonly eventEmitter: IEventEmitter,
) {}
// Global Middleware // Global Middleware
configure(consumer: MiddlewareConsumer) { configure(consumer: MiddlewareConsumer) {
consumer consumer
@ -79,30 +64,4 @@ export class AppModule implements OnApplicationBootstrap {
.apply(GlobalMiddleware) .apply(GlobalMiddleware)
.forRoutes({ path: '*', method: RequestMethod.ALL }); .forRoutes({ path: '*', method: RequestMethod.ALL });
} }
// app init
async onApplicationBootstrap(): Promise<void> {
process.env.NC_VERSION = '0105004';
await NocoCache.init();
await this.connection.init();
await NcConfigFactory.metaDbCreateIfNotExist(this.connection.config);
await this.metaService.init();
// todo: remove
// temporary hack
Noco._ncMeta = this.metaService;
Noco.config = this.connection.config;
Noco.eventEmitter = this.eventEmitter;
// init plugin manager
await NcPluginMgrv2.init(Noco.ncMeta);
await Noco.loadEEState();
// run upgrader
await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta });
}
} }

20
packages/nocodb/src/modules/global/global.module.ts

@ -1,19 +1,27 @@
import { Global, Module } from '@nestjs/common'; import { Global, Module } from '@nestjs/common';
import { JwtModule, JwtService } from '@nestjs/jwt';
import { ExtractJwt } from 'passport-jwt'; import { ExtractJwt } from 'passport-jwt';
import {
AppInitService,
appInitServiceProvider,
} from '../../services/app-init.service';
import { SocketGateway } from '../../gateways/socket.gateway'; import { SocketGateway } from '../../gateways/socket.gateway';
import { Connection } from '../../connection/connection'; import { Connection } from '../../connection/connection';
import { GlobalGuard } from '../../guards/global/global.guard'; import { GlobalGuard } from '../../guards/global/global.guard';
import { MetaService } from '../../meta/meta.service'; import { MetaService } from '../../meta/meta.service';
import Noco from '../../Noco';
import { JwtStrategy } from '../../strategies/jwt.strategy'; import { JwtStrategy } from '../../strategies/jwt.strategy';
import NcConfigFactory from '../../utils/NcConfigFactory';
import { UsersService } from '../../services/users/users.service'; import { UsersService } from '../../services/users/users.service';
import type { Provider } from '@nestjs/common'; import type { Provider } from '@nestjs/common';
export const JwtStrategyProvider: Provider = { export const JwtStrategyProvider: Provider = {
provide: JwtStrategy, provide: JwtStrategy,
useFactory: async (usersService: UsersService) => { useFactory: async (
const config = await NcConfigFactory.make(); usersService: UsersService,
appInitService: AppInitService,
) => {
const config = appInitService.appConfig;
await Noco.initJwt();
const options = { const options = {
// ignoreExpiration: false, // ignoreExpiration: false,
@ -26,13 +34,14 @@ export const JwtStrategyProvider: Provider = {
return new JwtStrategy(options, usersService); return new JwtStrategy(options, usersService);
}, },
inject: [UsersService], inject: [UsersService, AppInitService],
}; };
@Global() @Global()
@Module({ @Module({
imports: [], imports: [],
providers: [ providers: [
appInitServiceProvider,
Connection, Connection,
MetaService, MetaService,
UsersService, UsersService,
@ -41,6 +50,7 @@ export const JwtStrategyProvider: Provider = {
SocketGateway, SocketGateway,
], ],
exports: [ exports: [
AppInitService,
Connection, Connection,
MetaService, MetaService,
JwtStrategyProvider, JwtStrategyProvider,

19
packages/nocodb/src/services/app-init.service.spec.ts

@ -0,0 +1,19 @@
import { Test } from '@nestjs/testing';
import { AppInitService } from './app-init.service';
import type { TestingModule } from '@nestjs/testing';
describe('AppInitService', () => {
let service: AppInitService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AppInitService],
}).compile();
service = module.get<AppInitService>(AppInitService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

68
packages/nocodb/src/services/app-init.service.ts

@ -0,0 +1,68 @@
import { Inject, Injectable } from '@nestjs/common';
import NocoCache from '../cache/NocoCache';
import { Connection } from '../connection/connection';
import NcPluginMgrv2 from '../helpers/NcPluginMgrv2';
import { MetaService } from '../meta/meta.service';
import Noco from '../Noco';
import NcConfigFactory from '../utils/NcConfigFactory';
import NcUpgrader from '../version-upgrader/NcUpgrader';
import type { IEventEmitter } from '../modules/event-emitter/event-emitter.interface';
import type { Provider } from '@nestjs/common';
export class AppInitService {
private readonly config: any;
constructor(config) {
this.config = config;
}
get appConfig(): any {
return this.config;
}
}
export const appInitServiceProvider: Provider = {
provide: AppInitService,
// initialize app,
// 1. init cache
// 2. init db connection and create if not exist
// 3. init meta and set to Noco
// 4. init jwt
// 5. init plugin manager
// 6. run upgrader
useFactory: async (
connection: Connection,
metaService: MetaService,
eventEmitter: IEventEmitter,
) => {
process.env.NC_VERSION = '0105004';
await NocoCache.init();
await connection.init();
await NcConfigFactory.metaDbCreateIfNotExist(connection.config);
await metaService.init();
// todo: remove
// temporary hack
Noco._ncMeta = metaService;
Noco.config = connection.config;
Noco.eventEmitter = eventEmitter;
// init jwt secret
await Noco.initJwt();
// init plugin manager
await NcPluginMgrv2.init(Noco.ncMeta);
await Noco.loadEEState();
// run upgrader
await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta });
// todo: move app config to app-init service
return new AppInitService(connection.config);
},
inject: [Connection, MetaService, 'IEventEmitter'],
};

10
packages/nocodb/src/utils/NcConfigFactory.ts

@ -100,7 +100,7 @@ export default class NcConfigFactory {
ncConfig.auth = { ncConfig.auth = {
jwt: { jwt: {
secret: process.env.NC_AUTH_JWT_SECRET ?? 'temporary-key', secret: process.env.NC_AUTH_JWT_SECRET,
}, },
}; };
@ -421,7 +421,7 @@ export default class NcConfigFactory {
if (process.env.NC_AUTH_ADMIN_SECRET) { if (process.env.NC_AUTH_ADMIN_SECRET) {
config.auth = { config.auth = {
masterKey: { masterKey: {
secret: process.env.NC_AUTH_ADMIN_SECRET ?? 'temporary-key', secret: process.env.NC_AUTH_ADMIN_SECRET,
}, },
}; };
} else if (process.env.NC_NO_AUTH) { } else if (process.env.NC_NO_AUTH) {
@ -436,7 +436,7 @@ export default class NcConfigFactory {
dbAlias: dbAlias:
process.env.NC_AUTH_JWT_DB_ALIAS || process.env.NC_AUTH_JWT_DB_ALIAS ||
config.envs['_noco'].db[0].meta.dbAlias, config.envs['_noco'].db[0].meta.dbAlias,
secret: process.env.NC_AUTH_JWT_SECRET ?? 'temporary-key', secret: process.env.NC_AUTH_JWT_SECRET,
}, },
}; };
} }
@ -536,7 +536,7 @@ export default class NcConfigFactory {
if (process.env.NC_AUTH_ADMIN_SECRET) { if (process.env.NC_AUTH_ADMIN_SECRET) {
config.auth = { config.auth = {
masterKey: { masterKey: {
secret: process.env.NC_AUTH_ADMIN_SECRET ?? 'temporary-key', secret: process.env.NC_AUTH_ADMIN_SECRET,
}, },
}; };
} else if (process.env.NC_NO_AUTH) { } else if (process.env.NC_NO_AUTH) {
@ -551,7 +551,7 @@ export default class NcConfigFactory {
dbAlias: dbAlias:
process.env.NC_AUTH_JWT_DB_ALIAS || process.env.NC_AUTH_JWT_DB_ALIAS ||
config.envs['_noco'].db[0].meta.dbAlias, config.envs['_noco'].db[0].meta.dbAlias,
secret: process.env.NC_AUTH_JWT_SECRET ?? 'temporary-key', secret: process.env.NC_AUTH_JWT_SECRET,
}, },
}; };
} }

14
tests/playwright/pages/Dashboard/common/Cell/SelectOptionCell.ts

@ -118,7 +118,7 @@ export class SelectOptionCellPageObject extends BasePage {
index, index,
columnHeader, columnHeader,
option, option,
multiSelect, multiSelect = false,
}: { }: {
index: number; index: number;
columnHeader: string; columnHeader: string;
@ -134,10 +134,18 @@ export class SelectOptionCellPageObject extends BasePage {
await selectCell.locator('.ant-select-selection-search-input').type(option); await selectCell.locator('.ant-select-selection-search-input').type(option);
await selectCell.locator('.ant-select-selection-search-input').press('Enter'); // await selectCell.locator('.ant-select-selection-search-input').press('Enter');
// Wait for update api call
const saveRowAction = () => selectCell.locator('.ant-select-selection-search-input').press('Enter');
await this.waitForResponse({
uiAction: saveRowAction,
requestUrlPathToMatch: 'api/v1/db/data/noco/',
httpMethodsToMatch: ['PATCH'],
responseJsonMatcher: resJson => String(resJson?.[columnHeader]).includes(String(option)),
});
if (multiSelect) await selectCell.locator('.ant-select-selection-search-input').press('Escape'); if (multiSelect) await selectCell.locator('.ant-select-selection-search-input').press('Escape');
// todo: wait for update api call
} }
async verifySelectedOptions({ async verifySelectedOptions({

1
tests/playwright/pages/Dashboard/common/Toolbar/index.ts

@ -66,6 +66,7 @@ export class ToolbarPage extends BasePage {
// Wait for the menu to close // Wait for the menu to close
if (menuOpen) await this.fields.get().waitFor({ state: 'hidden' }); if (menuOpen) await this.fields.get().waitFor({ state: 'hidden' });
else await this.fields.get().waitFor({ state: 'visible' });
} }
async clickFindRowByScanButton() { async clickFindRowByScanButton() {

4
tests/playwright/tests/db/undo-redo.spec.ts

@ -178,6 +178,10 @@ test.describe('Undo Redo', () => {
await dashboard.closeTab({ title: 'Team & Auth' }); await dashboard.closeTab({ title: 'Team & Auth' });
await dashboard.treeView.openTable({ title: 'numberBased' }); await dashboard.treeView.openTable({ title: 'numberBased' });
// hack: wait for grid to load
// https://github.com/nocodb/nocodb/actions/runs/5025773509/jobs/9013176970
await page.waitForTimeout(1000);
await verifyFieldsOrder(['Number', 'Decimal', 'Currency']); await verifyFieldsOrder(['Number', 'Decimal', 'Currency']);
// Hide Decimal // Hide Decimal

Loading…
Cancel
Save