diff --git a/packages/nc-gui/components/smartsheet/Form.vue b/packages/nc-gui/components/smartsheet/Form.vue index 35b0d0a77f..36ab5528f9 100644 --- a/packages/nc-gui/components/smartsheet/Form.vue +++ b/packages/nc-gui/components/smartsheet/Form.vue @@ -484,7 +484,7 @@ async function handleAddOrRemoveAllColumns(value: T) { async function checkSMTPStatus() { if (emailMe.value && !isEeUI) { - const emailPluginActive = await $api.plugin.status('SMTP') + const emailPluginActive = await $api.plugin.status('smtp') if (!emailPluginActive) { emailMe.value = false // Please activate SMTP plugin in App store for enabling email notification diff --git a/packages/nc-gui/composables/useNocoAi.ts b/packages/nc-gui/composables/useNocoAi.ts index 8797addeda..7e36307c75 100644 --- a/packages/nc-gui/composables/useNocoAi.ts +++ b/packages/nc-gui/composables/useNocoAi.ts @@ -348,9 +348,17 @@ export const useNocoAi = createSharedComposable(() => { } } - onMounted(() => { - loadAiIntegrations() - }) + const { signedIn } = useGlobal() + + watch( + signedIn, + (val) => { + if (val) { + loadAiIntegrations() + } + }, + { immediate: true }, + ) return { aiIntegrationAvailable, diff --git a/packages/noco-docs/versioned_docs/version-0.109.7/040.developer-resources/020.rest-apis.md b/packages/noco-docs/versioned_docs/version-0.109.7/040.developer-resources/020.rest-apis.md index 1452a04855..fb0bb3a5c3 100644 --- a/packages/noco-docs/versioned_docs/version-0.109.7/040.developer-resources/020.rest-apis.md +++ b/packages/noco-docs/versioned_docs/version-0.109.7/040.developer-resources/020.rest-apis.md @@ -76,117 +76,117 @@ Currently, the default value for `{orgs}` is noco. Users will be able to ### Meta APIs -| Category | Method | Tag | Function Name | Path | -|---|---|---|---|---| -| Meta | Get | apiToken | list | /api/v1/db/meta/projects/`{projectId}`/api-tokens | -| Meta | Post | apiToken | create | /api/v1/db/meta/projects/`{projectId}`/api-tokens | -| Meta | Delete| apiToken | delete | /api/v1/db/meta/projects/`{projectId}`/api-tokens/`{token}` | -| Meta | Get | auth | projectUserList | /api/v1/db/meta/projects/`{projectId}`/users | -| Meta | Post | auth | projectUserAdd | /api/v1/db/meta/projects/`{projectId}`/users | -| Meta | Patch | auth | projectUserUpdate | /api/v1/db/meta/projects/`{projectId}`/users/`{userId}` | -| Meta | Delete| auth | projectUserRemove | /api/v1/db/meta/projects/`{projectId}`/users/`{userId}` | +| Category | Method | Tag | Function Name | Path | +|---|---|---|---|-----------------------------------------------------------------------| +| Meta | Get | apiToken | list | /api/v1/db/meta/projects/`{projectId}`/api-tokens | +| Meta | Post | apiToken | create | /api/v1/db/meta/projects/`{projectId}`/api-tokens | +| Meta | Delete| apiToken | delete | /api/v1/db/meta/projects/`{projectId}`/api-tokens/`{token}` | +| Meta | Get | auth | projectUserList | /api/v1/db/meta/projects/`{projectId}`/users | +| Meta | Post | auth | projectUserAdd | /api/v1/db/meta/projects/`{projectId}`/users | +| Meta | Patch | auth | projectUserUpdate | /api/v1/db/meta/projects/`{projectId}`/users/`{userId}` | +| Meta | Delete| auth | projectUserRemove | /api/v1/db/meta/projects/`{projectId}`/users/`{userId}` | | Meta | Post | auth | projectUserResendInvite | /api/v1/db/meta/projects/`{projectId}`/users/`{userId}`/resend-invite | -| Meta | Post | dbTable | create | /api/v1/db/meta/projects/`{projectId}`/tables | -| Meta | Get | dbTable | list | /api/v1/db/meta/projects/`{projectId}`/tables | -| Meta | Post | dbTableColumn | create | /api/v1/db/meta/tables/`{tableId}`/columns | -| Meta | Patch | dbTableColumn | update | /api/v1/db/meta/tables/`{tableId}`/columns/`{columnId}` | -| Meta | Delete| dbTableColumn | delete | /api/v1/db/meta/tables/`{tableId}`/columns/`{columnId}` | -| Meta | Post | dbTableColumn | primaryColumnSet | /api/v1/db/meta/tables/`{tableId}`/columns/`{columnId}`/primary | -| Meta | Get | dbTableFilter | get | /api/v1/db/meta/filters/`{filterId}` | -| Meta | Patch | dbTableFilter | update | /api/v1/db/meta/filters/`{filterId}` | -| Meta | Delete| dbTableFilter | delete | /api/v1/db/meta/filters/`{filterId}` | -| Meta | Get | dbTableFilter | read | /api/v1/db/meta/views/`{viewId}`/filters | -| Meta | Post | dbTableFilter | create | /api/v1/db/meta/views/`{viewId}`/filters | -| Meta | Get | dbTableFilter | get | /api/v1/db/meta/filters/`{filterId}` | -| Meta | Patch | dbTableFilter | update | /api/v1/db/meta/filters/`{filterId}` | -| Meta | Delete| dbTableFilter | delete | /api/v1/db/meta/filters/`{filterId}` | -| Meta | Get | dbTableFilter | childrenRead | /api/v1/db/meta/filters/`{filterGroupId}`/children | -| Meta | Get | dbTableSort | list | /api/v1/db/meta/views/`{viewId}`/sorts | -| Meta | Post | dbTableSort | create | /api/v1/db/meta/views/`{viewId}`/sorts | -| Meta | Get | dbTableSort | read | /api/v1/db/meta/sorts/`{sortId}` | -| Meta | Patch | dbTableSort | update | /api/v1/db/meta/sorts/`{sortId}` | -| Meta | Delete| dbTableSort | delete | /api/v1/db/meta/sorts/`{sortId}`/api/v1/db | -| Meta | Patch | dbTableWebhook | update | /api/v1/db/meta/hooks/`{hookId}` | -| Meta | Delete| dbTableWebhook | delete | /api/v1/db/meta/hooks/`{hookId}` | -| Meta | Get | dbTableWebhook | list | /api/v1/db/meta/tables/`{tableId}`/hooks | -| Meta | Post | dbTableWebhook | create | /api/v1/db/meta/tables/`{tableId}`/hooks | -| Meta | Post | dbTableWebhook | test | /api/v1/db/meta/tables/`{tableId}`/hooks/test | -| Meta | Get | dbTableWebhook | samplePayloadGet | /api/v1/db/meta/tables/`{tableId}`/hooks/samplePayload/`{operation}` | -| Meta | Get | dbTableWebhookFilter | read | /api/v1/db/meta/hooks/`{hookId}`/filters | -| Meta | Post | dbTableWebhookFilter | create | /api/v1/db/meta/hooks/`{hookId}`/filters | -| Meta | Get | dbView | list | /api/v1/db/meta/tables/`{tableId}`/views | -| Meta | Get | dbView | read | /api/v1/db/meta/tables/`{tableId}` | -| Meta | Patch | dbView | update | /api/v1/db/meta/tables/`{tableId}` | -| Meta | Delete| dbView | delete | /api/v1/db/meta/tables/`{tableId}` | -| Meta | Post | dbView | reorder | /api/v1/db/meta/tables/`{tableId}`/reorder | -| Meta | Post | dbView | formCreate | /api/v1/db/meta/tables/`{tableId}`/forms | -| Meta | Patch | dbView | formUpdate | /api/v1/db/meta/forms/`{formViewId}` | -| Meta | Get | dbView | formRead | /api/v1/db/meta/forms/`{formViewId}` | -| Meta | Patch | dbView | formColumnUpdate | /api/v1/db/meta/form-columns/`{formViewColumnId}` | -| Meta | Post | dbView | galleryCreate | /api/v1/db/meta/tables/`{tableId}`/galleries | -| Meta | Patch | dbView | galleryUpdate | /api/v1/db/meta/galleries/`{galleryViewId}` | -| Meta | Get | dbView | galleryRead | /api/v1/db/meta/galleries/`{galleryViewId}` | -| Meta | Post | dbView | kanbanCreate | /api/v1/db/meta/tables/`{tableId}`/kanbans | -| Meta | Patch | dbView | kanbanUpdate | /api/v1/db/meta/kanban/`{kanbanViewId}` | -| Meta | Get | dbView | kanbanRead | /api/v1/db/meta/kanbans/`{kanbanViewId}` | -| Meta | Post | dbView | mapCreate | /api/v1/db/meta/tables/`{tableId}`/maps | -| Meta | Patch | dbView | mapUpdate | /api/v1/db/meta/maps/`{mapViewId}` | -| Meta | Get | dbView | mapRead | /api/v1/db/meta/maps/`{mapViewId}` | -| Meta | Post | dbView | gridCreate | /api/v1/db/meta/tables/`{tableId}`/grids | -| Meta | Get | dbView | gridColumnsList | /api/v1/db/meta/grids/`{gridId}`/grid-columns | -| Meta | Patch | dbView | gridColumnUpdate | /api/v1/db/meta/grid-columns/`{columnId}` | -| Meta | Patch | dbView | update | /api/v1/db/meta/views/`{viewId}` | -| Meta | Delete| dbView | delete | /api/v1/db/meta/views/`{viewId}` | -| Meta | Post | dbView | showAllColumn | /api/v1/db/meta/views/`{viewId}`/show-all | -| Meta | Post | dbView | hideAllColumn | /api/v1/db/meta/views/`{viewId}`/hide-all | -| Meta | Get | dbViewColumn | list | /api/v1/db/meta/views/`{viewId}`/columns | -| Meta | Post | dbViewColumn | create | /api/v1/db/meta/views/`{viewId}`/columns | -| Meta | Patch | dbViewColumn | update | /api/v1/db/meta/views/`{viewId}`/columns/`{columnId}` | -| Meta | Get | dbViewShare | list | /api/v1/db/meta/views/`{viewId}`/share | -| Meta | Post | dbViewShare | create | /api/v1/db/meta/views/`{viewId}`/share | -| Meta | Patch | dbViewShare | update | /api/v1/db/meta/views/`{viewId}`/share | -| Meta | Delete| dbViewShare | delete | /api/v1/db/meta/views/`{viewId}`/share | -| Meta | Get | plugin | list | /api/v1/db/meta/plugins | -| Meta | Get | plugin | status | /api/v1/db/meta/plugins/`{pluginTitle}`/status | -| Meta | Post | plugin | test | /api/v1/db/meta/plugins/test | -| Meta | PATCH | plugin | update | /api/v1/db/meta/plugins/`{pluginId}` | -| Meta | Get | plugin | read | /api/v1/db/meta/plugins/`{pluginId}` | -| Meta | Get | project | metaGet | /api/v1/db/meta/projects/`{projectId}`/info | -| Meta | Get | project | modelVisibilityList | /api/v1/db/meta/projects/`{projectId}`/visibility-rules | -| Meta | Post | project | modelVisibilitySet | /api/v1/db/meta/projects/`{projectId}`/visibility-rules | -| Meta | Get | project | list | /api/v1/db/meta/projects | -| Meta | Post | project | create | /api/v1/db/meta/projects | -| Meta | Get | project | read | /api/v1/db/meta/projects/`{projectId}` | -| Meta | Delete| project | delete | /api/v1/db/meta/projects/`{projectId}` | -| Meta | Get | project | auditList | /api/v1/db/meta/projects/`{projectId}`/audits | -| Meta | Get | project | metaDiffGet | /api/v1/db/meta/projects/`{projectId}`/meta-diff | -| Meta | Post | project | metaDiffSync | /api/v1/db/meta/projects/`{projectId}`/meta-diff | -| Meta | Get | project | sharedBaseGet | /api/v1/db/meta/projects/`{projectId}`/shared | -| Meta | Delete| project | sharedBaseDisable | /api/v1/db/meta/projects/`{projectId}`/shared | -| Meta | Post | project | sharedBaseCreate | /api/v1/db/meta/projects/`{projectId}`/shared | -| Meta | Patch | project | sharedBaseUpdate | /api/v1/db/meta/projects/`{projectId}`/shared | -| Meta | Post | storage | upload | /api/v1/db/storage/upload | -| Meta | Post | storage | uploadByUrl | /api/v1/db/storage/upload-by-url | -| Meta | Get | utils | commentList | /api/v1/db/meta/audits/comments | -| Meta | Post | utils | commentRow | /api/v1/db/meta/audits/comments | -| Meta | Get | utils | commentCount | /api/v1/db/meta/audits/comments/count | -| Meta | Post | utils | auditRowUpdate | /api/v1/db/meta/audits/update | -| Meta | Get | utils | cacheGet | /api/v1/db/meta/cache | -| Meta | Delete| utils | cacheDelete | /api/v1/db/meta/cache | -| Meta | Post | utils | testConnection | /api/v1/db/meta/projects/connection/test | -| Meta | Get | utils | appInfo | /api/v1/db/meta/nocodb/info | -| Meta | Get | utils | appVersion | /api/v1/version | -| Meta | Get | utils | appHealth | /api/v1/health | -| Meta | Get | utils | aggregatedMetaInfo | /api/v1/aggregated-meta-info | -| Meta | Get | orgUsers | list | /api/v1/users | -| Meta | Post | orgUsers | add | /api/v1/users | -| Meta | Patch | orgUsers | update | /api/v1/users/`{userId}` | -| Meta | Delete | orgUsers | delete | /api/v1/users/`{userId}` | -| Meta | Get | orgTokens | list | /api/v1/tokens | -| Meta | Post | orgTokens | create | /api/v1/tokens | -| Meta | Delete | orgTokens | delete | /api/v1/tokens/`{token}` | -| Meta | Get | orgAppSettings | get | /api/v1/app-settings | -| Meta | Post | orgAppSettings | set | /api/v1/app-settings | +| Meta | Post | dbTable | create | /api/v1/db/meta/projects/`{projectId}`/tables | +| Meta | Get | dbTable | list | /api/v1/db/meta/projects/`{projectId}`/tables | +| Meta | Post | dbTableColumn | create | /api/v1/db/meta/tables/`{tableId}`/columns | +| Meta | Patch | dbTableColumn | update | /api/v1/db/meta/tables/`{tableId}`/columns/`{columnId}` | +| Meta | Delete| dbTableColumn | delete | /api/v1/db/meta/tables/`{tableId}`/columns/`{columnId}` | +| Meta | Post | dbTableColumn | primaryColumnSet | /api/v1/db/meta/tables/`{tableId}`/columns/`{columnId}`/primary | +| Meta | Get | dbTableFilter | get | /api/v1/db/meta/filters/`{filterId}` | +| Meta | Patch | dbTableFilter | update | /api/v1/db/meta/filters/`{filterId}` | +| Meta | Delete| dbTableFilter | delete | /api/v1/db/meta/filters/`{filterId}` | +| Meta | Get | dbTableFilter | read | /api/v1/db/meta/views/`{viewId}`/filters | +| Meta | Post | dbTableFilter | create | /api/v1/db/meta/views/`{viewId}`/filters | +| Meta | Get | dbTableFilter | get | /api/v1/db/meta/filters/`{filterId}` | +| Meta | Patch | dbTableFilter | update | /api/v1/db/meta/filters/`{filterId}` | +| Meta | Delete| dbTableFilter | delete | /api/v1/db/meta/filters/`{filterId}` | +| Meta | Get | dbTableFilter | childrenRead | /api/v1/db/meta/filters/`{filterGroupId}`/children | +| Meta | Get | dbTableSort | list | /api/v1/db/meta/views/`{viewId}`/sorts | +| Meta | Post | dbTableSort | create | /api/v1/db/meta/views/`{viewId}`/sorts | +| Meta | Get | dbTableSort | read | /api/v1/db/meta/sorts/`{sortId}` | +| Meta | Patch | dbTableSort | update | /api/v1/db/meta/sorts/`{sortId}` | +| Meta | Delete| dbTableSort | delete | /api/v1/db/meta/sorts/`{sortId}` | +| Meta | Patch | dbTableWebhook | update | /api/v1/db/meta/hooks/`{hookId}` | +| Meta | Delete| dbTableWebhook | delete | /api/v1/db/meta/hooks/`{hookId}` | +| Meta | Get | dbTableWebhook | list | /api/v1/db/meta/tables/`{tableId}`/hooks | +| Meta | Post | dbTableWebhook | create | /api/v1/db/meta/tables/`{tableId}`/hooks | +| Meta | Post | dbTableWebhook | test | /api/v1/db/meta/tables/`{tableId}`/hooks/test | +| Meta | Get | dbTableWebhook | samplePayloadGet | /api/v1/db/meta/tables/`{tableId}`/hooks/samplePayload/`{operation}` | +| Meta | Get | dbTableWebhookFilter | read | /api/v1/db/meta/hooks/`{hookId}`/filters | +| Meta | Post | dbTableWebhookFilter | create | /api/v1/db/meta/hooks/`{hookId}`/filters | +| Meta | Get | dbView | list | /api/v1/db/meta/tables/`{tableId}`/views | +| Meta | Get | dbView | read | /api/v1/db/meta/tables/`{tableId}` | +| Meta | Patch | dbView | update | /api/v1/db/meta/tables/`{tableId}` | +| Meta | Delete| dbView | delete | /api/v1/db/meta/tables/`{tableId}` | +| Meta | Post | dbView | reorder | /api/v1/db/meta/tables/`{tableId}`/reorder | +| Meta | Post | dbView | formCreate | /api/v1/db/meta/tables/`{tableId}`/forms | +| Meta | Patch | dbView | formUpdate | /api/v1/db/meta/forms/`{formViewId}` | +| Meta | Get | dbView | formRead | /api/v1/db/meta/forms/`{formViewId}` | +| Meta | Patch | dbView | formColumnUpdate | /api/v1/db/meta/form-columns/`{formViewColumnId}` | +| Meta | Post | dbView | galleryCreate | /api/v1/db/meta/tables/`{tableId}`/galleries | +| Meta | Patch | dbView | galleryUpdate | /api/v1/db/meta/galleries/`{galleryViewId}` | +| Meta | Get | dbView | galleryRead | /api/v1/db/meta/galleries/`{galleryViewId}` | +| Meta | Post | dbView | kanbanCreate | /api/v1/db/meta/tables/`{tableId}`/kanbans | +| Meta | Patch | dbView | kanbanUpdate | /api/v1/db/meta/kanban/`{kanbanViewId}` | +| Meta | Get | dbView | kanbanRead | /api/v1/db/meta/kanbans/`{kanbanViewId}` | +| Meta | Post | dbView | mapCreate | /api/v1/db/meta/tables/`{tableId}`/maps | +| Meta | Patch | dbView | mapUpdate | /api/v1/db/meta/maps/`{mapViewId}` | +| Meta | Get | dbView | mapRead | /api/v1/db/meta/maps/`{mapViewId}` | +| Meta | Post | dbView | gridCreate | /api/v1/db/meta/tables/`{tableId}`/grids | +| Meta | Get | dbView | gridColumnsList | /api/v1/db/meta/grids/`{gridId}`/grid-columns | +| Meta | Patch | dbView | gridColumnUpdate | /api/v1/db/meta/grid-columns/`{columnId}` | +| Meta | Patch | dbView | update | /api/v1/db/meta/views/`{viewId}` | +| Meta | Delete| dbView | delete | /api/v1/db/meta/views/`{viewId}` | +| Meta | Post | dbView | showAllColumn | /api/v1/db/meta/views/`{viewId}`/show-all | +| Meta | Post | dbView | hideAllColumn | /api/v1/db/meta/views/`{viewId}`/hide-all | +| Meta | Get | dbViewColumn | list | /api/v1/db/meta/views/`{viewId}`/columns | +| Meta | Post | dbViewColumn | create | /api/v1/db/meta/views/`{viewId}`/columns | +| Meta | Patch | dbViewColumn | update | /api/v1/db/meta/views/`{viewId}`/columns/`{columnId}` | +| Meta | Get | dbViewShare | list | /api/v1/db/meta/views/`{viewId}`/share | +| Meta | Post | dbViewShare | create | /api/v1/db/meta/views/`{viewId}`/share | +| Meta | Patch | dbViewShare | update | /api/v1/db/meta/views/`{viewId}`/share | +| Meta | Delete| dbViewShare | delete | /api/v1/db/meta/views/`{viewId}`/share | +| Meta | Get | plugin | list | /api/v1/db/meta/plugins | +| Meta | Get | plugin | status | /api/v1/db/meta/plugins/`{pluginId}`/status | +| Meta | Post | plugin | test | /api/v1/db/meta/plugins/test | +| Meta | PATCH | plugin | update | /api/v1/db/meta/plugins/`{pluginId}` | +| Meta | Get | plugin | read | /api/v1/db/meta/plugins/`{pluginId}` | +| Meta | Get | project | metaGet | /api/v1/db/meta/projects/`{projectId}`/info | +| Meta | Get | project | modelVisibilityList | /api/v1/db/meta/projects/`{projectId}`/visibility-rules | +| Meta | Post | project | modelVisibilitySet | /api/v1/db/meta/projects/`{projectId}`/visibility-rules | +| Meta | Get | project | list | /api/v1/db/meta/projects | +| Meta | Post | project | create | /api/v1/db/meta/projects | +| Meta | Get | project | read | /api/v1/db/meta/projects/`{projectId}` | +| Meta | Delete| project | delete | /api/v1/db/meta/projects/`{projectId}` | +| Meta | Get | project | auditList | /api/v1/db/meta/projects/`{projectId}`/audits | +| Meta | Get | project | metaDiffGet | /api/v1/db/meta/projects/`{projectId}`/meta-diff | +| Meta | Post | project | metaDiffSync | /api/v1/db/meta/projects/`{projectId}`/meta-diff | +| Meta | Get | project | sharedBaseGet | /api/v1/db/meta/projects/`{projectId}`/shared | +| Meta | Delete| project | sharedBaseDisable | /api/v1/db/meta/projects/`{projectId}`/shared | +| Meta | Post | project | sharedBaseCreate | /api/v1/db/meta/projects/`{projectId}`/shared | +| Meta | Patch | project | sharedBaseUpdate | /api/v1/db/meta/projects/`{projectId}`/shared | +| Meta | Post | storage | upload | /api/v1/db/storage/upload | +| Meta | Post | storage | uploadByUrl | /api/v1/db/storage/upload-by-url | +| Meta | Get | utils | commentList | /api/v1/db/meta/audits/comments | +| Meta | Post | utils | commentRow | /api/v1/db/meta/audits/comments | +| Meta | Get | utils | commentCount | /api/v1/db/meta/audits/comments/count | +| Meta | Post | utils | auditRowUpdate | /api/v1/db/meta/audits/update | +| Meta | Get | utils | cacheGet | /api/v1/db/meta/cache | +| Meta | Delete| utils | cacheDelete | /api/v1/db/meta/cache | +| Meta | Post | utils | testConnection | /api/v1/db/meta/projects/connection/test | +| Meta | Get | utils | appInfo | /api/v1/db/meta/nocodb/info | +| Meta | Get | utils | appVersion | /api/v1/version | +| Meta | Get | utils | appHealth | /api/v1/health | +| Meta | Get | utils | aggregatedMetaInfo | /api/v1/aggregated-meta-info | +| Meta | Get | orgUsers | list | /api/v1/users | +| Meta | Post | orgUsers | add | /api/v1/users | +| Meta | Patch | orgUsers | update | /api/v1/users/`{userId}` | +| Meta | Delete | orgUsers | delete | /api/v1/users/`{userId}` | +| Meta | Get | orgTokens | list | /api/v1/tokens | +| Meta | Post | orgTokens | create | /api/v1/tokens | +| Meta | Delete | orgTokens | delete | /api/v1/tokens/`{token}` | +| Meta | Get | orgAppSettings | get | /api/v1/app-settings | +| Meta | Post | orgAppSettings | set | /api/v1/app-settings | ## Query params diff --git a/packages/nocodb/src/controllers/plugins.controller.ts b/packages/nocodb/src/controllers/plugins.controller.ts index 45e16b1b02..6b2f633640 100644 --- a/packages/nocodb/src/controllers/plugins.controller.ts +++ b/packages/nocodb/src/controllers/plugins.controller.ts @@ -82,15 +82,15 @@ export class PluginsController { } @Get([ - '/api/v1/db/meta/plugins/:pluginTitle/status', - '/api/v2/meta/plugins/:pluginTitle/status', + '/api/v1/db/meta/plugins/:pluginId/status', + '/api/v2/meta/plugins/:pluginId/status', ]) @Acl('isPluginActive', { scope: 'org', }) - async isPluginActive(@Param('pluginTitle') pluginTitle: string) { + async isPluginActive(@Param('pluginId') pluginId: string) { return await this.pluginsService.isPluginActive({ - pluginTitle: pluginTitle, + pluginId, }); } } diff --git a/packages/nocodb/src/helpers/NcPluginMgrv2.ts b/packages/nocodb/src/helpers/NcPluginMgrv2.ts index 7dee51a1e6..98d84ec041 100644 --- a/packages/nocodb/src/helpers/NcPluginMgrv2.ts +++ b/packages/nocodb/src/helpers/NcPluginMgrv2.ts @@ -14,7 +14,7 @@ import DiscordPluginConfig from '~/plugins/discord'; import GcsPluginConfig from '~/plugins/gcs'; import LinodePluginConfig from '~/plugins/linode'; import MattermostPluginConfig from '~/plugins/mattermost'; -import MinioPluginConfig from '~/plugins/mino'; +import MinioPluginConfig from '~/plugins/minio'; import OvhCloudPluginConfig from '~/plugins/ovhCloud'; import S3PluginConfig from '~/plugins/s3'; import ScalewayPluginConfig from '~/plugins/scaleway'; @@ -67,15 +67,26 @@ class NcPluginMgrv2 { // } public static async init(ncMeta = Noco.ncMeta): Promise { + // extract duplicate plugin ids from default plugins and throw error + const duplicateIds = defaultPlugins + .map((p) => p.id) + .filter((id, index, self) => self.indexOf(id) !== index); + + if (duplicateIds.length) { + throw new Error( + `Duplicate plugin ids found in default plugins: ${duplicateIds.join( + ', ', + )}`, + ); + } + /* Populate rows into nc_plugins table if not present */ for (const plugin of defaultPlugins) { const pluginConfig = await ncMeta.metaGet( RootScopes.ROOT, RootScopes.ROOT, MetaTable.PLUGIN, - { - title: plugin.title, - }, + plugin.id, ); if (!pluginConfig) { @@ -84,6 +95,7 @@ class NcPluginMgrv2 { RootScopes.ROOT, MetaTable.PLUGIN, { + id: plugin.id, title: plugin.title, version: plugin.version, logo: plugin.logo, @@ -121,7 +133,7 @@ class NcPluginMgrv2 { * */ if (process.env.NC_S3_BUCKET_NAME && process.env.NC_S3_REGION) { - const s3Plugin = await Plugin.getPluginByTitle(S3PluginConfig.title); + const s3Plugin = await Plugin.getPlugin(S3PluginConfig.id); const s3CfgData: Record = { bucket: process.env.NC_S3_BUCKET_NAME, region: process.env.NC_S3_REGION, @@ -144,7 +156,7 @@ class NcPluginMgrv2 { process.env.NC_SMTP_HOST && process.env.NC_SMTP_PORT ) { - const smtpPlugin = await Plugin.getPluginByTitle(SMTPPluginConfig.title); + const smtpPlugin = await Plugin.getPlugin(SMTPPluginConfig.id); await Plugin.update(smtpPlugin.id, { active: true, input: JSON.stringify({ diff --git a/packages/nocodb/src/models/Plugin.ts b/packages/nocodb/src/models/Plugin.ts index 37ab8072bb..ccf11c4bea 100644 --- a/packages/nocodb/src/models/Plugin.ts +++ b/packages/nocodb/src/models/Plugin.ts @@ -89,23 +89,25 @@ export default class Plugin implements PluginType { ); await NocoCache.update(`${CacheScope.PLUGIN}:${pluginId}`, updateObj); - await NocoCache.update(`${CacheScope.PLUGIN}:${plugin.title}`, updateObj); return this.get(pluginId); } - public static async isPluginActive(title: string) { - return !!(await this.getPluginByTitle(title))?.active; + public static async isPluginActive(id: string, ncMeta = Noco.ncMeta) { + return !!( + (await this.getPlugin(id, ncMeta)) || + (await this.getPluginByTitle(id, ncMeta)) + )?.active; } /** - * get plugin by title + * get plugin by id */ - public static async getPluginByTitle(title: string, ncMeta = Noco.ncMeta) { + public static async getPlugin(id: string, ncMeta = Noco.ncMeta) { let plugin = - title && + id && (await NocoCache.get( - `${CacheScope.PLUGIN}:${title}`, + `${CacheScope.PLUGIN}:${id}`, CacheGetType.TYPE_OBJECT, )); if (!plugin) { @@ -113,12 +115,20 @@ export default class Plugin implements PluginType { RootScopes.ROOT, RootScopes.ROOT, MetaTable.PLUGIN, - { - title, - }, + id, ); - await NocoCache.set(`${CacheScope.PLUGIN}:${title}`, plugin); + await NocoCache.set(`${CacheScope.PLUGIN}:${id}`, plugin); } return plugin; } + + // keeping it for backward compatibility, if someone configured google auth via plugin it still relies on this + static async getPluginByTitle(title: string, ncMeta = Noco.ncMeta) { + return await ncMeta.metaGet2( + RootScopes.ROOT, + RootScopes.ROOT, + MetaTable.PLUGIN, + { title }, + ); + } } diff --git a/packages/nocodb/src/plugins/backblaze/index.ts b/packages/nocodb/src/plugins/backblaze/index.ts index 8b349539a8..67d2b3fc27 100644 --- a/packages/nocodb/src/plugins/backblaze/index.ts +++ b/packages/nocodb/src/plugins/backblaze/index.ts @@ -4,7 +4,9 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: BackblazePlugin, + id: 'backblaze', title: 'Backblaze', + recoveryTitle: 'Backblaze B2', version: '0.0.5', logo: 'plugins/backblaze.jpeg', tags: 'Storage', diff --git a/packages/nocodb/src/plugins/discord/index.ts b/packages/nocodb/src/plugins/discord/index.ts index a11c823481..6db3e2f9c0 100644 --- a/packages/nocodb/src/plugins/discord/index.ts +++ b/packages/nocodb/src/plugins/discord/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: DiscordPlugin, + id: 'discord', title: 'Discord', version: '0.0.1', logo: 'plugins/discord.png', diff --git a/packages/nocodb/src/plugins/gcs/index.ts b/packages/nocodb/src/plugins/gcs/index.ts index 6fe7cd0ae5..7e72005e1f 100644 --- a/packages/nocodb/src/plugins/gcs/index.ts +++ b/packages/nocodb/src/plugins/gcs/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: GcsPlugin, + id: 'gcs', title: 'GCS', version: '0.0.4', logo: 'plugins/gcs.png', diff --git a/packages/nocodb/src/plugins/linode/index.ts b/packages/nocodb/src/plugins/linode/index.ts index 1bde0cdaa3..fc006fc210 100644 --- a/packages/nocodb/src/plugins/linode/index.ts +++ b/packages/nocodb/src/plugins/linode/index.ts @@ -4,6 +4,8 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: LinodeObjectStoragePlugin, + id: 'linode', + recoveryTitle: 'Linode Object Storage', title: 'Linode', version: '0.0.4', logo: 'plugins/linode.svg', diff --git a/packages/nocodb/src/plugins/mailerSend/index.ts b/packages/nocodb/src/plugins/mailerSend/index.ts index 672188dde7..37475e8d98 100644 --- a/packages/nocodb/src/plugins/mailerSend/index.ts +++ b/packages/nocodb/src/plugins/mailerSend/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: MailerSendPlugin, + id: 'mailersend', title: 'MailerSend', version: '0.0.2', logo: 'plugins/mailersend.svg', diff --git a/packages/nocodb/src/plugins/mattermost/index.ts b/packages/nocodb/src/plugins/mattermost/index.ts index c6a8317572..e4f274d4e2 100644 --- a/packages/nocodb/src/plugins/mattermost/index.ts +++ b/packages/nocodb/src/plugins/mattermost/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: MattermostPlugin, + id: 'mattermost', title: 'Mattermost', version: '0.0.1', logo: 'plugins/mattermost.png', diff --git a/packages/nocodb/src/plugins/mino/Minio.ts b/packages/nocodb/src/plugins/minio/Minio.ts similarity index 100% rename from packages/nocodb/src/plugins/mino/Minio.ts rename to packages/nocodb/src/plugins/minio/Minio.ts diff --git a/packages/nocodb/src/plugins/mino/MinioPlugin.ts b/packages/nocodb/src/plugins/minio/MinioPlugin.ts similarity index 100% rename from packages/nocodb/src/plugins/mino/MinioPlugin.ts rename to packages/nocodb/src/plugins/minio/MinioPlugin.ts diff --git a/packages/nocodb/src/plugins/mino/index.ts b/packages/nocodb/src/plugins/minio/index.ts similarity index 99% rename from packages/nocodb/src/plugins/mino/index.ts rename to packages/nocodb/src/plugins/minio/index.ts index bd29a0fef2..64f3183d65 100644 --- a/packages/nocodb/src/plugins/mino/index.ts +++ b/packages/nocodb/src/plugins/minio/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: S3Plugin, + id: 'minio', title: 'Minio', version: '0.0.4', logo: 'plugins/minio.png', diff --git a/packages/nocodb/src/plugins/ovhCloud/index.ts b/packages/nocodb/src/plugins/ovhCloud/index.ts index bec2b454d2..0e1a1cbb5f 100644 --- a/packages/nocodb/src/plugins/ovhCloud/index.ts +++ b/packages/nocodb/src/plugins/ovhCloud/index.ts @@ -4,7 +4,9 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: OvhCloud, + id: 'ovh', title: 'Ovh', + recoveryTitle: 'OvhCloud Object Storage', version: '0.0.4', logo: 'plugins/ovhCloud.png', tags: 'Storage', diff --git a/packages/nocodb/src/plugins/r2/index.ts b/packages/nocodb/src/plugins/r2/index.ts index 9c44ca3917..501de376a2 100644 --- a/packages/nocodb/src/plugins/r2/index.ts +++ b/packages/nocodb/src/plugins/r2/index.ts @@ -4,7 +4,9 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: R2Plugin, + id: 'cloudflare-r2', title: 'Cloudflare R2', + recoveryTitle: 'Cloudflare R2 Storage', version: '0.0.3', logo: 'plugins/r2.png', description: diff --git a/packages/nocodb/src/plugins/s3/index.ts b/packages/nocodb/src/plugins/s3/index.ts index 1bceb96aef..206224a611 100644 --- a/packages/nocodb/src/plugins/s3/index.ts +++ b/packages/nocodb/src/plugins/s3/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: S3Plugin, + id: 'aws-s3', title: 'S3', version: '0.0.6', logo: 'plugins/s3.png', diff --git a/packages/nocodb/src/plugins/scaleway/index.ts b/packages/nocodb/src/plugins/scaleway/index.ts index 5d6d23516f..1547316485 100644 --- a/packages/nocodb/src/plugins/scaleway/index.ts +++ b/packages/nocodb/src/plugins/scaleway/index.ts @@ -4,7 +4,9 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: ScalewayObjectStoragePlugin, + id: 'scaleway', title: 'Scaleway', + recoveryTitle: 'Scaleway Object Storage', version: '0.0.4', logo: 'plugins/scaleway.png', tags: 'Storage', diff --git a/packages/nocodb/src/plugins/ses/index.ts b/packages/nocodb/src/plugins/ses/index.ts index 97de2731e0..e84a535b41 100644 --- a/packages/nocodb/src/plugins/ses/index.ts +++ b/packages/nocodb/src/plugins/ses/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: SESPlugin, + id: 'ses', title: 'SES', version: '0.0.2', logo: 'plugins/aws.png', diff --git a/packages/nocodb/src/plugins/slack/index.ts b/packages/nocodb/src/plugins/slack/index.ts index 69c4143ed5..7c162fa9e2 100644 --- a/packages/nocodb/src/plugins/slack/index.ts +++ b/packages/nocodb/src/plugins/slack/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: SlackPlugin, + id: 'slack', title: 'Slack', version: '0.0.1', logo: 'plugins/slack.webp', diff --git a/packages/nocodb/src/plugins/smtp/index.ts b/packages/nocodb/src/plugins/smtp/index.ts index 81bb89d57f..69bc2489e5 100644 --- a/packages/nocodb/src/plugins/smtp/index.ts +++ b/packages/nocodb/src/plugins/smtp/index.ts @@ -6,6 +6,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: SMTPPlugin, + id: 'smtp', title: 'SMTP', version: '0.0.4', // icon: 'mdi-email-outline', diff --git a/packages/nocodb/src/plugins/spaces/index.ts b/packages/nocodb/src/plugins/spaces/index.ts index 765906791f..c49fd8581f 100644 --- a/packages/nocodb/src/plugins/spaces/index.ts +++ b/packages/nocodb/src/plugins/spaces/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: SpacesPlugin, + id: 'spaces', title: 'Spaces', version: '0.0.2', logo: 'plugins/spaces.png', diff --git a/packages/nocodb/src/plugins/teams/index.ts b/packages/nocodb/src/plugins/teams/index.ts index a490be6319..5ffd697438 100644 --- a/packages/nocodb/src/plugins/teams/index.ts +++ b/packages/nocodb/src/plugins/teams/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: TeamsPlugin, + id: 'ms-teams', title: 'Microsoft Teams', version: '0.0.1', logo: 'plugins/teams.ico', diff --git a/packages/nocodb/src/plugins/twilio/index.ts b/packages/nocodb/src/plugins/twilio/index.ts index 21e8a90483..60258d0998 100644 --- a/packages/nocodb/src/plugins/twilio/index.ts +++ b/packages/nocodb/src/plugins/twilio/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: TwilioPlugin, + id: 'twilio', title: 'Twilio', version: '0.0.1', logo: 'plugins/twilio.png', diff --git a/packages/nocodb/src/plugins/twilioWhatsapp/index.ts b/packages/nocodb/src/plugins/twilioWhatsapp/index.ts index 381872b1a9..2e17cb340d 100644 --- a/packages/nocodb/src/plugins/twilioWhatsapp/index.ts +++ b/packages/nocodb/src/plugins/twilioWhatsapp/index.ts @@ -4,6 +4,7 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: TwilioWhatsappPlugin, + id: 'twilio-whatsapp', title: 'Whatsapp Twilio', version: '0.0.1', logo: 'plugins/whatsapp.png', diff --git a/packages/nocodb/src/plugins/upcloud/index.ts b/packages/nocodb/src/plugins/upcloud/index.ts index a02f0342d6..ef20860249 100644 --- a/packages/nocodb/src/plugins/upcloud/index.ts +++ b/packages/nocodb/src/plugins/upcloud/index.ts @@ -4,7 +4,9 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: UpCloudPlugin, + id: 'upcloud', title: 'UpCloud', + recoveryTitle: 'UpCloud Object Storage', version: '0.0.4', logo: 'plugins/upcloud.png', description: diff --git a/packages/nocodb/src/plugins/vultr/index.ts b/packages/nocodb/src/plugins/vultr/index.ts index 2b0449de57..b6269f97c0 100644 --- a/packages/nocodb/src/plugins/vultr/index.ts +++ b/packages/nocodb/src/plugins/vultr/index.ts @@ -5,6 +5,8 @@ import type { XcPluginConfig } from '~/types/nc-plugin'; const config: XcPluginConfig = { builder: VultrPlugin, title: 'Vultr', + id: 'vultr', + recoveryTitle: 'Vultr Object Storage', version: '0.0.4', logo: 'plugins/vultr.png', description: diff --git a/packages/nocodb/src/providers/init-meta-service.provider.ts b/packages/nocodb/src/providers/init-meta-service.provider.ts index d5adc91795..916b7ee879 100644 --- a/packages/nocodb/src/providers/init-meta-service.provider.ts +++ b/packages/nocodb/src/providers/init-meta-service.provider.ts @@ -31,7 +31,7 @@ export const InitMetaServiceProvider: FactoryProvider = { const config = await NcConfig.createByEnv(); // set version - process.env.NC_VERSION = '0225002'; + process.env.NC_VERSION = '0258003'; // set migration jobs version process.env.NC_MIGRATION_JOBS_VERSION = '2'; @@ -98,17 +98,17 @@ export const InitMetaServiceProvider: FactoryProvider = { // load super admin user from env if env is set await initAdminFromEnv(metaService); + await Noco.loadEEState(); + + // run upgrader + await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta }); + // init plugin manager await NcPluginMgrv2.init(Noco.ncMeta); - await Noco.loadEEState(); if (process.env.NC_CLOUD === 'true') { await populatePluginsForCloud({ ncMeta: Noco.ncMeta }); } - - // run upgrader - await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta }); - T.init({ instance: getInstance, }); diff --git a/packages/nocodb/src/schema/swagger-v2.json b/packages/nocodb/src/schema/swagger-v2.json index 6f3cefe642..d98647b2f4 100644 --- a/packages/nocodb/src/schema/swagger-v2.json +++ b/packages/nocodb/src/schema/swagger-v2.json @@ -10877,13 +10877,13 @@ ] } }, - "/api/v2/meta/plugins/{pluginTitle}/status": { + "/api/v2/meta/plugins/{pluginId}/status": { "parameters": [ { "schema": { "type": "string" }, - "name": "pluginTitle", + "name": "pluginId", "in": "path", "required": true, "description": "Plugin Title" diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json index 967186d1b1..045b8a547d 100644 --- a/packages/nocodb/src/schema/swagger.json +++ b/packages/nocodb/src/schema/swagger.json @@ -15069,13 +15069,13 @@ "tags": ["Plugin"] } }, - "/api/v1/db/meta/plugins/{pluginTitle}/status": { + "/api/v1/db/meta/plugins/{pluginId}/status": { "parameters": [ { "schema": { "type": "string" }, - "name": "pluginTitle", + "name": "pluginId", "in": "path", "required": true, "description": "Plugin Title" diff --git a/packages/nocodb/src/services/command-palette.service.ts b/packages/nocodb/src/services/command-palette.service.ts index 6a515b99ae..fdcc4be004 100644 --- a/packages/nocodb/src/services/command-palette.service.ts +++ b/packages/nocodb/src/services/command-palette.service.ts @@ -1,5 +1,5 @@ import { Injectable, Logger } from '@nestjs/common'; -import { viewTypeAlias, type UserType } from 'nocodb-sdk'; +import { type UserType, viewTypeAlias } from 'nocodb-sdk'; import { deserializeJSON } from '~/utils/serialize'; import { getCommandPaletteForUserWorkspace } from '~/helpers/commandPaletteHelpers'; diff --git a/packages/nocodb/src/services/plugins.service.ts b/packages/nocodb/src/services/plugins.service.ts index 9ee7e7d17e..43f69900e1 100644 --- a/packages/nocodb/src/services/plugins.service.ts +++ b/packages/nocodb/src/services/plugins.service.ts @@ -50,8 +50,8 @@ export class PluginsService { return plugin; } - async isPluginActive(param: { pluginTitle: string }) { - return await Plugin.isPluginActive(param.pluginTitle); + async isPluginActive(param: { pluginId: string }) { + return await Plugin.isPluginActive(param.pluginId); } async webhookPluginList() { diff --git a/packages/nocodb/src/types/nc-plugin/lib/XcPluginConfig.ts b/packages/nocodb/src/types/nc-plugin/lib/XcPluginConfig.ts index 5fbb8b9568..3cecbfb45f 100644 --- a/packages/nocodb/src/types/nc-plugin/lib/XcPluginConfig.ts +++ b/packages/nocodb/src/types/nc-plugin/lib/XcPluginConfig.ts @@ -4,7 +4,9 @@ import type XcPlugin from './XcPlugin'; import type XcPluginMigration from './XcPluginMigration'; export default interface XcPluginConfig { + id: string; title: string; + recoveryTitle?: string; logo?: string; tags?: string; description?: string; diff --git a/packages/nocodb/src/version-upgrader/NcUpgrader.ts b/packages/nocodb/src/version-upgrader/NcUpgrader.ts index 09b2e72276..5a3e7b2087 100644 --- a/packages/nocodb/src/version-upgrader/NcUpgrader.ts +++ b/packages/nocodb/src/version-upgrader/NcUpgrader.ts @@ -12,6 +12,7 @@ import ncXcdbLTARUpgrader from './upgraders/0108002_ncXcdbLTARUpgrader'; import ncXcdbLTARIndexUpgrader from './upgraders/0111002_ncXcdbLTARIndexUpgrader'; import ncXcdbCreatedAndUpdatedSystemFieldsUpgrader from './upgraders/0111005_ncXcdbCreatedAndUpdatedSystemFieldsUpgrader'; import ncDatasourceDecrypt from './upgraders/0225002_ncDatasourceDecrypt'; +import ncDuplicatePluginMerge from './upgraders/0258003_ncDuplicatePluginMerge'; import type { MetaService } from '~/meta/meta.service'; import type { NcConfig } from '~/interface/config'; import { T } from '~/utils'; @@ -150,6 +151,7 @@ export default class NcUpgrader { { name: '0111002', handler: ncXcdbLTARIndexUpgrader }, { name: '0111005', handler: ncXcdbCreatedAndUpdatedSystemFieldsUpgrader }, { name: '0225002', handler: ncDatasourceDecrypt }, + { name: '0258003', handler: ncDuplicatePluginMerge }, ]; } } diff --git a/packages/nocodb/src/version-upgrader/upgraders/0258003_ncDuplicatePluginMerge.ts b/packages/nocodb/src/version-upgrader/upgraders/0258003_ncDuplicatePluginMerge.ts new file mode 100644 index 0000000000..c8d885b462 --- /dev/null +++ b/packages/nocodb/src/version-upgrader/upgraders/0258003_ncDuplicatePluginMerge.ts @@ -0,0 +1,127 @@ +import type { NcUpgraderCtx } from '~/version-upgrader/NcUpgrader'; +import SlackPluginConfig from '~/plugins/slack'; +import TeamsPluginConfig from '~/plugins/teams'; +import DiscordPluginConfig from '~/plugins/discord'; +import TwilioWhatsappPluginConfig from '~/plugins/twilioWhatsapp'; +import TwilioPluginConfig from '~/plugins/twilio'; +import S3PluginConfig from '~/plugins/s3'; +import MinioPluginConfig from '~/plugins/minio'; +import GcsPluginConfig from '~/plugins/gcs'; +import MattermostPluginConfig from '~/plugins/mattermost'; +import SpacesPluginConfig from '~/plugins/spaces'; +import BackblazePluginConfig from '~/plugins/backblaze'; +import VultrPluginConfig from '~/plugins/vultr'; +import OvhCloudPluginConfig from '~/plugins/ovhCloud'; +import LinodePluginConfig from '~/plugins/linode'; +import UpcloudPluginConfig from '~/plugins/upcloud'; +import SMTPPluginConfig from '~/plugins/smtp'; +import MailerSendConfig from '~/plugins/mailerSend'; +import ScalewayPluginConfig from '~/plugins/scaleway'; +import SESPluginConfig from '~/plugins/ses'; +import R2PluginConfig from '~/plugins/r2'; +import { MetaTable } from '~/cli'; + +const defaultPlugins = [ + SlackPluginConfig, + TeamsPluginConfig, + DiscordPluginConfig, + TwilioWhatsappPluginConfig, + TwilioPluginConfig, + S3PluginConfig, + MinioPluginConfig, + GcsPluginConfig, + MattermostPluginConfig, + SpacesPluginConfig, + BackblazePluginConfig, + VultrPluginConfig, + OvhCloudPluginConfig, + LinodePluginConfig, + UpcloudPluginConfig, + SMTPPluginConfig, + MailerSendConfig, + ScalewayPluginConfig, + SESPluginConfig, + R2PluginConfig, +]; + +const logger = { + log: (message: string) => { + console.log(`[0258003_ncDuplicatePluginMerge ${Date.now()}] ` + message); + }, + error: (message: string) => { + console.error(`[0258003_ncDuplicatePluginMerge ${Date.now()}] ` + message); + }, +}; + +// This upgrader helps to merge the duplicate plugins and recover the broken plugins +// and also adds a unique id to the plugin to avoid the duplicate plugins in the future +export default async function ({ ncMeta }: NcUpgraderCtx) { + logger.log('Merging duplicate plugins and updating the plugin id'); + // get the plugins which are valid and matches the plugin title + // update the plugin with the new id + for (const pluginConfig of defaultPlugins) { + // get the valid plugin + const currentPlugin = await ncMeta + .knex(MetaTable.PLUGIN) + .where('title', pluginConfig.title) + .first(); + + if (currentPlugin) { + // update the plugin with the new id + await ncMeta + .knex(MetaTable.PLUGIN) + .where('id', currentPlugin.id) + .update({ id: pluginConfig.id }); + currentPlugin.id = pluginConfig.id; + } + + if (pluginConfig.recoveryTitle) { + // get the plugin with old title + const oldPlugin = await ncMeta + .knex(MetaTable.PLUGIN) + .where('title', pluginConfig.recoveryTitle) + .first(); + + // if the old plugin is not present then continue + if (!oldPlugin) continue; + + if (currentPlugin) { + // if the old plugin is present then update the new plugin with the old plugin configuration + // and only if new plugin is not configured or active + if ( + (!currentPlugin.active && oldPlugin?.active) || + (!currentPlugin.input && oldPlugin?.input) + ) { + await ncMeta + .knex(MetaTable.PLUGIN) + .update({ + input: oldPlugin.input, + active: currentPlugin.active || oldPlugin.active, + }) + // use the new plugin id since it's already updated at the start + .where('id', pluginConfig.id); + logger.log( + `Merged the old plugin with the new plugin: ${pluginConfig.id}`, + ); + } + if (oldPlugin) { + // delete the old plugin + await ncMeta + .knex(MetaTable.PLUGIN) + .where('id', oldPlugin.id) + .delete(); + logger.log(`Deleted the old duplicate plugin: ${oldPlugin.title}`); + } + } else { + // if new plugin is not present then update the old plugin with the new id + // we can skip rest of the props since it will get updated from the existing plugin initialization + await ncMeta + .knex(MetaTable.PLUGIN) + .where('id', oldPlugin.id) + .update({ id: pluginConfig.id }); + logger.log(`Updated the old plugin id: ${pluginConfig.id}`); + } + } + } + logger.log('Merging duplicate plugins and updating the plugin id completed'); +}