mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Clean up credential code
This commit is contained in:
parent
83c5da3ade
commit
efc809592a
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue