mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
⚡ Added RAW data option for assets, entries, content types
This commit is contained in:
parent
3a61ad5997
commit
198cd6258c
|
@ -95,6 +95,23 @@ export const fields = [
|
||||||
default: 100,
|
default: 100,
|
||||||
description: 'How many results to return.',
|
description: 'How many results to return.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Asset ID',
|
||||||
|
name: 'assetId',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
resource.value
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: 'Additional Fields',
|
||||||
name: 'additionalFields',
|
name: 'additionalFields',
|
||||||
|
@ -178,20 +195,30 @@ export const fields = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Asset ID',
|
displayName: 'Options',
|
||||||
name: 'assetId',
|
name: 'options',
|
||||||
type: 'string',
|
type: 'collection',
|
||||||
default: '',
|
placeholder: 'Select Option',
|
||||||
required: true,
|
default: {},
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
resource.value
|
resource.value,
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'get',
|
'getAll',
|
||||||
|
'get'
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'RAW Data',
|
||||||
|
name: 'rawData',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'If the data should be returned RAW instead of parsed.',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -66,4 +66,30 @@ export const fields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Options',
|
||||||
|
name: 'options',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Select Option',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
resource.value,
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'RAW Data',
|
||||||
|
name: 'rawData',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'If the data should be returned RAW instead of parsed.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -118,7 +118,13 @@ export class Contentful implements INodeType {
|
||||||
|
|
||||||
const id = this.getNodeParameter('contentTypeId', 0) as string;
|
const id = this.getNodeParameter('contentTypeId', 0) as string;
|
||||||
|
|
||||||
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||||
|
|
||||||
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/content_types/${id}`);
|
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/content_types/${id}`);
|
||||||
|
|
||||||
|
if (!options.rawData) {
|
||||||
|
responseData = responseData.fields;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resource === 'entry') {
|
if (resource === 'entry') {
|
||||||
|
@ -131,8 +137,14 @@ export class Contentful implements INodeType {
|
||||||
|
|
||||||
const id = this.getNodeParameter('entryId', 0) as string;
|
const id = this.getNodeParameter('entryId', 0) as string;
|
||||||
|
|
||||||
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||||
|
|
||||||
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries/${id}`, {}, qs);
|
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries/${id}`, {}, qs);
|
||||||
|
|
||||||
|
if (!options.rawData) {
|
||||||
|
responseData = responseData.fields;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (operation === 'getAll') {
|
} else if (operation === 'getAll') {
|
||||||
const credentials = this.getCredentials('contentfulApi');
|
const credentials = this.getCredentials('contentfulApi');
|
||||||
|
|
||||||
|
@ -142,6 +154,8 @@ export class Contentful implements INodeType {
|
||||||
|
|
||||||
const env = this.getNodeParameter('environmentId', i) as string;
|
const env = this.getNodeParameter('environmentId', i) as string;
|
||||||
|
|
||||||
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||||
|
|
||||||
Object.assign(qs, additionalFields);
|
Object.assign(qs, additionalFields);
|
||||||
|
|
||||||
if (qs.equal) {
|
if (qs.equal) {
|
||||||
|
@ -170,11 +184,29 @@ export class Contentful implements INodeType {
|
||||||
|
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries`, {}, qs);
|
responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries`, {}, qs);
|
||||||
|
|
||||||
|
if (!options.rawData) {
|
||||||
|
const assets : IDataObject[] = [];
|
||||||
|
// tslint:disable-next-line: no-any
|
||||||
|
responseData.map((asset : any) => {
|
||||||
|
assets.push(asset.fields);
|
||||||
|
});
|
||||||
|
responseData = assets;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const limit = this.getNodeParameter('limit', 0) as number;
|
const limit = this.getNodeParameter('limit', 0) as number;
|
||||||
qs.limit = limit;
|
qs.limit = limit;
|
||||||
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries`, {}, qs);
|
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries`, {}, qs);
|
||||||
responseData = responseData.items;
|
responseData = responseData.items;
|
||||||
|
|
||||||
|
if (!options.rawData) {
|
||||||
|
const assets : IDataObject[] = [];
|
||||||
|
// tslint:disable-next-line: no-any
|
||||||
|
responseData.map((asset : any) => {
|
||||||
|
assets.push(asset.fields);
|
||||||
|
});
|
||||||
|
responseData = assets;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,8 +219,14 @@ export class Contentful implements INodeType {
|
||||||
|
|
||||||
const id = this.getNodeParameter('assetId', 0) as string;
|
const id = this.getNodeParameter('assetId', 0) as string;
|
||||||
|
|
||||||
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||||
|
|
||||||
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets/${id}`, {}, qs);
|
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets/${id}`, {}, qs);
|
||||||
|
|
||||||
|
if (!options.rawData) {
|
||||||
|
responseData = responseData.fields;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (operation === 'getAll') {
|
} else if (operation === 'getAll') {
|
||||||
|
|
||||||
const credentials = this.getCredentials('contentfulApi');
|
const credentials = this.getCredentials('contentfulApi');
|
||||||
|
@ -199,6 +237,8 @@ export class Contentful implements INodeType {
|
||||||
|
|
||||||
const env = this.getNodeParameter('environmentId', i) as string;
|
const env = this.getNodeParameter('environmentId', i) as string;
|
||||||
|
|
||||||
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||||
|
|
||||||
Object.assign(qs, additionalFields);
|
Object.assign(qs, additionalFields);
|
||||||
|
|
||||||
if (qs.equal) {
|
if (qs.equal) {
|
||||||
|
@ -227,11 +267,29 @@ export class Contentful implements INodeType {
|
||||||
|
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets`, {}, qs);
|
responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets`, {}, qs);
|
||||||
|
|
||||||
|
if (!options.rawData) {
|
||||||
|
const assets : IDataObject[] = [];
|
||||||
|
// tslint:disable-next-line: no-any
|
||||||
|
responseData.map((asset : any) => {
|
||||||
|
assets.push(asset.fields);
|
||||||
|
});
|
||||||
|
responseData = assets;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const limit = this.getNodeParameter('limit', 0) as number;
|
const limit = this.getNodeParameter('limit', 0) as number;
|
||||||
qs.limit = limit;
|
qs.limit = limit;
|
||||||
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets`, {}, qs);
|
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets`, {}, qs);
|
||||||
responseData = responseData.items;
|
responseData = responseData.items;
|
||||||
|
|
||||||
|
if (!options.rawData) {
|
||||||
|
const assets : IDataObject[] = [];
|
||||||
|
// tslint:disable-next-line: no-any
|
||||||
|
responseData.map((asset : any) => {
|
||||||
|
assets.push(asset.fields);
|
||||||
|
});
|
||||||
|
responseData = assets;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,11 +305,13 @@ export class Contentful implements INodeType {
|
||||||
|
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/locales`, {}, qs);
|
responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/locales`, {}, qs);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const limit = this.getNodeParameter('limit', 0) as number;
|
const limit = this.getNodeParameter('limit', 0) as number;
|
||||||
qs.limit = limit;
|
qs.limit = limit;
|
||||||
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/locales`, {}, qs);
|
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/locales`, {}, qs);
|
||||||
responseData = responseData.items;
|
responseData = responseData.items;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,4 +201,31 @@ export const fields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
displayName: 'Options',
|
||||||
|
name: 'options',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Select Option',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
resource.value,
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'RAW Data',
|
||||||
|
name: 'rawData',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'If the data should be returned RAW instead of parsed.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -42,12 +42,12 @@ export async function contentfulApiRequest(this: IExecuteFunctions | IExecuteSin
|
||||||
|
|
||||||
let errorMessage = error;
|
let errorMessage = error;
|
||||||
|
|
||||||
if (error.response && error.response.body && error.response.body.details) {
|
// if (error.response && error.response.body && error.response.body.details) {
|
||||||
const details = error.response.body.details;
|
// const details = error.response.body.details;
|
||||||
errorMessage = details.errors.map((e: IDataObject) => e.details).join('|');
|
// errorMessage = details.errors.map((e: IDataObject) => e.details).join('|');
|
||||||
} else if (error.response && error.response.body && error.response.body.message) {
|
// } else if (error.response && error.response.body && error.response.body.message) {
|
||||||
errorMessage = error.response.body.message;
|
// errorMessage = error.response.body.message;
|
||||||
}
|
// }
|
||||||
|
|
||||||
throw new Error(`Contentful error response [${error.statusCode}]: ${errorMessage}`);
|
throw new Error(`Contentful error response [${error.statusCode}]: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue