diff --git a/packages/nodes-base/nodes/Contentful/AssetDescription.ts b/packages/nodes-base/nodes/Contentful/AssetDescription.ts index dfd523806e..a753f6dbdc 100644 --- a/packages/nodes-base/nodes/Contentful/AssetDescription.ts +++ b/packages/nodes-base/nodes/Contentful/AssetDescription.ts @@ -95,6 +95,23 @@ export const fields = [ default: 100, 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', name: 'additionalFields', @@ -178,20 +195,30 @@ export const fields = [ ], }, { - displayName: 'Asset ID', - name: 'assetId', - type: 'string', - default: '', - required: true, + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Select Option', + default: {}, displayOptions: { show: { resource: [ - resource.value + resource.value, ], 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[]; diff --git a/packages/nodes-base/nodes/Contentful/ContentTypeDescription.ts b/packages/nodes-base/nodes/Contentful/ContentTypeDescription.ts index 6b2fa4eb3f..9c31a32f48 100644 --- a/packages/nodes-base/nodes/Contentful/ContentTypeDescription.ts +++ b/packages/nodes-base/nodes/Contentful/ContentTypeDescription.ts @@ -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[]; diff --git a/packages/nodes-base/nodes/Contentful/Contentful.node.ts b/packages/nodes-base/nodes/Contentful/Contentful.node.ts index 7edd880490..0ad0a96bb6 100644 --- a/packages/nodes-base/nodes/Contentful/Contentful.node.ts +++ b/packages/nodes-base/nodes/Contentful/Contentful.node.ts @@ -118,7 +118,13 @@ export class Contentful implements INodeType { 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}`); + + if (!options.rawData) { + responseData = responseData.fields; + } } } if (resource === 'entry') { @@ -131,8 +137,14 @@ export class Contentful implements INodeType { 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); + if (!options.rawData) { + responseData = responseData.fields; + } + } else if (operation === 'getAll') { const credentials = this.getCredentials('contentfulApi'); @@ -142,6 +154,8 @@ export class Contentful implements INodeType { const env = this.getNodeParameter('environmentId', i) as string; + const options = this.getNodeParameter('options', i) as IDataObject; + Object.assign(qs, additionalFields); if (qs.equal) { @@ -170,11 +184,29 @@ export class Contentful implements INodeType { if (returnAll) { 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 { const limit = this.getNodeParameter('limit', 0) as number; qs.limit = limit; responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries`, {}, qs); 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 options = this.getNodeParameter('options', i) as IDataObject; + responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets/${id}`, {}, qs); + if (!options.rawData) { + responseData = responseData.fields; + } + } else if (operation === 'getAll') { const credentials = this.getCredentials('contentfulApi'); @@ -199,6 +237,8 @@ export class Contentful implements INodeType { const env = this.getNodeParameter('environmentId', i) as string; + const options = this.getNodeParameter('options', i) as IDataObject; + Object.assign(qs, additionalFields); if (qs.equal) { @@ -227,11 +267,29 @@ export class Contentful implements INodeType { if (returnAll) { 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 { const limit = this.getNodeParameter('limit', 0) as number; qs.limit = limit; responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets`, {}, qs); 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) { responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/locales`, {}, qs); + } else { const limit = this.getNodeParameter('limit', 0) as number; qs.limit = limit; responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/locales`, {}, qs); responseData = responseData.items; + } } } diff --git a/packages/nodes-base/nodes/Contentful/EntryDescription.ts b/packages/nodes-base/nodes/Contentful/EntryDescription.ts index 24fbfbed26..0cbd5a67d4 100644 --- a/packages/nodes-base/nodes/Contentful/EntryDescription.ts +++ b/packages/nodes-base/nodes/Contentful/EntryDescription.ts @@ -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[]; diff --git a/packages/nodes-base/nodes/Contentful/GenericFunctions.ts b/packages/nodes-base/nodes/Contentful/GenericFunctions.ts index 218a85cc71..1b6c0f818b 100644 --- a/packages/nodes-base/nodes/Contentful/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Contentful/GenericFunctions.ts @@ -42,12 +42,12 @@ export async function contentfulApiRequest(this: IExecuteFunctions | IExecuteSin let errorMessage = error; - if (error.response && error.response.body && error.response.body.details) { - const details = error.response.body.details; - errorMessage = details.errors.map((e: IDataObject) => e.details).join('|'); - } else if (error.response && error.response.body && error.response.body.message) { - errorMessage = error.response.body.message; - } + // if (error.response && error.response.body && error.response.body.details) { + // const details = error.response.body.details; + // errorMessage = details.errors.map((e: IDataObject) => e.details).join('|'); + // } else if (error.response && error.response.body && error.response.body.message) { + // errorMessage = error.response.body.message; + // } throw new Error(`Contentful error response [${error.statusCode}]: ${errorMessage}`); }