diff --git a/packages/nodes-base/credentials/StrapiApi.credentials.ts b/packages/nodes-base/credentials/StrapiApi.credentials.ts index 8de2a0b0ef..0cbc7aca20 100644 --- a/packages/nodes-base/credentials/StrapiApi.credentials.ts +++ b/packages/nodes-base/credentials/StrapiApi.credentials.ts @@ -1,32 +1,4 @@ -import { type ICredentialType, CredentialSchema, type InferCredentialSchema } from 'n8n-workflow'; - -export const strapiApiCredentialSchema = CredentialSchema.create({ - notice: CredentialSchema.notice('Make sure you are using a user account not an admin account'), - email: CredentialSchema.email({ placeholder: 'name@email.com' }), - password: CredentialSchema.password(), - url: CredentialSchema.url({ - placeholder: 'https://api.example.com', - }), - apiVersion: CredentialSchema.options({ - label: 'API Version', - description: 'The version of api to be used', - options: [ - { - label: 'Version 4', - value: 'v4', - description: 'API version supported by Strapi 4', - }, - { - label: 'Version 3', - value: 'v3', - default: true, - description: 'API version supported by Strapi 3', - }, - ], - }), -}); - -export type StrapiApiCredential = InferCredentialSchema<typeof strapiApiCredentialSchema>; +import { type ICredentialType, CredentialSchema } from 'n8n-workflow'; export class StrapiApi implements ICredentialType { name = 'strapiApi'; @@ -35,7 +7,31 @@ export class StrapiApi implements ICredentialType { documentationUrl = 'strapi'; - properties = strapiApiCredentialSchema.toNodeProperties(); + schema = CredentialSchema.create({ + notice: CredentialSchema.notice('Make sure you are using a user account not an admin account'), + email: CredentialSchema.email({ placeholder: 'name@email.com' }), + password: CredentialSchema.password(), + url: CredentialSchema.url({ + placeholder: 'https://api.example.com', + }), + apiVersion: CredentialSchema.options({ + label: 'API Version', + description: 'The version of api to be used', + options: [ + { + label: 'Version 4', + value: 'v4', + description: 'API version supported by Strapi 4', + }, + { + label: 'Version 3', + value: 'v3', + default: true, + description: 'API version supported by Strapi 3', + }, + ], + }), + }); - schema = strapiApiCredentialSchema; + properties = this.schema.toNodeProperties(); } diff --git a/packages/nodes-base/credentials/StrapiTokenApi.credentials.ts b/packages/nodes-base/credentials/StrapiTokenApi.credentials.ts index dab768bed2..d30cd3ba7b 100644 --- a/packages/nodes-base/credentials/StrapiTokenApi.credentials.ts +++ b/packages/nodes-base/credentials/StrapiTokenApi.credentials.ts @@ -5,28 +5,6 @@ import { type ICredentialTestRequest, } from 'n8n-workflow'; -const strapiTokenApiCredentialSchema = CredentialSchema.create({ - apiToken: CredentialSchema.password({ label: 'API Token' }), - url: CredentialSchema.url({ placeholder: 'https://api.example.com' }), - apiVersion: CredentialSchema.options({ - label: 'API Version', - description: 'The version of api to be used', - options: [ - { - label: 'Version 4', - value: 'v4', - description: 'API version supported by Strapi 4', - }, - { - label: 'Version 3', - value: 'v3', - default: true, - description: 'API version supported by Strapi 3', - }, - ], - }), -}); - export class StrapiTokenApi implements ICredentialType { name = 'strapiTokenApi'; @@ -34,9 +12,29 @@ export class StrapiTokenApi implements ICredentialType { documentationUrl = 'strapi'; - properties = strapiTokenApiCredentialSchema.toNodeProperties(); + schema = CredentialSchema.create({ + apiToken: CredentialSchema.password({ label: 'API Token' }), + url: CredentialSchema.url({ placeholder: 'https://api.example.com' }), + apiVersion: CredentialSchema.options({ + label: 'API Version', + description: 'The version of api to be used', + options: [ + { + label: 'Version 4', + value: 'v4', + description: 'API version supported by Strapi 4', + }, + { + label: 'Version 3', + value: 'v3', + default: true, + description: 'API version supported by Strapi 3', + }, + ], + }), + }); - schema = strapiTokenApiCredentialSchema; + properties = this.schema.toNodeProperties(); authenticate: IAuthenticateGeneric = { type: 'generic', diff --git a/packages/nodes-base/nodes/Strapi/Strapi.node.ts b/packages/nodes-base/nodes/Strapi/Strapi.node.ts index 3f7b0f8bd8..86c8058f9c 100644 --- a/packages/nodes-base/nodes/Strapi/Strapi.node.ts +++ b/packages/nodes-base/nodes/Strapi/Strapi.node.ts @@ -11,6 +11,10 @@ import type { } from 'n8n-workflow'; import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; +import { StrapiApi } from '@credentials/StrapiApi.credentials'; +import { StrapiTokenApi } from '@credentials/StrapiTokenApi.credentials'; + +import { entryFields, entryOperations } from './EntryDescription'; import { getToken, removeTrailingSlash, @@ -19,10 +23,6 @@ import { validateJSON, } from './GenericFunctions'; -import { StrapiApi, type StrapiApiCredential } from '@credentials/StrapiApi.credentials'; -import { StrapiTokenApi } from '../../credentials/StrapiTokenApi.credentials'; -import { entryFields, entryOperations } from './EntryDescription'; - export class Strapi implements INodeType { description: INodeTypeDescription = { displayName: 'Strapi', @@ -145,7 +145,7 @@ export class Strapi implements INodeType { const authenticationMethod = this.getNodeParameter('authentication', 0); - let apiVersion: StrapiApiCredential['apiVersion']; + let apiVersion: 'v3' | 'v4'; if (authenticationMethod === 'password') { const { jwt } = await getToken.call(this);