Browse Source

feat(nocodb): add missing schema

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5174/head
Pranav C 2 years ago
parent
commit
be377add99
  1. 1
      packages/nocodb/src/lib/meta/api/ajvSchemas/index.ts
  2. 2
      packages/nocodb/src/lib/meta/api/apiTokenApis.ts
  3. 4
      packages/nocodb/src/lib/meta/api/baseApis.ts
  4. 2
      packages/nocodb/src/lib/meta/api/formViewApis.ts
  5. 2
      packages/nocodb/src/lib/meta/api/formViewColumnApis.ts
  6. 3
      packages/nocodb/src/lib/meta/api/galleryViewApis.ts
  7. 2
      packages/nocodb/src/lib/meta/api/gridViewApis.ts
  8. 2
      packages/nocodb/src/lib/meta/api/gridViewColumnApis.ts
  9. 3
      packages/nocodb/src/lib/meta/api/hookFilterApis.ts
  10. 3
      packages/nocodb/src/lib/meta/api/kanbanViewApis.ts
  11. 2
      packages/nocodb/src/lib/meta/api/modelVisibilityApis.ts
  12. 2
      packages/nocodb/src/lib/meta/api/orgLicenseApis.ts
  13. 64
      packages/nocodb/src/lib/meta/api/userApi/userApis.ts
  14. 10
      packages/nocodb/src/lib/meta/helpers/catchError.ts
  15. 246
      scripts/sdk/swagger.json

1
packages/nocodb/src/lib/meta/api/ajvSchemas/index.ts

@ -1 +0,0 @@
export * from './ajiAjv'

2
packages/nocodb/src/lib/meta/api/apiTokenApis.ts

