first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
import type { INodeProperties, INodePropertyOptions } from 'n8n-workflow';
|
||||
|
||||
export const resource = {
|
||||
name: 'Asset',
|
||||
value: 'asset',
|
||||
} as INodePropertyOptions;
|
||||
|
||||
export const operations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
},
|
||||
],
|
||||
default: 'getAll',
|
||||
},
|
||||
];
|
||||
|
||||
export const fields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Environment ID',
|
||||
name: 'environmentId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get', 'getAll'],
|
||||
},
|
||||
},
|
||||
default: 'master',
|
||||
description:
|
||||
'The ID for the Contentful environment (e.g. master, staging, etc.). Depending on your plan, you might not have environments. In that case use "master".',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: [resource.value],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: [resource.value],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Asset ID',
|
||||
name: 'assetId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Equal',
|
||||
name: 'equal',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.title=n8n',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Exclude',
|
||||
name: 'exclude',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.tags[nin]=accessories,flowers',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}[nin]={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Exist',
|
||||
name: 'exist',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.tags[exists]=true',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}[exists]={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'select',
|
||||
type: 'string',
|
||||
placeholder: 'fields.title',
|
||||
default: '',
|
||||
description:
|
||||
'The select operator allows you to choose what fields to return from an entity. You can choose multiple values by combining comma-separated operators.',
|
||||
},
|
||||
{
|
||||
displayName: 'Include',
|
||||
name: 'include',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.tags[in]=accessories,flowers',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}[in]={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Not Equal',
|
||||
name: 'notEqual',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.title[ne]=n8n',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}[ne]={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Order',
|
||||
name: 'order',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'sys.createdAt',
|
||||
description:
|
||||
'You can order items in the response by specifying the order search parameter. You can use sys properties (such as sys.createdAt) or field values (such as fields.myCustomDateField) for ordering.',
|
||||
},
|
||||
{
|
||||
displayName: 'Query',
|
||||
name: 'query',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'Full-text search is case insensitive and might return more results than expected. A query will only take values with more than 1 character.',
|
||||
},
|
||||
{
|
||||
displayName: 'RAW Data',
|
||||
name: 'rawData',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the data should be returned RAW instead of parsed',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,79 @@
|
||||
import type { INodeProperties, INodePropertyOptions } from 'n8n-workflow';
|
||||
|
||||
export const resource = {
|
||||
name: 'Content Type',
|
||||
value: 'contentType',
|
||||
} as INodePropertyOptions;
|
||||
|
||||
export const operations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
export const fields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Environment ID',
|
||||
name: 'environmentId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
default: 'master',
|
||||
description:
|
||||
'The ID for the Contentful environment (e.g. master, staging, etc.). Depending on your plan, you might not have environments. In that case use "master".',
|
||||
},
|
||||
{
|
||||
displayName: 'Content Type ID',
|
||||
name: 'contentTypeId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'RAW Data',
|
||||
name: 'rawData',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the data should be returned RAW instead of parsed',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.contentful",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Marketing", "Development"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/contentful/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.contentful/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import * as AssetDescription from './AssetDescription';
|
||||
import * as ContentTypeDescription from './ContentTypeDescription';
|
||||
import * as EntryDescription from './EntryDescription';
|
||||
import { contentfulApiRequestAllItems, contentfulApiRequest } from './GenericFunctions';
|
||||
import * as LocaleDescription from './LocaleDescription';
|
||||
import * as SpaceDescription from './SpaceDescription';
|
||||
|
||||
export class Contentful implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Contentful',
|
||||
name: 'contentful',
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
||||
icon: 'file:contentful.png',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Consume Contentful API',
|
||||
defaults: {
|
||||
name: 'Contentful',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'contentfulApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Source',
|
||||
name: 'source',
|
||||
type: 'options',
|
||||
default: 'deliveryApi',
|
||||
description: 'Pick where your data comes from, delivery or preview API',
|
||||
options: [
|
||||
{
|
||||
name: 'Delivery API',
|
||||
value: 'deliveryApi',
|
||||
},
|
||||
{
|
||||
name: 'Preview API',
|
||||
value: 'previewApi',
|
||||
},
|
||||
],
|
||||
},
|
||||
// Resources:
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
AssetDescription.resource,
|
||||
ContentTypeDescription.resource,
|
||||
EntryDescription.resource,
|
||||
LocaleDescription.resource,
|
||||
SpaceDescription.resource,
|
||||
],
|
||||
default: 'entry',
|
||||
},
|
||||
|
||||
// Operations:
|
||||
...SpaceDescription.operations,
|
||||
...ContentTypeDescription.operations,
|
||||
...EntryDescription.operations,
|
||||
...AssetDescription.operations,
|
||||
...LocaleDescription.operations,
|
||||
|
||||
// Resource specific fields:
|
||||
...SpaceDescription.fields,
|
||||
...ContentTypeDescription.fields,
|
||||
...EntryDescription.fields,
|
||||
...AssetDescription.fields,
|
||||
...LocaleDescription.fields,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
let responseData;
|
||||
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const qs: Record<string, string | number> = {};
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
if (resource === 'space') {
|
||||
if (operation === 'get') {
|
||||
const credentials = await this.getCredentials('contentfulApi');
|
||||
|
||||
responseData = await contentfulApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (resource === 'contentType') {
|
||||
if (operation === 'get') {
|
||||
const credentials = await this.getCredentials('contentfulApi');
|
||||
|
||||
const env = this.getNodeParameter('environmentId', 0) as string;
|
||||
|
||||
const id = this.getNodeParameter('contentTypeId', 0) as string;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
responseData = await contentfulApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/content_types/${id}`,
|
||||
);
|
||||
|
||||
if (!additionalFields.rawData) {
|
||||
responseData = responseData.fields;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'entry') {
|
||||
if (operation === 'get') {
|
||||
const credentials = await this.getCredentials('contentfulApi');
|
||||
|
||||
const env = this.getNodeParameter('environmentId', 0) as string;
|
||||
|
||||
const id = this.getNodeParameter('entryId', 0) as string;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
responseData = await contentfulApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/entries/${id}`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
|
||||
if (!additionalFields.rawData) {
|
||||
responseData = responseData.fields;
|
||||
}
|
||||
} else if (operation === 'getAll') {
|
||||
const credentials = await this.getCredentials('contentfulApi');
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', 0);
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
const rawData = additionalFields.rawData;
|
||||
additionalFields.rawData = undefined;
|
||||
|
||||
const env = this.getNodeParameter('environmentId', i) as string;
|
||||
|
||||
Object.assign(qs, additionalFields);
|
||||
|
||||
if (qs.equal) {
|
||||
const [atribute, value] = (qs.equal as string).split('=');
|
||||
qs[atribute] = value;
|
||||
delete qs.equal;
|
||||
}
|
||||
|
||||
if (qs.notEqual) {
|
||||
const [atribute, value] = (qs.notEqual as string).split('=');
|
||||
qs[atribute] = value;
|
||||
delete qs.notEqual;
|
||||
}
|
||||
|
||||
if (qs.include) {
|
||||
const [atribute, value] = (qs.include as string).split('=');
|
||||
qs[atribute] = value;
|
||||
delete qs.include;
|
||||
}
|
||||
|
||||
if (qs.exclude) {
|
||||
const [atribute, value] = (qs.exclude as string).split('=');
|
||||
qs[atribute] = value;
|
||||
delete qs.exclude;
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await contentfulApiRequestAllItems.call(
|
||||
this,
|
||||
'items',
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/entries`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
|
||||
if (!rawData) {
|
||||
const assets: IDataObject[] = [];
|
||||
|
||||
responseData.map((asset: any) => {
|
||||
assets.push(asset.fields as IDataObject);
|
||||
});
|
||||
responseData = assets;
|
||||
}
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', 0);
|
||||
qs.limit = limit;
|
||||
responseData = await contentfulApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/entries`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
|
||||
if (!rawData) {
|
||||
const assets: IDataObject[] = [];
|
||||
|
||||
responseData.map((asset: any) => {
|
||||
assets.push(asset.fields as IDataObject);
|
||||
});
|
||||
responseData = assets;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'asset') {
|
||||
if (operation === 'get') {
|
||||
const credentials = await this.getCredentials('contentfulApi');
|
||||
|
||||
const env = this.getNodeParameter('environmentId', 0) as string;
|
||||
|
||||
const id = this.getNodeParameter('assetId', 0) as string;
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
responseData = await contentfulApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/assets/${id}`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
|
||||
if (!additionalFields.rawData) {
|
||||
responseData = responseData.fields;
|
||||
}
|
||||
} else if (operation === 'getAll') {
|
||||
const credentials = await this.getCredentials('contentfulApi');
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', 0);
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
const rawData = additionalFields.rawData;
|
||||
additionalFields.rawData = undefined;
|
||||
|
||||
const env = this.getNodeParameter('environmentId', i) as string;
|
||||
|
||||
Object.assign(qs, additionalFields);
|
||||
|
||||
if (qs.equal) {
|
||||
const [atribute, value] = (qs.equal as string).split('=');
|
||||
qs[atribute] = value;
|
||||
delete qs.equal;
|
||||
}
|
||||
|
||||
if (qs.notEqual) {
|
||||
const [atribute, value] = (qs.notEqual as string).split('=');
|
||||
qs[atribute] = value;
|
||||
delete qs.notEqual;
|
||||
}
|
||||
|
||||
if (qs.include) {
|
||||
const [atribute, value] = (qs.include as string).split('=');
|
||||
qs[atribute] = value;
|
||||
delete qs.include;
|
||||
}
|
||||
|
||||
if (qs.exclude) {
|
||||
const [atribute, value] = (qs.exclude as string).split('=');
|
||||
qs[atribute] = value;
|
||||
delete qs.exclude;
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await contentfulApiRequestAllItems.call(
|
||||
this,
|
||||
'items',
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/assets`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
|
||||
if (!rawData) {
|
||||
const assets: IDataObject[] = [];
|
||||
|
||||
responseData.map((asset: any) => {
|
||||
assets.push(asset.fields as IDataObject);
|
||||
});
|
||||
responseData = assets;
|
||||
}
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
qs.limit = limit;
|
||||
responseData = await contentfulApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/assets`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
|
||||
if (!rawData) {
|
||||
const assets: IDataObject[] = [];
|
||||
|
||||
responseData.map((asset: any) => {
|
||||
assets.push(asset.fields as IDataObject);
|
||||
});
|
||||
responseData = assets;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resource === 'locale') {
|
||||
if (operation === 'getAll') {
|
||||
const credentials = await this.getCredentials('contentfulApi');
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', 0);
|
||||
|
||||
const env = this.getNodeParameter('environmentId', i) as string;
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await contentfulApiRequestAllItems.call(
|
||||
this,
|
||||
'items',
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/locales`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', 0);
|
||||
qs.limit = limit;
|
||||
responseData = await contentfulApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/spaces/${credentials?.spaceId}/environments/${env}/locales`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.items;
|
||||
}
|
||||
}
|
||||
}
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message, json: {} });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
import type { INodeProperties, INodePropertyOptions } from 'n8n-workflow';
|
||||
|
||||
export const resource = {
|
||||
name: 'Entry',
|
||||
value: 'entry',
|
||||
} as INodePropertyOptions;
|
||||
|
||||
export const operations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
export const fields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Environment ID',
|
||||
name: 'environmentId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get', 'getAll'],
|
||||
},
|
||||
},
|
||||
default: 'master',
|
||||
description:
|
||||
'The ID for the Contentful environment (e.g. master, staging, etc.). Depending on your plan, you might not have environments. In that case use "master".',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: [resource.value],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: [resource.value],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Content Type ID',
|
||||
name: 'content_type',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'To search for entries with a specific content type',
|
||||
},
|
||||
{
|
||||
displayName: 'Equal',
|
||||
name: 'equal',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.title=n8n',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Exclude',
|
||||
name: 'exclude',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.tags[nin]=accessories,flowers',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}[nin]={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Exist',
|
||||
name: 'exist',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.tags[exists]=true',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}[exists]={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'select',
|
||||
type: 'string',
|
||||
placeholder: 'fields.title',
|
||||
default: '',
|
||||
description:
|
||||
'The select operator allows you to choose what fields to return from an entity. You can choose multiple values by combining comma-separated operators.',
|
||||
},
|
||||
{
|
||||
displayName: 'Include',
|
||||
name: 'include',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.tags[in]=accessories,flowers',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}[in]={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Not Equal',
|
||||
name: 'notEqual',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'fields.title[ne]=n8n',
|
||||
description:
|
||||
'Search for all data that matches the condition: {attribute}[ne]={value}. Attribute can use dot notation.',
|
||||
},
|
||||
{
|
||||
displayName: 'Order',
|
||||
name: 'order',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'sys.createdAt',
|
||||
description:
|
||||
'You can order items in the response by specifying the order search parameter. You can use sys properties (such as sys.createdAt) or field values (such as fields.myCustomDateField) for ordering.',
|
||||
},
|
||||
{
|
||||
displayName: 'Query',
|
||||
name: 'query',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'Full-text search is case insensitive and might return more results than expected. A query will only take values with more than 1 character.',
|
||||
},
|
||||
{
|
||||
displayName: 'RAW Data',
|
||||
name: 'rawData',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the data should be returned RAW instead of parsed',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Entry ID',
|
||||
name: 'entryId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'RAW Data',
|
||||
name: 'rawData',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether the data should be returned RAW instead of parsed',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,69 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHttpRequestMethods,
|
||||
ILoadOptionsFunctions,
|
||||
IRequestOptions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function contentfulApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
_option: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('contentfulApi');
|
||||
const source = this.getNodeParameter('source', 0) as string;
|
||||
const isPreview = source === 'previewApi';
|
||||
|
||||
const options: IRequestOptions = {
|
||||
method,
|
||||
qs,
|
||||
body,
|
||||
uri: uri || `https://${isPreview ? 'preview' : 'cdn'}.contentful.com${resource}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
if (isPreview) {
|
||||
qs.access_token = credentials.ContentPreviewaccessToken as string;
|
||||
} else {
|
||||
qs.access_token = credentials.ContentDeliveryaccessToken as string;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
export async function contentfulApiRequestAllItems(
|
||||
this: ILoadOptionsFunctions | IExecuteFunctions,
|
||||
propertyName: string,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
|
||||
query.limit = 100;
|
||||
query.skip = 0;
|
||||
|
||||
do {
|
||||
responseData = await contentfulApiRequest.call(this, method, resource, body, query);
|
||||
query.skip = (query.skip + 1) * query.limit;
|
||||
returnData.push.apply(returnData, responseData[propertyName] as IDataObject[]);
|
||||
} while (returnData.length < responseData.total);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import type { INodeProperties, INodePropertyOptions } from 'n8n-workflow';
|
||||
|
||||
export const resource = {
|
||||
name: 'Locale',
|
||||
value: 'locale',
|
||||
} as INodePropertyOptions;
|
||||
|
||||
export const operations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
},
|
||||
],
|
||||
default: 'getAll',
|
||||
},
|
||||
];
|
||||
|
||||
export const fields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Environment ID',
|
||||
name: 'environmentId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
operation: ['get', 'getAll'],
|
||||
},
|
||||
},
|
||||
default: 'master',
|
||||
description:
|
||||
'The ID for the Contentful environment (e.g. master, staging, etc.). Depending on your plan, you might not have environments. In that case use "master".',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: [resource.value],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: [resource.value],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const fields: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Search Parameters',
|
||||
name: 'search_parameters',
|
||||
description: 'You can use a variety of query parameters to search and filter items',
|
||||
placeholder: 'Add parameter',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Parameters',
|
||||
name: 'parameters',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Parameter Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of the search parameter to set',
|
||||
},
|
||||
{
|
||||
displayName: 'Parameter Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the search parameter to set',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const resource = {
|
||||
name: 'Space',
|
||||
value: 'space',
|
||||
};
|
||||
|
||||
export const operations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [resource.value],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
},
|
||||
];
|
||||
|
||||
export const fields: INodeProperties[] = [];
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"disabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"localized": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"omitted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"required": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"internalName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"sys": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"contentType": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"sys": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"linkType": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"environment": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"sys": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"linkType": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"locale": {
|
||||
"type": "string"
|
||||
},
|
||||
"publishedVersion": {
|
||||
"type": "integer"
|
||||
},
|
||||
"revision": {
|
||||
"type": "integer"
|
||||
},
|
||||
"space": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"sys": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"linkType": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
},
|
||||
"updatedAt": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": 2
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Reference in New Issue
Block a user