Skip to content

Commit 9be956b

Browse files
authored
Merge pull request #1 from drudge/develop
Search orders works
2 parents c550fc4 + 5ccdbdb commit 9be956b

File tree

4 files changed

+29
-38
lines changed

4 files changed

+29
-38
lines changed

credentials/SalesforceOcapi.credentials.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import {
44
} from 'n8n-workflow';
55

66
export class SalesforceOcapi implements ICredentialType {
7-
name = 'salesfoce-ocapi';
7+
name = 'salesforceOcapi';
88
displayName = 'Salesforce OpenCommerce API';
9-
documentationUrl = 'salesforce';
109
properties: INodeProperties[] = [
1110
{
1211
displayName: 'Environment Type',
@@ -57,8 +56,8 @@ export class SalesforceOcapi implements ICredentialType {
5756
displayName: 'Version',
5857
name: 'version',
5958
type: 'string',
60-
default: '21_1',
59+
default: 'v21_1',
6160
required: true,
62-
}
61+
},
6362
];
6463
}

nodes/SalesforceOcapi/SalesforceOcapi.node.ts

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ import {
44
INodeExecutionData,
55
INodeType,
66
INodeTypeDescription,
7-
IRunExecutionData,
87
} from 'n8n-workflow';
98
import { ISalesforceOcapiCredentials } from './SalesforceOcapi.node.types';
109

1110
import * as ocapi from '@fye/ocapi';
1211

13-
1412
export class SalesforceOcapi implements INodeType {
1513
description: INodeTypeDescription = {
1614
displayName: 'Salesforce OpenCommerce API',
17-
name: 'salesforce-ocapi',
15+
name: 'salesforceOcapi',
1816
group: ['salesforce', 'ocapi', 'demandware'],
1917
version: 1,
2018
description: 'OCAPI for Salesforce Commerce Cloud',
@@ -27,7 +25,7 @@ export class SalesforceOcapi implements INodeType {
2725
outputs: ['main'],
2826
credentials: [
2927
{
30-
name: 'salesforce-ocapi',
28+
name: 'salesforceOcapi',
3129
required: true,
3230
},
3331
],
@@ -100,7 +98,7 @@ export class SalesforceOcapi implements INodeType {
10098
name: 'select',
10199
type: 'string',
102100
required: true,
103-
default: '**',
101+
default: '(**)',
104102
displayOptions: {
105103
show: {
106104
operation: [
@@ -190,10 +188,8 @@ export class SalesforceOcapi implements INodeType {
190188
],
191189
};
192190

193-
194191
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
195-
196-
const credentials = (await this.getCredentials('salesforce-ocapi') as ISalesforceOcapiCredentials);
192+
const credentials = (await this.getCredentials('salesforceOcapi') as ISalesforceOcapiCredentials);
197193
const siteId = this.getNodeParameter('siteId', 0) as string;
198194
const operation = this.getNodeParameter('operation', 0) as string;
199195
const config = ocapi.getConfig({
@@ -203,32 +199,28 @@ export class SalesforceOcapi implements INodeType {
203199
siteId,
204200
version: credentials.version,
205201
});
202+
const items = this.getInputData();
203+
const returnData: INodeExecutionData[] = [];
206204

207-
let items: INodeExecutionData[] = [];
208-
209-
if (operation === 'searchOrders') {
210-
const select = this.getNodeParameter('select', 0, '{}') as string;
211-
const query = JSON.parse(this.getNodeParameter('query', 0) as string);
212-
for await (const hit of ocapi.searchOrders({ config, select, query })) {
213-
items.push({
214-
json: hit,
215-
});
216-
}
217-
} else if ([ 'getOrder', 'getProduct' ].includes(operation)) {
218-
items = this.getInputData();
219-
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
220-
const item: INodeExecutionData = items[itemIndex];
205+
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
206+
if (operation === 'searchOrders') {
207+
const select = this.getNodeParameter('select', itemIndex, '{}') as string;
208+
const query = JSON.parse(this.getNodeParameter('query', itemIndex) as string);
209+
for await (const json of ocapi.searchOrders({ config, select, query })) {
210+
returnData.push({ json });
211+
}
212+
} else if ([ 'getOrder', 'getProduct' ].includes(operation)) {
221213
if (operation === 'getProduct') {
222214
const productId = this.getNodeParameter('productId', itemIndex) as string;
223215
const expand = this.getNodeParameter('expand', itemIndex) as IDataObject & { type: '' };
224-
item.json = await ocapi.getProduct(config, expand.type ? `${productId}?expand=${expand.type}` : productId);
225-
} else if (operation === 'getOrder') {
226-
const orderNo = this.getNodeParameter('orderNo', itemIndex) as string;
227-
item.json = await ocapi.getOrder(config, orderNo);
228-
}
216+
returnData.push({ json: await ocapi.getProduct(config, expand.type ? `${productId}?expand=${expand.type}` : productId) });
217+
}// } else if (operation === 'getOrder') {
218+
// const orderNo = this.getNodeParameter('orderNo', itemIndex) as string;
219+
// item.json = await ocapi.getOrder(config, orderNo);
220+
// }
229221
}
230222
}
231223

232-
return this.prepareOutputData(items);
224+
return this.prepareOutputData(returnData);
233225
}
234226
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
export type ISalesforceOcapiCredentials = {
3-
clientId: string;
4-
clientSecret: string;
5-
hostname: string;
6-
siteId: string;
7-
version: string;
3+
clientId: string;
4+
clientSecret: string;
5+
hostname: string;
6+
siteId: string;
7+
version: string;
88
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "n8n-nodes-salesforce-ocapi",
3-
"version": "0.1.2",
3+
"version": "0.3.0",
44
"description": "n8n node for Salesforce Commerce Cloud using the Open Commerce API",
55
"license": "MIT",
66
"homepage": "https://github.com/drudge/n8n-nodes-salesforce-ocapi",

0 commit comments

Comments
 (0)