diff --git a/.vscode/settings.json b/.vscode/settings.json index 61974d86f41..478c58fee04 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,7 +13,7 @@ "files.trimFinalNewlines": true, "files.trimTrailingWhitespace": true, "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" }, "vsicons.presets.angular": true, "deepscan.enable": true, diff --git a/apps/api/src/plugin-config.ts b/apps/api/src/plugin-config.ts index 36231b235fd..f7f3333d8bd 100644 --- a/apps/api/src/plugin-config.ts +++ b/apps/api/src/plugin-config.ts @@ -96,7 +96,14 @@ function getDbConfig(): DataSourceOptions { database: process.env.DB_NAME || 'postgres', username: process.env.DB_USER || 'postgres', password: process.env.DB_PASS || 'root', - logging: process.env.DB_LOGGING == 'all' ? 'all' : ['query', 'error'], + logging: + process.env.DB_LOGGING == 'false' + ? false + : process.env.DB_LOGGING == 'all' + ? 'all' + : process.env.DB_LOGGING == 'query' + ? ['query', 'error'] + : ['error'], // by default set to error only logger: 'advanced-console', // log queries that take more than 3 sec as warnings maxQueryExecutionTime: process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT diff --git a/apps/desktop-timer/package.json b/apps/desktop-timer/package.json index 1add23b7485..25f587e4fa2 100644 --- a/apps/desktop-timer/package.json +++ b/apps/desktop-timer/package.json @@ -77,8 +77,8 @@ "ngx-electron": "^2.2.0", "node-fetch": "^2.6.7", "node-notifier": "^8.0.0", - "pg": "^8.8.0", - "pg-query-stream": "^4.2.4", + "pg": "^8.11.3", + "pg-query-stream": "^4.5.3", "rxjs": "^7.4.0", "screenshot-desktop": "^1.12.7", "sound-play": "1.1.0", diff --git a/apps/desktop-timer/src/package.json b/apps/desktop-timer/src/package.json index 97247e00b45..441ab198e12 100644 --- a/apps/desktop-timer/src/package.json +++ b/apps/desktop-timer/src/package.json @@ -1,168 +1,168 @@ { - "name": "gauzy-desktop-timer", - "productName": "Gauzy Desktop Timer", - "version": "0.1.0", - "description": "Gauzy Desktop Timer", - "license": "AGPL-3.0", - "homepage": "https://gauzy.co", - "repository": { - "type": "git", - "url": "https://github.com/ever-co/ever-gauzy.git" - }, - "bugs": { - "url": "https://github.com/ever-co/ever-gauzy/issues" - }, - "private": true, - "author": { - "name": "Ever Co. LTD", - "email": "ever@ever.co", - "url": "https://ever.co" - }, - "main": "index.js", - "workspaces": { - "packages": [ - "../../../packages/contracts", - "../../../packages/desktop-window", - "../../../packages/desktop-libs" - ] - }, - "build": { - "appId": "com.ever.gauzydesktoptimer", - "artifactName": "${name}-${version}.${ext}", - "productName": "Gauzy Desktop Timer", - "copyright": "Copyright © 2019-Present. Ever Co. LTD", - "afterSign": "tools/notarize.js", - "dmg": { - "sign": false - }, - "asar": true, - "npmRebuild": true, - "asarUnpack": [ - "node_modules/screenshot-desktop/lib/win32", - "node_modules/@sentry/electron", - "node_modules/sqlite3/lib", - "node_modules/better-sqlite3" - ], - "directories": { - "buildResources": "icons", - "output": "../desktop-timer-packages" - }, - "publish": [ - { - "provider": "github", - "repo": "ever-gauzy-desktop-timer", - "releaseType": "release" - }, - { - "provider": "spaces", - "name": "ever", - "region": "sfo3", - "path": "/ever-gauzy-desktop-timer", - "acl": "public-read" - } - ], - "mac": { - "category": "public.app-category.developer-tools", - "icon": "icon.icns", - "target": [ - "zip", - "dmg" - ], - "asarUnpack": "**/*.node", - "artifactName": "${name}-${version}.${ext}", - "hardenedRuntime": true, - "gatekeeperAssess": false, - "entitlements": "tools/build/entitlements.mas.plist", - "entitlementsInherit": "tools/build/entitlements.mas.plist", - "extendInfo": { - "NSAppleEventsUsageDescription": "Please allow access to script browser applications to detect the current URL when triggering instant lookup.", - "NSCameraUsageDescription": "Please allow access to Gauzy Desktop Timer to make screenshot" - } - }, - "win": { - "publisherName": "Ever", - "target": [ - { - "target": "nsis", - "arch": [ - "x64" - ] - } - ], - "icon": "icon.ico", - "verifyUpdateCodeSignature": false - }, - "linux": { - "icon": "linux", - "target": [ - "AppImage", - "deb", - "tar.gz" - ], - "executableName": "gauzy-desktop-timer", - "artifactName": "${name}-${version}.${ext}", - "synopsis": "Desktop", - "category": "Development" - }, - "nsis": { - "oneClick": false, - "perMachine": true, - "createDesktopShortcut": true, - "createStartMenuShortcut": true, - "allowToChangeInstallationDirectory": true, - "allowElevation": true, - "installerIcon": "icon.ico", - "artifactName": "${name}-${version}.${ext}", - "deleteAppDataOnUninstall": true, - "menuCategory": true - }, - "extraResources": [ - "./data/**/*", - "databaseDir", - { - "from": "assets", - "to": "assets" - } - ], - "extraFiles": [ - "./**/desktop-libs/**/migrations/*" - ] - }, - "dependencies": { - "@datorama/akita": "^7.1.1", - "@datorama/akita-ngdevtools": "^7.0.0", - "@electron/remote": "^2.0.8", - "@gauzy/contracts": "^0.1.0", - "@gauzy/desktop-libs": "^0.1.0", - "@gauzy/desktop-window": "^0.1.0", - "@sentry/electron": "^4.15.0", - "@sentry/node": "^7.85.0", - "@sentry/tracing": "^7.85.0", - "@sentry/types": "^7.85.0", - "auto-launch": "5.0.5", - "consolidate": "^0.16.0", - "electron-log": "^4.4.8", - "electron-store": "^8.1.0", - "electron-updater": "^6.1.7", - "electron-util": "^0.17.2", - "embedded-queue": "^0.0.11", - "ffi-napi": "^4.0.3", - "form-data": "^3.0.0", - "htmlparser2": "^8.0.2", - "iconv": "^3.0.1", - "knex": "^2.4.0", - "mac-screen-capture-permissions": "^2.0.0", - "moment": "^2.29.4", - "node-fetch": "^2.6.7", - "node-notifier": "^8.0.0", - "pg": "^8.8.0", - "pg-query-stream": "^4.2.4", - "screenshot-desktop": "^1.12.7", - "sound-play": "1.1.0", - "sqlite3": "^5.1.5", - "squirrelly": "^8.0.8", - "tslib": "^2.3.1", - "twing": "^5.0.2", - "underscore": "^1.13.3" - } -} \ No newline at end of file + "name": "gauzy-desktop-timer", + "productName": "Gauzy Desktop Timer", + "version": "0.1.0", + "description": "Gauzy Desktop Timer", + "license": "AGPL-3.0", + "homepage": "https://gauzy.co", + "repository": { + "type": "git", + "url": "https://github.com/ever-co/ever-gauzy.git" + }, + "bugs": { + "url": "https://github.com/ever-co/ever-gauzy/issues" + }, + "private": true, + "author": { + "name": "Ever Co. LTD", + "email": "ever@ever.co", + "url": "https://ever.co" + }, + "main": "index.js", + "workspaces": { + "packages": [ + "../../../packages/contracts", + "../../../packages/desktop-window", + "../../../packages/desktop-libs" + ] + }, + "build": { + "appId": "com.ever.gauzydesktoptimer", + "artifactName": "${name}-${version}.${ext}", + "productName": "Gauzy Desktop Timer", + "copyright": "Copyright © 2019-Present. Ever Co. LTD", + "afterSign": "tools/notarize.js", + "dmg": { + "sign": false + }, + "asar": true, + "npmRebuild": true, + "asarUnpack": [ + "node_modules/screenshot-desktop/lib/win32", + "node_modules/@sentry/electron", + "node_modules/sqlite3/lib", + "node_modules/better-sqlite3" + ], + "directories": { + "buildResources": "icons", + "output": "../desktop-timer-packages" + }, + "publish": [ + { + "provider": "github", + "repo": "ever-gauzy-desktop-timer", + "releaseType": "release" + }, + { + "provider": "spaces", + "name": "ever", + "region": "sfo3", + "path": "/ever-gauzy-desktop-timer", + "acl": "public-read" + } + ], + "mac": { + "category": "public.app-category.developer-tools", + "icon": "icon.icns", + "target": [ + "zip", + "dmg" + ], + "asarUnpack": "**/*.node", + "artifactName": "${name}-${version}.${ext}", + "hardenedRuntime": true, + "gatekeeperAssess": false, + "entitlements": "tools/build/entitlements.mas.plist", + "entitlementsInherit": "tools/build/entitlements.mas.plist", + "extendInfo": { + "NSAppleEventsUsageDescription": "Please allow access to script browser applications to detect the current URL when triggering instant lookup.", + "NSCameraUsageDescription": "Please allow access to Gauzy Desktop Timer to make screenshot" + } + }, + "win": { + "publisherName": "Ever", + "target": [ + { + "target": "nsis", + "arch": [ + "x64" + ] + } + ], + "icon": "icon.ico", + "verifyUpdateCodeSignature": false + }, + "linux": { + "icon": "linux", + "target": [ + "AppImage", + "deb", + "tar.gz" + ], + "executableName": "gauzy-desktop-timer", + "artifactName": "${name}-${version}.${ext}", + "synopsis": "Desktop", + "category": "Development" + }, + "nsis": { + "oneClick": false, + "perMachine": true, + "createDesktopShortcut": true, + "createStartMenuShortcut": true, + "allowToChangeInstallationDirectory": true, + "allowElevation": true, + "installerIcon": "icon.ico", + "artifactName": "${name}-${version}.${ext}", + "deleteAppDataOnUninstall": true, + "menuCategory": true + }, + "extraResources": [ + "./data/**/*", + "databaseDir", + { + "from": "assets", + "to": "assets" + } + ], + "extraFiles": [ + "./**/desktop-libs/**/migrations/*" + ] + }, + "dependencies": { + "@datorama/akita": "^7.1.1", + "@datorama/akita-ngdevtools": "^7.0.0", + "@electron/remote": "^2.0.8", + "@gauzy/contracts": "^0.1.0", + "@gauzy/desktop-libs": "^0.1.0", + "@gauzy/desktop-window": "^0.1.0", + "@sentry/electron": "^4.15.0", + "@sentry/node": "^7.85.0", + "@sentry/tracing": "^7.85.0", + "@sentry/types": "^7.85.0", + "auto-launch": "5.0.5", + "consolidate": "^0.16.0", + "electron-log": "^4.4.8", + "electron-store": "^8.1.0", + "electron-updater": "^6.1.7", + "electron-util": "^0.17.2", + "embedded-queue": "^0.0.11", + "ffi-napi": "^4.0.3", + "form-data": "^3.0.0", + "htmlparser2": "^8.0.2", + "iconv": "^3.0.1", + "knex": "^2.4.0", + "mac-screen-capture-permissions": "^2.0.0", + "moment": "^2.29.4", + "node-fetch": "^2.6.7", + "node-notifier": "^8.0.0", + "pg": "^8.11.3", + "pg-query-stream": "^4.5.3", + "screenshot-desktop": "^1.12.7", + "sound-play": "1.1.0", + "sqlite3": "^5.1.5", + "squirrelly": "^8.0.8", + "tslib": "^2.3.1", + "twing": "^5.0.2", + "underscore": "^1.13.3" + } +} diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 20a50ff5021..85da09b190b 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -78,16 +78,15 @@ "ngx-electron": "^2.2.0", "node-fetch": "^2.6.7", "node-notifier": "^8.0.0", - "pg": "^8.8.0", - "pg-query-stream": "^4.2.4", + "pg": "^8.11.3", + "pg-query-stream": "^4.5.3", "rxjs": "^7.4.0", "screenshot-desktop": "^1.12.7", "sound-play": "1.1.0", "sqlite3": "^5.1.5", "squirrelly": "^8.0.8", "twing": "^5.0.2", - "typeorm": "0.3.7", - "typeorm-express-query-builder": "https://github.com/ever-co/typeorm-express-query-builder.git", + "typeorm": "^0.3.17", "underscore": "^1.13.3" }, "optionalDependencies": { diff --git a/apps/desktop/src/package.json b/apps/desktop/src/package.json index 3cd904d224e..e3f5a05d658 100644 --- a/apps/desktop/src/package.json +++ b/apps/desktop/src/package.json @@ -1,179 +1,179 @@ { - "name": "gauzy-desktop", - "productName": "Gauzy Desktop", - "version": "0.1.0", - "description": "Gauzy Desktop", - "license": "AGPL-3.0", - "homepage": "https://gauzy.co", - "repository": { - "type": "git", - "url": "https://github.com/ever-co/ever-gauzy.git" - }, - "bugs": { - "url": "https://github.com/ever-co/ever-gauzy/issues" - }, - "private": true, - "author": { - "name": "Ever Co. LTD", - "email": "ever@ever.co", - "url": "https://ever.co" - }, - "main": "index.js", - "workspaces": { - "packages": [ - "../../../packages/core", - "../../../packages/auth", - "../../../packages/desktop-window", - "../../../packages/desktop-libs", - "../../../packages/plugins/knowledge-base", - "../../../packages/plugins/changelog", - "../../../packages/common", - "../../../packages/config", - "../../../packages/contracts", - "../../../packages/plugins/integration-ai", - "../../../packages/plugins/integration-hubstaff", - "../../../packages/plugins/integration-upwork", - "../../../packages/plugins/integration-github", - "../../../packages/plugins/integration-jira", - "../../../packages/plugin" - ] - }, - "build": { - "appId": "com.ever.gauzydesktop", - "artifactName": "${name}-${version}.${ext}", - "productName": "Gauzy Desktop", - "copyright": "Copyright © 2019-Present. Ever Co. LTD", - "dmg": { - "sign": false - }, - "asar": true, - "npmRebuild": true, - "asarUnpack": [ - "node_modules/screenshot-desktop/lib/win32", - "node_modules/@sentry/electron", - "node_modules/sqlite3/lib", - "node_modules/better-sqlite3" - ], - "directories": { - "buildResources": "icons", - "output": "../desktop-packages" - }, - "publish": [ - { - "provider": "github", - "repo": "ever-gauzy-desktop", - "releaseType": "release" - }, - { - "provider": "spaces", - "name": "ever", - "region": "sfo3", - "path": "/ever-gauzy-desktop", - "acl": "public-read" - } - ], - "mac": { - "category": "public.app-category.developer-tools", - "icon": "icon.icns", - "target": [ - "zip", - "dmg" - ], - "asarUnpack": "**/*.node", - "artifactName": "${name}-${version}.${ext}", - "hardenedRuntime": true, - "gatekeeperAssess": false, - "entitlements": "tools/build/entitlements.mas.plist", - "entitlementsInherit": "tools/build/entitlements.mas.plist", - "extendInfo": { - "NSAppleEventsUsageDescription": "Please allow access to script browser applications to detect the current URL when triggering instant lookup." - } - }, - "win": { - "publisherName": "Ever", - "target": [ - { - "target": "nsis", - "arch": [ - "x64" - ] - } - ], - "icon": "icon.ico", - "verifyUpdateCodeSignature": false - }, - "linux": { - "icon": "linux", - "target": [ - "AppImage", - "deb", - "tar.gz" - ], - "executableName": "gauzy-desktop", - "artifactName": "${name}-${version}.${ext}", - "synopsis": "Desktop", - "category": "Development" - }, - "nsis": { - "oneClick": false, - "perMachine": true, - "createDesktopShortcut": true, - "createStartMenuShortcut": true, - "allowToChangeInstallationDirectory": true, - "allowElevation": true, - "installerIcon": "icon.ico", - "artifactName": "${name}-${version}.${ext}", - "deleteAppDataOnUninstall": true, - "menuCategory": true - }, - "extraResources": [ - "./data/**/*" - ] - }, - "dependencies": { - "@datorama/akita": "^7.1.1", - "@datorama/akita-ngdevtools": "^7.0.0", - "@electron/remote": "^2.0.8", - "@gauzy/auth": "^0.1.0", - "@gauzy/changelog": "^0.1.0", - "@gauzy/core": "^0.1.0", - "@gauzy/desktop-libs": "^0.1.0", - "@gauzy/desktop-window": "^0.1.0", - "@gauzy/knowledge-base": "^0.1.0", - "@nestjs/platform-express": "^9.2.1", - "@sentry/electron": "^4.15.0", - "@sentry/node": "^7.85.0", - "@sentry/tracing": "^7.85.0", - "@sentry/types": "^7.85.0", - "auto-launch": "5.0.5", - "consolidate": "^0.16.0", - "electron-log": "^4.4.8", - "electron-store": "^8.1.0", - "electron-updater": "^6.1.7", - "electron-util": "^0.17.2", - "embedded-queue": "^0.0.11", - "ffi-napi": "^4.0.3", - "form-data": "^3.0.0", - "htmlparser2": "^8.0.2", - "iconv": "^3.0.1", - "knex": "^2.4.0", - "mac-screen-capture-permissions": "^2.0.0", - "moment": "^2.29.4", - "node-fetch": "^2.6.7", - "node-notifier": "^8.0.0", - "pg": "^8.8.0", - "pg-query-stream": "^4.2.4", - "screenshot-desktop": "^1.12.7", - "sound-play": "1.1.0", - "sqlite3": "^5.1.5", - "squirrelly": "^8.0.8", - "tslib": "^2.3.1", - "twing": "^5.0.2", - "underscore": "^1.13.3" - }, - "optionalDependencies": { - "node-linux": "^0.1.12", - "node-mac": "^1.0.1", - "node-windows": "^1.0.0-beta.8" - } + "name": "gauzy-desktop", + "productName": "Gauzy Desktop", + "version": "0.1.0", + "description": "Gauzy Desktop", + "license": "AGPL-3.0", + "homepage": "https://gauzy.co", + "repository": { + "type": "git", + "url": "https://github.com/ever-co/ever-gauzy.git" + }, + "bugs": { + "url": "https://github.com/ever-co/ever-gauzy/issues" + }, + "private": true, + "author": { + "name": "Ever Co. LTD", + "email": "ever@ever.co", + "url": "https://ever.co" + }, + "main": "index.js", + "workspaces": { + "packages": [ + "../../../packages/core", + "../../../packages/auth", + "../../../packages/desktop-window", + "../../../packages/desktop-libs", + "../../../packages/plugins/knowledge-base", + "../../../packages/plugins/changelog", + "../../../packages/common", + "../../../packages/config", + "../../../packages/contracts", + "../../../packages/plugins/integration-ai", + "../../../packages/plugins/integration-hubstaff", + "../../../packages/plugins/integration-upwork", + "../../../packages/plugins/integration-github", + "../../../packages/plugins/integration-jira", + "../../../packages/plugin" + ] + }, + "build": { + "appId": "com.ever.gauzydesktop", + "artifactName": "${name}-${version}.${ext}", + "productName": "Gauzy Desktop", + "copyright": "Copyright © 2019-Present. Ever Co. LTD", + "dmg": { + "sign": false + }, + "asar": true, + "npmRebuild": true, + "asarUnpack": [ + "node_modules/screenshot-desktop/lib/win32", + "node_modules/@sentry/electron", + "node_modules/sqlite3/lib", + "node_modules/better-sqlite3" + ], + "directories": { + "buildResources": "icons", + "output": "../desktop-packages" + }, + "publish": [ + { + "provider": "github", + "repo": "ever-gauzy-desktop", + "releaseType": "release" + }, + { + "provider": "spaces", + "name": "ever", + "region": "sfo3", + "path": "/ever-gauzy-desktop", + "acl": "public-read" + } + ], + "mac": { + "category": "public.app-category.developer-tools", + "icon": "icon.icns", + "target": [ + "zip", + "dmg" + ], + "asarUnpack": "**/*.node", + "artifactName": "${name}-${version}.${ext}", + "hardenedRuntime": true, + "gatekeeperAssess": false, + "entitlements": "tools/build/entitlements.mas.plist", + "entitlementsInherit": "tools/build/entitlements.mas.plist", + "extendInfo": { + "NSAppleEventsUsageDescription": "Please allow access to script browser applications to detect the current URL when triggering instant lookup." + } + }, + "win": { + "publisherName": "Ever", + "target": [ + { + "target": "nsis", + "arch": [ + "x64" + ] + } + ], + "icon": "icon.ico", + "verifyUpdateCodeSignature": false + }, + "linux": { + "icon": "linux", + "target": [ + "AppImage", + "deb", + "tar.gz" + ], + "executableName": "gauzy-desktop", + "artifactName": "${name}-${version}.${ext}", + "synopsis": "Desktop", + "category": "Development" + }, + "nsis": { + "oneClick": false, + "perMachine": true, + "createDesktopShortcut": true, + "createStartMenuShortcut": true, + "allowToChangeInstallationDirectory": true, + "allowElevation": true, + "installerIcon": "icon.ico", + "artifactName": "${name}-${version}.${ext}", + "deleteAppDataOnUninstall": true, + "menuCategory": true + }, + "extraResources": [ + "./data/**/*" + ] + }, + "dependencies": { + "@datorama/akita": "^7.1.1", + "@datorama/akita-ngdevtools": "^7.0.0", + "@electron/remote": "^2.0.8", + "@gauzy/auth": "^0.1.0", + "@gauzy/changelog": "^0.1.0", + "@gauzy/core": "^0.1.0", + "@gauzy/desktop-libs": "^0.1.0", + "@gauzy/desktop-window": "^0.1.0", + "@gauzy/knowledge-base": "^0.1.0", + "@nestjs/platform-express": "^9.2.1", + "@sentry/electron": "^4.15.0", + "@sentry/node": "^7.85.0", + "@sentry/tracing": "^7.85.0", + "@sentry/types": "^7.85.0", + "auto-launch": "5.0.5", + "consolidate": "^0.16.0", + "electron-log": "^4.4.8", + "electron-store": "^8.1.0", + "electron-updater": "^6.1.7", + "electron-util": "^0.17.2", + "embedded-queue": "^0.0.11", + "ffi-napi": "^4.0.3", + "form-data": "^3.0.0", + "htmlparser2": "^8.0.2", + "iconv": "^3.0.1", + "knex": "^2.4.0", + "mac-screen-capture-permissions": "^2.0.0", + "moment": "^2.29.4", + "node-fetch": "^2.6.7", + "node-notifier": "^8.0.0", + "pg": "^8.11.3", + "pg-query-stream": "^4.5.3", + "screenshot-desktop": "^1.12.7", + "sound-play": "1.1.0", + "sqlite3": "^5.1.5", + "squirrelly": "^8.0.8", + "tslib": "^2.3.1", + "twing": "^5.0.2", + "underscore": "^1.13.3" + }, + "optionalDependencies": { + "node-linux": "^0.1.12", + "node-mac": "^1.0.1", + "node-windows": "^1.0.0-beta.8" + } } diff --git a/apps/server/package.json b/apps/server/package.json index 4bdc5970406..39a53c3efb2 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -75,14 +75,13 @@ "moment-timezone": "^0.5.40", "ngx-electron": "^2.2.0", "node-static": "^0.7.11", - "pg": "^8.8.0", - "pg-query-stream": "^4.2.4", + "pg": "^8.11.3", + "pg-query-stream": "^4.5.3", "rxjs": "^7.4.0", "sqlite3": "^5.1.5", "squirrelly": "^8.0.8", "twing": "^5.0.2", - "typeorm": "0.3.7", - "typeorm-express-query-builder": "https://github.com/ever-co/typeorm-express-query-builder.git" + "typeorm": "^0.3.17" }, "optionalDependencies": { "node-linux": "^0.1.12", diff --git a/apps/server/src/package.json b/apps/server/src/package.json index b11e4877c78..e2095f7e631 100755 --- a/apps/server/src/package.json +++ b/apps/server/src/package.json @@ -1,185 +1,185 @@ { - "name": "gauzy-server", - "productName": "Gauzy Server", - "version": "0.1.0", - "description": "Gauzy Server", - "license": "AGPL-3.0", - "homepage": "https://gauzy.co", - "repository": { - "type": "git", - "url": "https://github.com/ever-co/ever-gauzy.git" - }, - "bugs": { - "url": "https://github.com/ever-co/ever-gauzy/issues" - }, - "private": true, - "author": { - "name": "Ever Co. LTD", - "email": "ever@ever.co", - "url": "https://ever.co" - }, - "main": "index.js", - "bin": "api/main.js", - "workspaces": { - "packages": [ - "../../../packages/core", - "../../../packages/auth", - "../../../packages/desktop-window", - "../../../packages/desktop-libs", - "../../../packages/plugins/knowledge-base", - "../../../packages/plugins/changelog", - "../../../packages/common", - "../../../packages/config", - "../../../packages/contracts", - "../../../packages/plugins/integration-ai", - "../../../packages/plugins/integration-hubstaff", - "../../../packages/plugins/integration-upwork", - "../../../packages/plugins/integration-github", - "../../../packages/plugins/integration-jira", - "../../../packages/plugin" - ] - }, - "build": { - "appId": "com.ever.gauzyserver", - "artifactName": "${name}-${version}.${ext}", - "productName": "Gauzy Server", - "copyright": "Copyright © 2019-Present. Ever Co. LTD", - "asar": true, - "npmRebuild": true, - "asarUnpack": [ - "node_modules/@sentry/electron", - "node_modules/sqlite3/lib", - "node_modules/better-sqlite3" - ], - "directories": { - "buildResources": "icons", - "output": "../desktop-packages" - }, - "publish": [ - { - "provider": "github", - "repo": "ever-gauzy-server", - "releaseType": "release" - }, - { - "provider": "spaces", - "name": "ever", - "region": "sfo3", - "path": "/ever-gauzy-server", - "acl": "public-read" - } - ], - "mac": { - "category": "public.app-category.developer-tools", - "icon": "icon.icns", - "target": [ - "zip", - "dmg" - ], - "asarUnpack": "**/*.node", - "artifactName": "${name}-${version}.${ext}", - "hardenedRuntime": true, - "gatekeeperAssess": false, - "entitlements": "tools/build/entitlements.mas.plist", - "entitlementsInherit": "tools/build/entitlements.mas.plist" - }, - "win": { - "publisherName": "Ever", - "target": [ - { - "target": "nsis", - "arch": [ - "x64" - ] - } - ], - "icon": "icon.ico", - "verifyUpdateCodeSignature": false, - "requestedExecutionLevel": "requireAdministrator" - }, - "linux": { - "icon": "linux", - "target": [ - "AppImage", - "deb", - "tar.gz" - ], - "executableName": "gauzy-server", - "artifactName": "${name}-${version}.${ext}", - "synopsis": "Server", - "category": "Development" - }, - "nsis": { - "oneClick": false, - "perMachine": true, - "createDesktopShortcut": true, - "createStartMenuShortcut": true, - "allowToChangeInstallationDirectory": true, - "allowElevation": true, - "installerIcon": "icon.ico", - "artifactName": "${name}-${version}.${ext}", - "deleteAppDataOnUninstall": true, - "menuCategory": true - }, - "extraResources": [ - "./data/**/*" - ] - }, - "dependencies": { - "@datorama/akita": "^7.1.1", - "@datorama/akita-ngdevtools": "^7.0.0", - "@electron/remote": "^2.0.8", - "@gauzy/auth": "^0.1.0", - "@gauzy/changelog": "^0.1.0", - "@gauzy/core": "^0.1.0", - "@gauzy/desktop-libs": "^0.1.0", - "@gauzy/desktop-window": "^0.1.0", - "@gauzy/knowledge-base": "^0.1.0", - "@nestjs/platform-express": "^9.2.1", - "@sentry/electron": "^4.15.0", - "@sentry/node": "^7.85.0", - "@sentry/tracing": "^7.85.0", - "@sentry/types": "^7.85.0", - "auto-launch": "5.0.5", - "consolidate": "^0.16.0", - "electron-log": "^4.4.8", - "electron-store": "^8.1.0", - "electron-updater": "^6.1.7", - "electron-util": "^0.17.2", - "ffi-napi": "^4.0.3", - "form-data": "^3.0.0", - "htmlparser2": "^8.0.2", - "iconv": "^3.0.1", - "knex": "^2.4.0", - "moment": "^2.29.4", - "node-fetch": "^2.6.7", - "node-notifier": "^8.0.0", - "node-static": "^0.7.11", - "pdfmake": "^0.2.0", - "pg": "^8.8.0", - "pg-query-stream": "^4.2.4", - "sound-play": "1.1.0", - "sqlite3": "^5.1.5", - "squirrelly": "^8.0.8", - "tslib": "^2.3.1", - "twing": "^5.0.2", - "underscore": "^1.13.3" - }, - "optionalDependencies": { - "node-linux": "^0.1.12", - "node-mac": "^1.0.1", - "node-windows": "^1.0.0-beta.8" - }, - "pkg": { - "assets": [ - "api/assets/**/*", - "node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node", - "node_modules/linebreak/src/classes.trie" - ], - "targets": [ - "node16-linux-x64", - "node16-mac-x64", - "node16-win-x64" - ] - } + "name": "gauzy-server", + "productName": "Gauzy Server", + "version": "0.1.0", + "description": "Gauzy Server", + "license": "AGPL-3.0", + "homepage": "https://gauzy.co", + "repository": { + "type": "git", + "url": "https://github.com/ever-co/ever-gauzy.git" + }, + "bugs": { + "url": "https://github.com/ever-co/ever-gauzy/issues" + }, + "private": true, + "author": { + "name": "Ever Co. LTD", + "email": "ever@ever.co", + "url": "https://ever.co" + }, + "main": "index.js", + "bin": "api/main.js", + "workspaces": { + "packages": [ + "../../../packages/core", + "../../../packages/auth", + "../../../packages/desktop-window", + "../../../packages/desktop-libs", + "../../../packages/plugins/knowledge-base", + "../../../packages/plugins/changelog", + "../../../packages/common", + "../../../packages/config", + "../../../packages/contracts", + "../../../packages/plugins/integration-ai", + "../../../packages/plugins/integration-hubstaff", + "../../../packages/plugins/integration-upwork", + "../../../packages/plugins/integration-github", + "../../../packages/plugins/integration-jira", + "../../../packages/plugin" + ] + }, + "build": { + "appId": "com.ever.gauzyserver", + "artifactName": "${name}-${version}.${ext}", + "productName": "Gauzy Server", + "copyright": "Copyright © 2019-Present. Ever Co. LTD", + "asar": true, + "npmRebuild": true, + "asarUnpack": [ + "node_modules/@sentry/electron", + "node_modules/sqlite3/lib", + "node_modules/better-sqlite3" + ], + "directories": { + "buildResources": "icons", + "output": "../desktop-packages" + }, + "publish": [ + { + "provider": "github", + "repo": "ever-gauzy-server", + "releaseType": "release" + }, + { + "provider": "spaces", + "name": "ever", + "region": "sfo3", + "path": "/ever-gauzy-server", + "acl": "public-read" + } + ], + "mac": { + "category": "public.app-category.developer-tools", + "icon": "icon.icns", + "target": [ + "zip", + "dmg" + ], + "asarUnpack": "**/*.node", + "artifactName": "${name}-${version}.${ext}", + "hardenedRuntime": true, + "gatekeeperAssess": false, + "entitlements": "tools/build/entitlements.mas.plist", + "entitlementsInherit": "tools/build/entitlements.mas.plist" + }, + "win": { + "publisherName": "Ever", + "target": [ + { + "target": "nsis", + "arch": [ + "x64" + ] + } + ], + "icon": "icon.ico", + "verifyUpdateCodeSignature": false, + "requestedExecutionLevel": "requireAdministrator" + }, + "linux": { + "icon": "linux", + "target": [ + "AppImage", + "deb", + "tar.gz" + ], + "executableName": "gauzy-server", + "artifactName": "${name}-${version}.${ext}", + "synopsis": "Server", + "category": "Development" + }, + "nsis": { + "oneClick": false, + "perMachine": true, + "createDesktopShortcut": true, + "createStartMenuShortcut": true, + "allowToChangeInstallationDirectory": true, + "allowElevation": true, + "installerIcon": "icon.ico", + "artifactName": "${name}-${version}.${ext}", + "deleteAppDataOnUninstall": true, + "menuCategory": true + }, + "extraResources": [ + "./data/**/*" + ] + }, + "dependencies": { + "@datorama/akita": "^7.1.1", + "@datorama/akita-ngdevtools": "^7.0.0", + "@electron/remote": "^2.0.8", + "@gauzy/auth": "^0.1.0", + "@gauzy/changelog": "^0.1.0", + "@gauzy/core": "^0.1.0", + "@gauzy/desktop-libs": "^0.1.0", + "@gauzy/desktop-window": "^0.1.0", + "@gauzy/knowledge-base": "^0.1.0", + "@nestjs/platform-express": "^9.2.1", + "@sentry/electron": "^4.15.0", + "@sentry/node": "^7.85.0", + "@sentry/tracing": "^7.85.0", + "@sentry/types": "^7.85.0", + "auto-launch": "5.0.5", + "consolidate": "^0.16.0", + "electron-log": "^4.4.8", + "electron-store": "^8.1.0", + "electron-updater": "^6.1.7", + "electron-util": "^0.17.2", + "ffi-napi": "^4.0.3", + "form-data": "^3.0.0", + "htmlparser2": "^8.0.2", + "iconv": "^3.0.1", + "knex": "^2.4.0", + "moment": "^2.29.4", + "node-fetch": "^2.6.7", + "node-notifier": "^8.0.0", + "node-static": "^0.7.11", + "pdfmake": "^0.2.0", + "pg": "^8.11.3", + "pg-query-stream": "^4.5.3", + "sound-play": "1.1.0", + "sqlite3": "^5.1.5", + "squirrelly": "^8.0.8", + "tslib": "^2.3.1", + "twing": "^5.0.2", + "underscore": "^1.13.3" + }, + "optionalDependencies": { + "node-linux": "^0.1.12", + "node-mac": "^1.0.1", + "node-windows": "^1.0.0-beta.8" + }, + "pkg": { + "assets": [ + "api/assets/**/*", + "node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node", + "node_modules/linebreak/src/classes.trie" + ], + "targets": [ + "node16-linux-x64", + "node16-mac-x64", + "node16-win-x64" + ] + } } diff --git a/packages/config/src/database.ts b/packages/config/src/database.ts index b400e2a0a69..8d2eb43dda1 100644 --- a/packages/config/src/database.ts +++ b/packages/config/src/database.ts @@ -45,7 +45,14 @@ switch (dbType) { database: process.env.DB_NAME || 'postgres', username: process.env.DB_USER || 'postgres', password: process.env.DB_PASS || 'root', - logging: process.env.DB_LOGGING == 'all' ? 'all' : ['query', 'error'], + logging: + process.env.DB_LOGGING == 'false' + ? false + : process.env.DB_LOGGING == 'all' + ? 'all' + : process.env.DB_LOGGING == 'query' + ? ['query', 'error'] + : ['error'], // by default set to error only logger: 'advanced-console', // log queries that take more than 3 sec as warnings maxQueryExecutionTime: process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT diff --git a/packages/core/package.json b/packages/core/package.json index 824da63a3cc..b7a5cd4f554 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -95,7 +95,7 @@ "atlassian-connect-express": "^8.5.0", "axios": "^1.5.0", "bcrypt": "^5.1.0", - "better-sqlite3": "^8.7.0", + "better-sqlite3": "^9.2.2", "cache-manager": "^3.4.0", "camelcase": "^6.2.1", "chalk": "4.1.2", @@ -128,6 +128,7 @@ "jimp": "^0.22.7", "jsonwebtoken": "^9.0.0", "kafkajs": "^1.14.0", + "mkdirp": "^3.0.1", "mjml": "^4.14.1", "moment": "^2.29.4", "moment-range": "^4.0.2", @@ -145,8 +146,8 @@ "passport": "^0.6.0", "passport-jwt": "^4.0.0", "pdfmake": "^0.2.0", - "pg": "^8.8.0", - "pg-query-stream": "^4.2.4", + "pg": "^8.11.3", + "pg-query-stream": "^4.5.3", "prettier": "^2.8.4", "redis": "^3.1.2", "reflect-metadata": "^0.1.13", @@ -157,8 +158,7 @@ "sqlite3": "^5.1.5", "streamifier": "^0.1.1", "swagger-ui-express": "^4.1.4", - "typeorm": "0.3.7", - "typeorm-express-query-builder": "https://github.com/ever-co/typeorm-express-query-builder.git", + "typeorm": "^0.3.17", "underscore": "^1.13.3", "unleash-client": "^3.16.1", "unzipper": "^0.10.11", diff --git a/packages/core/src/bootstrap/index.ts b/packages/core/src/bootstrap/index.ts index b22715d91fc..bd2c5193492 100644 --- a/packages/core/src/bootstrap/index.ts +++ b/packages/core/src/bootstrap/index.ts @@ -69,7 +69,7 @@ export async function bootstrap(pluginConfig?: Partial): Promise< 'Authorization, Language, Tenant-Id, Organization-Id, X-Requested-With, X-Auth-Token, X-HTTP-Method-Override, Content-Type, Content-Language, Accept, Accept-Language, Observe' }); - // TODO: enable csurf is not good idea because it was depricated. + // TODO: enable csurf is not good idea because it was deprecated. // Maybe review https://github.com/Psifi-Solutions/csrf-csrf as alternative? // As explained on the csurf middleware page https://github.com/expressjs/csurf#csurf, // the csurf module requires either a session middleware or cookie-parser to be initialized first. diff --git a/packages/core/src/database/migration-utils.ts b/packages/core/src/database/migration-utils.ts index 7cfa81bb8da..ed54e911dc6 100644 --- a/packages/core/src/database/migration-utils.ts +++ b/packages/core/src/database/migration-utils.ts @@ -1,46 +1,48 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as mkdirp from 'mkdirp'; +import { mkdirp } from 'mkdirp'; /** * Migration utils functions. * From https://github.com/typeorm/typeorm/blob/2bb0e398f922561f1cbb8ebbb19d20aa093e8bc2/src/commands/MigrationGenerateCommand.ts */ export class MigrationUtils { + /** + * Creates directories recursively. + */ + static createDirectories(directory: string): Promise { + return new Promise(async (resolve, reject) => { + try { + await mkdirp(directory); + resolve(); + } catch (err) { + return reject(err); + } + }); + } - /** - * Creates directories recursively. - */ - static createDirectories(directory: string): Promise { - return new Promise( - (resolve, reject) => mkdirp(directory, (err: any) => err ? reject(err) : resolve()) - ); - } + /** + * Creates a file with the given content in the given path. + */ + static async createFile(filePath: string, content: string, override: boolean = true): Promise { + await MigrationUtils.createDirectories(path.dirname(filePath)); + return new Promise((resolve, reject) => { + if (override === false && fs.existsSync(filePath)) return resolve(); - /** - * Creates a file with the given content in the given path. - */ - static async createFile(filePath: string, content: string, override: boolean = true): Promise { - await MigrationUtils.createDirectories(path.dirname(filePath)); - return new Promise((resolve, reject) => { - if (override === false && fs.existsSync(filePath)) - return resolve(); + fs.writeFile(filePath, content, (err) => (err ? reject(err) : resolve())); + }); + } - fs.writeFile(filePath, content, err => err ? reject(err) : resolve()); - }); - } + /** + * Reads everything from a given file and returns its content as a string. + */ + static async readFile(filePath: string): Promise { + return new Promise((resolve, reject) => { + fs.readFile(filePath, (err, data) => (err ? fail(err) : resolve(data.toString()))); + }); + } - /** - * Reads everything from a given file and returns its content as a string. - */ - static async readFile(filePath: string): Promise { - return new Promise((resolve, reject) => { - fs.readFile(filePath, (err, data) => err ? fail(err) : resolve(data.toString())); - }); - } - - - static async fileExists(filePath: string) { - return fs.existsSync(filePath); - } + static async fileExists(filePath: string) { + return fs.existsSync(filePath); + } } diff --git a/packages/core/src/database/migrations/1654675304373-SeedChangeLogFeature.ts b/packages/core/src/database/migrations/1654675304373-SeedChangeLogFeature.ts index dd927c8032a..223be0bc341 100644 --- a/packages/core/src/database/migrations/1654675304373-SeedChangeLogFeature.ts +++ b/packages/core/src/database/migrations/1654675304373-SeedChangeLogFeature.ts @@ -1,67 +1,68 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; -import * as chalk from "chalk"; +import { MigrationInterface, QueryRunner } from 'typeorm'; +import * as chalk from 'chalk'; import { v4 as uuidV4 } from 'uuid'; export class SeedChangeLogFeature1654675304373 implements MigrationInterface { + name = 'SeedChangeLogFeature1654675304373'; - name = 'SeedChangeLogFeature1654675304373'; + public async up(queryRunner: QueryRunner): Promise { + console.log(chalk.yellow(this.name + ' start running!')); - public async up(queryRunner: QueryRunner): Promise { - console.log(chalk.yellow(this.name + ' start running!')); + const isSQlite = ['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type); - const date = ['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type) ? Date.now() : new Date(); - const features = [ - { - icon: 'cube-outline', - title: 'New CRM', - date, - isFeature: true, - content: 'Now you can read latest features changelog directly in Gauzy', - learnMoreUrl: '', - imageUrl: 'assets/images/features/macbook-2.png' - }, - { - icon: 'globe-outline', - title: 'Most popular in 20 countries', - date, - isFeature: true, - content: 'Europe, Americas and Asia get choise', - learnMoreUrl: '', - imageUrl: 'assets/images/features/macbook-1.png' - }, - { - icon: 'flash-outline', - title: 'Visit our website', - date, - isFeature: true, - content: 'You are welcome to check more information about the platform at our official website.', - learnMoreUrl: '', - imageUrl: '' - } - ]; - try { - for await (const feature of features) { - const payload = Object.values(feature); - if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { - payload.push(uuidV4()); - await queryRunner.connection.manager.query(` + const date = isSQlite ? Date.now() : new Date(); + const features = [ + { + icon: 'cube-outline', + title: 'New CRM', + date, + isFeature: isSQlite ? 1 : true, + content: 'Now you can read latest features changelog directly in Gauzy', + learnMoreUrl: '', + imageUrl: 'assets/images/features/macbook-2.png' + }, + { + icon: 'globe-outline', + title: 'Most popular in 20 countries', + date, + isFeature: isSQlite ? 1 : true, + content: 'Europe, Americas and Asia get choise', + learnMoreUrl: '', + imageUrl: 'assets/images/features/macbook-1.png' + }, + { + icon: 'flash-outline', + title: 'Visit our website', + date, + isFeature: isSQlite ? 1 : true, + content: 'You are welcome to check more information about the platform at our official website.', + learnMoreUrl: '', + imageUrl: '' + } + ]; + try { + for await (const feature of features) { + const payload = Object.values(feature); + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + payload.push(uuidV4()); + await queryRunner.connection.manager.query( + ` INSERT INTO "changelog" ("icon", "title", "date", "isFeature", "content", "learnMoreUrl", "imageUrl", "id") VALUES(?, ?, ?, ?, ?, ?, ?, ?)`, - payload - ); - } else { - await queryRunner.connection.manager.query(` + payload + ); + } else { + await queryRunner.connection.manager.query( + ` INSERT INTO "changelog" ("icon", "title", "date", "isFeature", "content", "learnMoreUrl", "imageUrl") VALUES($1, $2, $3, $4, $5, $6, $7)`, - payload - ); - } - } - } catch (error) { - // since we have errors let's rollback changes we made - console.log('Error while insert changelog changes in production server', error); - } - } + payload + ); + } + } + } catch (error) { + // since we have errors let's rollback changes we made + console.log('Error while insert changelog changes in production server', error); + } + } - public async down(queryRunner: QueryRunner): Promise { - - } + public async down(queryRunner: QueryRunner): Promise {} } diff --git a/packages/core/src/database/migrations/1674044473393-SeedDefaultGlobalTaskStatus.ts b/packages/core/src/database/migrations/1674044473393-SeedDefaultGlobalTaskStatus.ts index 4c1306ce52d..da29f554695 100644 --- a/packages/core/src/database/migrations/1674044473393-SeedDefaultGlobalTaskStatus.ts +++ b/packages/core/src/database/migrations/1674044473393-SeedDefaultGlobalTaskStatus.ts @@ -1,42 +1,51 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; -import * as chalk from "chalk"; +import { MigrationInterface, QueryRunner } from 'typeorm'; +import * as chalk from 'chalk'; import { v4 as uuidV4 } from 'uuid'; -import { DEFAULT_GLOBAL_STATUSES } from "./../../tasks/statuses/default-global-statuses"; +import { DEFAULT_GLOBAL_STATUSES } from './../../tasks/statuses/default-global-statuses'; export class SeedDefaultGlobalTaskStatus1674044473393 implements MigrationInterface { + name = 'SeedDefaultGlobalTaskStatus1674044473393'; - name = 'SeedDefaultGlobalTaskStatus1674044473393'; + /** + * Up Migration + * + * @param queryRunner + */ + public async up(queryRunner: QueryRunner): Promise { + console.log(chalk.yellow(this.name + ' start running!')); - /** - * Up Migration - * - * @param queryRunner - */ - public async up(queryRunner: QueryRunner): Promise { - console.log(chalk.yellow(this.name + ' start running!')); + try { + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + const DEFAULT_GLOBAL_STATUSES_SQLITE = DEFAULT_GLOBAL_STATUSES.map((status) => { + return { + ...status, + isSystem: 1 // Transform boolean true to integer 1 + }; + }); - try { - for await (const status of DEFAULT_GLOBAL_STATUSES) { - const payload = Object.values(status); - if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { - payload.push(uuidV4()); - const query = `INSERT INTO "status" ("name", "value", "description", "icon", "color", "isSystem", "id") VALUES(?, ?, ?, ?, ?, ?, ?)`; - await queryRunner.connection.manager.query(query, payload); - } else { - const query = `INSERT INTO "status" ("name", "value", "description", "icon", "color", "isSystem") VALUES($1, $2, $3, $4, $5, $6)`; - await queryRunner.connection.manager.query(query, payload); - } - } - } catch (error) { - // since we have errors let's rollback changes we made - console.log('Error while insert default global task statuses in production server', error); - } - } + for await (const status of DEFAULT_GLOBAL_STATUSES_SQLITE) { + const payload = Object.values(status); + payload.push(uuidV4()); + const query = `INSERT INTO "status" ("name", "value", "description", "icon", "color", "isSystem", "id") VALUES(?, ?, ?, ?, ?, ?, ?)`; + await queryRunner.connection.manager.query(query, payload); + } + } else { + for await (const status of DEFAULT_GLOBAL_STATUSES) { + const payload = Object.values(status); + const query = `INSERT INTO "status" ("name", "value", "description", "icon", "color", "isSystem") VALUES($1, $2, $3, $4, $5, $6)`; + await queryRunner.connection.manager.query(query, payload); + } + } + } catch (error) { + // since we have errors let's rollback changes we made + console.log('Error while insert default global task statuses in production server', error); + } + } - /** - * Down Migration - * - * @param queryRunner - */ - public async down(queryRunner: QueryRunner): Promise { } + /** + * Down Migration + * + * @param queryRunner + */ + public async down(queryRunner: QueryRunner): Promise {} } diff --git a/packages/core/src/database/migrations/1674638501088-SeedDefaultGlobalTaskPriorityAndSize.ts b/packages/core/src/database/migrations/1674638501088-SeedDefaultGlobalTaskPriorityAndSize.ts index efaf084326e..f62f864e0d0 100644 --- a/packages/core/src/database/migrations/1674638501088-SeedDefaultGlobalTaskPriorityAndSize.ts +++ b/packages/core/src/database/migrations/1674638501088-SeedDefaultGlobalTaskPriorityAndSize.ts @@ -1,77 +1,96 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; -import * as chalk from "chalk"; +import { MigrationInterface, QueryRunner } from 'typeorm'; +import * as chalk from 'chalk'; import { v4 as uuidV4 } from 'uuid'; -import { DEFAULT_GLOBAL_PRIORITIES } from "./../../tasks/priorities/default-global-priorities"; -import { DEFAULT_GLOBAL_SIZES } from "./../../tasks/sizes/default-global-sizes"; +import { DEFAULT_GLOBAL_PRIORITIES } from './../../tasks/priorities/default-global-priorities'; +import { DEFAULT_GLOBAL_SIZES } from './../../tasks/sizes/default-global-sizes'; export class SeedDefaultGlobalTaskPriorityAndSize1674638501088 implements MigrationInterface { + name = 'SeedDefaultGlobalTaskPriorityAndSize1674638501088'; - name = 'SeedDefaultGlobalTaskPriorityAndSize1674638501088'; + /** + * Up Migration + * + * @param queryRunner + */ + public async up(queryRunner: QueryRunner): Promise { + console.log(chalk.yellow(this.name + ' start running!')); - /** - * Up Migration - * - * @param queryRunner - */ - public async up(queryRunner: QueryRunner): Promise { - console.log(chalk.yellow(this.name + ' start running!')); + await this.seedDefaultTaskPriorities(queryRunner); + await this.seedDefaultTaskSizes(queryRunner); + } - await this.seedDefaultTaskPriorities(queryRunner); - await this.seedDefaultTaskSizes(queryRunner); - } + /** + * Down Migration + * + * @param queryRunner + */ + public async down(queryRunner: QueryRunner): Promise {} - /** - * Down Migration - * - * @param queryRunner - */ - public async down(queryRunner: QueryRunner): Promise { } + /** + * Default global task priorities + * + * @param queryRunner + */ + async seedDefaultTaskPriorities(queryRunner: QueryRunner) { + try { + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + const DEFAULT_GLOBAL_PRIORITIES_SQLITE = DEFAULT_GLOBAL_PRIORITIES.map((priority) => { + return { + ...priority, + isSystem: 1 // Transform boolean true to integer 1 + }; + }); - /** - * Default global task priorities - * - * @param queryRunner - */ - async seedDefaultTaskPriorities(queryRunner: QueryRunner) { - try { - for await (const priority of DEFAULT_GLOBAL_PRIORITIES) { - const payload = Object.values(priority); - if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { - payload.push(uuidV4()); - const query = `INSERT INTO "task_priority" ("name", "value", "description", "icon", "color", "isSystem", "id") VALUES(?, ?, ?, ?, ?, ?, ?)`; - await queryRunner.connection.manager.query(query, payload); - } else { - const query = `INSERT INTO "task_priority" ("name", "value", "description", "icon", "color", "isSystem") VALUES($1, $2, $3, $4, $5, $6)`; - await queryRunner.connection.manager.query(query, payload); - } - } - } catch (error) { - // since we have errors let's rollback changes we made - console.log('Error while insert default global task priorities in production server', error); - } - } + for await (const priority of DEFAULT_GLOBAL_PRIORITIES_SQLITE) { + const payload = Object.values(priority); + payload.push(uuidV4()); + const query = `INSERT INTO "task_priority" ("name", "value", "description", "icon", "color", "isSystem", "id") VALUES(?, ?, ?, ?, ?, ?, ?)`; + await queryRunner.connection.manager.query(query, payload); + } + } else { + for await (const priority of DEFAULT_GLOBAL_PRIORITIES) { + const payload = Object.values(priority); + const query = `INSERT INTO "task_priority" ("name", "value", "description", "icon", "color", "isSystem") VALUES($1, $2, $3, $4, $5, $6)`; + await queryRunner.connection.manager.query(query, payload); + } + } + } catch (error) { + // since we have errors let's rollback changes we made + console.log('Error while insert default global task priorities in production server', error); + } + } - /** - * Default global task sizes - * - * @param queryRunner - */ - async seedDefaultTaskSizes(queryRunner: QueryRunner) { - try { - for await (const size of DEFAULT_GLOBAL_SIZES) { - const payload = Object.values(size); - if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { - payload.push(uuidV4()); - const query = `INSERT INTO "task_size" ("name", "value", "description", "icon", "color", "isSystem", "id") VALUES(?, ?, ?, ?, ?, ?, ?)`; - await queryRunner.connection.manager.query(query, payload); - } else { - const query = `INSERT INTO "task_size" ("name", "value", "description", "icon", "color", "isSystem") VALUES($1, $2, $3, $4, $5, $6)`; - await queryRunner.connection.manager.query(query, payload); - } - } - } catch (error) { - // since we have errors let's rollback changes we made - console.log('Error while insert default global task sizes in production server', error); - } - } + /** + * Default global task sizes + * + * @param queryRunner + */ + async seedDefaultTaskSizes(queryRunner: QueryRunner) { + try { + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + const DEFAULT_GLOBAL_SIZES_SQLITE = DEFAULT_GLOBAL_SIZES.map((priority) => { + return { + ...priority, + isSystem: 1 // Transform boolean true to integer 1 + }; + }); + + for await (const size of DEFAULT_GLOBAL_SIZES_SQLITE) { + const payload = Object.values(size); + payload.push(uuidV4()); + const query = `INSERT INTO "task_size" ("name", "value", "description", "icon", "color", "isSystem", "id") VALUES(?, ?, ?, ?, ?, ?, ?)`; + await queryRunner.connection.manager.query(query, payload); + } + } else { + for await (const size of DEFAULT_GLOBAL_SIZES) { + const payload = Object.values(size); + const query = `INSERT INTO "task_size" ("name", "value", "description", "icon", "color", "isSystem") VALUES($1, $2, $3, $4, $5, $6)`; + await queryRunner.connection.manager.query(query, payload); + } + } + } catch (error) { + // since we have errors let's rollback changes we made + console.log('Error while insert default global task sizes in production server', error); + } + } } diff --git a/packages/core/src/database/migrations/1680622389221-SeedDafaultGlobalIssueType.ts b/packages/core/src/database/migrations/1680622389221-SeedDafaultGlobalIssueType.ts index e0ce0a073ea..86577781d83 100644 --- a/packages/core/src/database/migrations/1680622389221-SeedDafaultGlobalIssueType.ts +++ b/packages/core/src/database/migrations/1680622389221-SeedDafaultGlobalIssueType.ts @@ -1,5 +1,5 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; -import * as chalk from "chalk"; +import * as chalk from 'chalk'; import { v4 as uuidv4 } from 'uuid'; import * as path from 'path'; import * as fs from 'fs'; @@ -10,7 +10,6 @@ import { copyAssets } from './../../core/seeds/utils'; import { DEFAULT_GLOBAL_ISSUE_TYPES } from './../../tasks/issue-type/default-global-issue-types'; export class SeedDafaultGlobalIssueType1680622389221 implements MigrationInterface { - private config = getConfig(); name = 'SeedDafaultGlobalIssueType1680622389221'; @@ -30,7 +29,7 @@ export class SeedDafaultGlobalIssueType1680622389221 implements MigrationInterfa * * @param queryRunner */ - public async down(queryRunner: QueryRunner): Promise { } + public async down(queryRunner: QueryRunner): Promise {} /** * Default global issue types @@ -50,25 +49,11 @@ export class SeedDafaultGlobalIssueType1680622389221 implements MigrationInterfa const { height, width } = imageSize(iconPath); const { size } = fs.statSync(iconPath); - const imageAsset = [ - name, - filepath, - FileStorageProviderEnum.LOCAL, - height, - width, - size - ]; - - const payload = [ - name, - value, - description, - filepath, - color, - isSystem - ]; + const imageAsset = [name, filepath, FileStorageProviderEnum.LOCAL, height, width, size]; if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + const payload = [name, value, description, filepath, color, isSystem ? 1 : 0]; + const imageAssetId = uuidv4(); imageAsset.push(imageAssetId); @@ -80,16 +65,23 @@ export class SeedDafaultGlobalIssueType1680622389221 implements MigrationInterfa ?, ?, ?, ?, ?, ?, ? ); `; + await queryRunner.connection.manager.query(insertQuery, imageAsset); payload.push(uuidv4(), imageAssetId); - await queryRunner.connection.manager.query(` + + await queryRunner.connection.manager.query( + ` INSERT INTO "issue_type" ( "name", "value", "description", "icon", "color", "isSystem", "id", "imageId" ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?); - `, payload); + `, + payload + ); } else { + const payload = [name, value, description, filepath, color, isSystem]; + const insertQuery = ` INSERT INTO "image_asset" ( "name", "url", "storageProvider", "height", "width", "size" @@ -102,13 +94,16 @@ export class SeedDafaultGlobalIssueType1680622389221 implements MigrationInterfa const imageAssetId = image_asset[0]['id']; payload.push(imageAssetId); - await queryRunner.connection.manager.query(` + await queryRunner.connection.manager.query( + ` INSERT INTO "issue_type" ( "name", "value", "description", "icon", "color", "isSystem", "imageId" ) VALUES ( $1, $2, $3, $4, $5, $6, $7 ); - `, payload); + `, + payload + ); } } } catch (error) { diff --git a/packages/core/src/database/migrations/1691494801748-SeedIntegrationTable.ts b/packages/core/src/database/migrations/1691494801748-SeedIntegrationTable.ts index c59267e03c7..bc976928b82 100644 --- a/packages/core/src/database/migrations/1691494801748-SeedIntegrationTable.ts +++ b/packages/core/src/database/migrations/1691494801748-SeedIntegrationTable.ts @@ -1,52 +1,53 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; +import { MigrationInterface, QueryRunner } from 'typeorm'; import { v4 as uuidv4 } from 'uuid'; import * as chalk from 'chalk'; -import { getConfig } from "@gauzy/config"; -import { copyAssets } from "./../../core/seeds/utils"; -import { DEFAULT_SYSTEM_INTEGRATIONS } from "./../../integration/default-integration"; -import { IntegrationsUtils } from "./../../integration/utils"; +import { getConfig } from '@gauzy/config'; +import { copyAssets } from './../../core/seeds/utils'; +import { DEFAULT_SYSTEM_INTEGRATIONS } from './../../integration/default-integration'; +import { IntegrationsUtils } from './../../integration/utils'; export class SeedIntegrationTable1691494801748 implements MigrationInterface { + name = 'SeedIntegrationTable1691494801748'; - name = 'SeedIntegrationTable1691494801748'; - - /** - * Up Migration - * - * @param queryRunner - */ - public async up(queryRunner: QueryRunner): Promise { - console.log(chalk.yellow(this.name + ' start running!')); - - await this.upsertIntegrationsAndIntegrationTypes(queryRunner); - } - - /** - * Down Migration - * - * @param queryRunner - */ - public async down(queryRunner: QueryRunner): Promise { } - - /** - * - * @param queryRunner - */ - public async upsertIntegrationsAndIntegrationTypes(queryRunner: QueryRunner): Promise { - const destDir = 'integrations'; - - for await (const { name, imgSrc, isComingSoon, order, integrationTypesMap } of DEFAULT_SYSTEM_INTEGRATIONS) { - try { - const filepath = `integrations/${imgSrc}`; - - let upsertQuery = ``; - const payload = [name, filepath, isComingSoon, order]; - - if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { - // For SQLite, manually generate a UUID using uuidv4() - const generatedId = uuidv4(); payload.push(generatedId); - - upsertQuery = ` + /** + * Up Migration + * + * @param queryRunner + */ + public async up(queryRunner: QueryRunner): Promise { + console.log(chalk.yellow(this.name + ' start running!')); + + await this.upsertIntegrationsAndIntegrationTypes(queryRunner); + } + + /** + * Down Migration + * + * @param queryRunner + */ + public async down(queryRunner: QueryRunner): Promise {} + + /** + * + * @param queryRunner + */ + public async upsertIntegrationsAndIntegrationTypes(queryRunner: QueryRunner): Promise { + const destDir = 'integrations'; + + for await (const { name, imgSrc, isComingSoon, order, integrationTypesMap } of DEFAULT_SYSTEM_INTEGRATIONS) { + try { + const filepath = `integrations/${imgSrc}`; + + let upsertQuery = ``; + + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + const payload = [name, filepath, isComingSoon ? 1 : 0, order]; + + // For SQLite, manually generate a UUID using uuidv4() + const generatedId = uuidv4(); + payload.push(generatedId); + + upsertQuery = ` INSERT INTO "integration" ("name", "imgSrc", "isComingSoon", "order", "id") VALUES (?, ?, ?, ?, ?) ON CONFLICT ("name") @@ -55,8 +56,18 @@ export class SeedIntegrationTable1691494801748 implements MigrationInterface { "order" = EXCLUDED."order" RETURNING "id"; `; - } else { - upsertQuery = ` + + const [integration] = await queryRunner.query(upsertQuery, payload); + + await IntegrationsUtils.syncIntegrationType( + queryRunner, + integration, + await IntegrationsUtils.getIntegrationTypeByName(queryRunner, integrationTypesMap) + ); + } else { + const payload = [name, filepath, isComingSoon, order]; + + upsertQuery = ` INSERT INTO "integration" ( "name", "imgSrc", "isComingSoon", "order" ) @@ -70,22 +81,22 @@ export class SeedIntegrationTable1691494801748 implements MigrationInterface { "order" = $4 RETURNING id; `; - } - - const [integration] = await queryRunner.query(upsertQuery, payload); - - // Step 3: Insert entry in join table to associate Integration with IntegrationType - await IntegrationsUtils.syncIntegrationType( - queryRunner, - integration, - await IntegrationsUtils.getIntegrationTypeByName(queryRunner, integrationTypesMap) - ); - - copyAssets(imgSrc, getConfig(), destDir); - } catch (error) { - // since we have errors let's rollback changes we made - console.log(`Error while updating integration: (${name}) in production server`, error); - } - } - } + + const [integration] = await queryRunner.query(upsertQuery, payload); + + await IntegrationsUtils.syncIntegrationType( + queryRunner, + integration, + await IntegrationsUtils.getIntegrationTypeByName(queryRunner, integrationTypesMap) + ); + } + + // Step 3: Insert entry in join table to associate Integration with IntegrationType + copyAssets(imgSrc, getConfig(), destDir); + } catch (error) { + // since we have errors let's rollback changes we made + console.log(`Error while updating integration: (${name}) in production server`, error); + } + } + } } diff --git a/packages/core/src/database/migrations/1692171665427-SeedIntegrationTable.ts b/packages/core/src/database/migrations/1692171665427-SeedIntegrationTable.ts index acaa9d12760..9fe5095c657 100644 --- a/packages/core/src/database/migrations/1692171665427-SeedIntegrationTable.ts +++ b/packages/core/src/database/migrations/1692171665427-SeedIntegrationTable.ts @@ -1,52 +1,53 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; +import { MigrationInterface, QueryRunner } from 'typeorm'; import { v4 as uuidv4 } from 'uuid'; -import { getConfig } from "@gauzy/config"; +import { getConfig } from '@gauzy/config'; import * as chalk from 'chalk'; -import { copyAssets } from "./../../core/seeds/utils"; -import { DEFAULT_AI_INTEGRATIONS } from "./../../integration/default-integration"; -import { IntegrationsUtils } from "./../../integration/utils"; +import { copyAssets } from './../../core/seeds/utils'; +import { DEFAULT_AI_INTEGRATIONS } from './../../integration/default-integration'; +import { IntegrationsUtils } from './../../integration/utils'; export class SeedIntegrationTable1692171665427 implements MigrationInterface { + name = 'SeedIntegrationTable1692171665427'; - name = 'SeedIntegrationTable1692171665427'; - - /** - * Up Migration - * - * @param queryRunner - */ - public async up(queryRunner: QueryRunner): Promise { - console.log(chalk.yellow(this.name + ' start running!')); - - await this.upsertIntegrationsAndIntegrationTypes(queryRunner); - } - - /** - * Down Migration - * - * @param queryRunner - */ - public async down(queryRunner: QueryRunner): Promise { } - - /** - * - * @param queryRunner - */ - public async upsertIntegrationsAndIntegrationTypes(queryRunner: QueryRunner): Promise { - const destDir = 'integrations'; - - for await (const { name, imgSrc, isComingSoon, order, integrationTypesMap } of DEFAULT_AI_INTEGRATIONS) { - try { - const filepath = `integrations/${imgSrc}`; - - let upsertQuery = ``; - const payload = [name, filepath, isComingSoon, order]; - - if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { - // For SQLite, manually generate a UUID using uuidv4() - const generatedId = uuidv4(); payload.push(generatedId); - - upsertQuery = ` + /** + * Up Migration + * + * @param queryRunner + */ + public async up(queryRunner: QueryRunner): Promise { + console.log(chalk.yellow(this.name + ' start running!')); + + await this.upsertIntegrationsAndIntegrationTypes(queryRunner); + } + + /** + * Down Migration + * + * @param queryRunner + */ + public async down(queryRunner: QueryRunner): Promise {} + + /** + * + * @param queryRunner + */ + public async upsertIntegrationsAndIntegrationTypes(queryRunner: QueryRunner): Promise { + const destDir = 'integrations'; + + for await (const { name, imgSrc, isComingSoon, order, integrationTypesMap } of DEFAULT_AI_INTEGRATIONS) { + try { + const filepath = `integrations/${imgSrc}`; + + let upsertQuery = ``; + + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + const payload = [name, filepath, isComingSoon ? 1 : 0, order]; + + // For SQLite, manually generate a UUID using uuidv4() + const generatedId = uuidv4(); + payload.push(generatedId); + + upsertQuery = ` INSERT INTO "integration" ("name", "imgSrc", "isComingSoon", "order", "id") VALUES (?, ?, ?, ?, ?) ON CONFLICT ("name") @@ -55,8 +56,19 @@ export class SeedIntegrationTable1692171665427 implements MigrationInterface { "order" = EXCLUDED."order" RETURNING "id"; `; - } else { - upsertQuery = ` + + const [integration] = await queryRunner.query(upsertQuery, payload); + + // Step 3: Insert entry in join table to associate Integration with IntegrationType + await IntegrationsUtils.syncIntegrationType( + queryRunner, + integration, + await IntegrationsUtils.getIntegrationTypeByName(queryRunner, integrationTypesMap) + ); + } else { + const payload = [name, filepath, isComingSoon, order]; + + upsertQuery = ` INSERT INTO "integration" ( "name", "imgSrc", "isComingSoon", "order" ) @@ -70,22 +82,22 @@ export class SeedIntegrationTable1692171665427 implements MigrationInterface { "order" = $4 RETURNING id; `; - } - - const [integration] = await queryRunner.query(upsertQuery, payload); - - // Step 3: Insert entry in join table to associate Integration with IntegrationType - await IntegrationsUtils.syncIntegrationType( - queryRunner, - integration, - await IntegrationsUtils.getIntegrationTypeByName(queryRunner, integrationTypesMap) - ); - - copyAssets(imgSrc, getConfig(), destDir); - } catch (error) { - // since we have errors let's rollback changes we made - console.log(`Error while updating integration: (${name}) in production server`, error); - } - } - } + + const [integration] = await queryRunner.query(upsertQuery, payload); + + // Step 3: Insert entry in join table to associate Integration with IntegrationType + await IntegrationsUtils.syncIntegrationType( + queryRunner, + integration, + await IntegrationsUtils.getIntegrationTypeByName(queryRunner, integrationTypesMap) + ); + } + + copyAssets(imgSrc, getConfig(), destDir); + } catch (error) { + // since we have errors let's rollback changes we made + console.log(`Error while updating integration: (${name}) in production server`, error); + } + } + } } diff --git a/packages/core/src/health-indicator/health-indicator.module.ts b/packages/core/src/health-indicator/health-indicator.module.ts index 17b4002df7b..47b51a2dd10 100644 --- a/packages/core/src/health-indicator/health-indicator.module.ts +++ b/packages/core/src/health-indicator/health-indicator.module.ts @@ -4,6 +4,10 @@ import { HealthController } from './health.controller'; @Module({ controllers: [HealthController], - imports: [TerminusModule] + imports: [ + TerminusModule.forRoot({ + // gracefulShutdownTimeoutMs: 1000 + }) + ] }) export class HealthIndicatorModule {} diff --git a/packages/core/src/health-indicator/health.controller.ts b/packages/core/src/health-indicator/health.controller.ts index 08fb44724f7..e8e55437cb2 100644 --- a/packages/core/src/health-indicator/health.controller.ts +++ b/packages/core/src/health-indicator/health.controller.ts @@ -1,18 +1,21 @@ import { Public } from '@gauzy/common'; import { Controller, Get } from '@nestjs/common'; -import { HealthCheckService, TypeOrmHealthIndicator } from '@nestjs/terminus'; +import { HealthCheckService, TypeOrmHealthIndicator, DiskHealthIndicator } from '@nestjs/terminus'; +import * as path from 'path'; @Controller('health') export class HealthController { constructor( - private health: HealthCheckService, - private db: TypeOrmHealthIndicator + private readonly health: HealthCheckService, + private readonly db: TypeOrmHealthIndicator, + private readonly disk: DiskHealthIndicator ) {} @Public() @Get() check() { return this.health.check([ + () => this.disk.checkStorage('storage', { path: path.resolve(__dirname), thresholdPercent: 99.999999 }), // basically will fail if disk is full async () => this.db.pingCheck('database', { timeout: 300 }) ]); } diff --git a/packages/core/src/integration/utils.ts b/packages/core/src/integration/utils.ts index 6ff5d7c2aef..2076da2d07a 100644 --- a/packages/core/src/integration/utils.ts +++ b/packages/core/src/integration/utils.ts @@ -1,37 +1,37 @@ - -import { QueryRunner } from "typeorm"; +import { QueryRunner } from 'typeorm'; import { v4 as uuidv4 } from 'uuid'; -import { getConfig } from "@gauzy/config"; -import { IIntegration, IIntegrationType, IntegrationTypeEnum } from "@gauzy/contracts"; -import { copyAssets } from "./../core/seeds/utils"; -import { DEFAULT_INTEGRATION_TYPES } from "./default-integration-type"; +import { getConfig } from '@gauzy/config'; +import { IIntegration, IIntegrationType, IntegrationTypeEnum } from '@gauzy/contracts'; +import { copyAssets } from './../core/seeds/utils'; +import { DEFAULT_INTEGRATION_TYPES } from './default-integration-type'; export class IntegrationsUtils { - /** - * - * @param queryRunner - */ - public static async upsertIntegrationsAndIntegrationTypes(queryRunner: QueryRunner, integrations: any[]): Promise { - const destDir = 'integrations'; - for await (const { name, imgSrc, isComingSoon, order, redirectUrl, provider, integrationTypesMap } of integrations) { - try { - const filepath = `integrations/${imgSrc}`; + /** + * + * @param queryRunner + */ + public static async upsertIntegrationsAndIntegrationTypes( + queryRunner: QueryRunner, + integrations: any[] + ): Promise { + const destDir = 'integrations'; + for await (const { + name, + imgSrc, + isComingSoon, + order, + redirectUrl, + provider, + integrationTypesMap + } of integrations) { + try { + const filepath = `integrations/${imgSrc}`; let upsertQuery = ``; - const payload = [ - name, - filepath, - isComingSoon, - order, - redirectUrl, - provider, - ]; - if ( - ['sqlite', 'better-sqlite3'].includes( - queryRunner.connection.options.type - ) - ) { + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + const payload = [name, filepath, isComingSoon ? 1 : 0, order, redirectUrl, provider]; + // For SQLite, manually generate a UUID using uuidv4() const generatedId = uuidv4(); payload.push(generatedId); @@ -50,7 +50,18 @@ export class IntegrationsUtils { "provider" = EXCLUDED."provider" RETURNING id; `; + + const [integration] = await queryRunner.query(upsertQuery, payload); + + // Step 3: Insert entry in join table to associate Integration with IntegrationType + await IntegrationsUtils.syncIntegrationType( + queryRunner, + integration, + await this.getIntegrationTypeByName(queryRunner, integrationTypesMap) + ); } else { + const payload = [name, filepath, isComingSoon, order, redirectUrl, provider]; + upsertQuery = ` INSERT INTO "integration" ( "name", "imgSrc", "isComingSoon", "order", "redirectUrl", "provider" @@ -67,63 +78,61 @@ export class IntegrationsUtils { "provider" = $6 RETURNING id; `; - } - const [integration] = await queryRunner.query(upsertQuery, payload); - // Step 3: Insert entry in join table to associate Integration with IntegrationType - await IntegrationsUtils.syncIntegrationType( - queryRunner, - integration, - await this.getIntegrationTypeByName(queryRunner, integrationTypesMap) - ); + const [integration] = await queryRunner.query(upsertQuery, payload); + + // Step 3: Insert entry in join table to associate Integration with IntegrationType + await IntegrationsUtils.syncIntegrationType( + queryRunner, + integration, + await this.getIntegrationTypeByName(queryRunner, integrationTypesMap) + ); + } - copyAssets(imgSrc, getConfig(), destDir); - } catch (error) { - // since we have errors let's rollback changes we made - console.log(`Error while updating integration: (${name}) in production server`, error); - } - } - } + copyAssets(imgSrc, getConfig(), destDir); + } catch (error) { + // since we have errors let's rollback changes we made + console.log(`Error while updating integration: (${name}) in production server`, error); + } + } + } - /** - * - * @param queryRunner - * @param integrationTypesMap - * @returns - */ - public static async getIntegrationTypeByName( - queryRunner: QueryRunner, - integrationTypeNames: any[] - ): Promise { - try { - return await queryRunner.query(`SELECT * FROM "integration_type" WHERE "integration_type"."name" IN ('${integrationTypeNames.join("','")}')`); - } catch (error) { - console.log('Error while querying integration types:', error); - return []; - } - } + /** + * + * @param queryRunner + * @param integrationTypesMap + * @returns + */ + public static async getIntegrationTypeByName( + queryRunner: QueryRunner, + integrationTypeNames: any[] + ): Promise { + try { + return await queryRunner.query( + `SELECT * FROM "integration_type" WHERE "integration_type"."name" IN ('${integrationTypeNames.join( + "','" + )}')` + ); + } catch (error) { + console.log('Error while querying integration types:', error); + return []; + } + } - /** - * - * @param queryRunner - * @param integrationTypeName - */ - public static async upsertIntegrationTypes( - queryRunner: QueryRunner, - integrationTypeNames: IntegrationTypeEnum[] - ) { - for await (const integrationTypeName of integrationTypeNames) { - const { name, description, icon, groupName, order } = DEFAULT_INTEGRATION_TYPES.find( - (type) => type.name === integrationTypeName - ); - const payload = [name, description, icon, groupName, order]; + /** + * + * @param queryRunner + * @param integrationTypeName + */ + public static async upsertIntegrationTypes(queryRunner: QueryRunner, integrationTypeNames: IntegrationTypeEnum[]) { + for await (const integrationTypeName of integrationTypeNames) { + const { name, description, icon, groupName, order } = DEFAULT_INTEGRATION_TYPES.find( + (type) => type.name === integrationTypeName + ); + const payload = [name, description, icon, groupName, order]; let upsertQuery = ``; - if ( - ['sqlite', 'better-sqlite3'].includes( - queryRunner.connection.options.type - ) - ) { + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { // For SQLite, manually generate a UUID using uuidv4() const generatedId = uuidv4(); payload.push(generatedId); @@ -162,22 +171,22 @@ export class IntegrationsUtils { } } - /** - * - * - * @param queryRunner - * @param integration - * @param integrationTypes - */ - public static async syncIntegrationType( - queryRunner: QueryRunner, - integration: IIntegration, - integrationTypes: IIntegrationType[] - ) { - if (integration) { - const integrationId = integration.id; - for await (const integrationType of integrationTypes) { - let insertPivotQuery = ` + /** + * + * + * @param queryRunner + * @param integration + * @param integrationTypes + */ + public static async syncIntegrationType( + queryRunner: QueryRunner, + integration: IIntegration, + integrationTypes: IIntegrationType[] + ) { + if (integration) { + const integrationId = integration.id; + for await (const integrationType of integrationTypes) { + let insertPivotQuery = ` INSERT INTO "integration_integration_type" ( "integrationId", "integrationTypeId" @@ -199,10 +208,7 @@ export class IntegrationsUtils { `; } - await queryRunner.query(insertPivotQuery, [ - integrationId, - integrationType.id, - ]); + await queryRunner.query(insertPivotQuery, [integrationId, integrationType.id]); } } } diff --git a/packages/core/src/language/language-utils.ts b/packages/core/src/language/language-utils.ts index bf7c7f2bd22..3d588d1a7e7 100644 --- a/packages/core/src/language/language-utils.ts +++ b/packages/core/src/language/language-utils.ts @@ -6,20 +6,18 @@ import { faker } from '@faker-js/faker'; import { v4 as uuidV4 } from 'uuid'; export class LanguageUtils { - private static async addLanguages( - queryRunner: QueryRunner, - languages: ILanguage[] - ): Promise { + private static async addLanguages(queryRunner: QueryRunner, languages: ILanguage[]): Promise { for await (const language of languages) { const { name, code, is_system, description, color } = language; - const payload = [name, code, is_system, description, color]; + let insertOrUpdateQuery = ''; - if ( - ['sqlite', 'better-sqlite3'].includes( - queryRunner.connection.options.type - ) - ) { + if (['sqlite', 'better-sqlite3'].includes(queryRunner.connection.options.type)) { + const payload = [name, code, is_system ? 1 : 0, description, color]; + payload.push(uuidV4()); + + console.log('Inserting languages: ', JSON.stringify(payload)); + insertOrUpdateQuery = ` INSERT INTO language (name, code, is_system, description, color, id) VALUES (?, ?, ?, ?, ?, ?) @@ -30,7 +28,11 @@ export class LanguageUtils { description = EXCLUDED.description, color = EXCLUDED.color; `; + + await queryRunner.connection.manager.query(insertOrUpdateQuery, payload); } else { + const payload = [name, code, is_system, description, color]; + insertOrUpdateQuery = ` INSERT INTO language (name, code, is_system, description, color) VALUES ($1, $2, $3, $4, $5) @@ -41,11 +43,9 @@ export class LanguageUtils { description = EXCLUDED.description, color = EXCLUDED.color; `; + + await queryRunner.connection.manager.query(insertOrUpdateQuery, payload); } - await queryRunner.connection.manager.query( - insertOrUpdateQuery, - payload - ); } } @@ -67,9 +67,7 @@ export class LanguageUtils { return languages; } - public static async migrateLanguages( - queryRunner: QueryRunner - ): Promise { + public static async migrateLanguages(queryRunner: QueryRunner): Promise { await this.addLanguages(queryRunner, this.registeredLanguages); } } diff --git a/packages/desktop-libs/package.json b/packages/desktop-libs/package.json index 95463dde866..a4eea1c4dab 100644 --- a/packages/desktop-libs/package.json +++ b/packages/desktop-libs/package.json @@ -30,7 +30,7 @@ "@electron/remote": "^2.0.8", "@gauzy/desktop-window": "^0.1.0", "active-win": "^8.1.0", - "better-sqlite3": "^8.7.0", + "better-sqlite3": "^9.2.2", "electron-store": "^8.1.0", "electron-util": "^0.17.2", "embedded-queue": "^0.0.11", diff --git a/packages/plugins/changelog/package.json b/packages/plugins/changelog/package.json index 641a02095ae..7837074a645 100644 --- a/packages/plugins/changelog/package.json +++ b/packages/plugins/changelog/package.json @@ -40,8 +40,7 @@ "@nestjs/typeorm": "^9.0.1", "class-validator": "^0.14.0", "nest-router": "^1.0.9", - "typeorm": "0.3.7", - "typeorm-express-query-builder": "https://github.com/ever-co/typeorm-express-query-builder.git" + "typeorm": "^0.3.17" }, "devDependencies": { "@types/node": "^17.0.33", diff --git a/packages/plugins/integration-wakatime/package.json b/packages/plugins/integration-wakatime/package.json index 4940517588b..baf460a0ea3 100644 --- a/packages/plugins/integration-wakatime/package.json +++ b/packages/plugins/integration-wakatime/package.json @@ -31,7 +31,7 @@ "@gauzy/contracts": "^0.1.0", "@nestjs/common": "^9.2.1", "@nestjs/typeorm": "^9.0.1", - "typeorm": "0.3.7" + "typeorm": "^0.3.17" }, "devDependencies": { "@types/node": "^17.0.33", diff --git a/packages/plugins/knowledge-base/package.json b/packages/plugins/knowledge-base/package.json index cedf51b993a..23ef8b463e5 100644 --- a/packages/plugins/knowledge-base/package.json +++ b/packages/plugins/knowledge-base/package.json @@ -40,8 +40,7 @@ "@nestjs/typeorm": "^9.0.1", "class-validator": "^0.14.0", "nest-router": "^1.0.9", - "typeorm": "0.3.7", - "typeorm-express-query-builder": "https://github.com/ever-co/typeorm-express-query-builder.git" + "typeorm": "^0.3.17" }, "devDependencies": { "@types/node": "^17.0.33", diff --git a/packages/plugins/product-reviews/package.json b/packages/plugins/product-reviews/package.json index b5ec81592bf..7b8d50ee9d1 100644 --- a/packages/plugins/product-reviews/package.json +++ b/packages/plugins/product-reviews/package.json @@ -30,7 +30,7 @@ "dependencies": { "@gauzy/plugin": "^0.1.0", "apollo-server-core": "^3.10.1", - "typeorm": "0.3.7" + "typeorm": "^0.3.17" }, "devDependencies": { "@types/node": "^17.0.33", diff --git a/yarn.lock b/yarn.lock index 71ba3acbaad..9636f23a0ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9119,7 +9119,7 @@ resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz#96116f2a912e0c02817345b3c10751069920d553" integrity sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg== -"@sqltools/formatter@^1.2.2": +"@sqltools/formatter@^1.2.5": version "1.2.5" resolved "https://registry.yarnpkg.com/@sqltools/formatter/-/formatter-1.2.5.tgz#3abc203c79b8c3e90fd6c156a0c62d5403520e12" integrity sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw== @@ -11464,7 +11464,7 @@ app-builder-lib@24.9.1: tar "^6.1.12" temp-file "^3.4.0" -app-root-path@^3.0.0: +app-root-path@^3.0.0, app-root-path@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-3.1.0.tgz#5971a2fc12ba170369a7a1ef018c71e6e47c2e86" integrity sha512-biN3PwB2gUtjaYy/isrU3aNWI5w+fAfvHkSvCKeQGxhmYpwKFUxudR3Yya+KqVRHBmEDYh+/lTozYCFbmzX4nA== @@ -12594,10 +12594,10 @@ before-after-hook@^2.2.0: resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.2.3.tgz#c51e809c81a4e354084422b9b26bad88249c517c" integrity sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ== -better-sqlite3@^8.7.0: - version "8.7.0" - resolved "https://registry.yarnpkg.com/better-sqlite3/-/better-sqlite3-8.7.0.tgz#bcc341856187b1d110a8a47234fa89c48c8ef538" - integrity sha512-99jZU4le+f3G6aIl6PmmV0cxUIWqKieHxsiF7G34CVFiE+/UabpYqkU0NJIkY/96mQKikHeBjtR27vFfs5JpEw== +better-sqlite3@^9.2.2: + version "9.2.2" + resolved "https://registry.yarnpkg.com/better-sqlite3/-/better-sqlite3-9.2.2.tgz#3ce1ed24f327ed8c9b0c39b825cdc2341aeb249f" + integrity sha512-qwjWB46il0lsDkeB4rSRI96HyDQr8sxeu1MkBVLMrwusq1KRu4Bpt1TMI+8zIJkDUtZ3umjAkaEjIlokZKWCQw== dependencies: bindings "^1.5.0" prebuild-install "^7.1.1" @@ -16460,7 +16460,7 @@ date-easter@^0.2.5: resolved "https://registry.yarnpkg.com/date-easter/-/date-easter-0.2.5.tgz#85ddce23ee4e08b7b71fd3420c89d3d3576bec2f" integrity sha512-pMvZSqQgPBqnUQEHhRMy7f8Dk3KYY/NPFMFHGK4mU+xM1+SX+zc9IoQMcNtS3HuJjCn3mp0GQwBzsZXz3Thjww== -date-fns@^2.0.1, date-fns@^2.28.0: +date-fns@^2.0.1, date-fns@^2.28.0, date-fns@^2.29.3: version "2.30.0" resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0" integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw== @@ -17262,7 +17262,7 @@ dotenv@16.1.4: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.1.4.tgz#67ac1a10cd9c25f5ba604e4e08bc77c0ebe0ca8c" integrity sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw== -dotenv@^16.0.0, dotenv@^16.0.3: +dotenv@^16.0.3: version "16.3.1" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== @@ -27580,11 +27580,16 @@ mkdirp@1.0.4, mkdirp@1.x, mkdirp@^1.0.3, mkdirp@^1.0.4, mkdirp@~1.0.4: dependencies: minimist "^1.2.6" -mkdirp@^2.1.6: +mkdirp@^2.1.3, mkdirp@^2.1.6: version "2.1.6" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.6.tgz#964fbcb12b2d8c5d6fbc62a963ac95a273e2cc19" integrity sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A== +mkdirp@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-3.0.1.tgz#e44e4c5607fb279c168241713cc6e0fea9adcb50" + integrity sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg== + mnemonist@0.38.3: version "0.38.3" resolved "https://registry.yarnpkg.com/mnemonist/-/mnemonist-0.38.3.tgz#35ec79c1c1f4357cfda2fe264659c2775ccd7d9d" @@ -30629,7 +30634,7 @@ pg-protocol@*, pg-protocol@^1.6.0: resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.6.0.tgz#4c91613c0315349363af2084608db843502f8833" integrity sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q== -pg-query-stream@^4.2.4: +pg-query-stream@^4.5.3: version "4.5.3" resolved "https://registry.yarnpkg.com/pg-query-stream/-/pg-query-stream-4.5.3.tgz#841ce414064d7b14bd2540d2267bdf40779d26f2" integrity sha512-ufa94r/lHJdjAm3+zPZEO0gXAmCb4tZPaOt7O76mjcxdL/HxwTuryy76km+u0odBBgtfdKFYq/9XGfiYeQF0yA== @@ -30660,7 +30665,7 @@ pg-types@^4.0.1: postgres-interval "^3.0.0" postgres-range "^1.1.1" -pg@^8.8.0: +pg@^8.11.3: version "8.11.3" resolved "https://registry.yarnpkg.com/pg/-/pg-8.11.3.tgz#d7db6e3fe268fcedd65b8e4599cda0b8b4bf76cb" integrity sha512-+9iuvG8QfaaUrrph+kpF24cXkH1YOOUeArRNYIxq1viYHZagBxrTno7cecY1Fa44tJeZvaoG+Djpkc3JwehN5g== @@ -36915,32 +36920,26 @@ typeface-exo@^0.0.61: resolved "https://registry.yarnpkg.com/typeface-exo/-/typeface-exo-0.0.61.tgz#10c6113292da354cb9f26ee9d0b0c996f1a7a3bd" integrity sha512-AH3bMVYnVpg2G+CJbgtogTuJpWGS0zspHJzzVR8cCgTtkbUI0pj8WBB+RFo14CHbF5MmZgYe7TVoWz+j4Yo6Jg== -"typeorm-express-query-builder@https://github.com/ever-co/typeorm-express-query-builder.git": - version "1.5.1" - resolved "https://github.com/ever-co/typeorm-express-query-builder.git#b6b20e53f44b8f6639af1d2c124e9968b4b5d6a8" - -typeorm@0.3.7: - version "0.3.7" - resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.3.7.tgz#5776ed5058f0acb75d64723b39ff458d21de64c1" - integrity sha512-MsPJeP6Zuwfe64c++l80+VRqpGEGxf0CkztIEnehQ+CMmQPSHjOnFbFxwBuZ2jiLqZTjLk2ZqQdVF0RmvxNF3Q== +typeorm@^0.3.17: + version "0.3.17" + resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.3.17.tgz#a73c121a52e4fbe419b596b244777be4e4b57949" + integrity sha512-UDjUEwIQalO9tWw9O2A4GU+sT3oyoUXheHJy4ft+RFdnRdQctdQ34L9SqE2p7LdwzafHx1maxT+bqXON+Qnmig== dependencies: - "@sqltools/formatter" "^1.2.2" - app-root-path "^3.0.0" + "@sqltools/formatter" "^1.2.5" + app-root-path "^3.1.0" buffer "^6.0.3" - chalk "^4.1.0" + chalk "^4.1.2" cli-highlight "^2.1.11" - date-fns "^2.28.0" - debug "^4.3.3" - dotenv "^16.0.0" - glob "^7.2.0" - js-yaml "^4.1.0" - mkdirp "^1.0.4" + date-fns "^2.29.3" + debug "^4.3.4" + dotenv "^16.0.3" + glob "^8.1.0" + mkdirp "^2.1.3" reflect-metadata "^0.1.13" sha.js "^2.4.11" - tslib "^2.3.1" - uuid "^8.3.2" - xml2js "^0.4.23" - yargs "^17.3.1" + tslib "^2.5.0" + uuid "^9.0.0" + yargs "^17.6.2" typescript@4.5.5: version "4.5.5" @@ -38567,7 +38566,7 @@ xml-parse-from-string@^1.0.0: resolved "https://registry.yarnpkg.com/xml-parse-from-string/-/xml-parse-from-string-1.0.1.tgz#a9029e929d3dbcded169f3c6e28238d95a5d5a28" integrity sha512-ErcKwJTF54uRzzNMXq2X5sMIy88zJvfN2DmdoQvy7PAFJ+tPRU6ydWuOKNMyfmOjdyBQTFREi60s0Y0SyI0G0g== -xml2js@^0.4.17, xml2js@^0.4.23, xml2js@^0.4.5, xml2js@~0.4.23: +xml2js@^0.4.17, xml2js@^0.4.5, xml2js@~0.4.23: version "0.4.23" resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.23.tgz#a0c69516752421eb2ac758ee4d4ccf58843eac66" integrity sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug== @@ -38872,7 +38871,7 @@ yargs@^16.0.0, yargs@^16.1.0, yargs@^16.2.0: y18n "^5.0.5" yargs-parser "^20.2.2" -yargs@^17.0.0, yargs@^17.0.1, yargs@^17.2.1, yargs@^17.3.1, yargs@^17.4.0, yargs@^17.5.0, yargs@^17.5.1, yargs@^17.6.2, yargs@^17.7.2: +yargs@^17.0.0, yargs@^17.0.1, yargs@^17.2.1, yargs@^17.4.0, yargs@^17.5.0, yargs@^17.5.1, yargs@^17.6.2, yargs@^17.7.2: version "17.7.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269" integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==