@ -5,6 +5,7 @@ import { NcError } from '../helpers/catchError';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import ApiToken from '../../models/ApiToken';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
export async function apiTokenList(req: Request, res: Response) {
res.json(await ApiToken.list(req['user'].id));
@ -40,6 +41,7 @@ router.get(
router.post(
'/api/v1/db/meta/projects/:projectId/api-tokens',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/ApiTokenReq'),
ncMetaAclMw(apiTokenCreate, 'apiTokenCreate')
);
router.delete(

4
packages/nocodb/src/lib/meta/api/baseApis.ts

@ -7,7 +7,7 @@ import Base from '../../models/Base';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { populateMeta } from './helpers';
import { getAjvValidatorMw, populateMeta } from './helpers'
export async function baseGet(
req: Request<any, any, any>,
@ -107,6 +107,7 @@ export default (router) => {
router.patch(
'/api/v1/db/meta/projects/:projectId/bases/:baseId',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/BaseReq'),
ncMetaAclMw(baseUpdate, 'baseUpdate')
);
router.delete(
@ -117,6 +118,7 @@ export default (router) => {
router.post(
'/api/v1/db/meta/projects/:projectId/bases',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/BaseReq'),
ncMetaAclMw(baseCreate, 'baseCreate')
);
router.get(

2
packages/nocodb/src/lib/meta/api/formViewApis.ts

@ -13,6 +13,7 @@ import View from '../../models/View';
import FormView from '../../models/FormView';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
// @ts-ignore
export async function formViewGet(req: Request, res: Response<FormType>) {
@ -43,6 +44,7 @@ const router = Router({ mergeParams: true });
router.post(
'/api/v1/db/meta/tables/:tableId/forms',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/FormReq'),
ncMetaAclMw(formViewCreate, 'formViewCreate')
);
router.get(

2
packages/nocodb/src/lib/meta/api/formViewColumnApis.ts

@ -3,6 +3,7 @@ import FormViewColumn from '../../models/FormViewColumn';
import { Tele } from 'nc-help';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
// import { getAjvValidatorMw } from './helpers'
export async function columnUpdate(req: Request, res: Response) {
Tele.emit('evt', { evt_type: 'formViewColumn:updated' });
@ -13,6 +14,7 @@ const router = Router({ mergeParams: true });
router.patch(
'/api/v1/db/meta/form-columns/:formViewColumnId',
metaApiMetrics,
// getAjvValidatorMw('swagger.json#/components/schemas/FormViewColumnReq'),
ncMetaAclMw(columnUpdate, 'columnUpdate')
);
export default router;

3
packages/nocodb/src/lib/meta/api/galleryViewApis.ts

@ -5,6 +5,7 @@ import GalleryView from '../../models/GalleryView';
import { Tele } from 'nc-help';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
export async function galleryViewGet(req: Request, res: Response<GalleryType>) {
res.json(await GalleryView.get(req.params.galleryViewId));
}
@ -29,11 +30,13 @@ const router = Router({ mergeParams: true });
router.post(
'/api/v1/db/meta/tables/:tableId/galleries',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/GalleryReq'),
ncMetaAclMw(galleryViewCreate, 'galleryViewCreate')
);
router.patch(
'/api/v1/db/meta/galleries/:galleryViewId',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/GalleryReq'),
ncMetaAclMw(galleryViewUpdate, 'galleryViewUpdate')
);
router.get(

2
packages/nocodb/src/lib/meta/api/gridViewApis.ts

@ -13,6 +13,7 @@ import View from '../../models/View';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import GridView from '../../models/GridView';
import { getAjvValidatorMw } from './helpers'
// @ts-ignore
export async function gridViewCreate(req: Request<any, any>, res) {
@ -35,6 +36,7 @@ const router = Router({ mergeParams: true });
router.post(
'/api/v1/db/meta/tables/:tableId/grids/',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/GridReq'),
ncMetaAclMw(gridViewCreate, 'gridViewCreate')
);
router.patch(

2
packages/nocodb/src/lib/meta/api/gridViewColumnApis.ts

@ -3,6 +3,7 @@ import GridViewColumn from '../../models/GridViewColumn';
import { Tele } from 'nc-help';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
export async function columnList(req: Request, res: Response) {
res.json(await GridViewColumn.list(req.params.gridViewId));
@ -22,6 +23,7 @@ router.get(
router.patch(
'/api/v1/db/meta/grid-columns/:gridViewColumnId',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/GridViewColumnReq'),
ncMetaAclMw(gridColumnUpdate, 'gridColumnUpdate')
);
export default router;

3
packages/nocodb/src/lib/meta/api/hookFilterApis.ts

@ -13,6 +13,7 @@ import Project from '../../models/Project';
import Filter from '../../models/Filter';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
// @ts-ignore
export async function filterGet(req: Request, res: Response, next) {
@ -117,6 +118,7 @@ router.get(
router.post(
'/hooks/:hookId/filters/',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/filterReq'),
ncMetaAclMw(filterCreate, 'filterCreate')
);
router.get(
@ -127,6 +129,7 @@ router.get(
router.patch(
'/hooks/:hookId/filters/:filterId',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/filterReq'),
ncMetaAclMw(filterUpdate, 'filterUpdate')
);
router.delete(

3
packages/nocodb/src/lib/meta/api/kanbanViewApis.ts

@ -5,6 +5,7 @@ import KanbanView from '../../models/KanbanView';
import { Tele } from 'nc-help';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
export async function kanbanViewGet(req: Request, res: Response<KanbanType>) {
res.json(await KanbanView.get(req.params.kanbanViewId));
@ -31,11 +32,13 @@ const router = Router({ mergeParams: true });
router.post(
'/api/v1/db/meta/tables/:tableId/kanbans',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/KanbanReq'),
ncMetaAclMw(kanbanViewCreate, 'kanbanViewCreate')
);
router.patch(
'/api/v1/db/meta/kanbans/:kanbanViewId',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/KanbanUpdateReq'),
ncMetaAclMw(kanbanViewUpdate, 'kanbanViewUpdate')
);
router.get(

2
packages/nocodb/src/lib/meta/api/modelVisibilityApis.ts

@ -4,6 +4,7 @@ import { Router } from 'express';
import { Tele } from 'nc-help';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { getAjvValidatorMw } from './helpers'
async function xcVisibilityMetaSetAll(req, res) {
Tele.emit('evt', { evt_type: 'uiAcl:updated' });
for (const d of req.body) {
@ -122,6 +123,7 @@ router.get(
router.post(
'/api/v1/db/meta/projects/:projectId/visibility-rules',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/KanbanViewReq'),
ncMetaAclMw(xcVisibilityMetaSetAll, 'modelVisibilitySet')
);
export default router;

2
packages/nocodb/src/lib/meta/api/orgLicenseApis.ts

@ -5,6 +5,7 @@ import Store from '../../models/Store';
import Noco from '../../Noco';
import { metaApiMetrics } from '../helpers/apiMetrics';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { getAjvValidatorMw } from './helpers'
async function licenseGet(_req, res) {
const license = await Store.get(NC_LICENSE_KEY);
@ -30,6 +31,7 @@ router.get(
router.post(
'/api/v1/license',
metaApiMetrics,
getAjvValidatorMw('swagger.json#/components/schemas/LicenseReq'),
ncMetaAclMw(licenseSet, 'licenseSet', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,

64
packages/nocodb/src/lib/meta/api/userApi/userApis.ts

@ -22,6 +22,7 @@ import extractProjectIdAndAuthenticate from '../../helpers/extractProjectIdAndAu
import ncMetaAclMw from '../../helpers/ncMetaAclMw';
import { MetaTable } from '../../../utils/globals';
import Noco from '../../../Noco';
import { getAjvValidatorMw } from '../helpers';
import { genJwt } from './helpers';
import { randomTokenString } from '../../helpers/stringHelpers';
@ -523,15 +524,32 @@ async function renderPasswordReset(req, res): Promise<any> {
const mapRoutes = (router) => {
// todo: old api - /auth/signup?tool=1
router.post('/auth/user/signup', catchError(signup));
router.post('/auth/user/signin', catchError(signin));
router.post(
'/auth/user/signup',
getAjvValidatorMw('swagger.json#/components/schemas/SignUpReq'),
catchError(signup)
);
router.post(
'/auth/user/signin',
getAjvValidatorMw('swagger.json#/components/schemas/SignInReq'),
catchError(signin)
);
router.get('/auth/user/me', extractProjectIdAndAuthenticate, catchError(me));
router.post('/auth/password/forgot', catchError(passwordForgot));
router.post(
'/auth/password/forgot',
getAjvValidatorMw('swagger.json#/components/schemas/ForgotPasswordReq'),
catchError(passwordForgot)
);
router.post('/auth/token/validate/:tokenId', catchError(tokenValidate));
router.post('/auth/password/reset/:tokenId', catchError(passwordReset));
router.post(
'/auth/password/reset/:tokenId',
getAjvValidatorMw('swagger.json#/components/schemas/PasswordResetReq'),
catchError(passwordReset)
);
router.post('/auth/email/validate/:tokenId', catchError(emailVerification));
router.post(
'/user/password/change',
getAjvValidatorMw('swagger.json#/components/schemas/PasswordChangeReq'),
ncMetaAclMw(passwordChange, 'passwordChange')
);
router.post('/auth/token/refresh', catchError(refreshToken));
@ -549,14 +567,26 @@ const mapRoutes = (router) => {
);
// deprecated APIs
router.post('/api/v1/db/auth/user/signup', catchError(signup));
router.post('/api/v1/db/auth/user/signin', catchError(signin));
router.post(
'/api/v1/db/auth/user/signup',
getAjvValidatorMw('swagger.json#/components/schemas/SignUpReq'),
catchError(signup)
);
router.post(
'/api/v1/db/auth/user/signin',
getAjvValidatorMw('swagger.json#/components/schemas/SignInReq'),
catchError(signin)
);
router.get(
'/api/v1/db/auth/user/me',
extractProjectIdAndAuthenticate,
catchError(me)
);
router.post('/api/v1/db/auth/password/forgot', catchError(passwordForgot));
router.post(
'/api/v1/db/auth/password/forgot',
getAjvValidatorMw('swagger.json#/components/schemas/ForgotPasswordReq'),
catchError(passwordForgot)
);
router.post(
'/api/v1/db/auth/token/validate/:tokenId',
catchError(tokenValidate)
@ -571,6 +601,7 @@ const mapRoutes = (router) => {
);
router.post(
'/api/v1/db/auth/password/change',
getAjvValidatorMw('swagger.json#/components/schemas/PasswordChangeReq'),
ncMetaAclMw(passwordChange, 'passwordChange')
);
router.post('/api/v1/db/auth/token/refresh', catchError(refreshToken));
@ -580,14 +611,26 @@ const mapRoutes = (router) => {
);
// new API
router.post('/api/v1/auth/user/signup', catchError(signup));
router.post('/api/v1/auth/user/signin', catchError(signin));
router.post(
'/api/v1/auth/user/signup',
getAjvValidatorMw('swagger.json#/components/schemas/SignUpReq'),
catchError(signup)
);
router.post(
'/api/v1/auth/user/signin',
getAjvValidatorMw('swagger.json#/components/schemas/SignInReq'),
catchError(signin)
);
router.get(
'/api/v1/auth/user/me',
extractProjectIdAndAuthenticate,
catchError(me)
);
router.post('/api/v1/auth/password/forgot', catchError(passwordForgot));
router.post(
'/api/v1/auth/password/forgot',
getAjvValidatorMw('swagger.json#/components/schemas/ForgotPasswordReq'),
catchError(passwordForgot)
);
router.post(
'/api/v1/auth/token/validate/:tokenId',
catchError(tokenValidate)
@ -602,6 +645,7 @@ const mapRoutes = (router) => {
);
router.post(
'/api/v1/auth/password/change',
getAjvValidatorMw('swagger.json#/components/schemas/PasswordChangeReq'),
ncMetaAclMw(passwordChange, 'passwordChange')
);
router.post('/api/v1/auth/token/refresh', catchError(refreshToken));

10
packages/nocodb/src/lib/meta/helpers/catchError.ts

@ -1,3 +1,9 @@
function extractDBError(_error:Error) {
// if (error instanceof knex.DBError) { switch (error.code) { case 'ER_NO_SUCH_TABLE': console.error('Table does not exist'); break; case 'ER_BAD_FIELD_ERROR': console.error('Invalid column name'); break; // Add more cases for other common errors here default: console.error('Unknown error:', error); break; } } else { console.error('Unexpected error:', error); } }).finally(() => { knex.destroy(); // Close the database connection });
}
export default function (
requestHandler: (req: any, res: any, next?: any) => any
) {
@ -5,6 +11,10 @@ export default function (
try {
return await requestHandler(req, res, next);
} catch (e) {
extractDBError(e)
// todo: error log
console.log(requestHandler.name ? `${requestHandler.name} ::` : '', e);

246
scripts/sdk/swagger.json

@ -6975,7 +6975,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiToken"
"$ref": "#/components/schemas/ApiTokenReq"
}
}
}
@ -8739,6 +8739,33 @@
},
"description": ""
},
"GridReq": {
"title": "Grid",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"order": {
"type": "number"
},
"lock_type": {
"type": "string",
"enum": [
"collaborative",
"locked",
"personal"
]
},
"row_height": {
"type": "number"
}
},
"description": "",
"required": [
"title"
]
},
"Gallery": {
"title": "Gallery",
"type": "object",
@ -8802,6 +8829,51 @@
}
}
},
"GalleryReq": {
"title": "Gallery",
"type": "object",
"description": "",
"properties": {
"title": {
"type": "string"
},
"next_enabled": {
"type": "boolean"
},
"prev_enabled": {
"type": "boolean"
},
"cover_image_idx": {
"type": "integer"
},
"cover_image": {
"type": "string"
},
"restrict_types": {
"type": "string"
},
"restrict_size": {
"type": "string"
},
"restrict_number": {
"type": "string"
},
"fk_cover_image_col_id": {
"type": "string"
},
"lock_type": {
"type": "string",
"enum": [
"collaborative",
"locked",
"personal"
]
}
},
"required": [
"title"
]
},
"GalleryColumn": {
"title": "GalleryColumn",
"type": "object",
@ -8992,6 +9064,46 @@
}
}
},
"KanbanReq": {
"title": "Kanban",
"type": "object",
"description": "",
"properties": {
"title": {
"type": "string"
},
"fk_grp_col_id": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"required": [
"title"
]
},
"KanbanUpdateReq": {
"title": "Kanban",
"type": "object",
"description": "",
"properties": {
"fk_grp_col_id": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
}
},
"Form": {
"title": "Form",
"type": "object",
@ -9053,6 +9165,61 @@
"meta": {}
}
},
"FormReq": {
"title": "Form",
"type": "object",
"description": "",
"properties": {
"title": {
"type": "string"
},
"heading": {
"type": "string"
},
"subheading": {
"type": "string"
},
"success_msg": {
"type": "string"
},
"redirect_url": {
"type": "string"
},
"redirect_after_secs": {
"type": "string"
},
"email": {
"type": "string"
},
"banner_image_url": {
"type": "string"
},
"logo_url": {
"type": "string"
},
"submit_another_form": {
"type": "boolean"
},
"show_blank_form": {
"type": "boolean"
},
"fk_model_id": {
"type": "string"
},
"lock_type": {
"type": "string",
"enum": [
"collaborative",
"locked",
"personal"
]
},
"meta": {}
},
"required": [
"title"
]
},
"FormColumn": {
"description": "",
"type": "object",
@ -9542,7 +9709,82 @@
"hook"
]
},
"SignUpReq": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
}
},
"required": [
"email",
"password"
]
},
"SignInReq": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
}
},
"required": [
"email",
"password"
]
},
"ForgotPasswordReq": {
"type": "object",
"properties": {
"email": {
"type": "string"
}
},
"required": [
"email"
]
},
"PasswordResetReq": {
"type": "object",
"properties": {
"password": {
"type": "string"
}
},
"required": [
"password"
]
},
"PasswordChangeReq": {
"type": "object",
"properties": {
"currentPassword": {
"type": "string"
},
"newPassword": {
"type": "string"
}
},
"required": [
"currentPassword",
"newPassword"
]
},
"ApiTokenReq": {
"title": "API Token Request",
"type": "object",
"properties": {
"description": {
"type": "string"
}
}
},
"Plugin": {
"title": "Plugin",
"type": "object",

Loading…
Cancel
Save