Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/ApiClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Logger } from '@rocket.chat/logger';
import { Users } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
import type { JoinPathPattern, Method } from '@rocket.chat/rest-typings';
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
import { ajv } from '@rocket.chat/rest-typings';
import { wrapExceptions } from '@rocket.chat/tools';
import type { ValidateFunction } from 'ajv';
import { Accounts } from 'meteor/accounts-base';
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/app/api/server/default/openApi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { schemas } from '@rocket.chat/core-typings';
import type { Route } from '@rocket.chat/http-router';
import { isOpenAPIJSONEndpoint } from '@rocket.chat/rest-typings';
import express from 'express';
Expand Down Expand Up @@ -65,8 +66,9 @@ const makeOpenAPIResponse = (paths: Record<string, Record<string, Route>>) => ({
name: 'X-Auth-Token',
},
},
schemas: {},
schemas: schemas.components.schemas,
},
schemas: schemas.components.schemas,
paths,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/custom-sounds.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ICustomSound } from '@rocket.chat/core-typings';
import { CustomSounds } from '@rocket.chat/models';
import type { PaginatedRequest, PaginatedResult } from '@rocket.chat/rest-typings';
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
import { ajv } from '@rocket.chat/rest-typings';
import { escapeRegExp } from '@rocket.chat/string-helpers';

import type { ExtractRoutesFromAPI } from '../ApiClass';
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/api/server/v1/federation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Federation, FederationEE } from '@rocket.chat/core-services';
import { License } from '@rocket.chat/license';
import { isFederationVerifyMatrixIdProps } from '@rocket.chat/rest-typings';
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
import { ajv, isFederationVerifyMatrixIdProps } from '@rocket.chat/rest-typings';

import { API } from '../api';

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/invites.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { IInvite } from '@rocket.chat/core-typings';
import {
ajv,
isFindOrCreateInviteParams,
isUseInviteTokenProps,
isValidateInviteTokenProps,
isSendInvitationEmailParams,
} from '@rocket.chat/rest-typings';
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';

import { findOrCreateInvite } from '../../../invites/server/functions/findOrCreateInvite';
import { listInvites } from '../../../invites/server/functions/listInvites';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/webdav.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { api } from '@rocket.chat/core-services';
import type { IWebdavAccount, IWebdavAccountIntegration } from '@rocket.chat/core-typings';
import { WebdavAccounts } from '@rocket.chat/models';
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
import { ajv } from '@rocket.chat/rest-typings';
import type { DeleteResult } from 'mongodb';

import type { ExtractRoutesFromAPI } from '../ApiClass';
Expand Down
20 changes: 20 additions & 0 deletions apps/meteor/app/livechat/server/ajv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { schemas } from '@rocket.chat/core-typings';
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
allowUnionTypes: true,
code: { source: true },
});

export { ajv };

const components = schemas.components?.schemas;

if (components) {
for (const key in components) {
if (Object.prototype.hasOwnProperty.call(components, key)) {
ajv.addSchema(components[key], `#/components/schemas/${key}`);
}
}
}
1 change: 1 addition & 0 deletions apps/meteor/app/livechat/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './ajv';
import './livechat';
import './startup';
import '../lib/messageTypes';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IOutboundProvider } from '@rocket.chat/core-typings';
import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv';
import { ajv } from '@rocket.chat/rest-typings';

import { API } from '../../../../../app/api/server';
import { isGETOutboundProviderParams } from '../outboundcomms/rest';
Expand Down
11 changes: 9 additions & 2 deletions packages/core-typings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
"devDependencies": {
"@rocket.chat/apps-engine": "workspace:^",
"@rocket.chat/eslint-config": "workspace:^",
"@types/express": "^4.17.23",
"eslint": "~8.45.0",
"mongodb": "6.10.0",
"npm-run-all": "~4.1.5",
"prettier": "~3.3.3",
"rimraf": "^6.0.1",
"ts-patch": "^3.3.0",
"typescript": "~5.8.3"
},
"scripts": {
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "eslint --ext .js,.jsx,.ts,.tsx . --fix",
"test": "echo \"no tests\" && exit 1",
".:build:prepare": "ts-patch install && typia patch",
".:build:clean": "rimraf dist",
".:build:build": "tsc -p tsconfig.json",
"dev": "tsc --watch --preserveWatchOutput -p tsconfig.json",
"build": "rm -rf dist && tsc -p tsconfig.json"
"build": "run-s .:build:prepare .:build:clean .:build:build"
},
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
Expand All @@ -27,7 +34,7 @@
"@rocket.chat/icons": "^0.43.0",
"@rocket.chat/message-parser": "workspace:^",
"@rocket.chat/ui-kit": "workspace:~",
"@types/express": "^4.17.23"
"typia": "~9.3.1"
},
"volta": {
"extends": "../../package.json"
Expand Down
5 changes: 5 additions & 0 deletions packages/core-typings/src/Ajv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import typia from 'typia';

import type { ISubscription } from './ISubscription';

export const schemas = typia.json.schemas<[ISubscription], '3.0'>();
2 changes: 2 additions & 0 deletions packages/core-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,5 @@ export * from './RoomRouteData';

export * as Cloud from './cloud';
export * from './themes';

export { schemas } from './Ajv';
3 changes: 2 additions & 1 deletion packages/core-typings/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"lib": ["dom", "dom.iterable"],
"declaration": true,
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./dist",
"plugins": [{ "transform": "typia/lib/transform" }]
},
"include": ["./src/**/*"]
}
2 changes: 2 additions & 0 deletions packages/livechat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
"@rocket.chat/message-parser": "workspace:^",
"@rocket.chat/random": "workspace:~",
"@rocket.chat/ui-kit": "workspace:~",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"css-vars-ponyfill": "^2.4.9",
"date-fns": "^2.30.0",
"dompurify": "^3.2.6",
Expand Down
3 changes: 3 additions & 0 deletions packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,6 @@ export * from './v1/auth';
export * from './v1/cloud';
export * from './v1/banners';
export * from './default';

// Export the ajv instance for use in other packages
export { ajv } from './v1/Ajv';
4 changes: 2 additions & 2 deletions packages/rest-typings/src/v1/Ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import addFormats from 'ajv-formats';
const ajv = new Ajv({
coerceTypes: true,
allowUnionTypes: true,
code: { source: true },
});

// TODO: keep ajv extension here
addFormats(ajv);

ajv.addFormat('basic_email', /^[^@]+@[^@]+$/);
ajv.addFormat(
'rfc_email',
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
);

ajv.addKeyword({
keyword: 'isNotEmpty',
type: 'string',
validate: (_schema: unknown, data: unknown): boolean => typeof data === 'string' && !!data.trim(),
});

export { ajv };
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7119,8 +7119,12 @@ __metadata:
"@types/express": "npm:^4.17.23"
eslint: "npm:~8.45.0"
mongodb: "npm:6.10.0"
npm-run-all: "npm:~4.1.5"
prettier: "npm:~3.3.3"
rimraf: "npm:^6.0.1"
ts-patch: "npm:^3.3.0"
typescript: "npm:~5.8.3"
typia: "npm:~9.3.1"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -7672,6 +7676,8 @@ __metadata:
"@types/whatwg-fetch": "npm:~0.0.33"
"@typescript-eslint/eslint-plugin": "npm:~5.60.1"
"@typescript-eslint/parser": "npm:~5.60.1"
ajv: "npm:^8.17.1"
ajv-formats: "npm:^3.0.1"
autoprefixer: "npm:^9.8.8"
babel-loader: "npm:^9.2.1"
cross-env: "npm:^7.0.3"
Expand Down
Loading