@@ -4,17 +4,15 @@ import {
44 INodeExecutionData ,
55 INodeType ,
66 INodeTypeDescription ,
7- IRunExecutionData ,
87} from 'n8n-workflow' ;
98import { ISalesforceOcapiCredentials } from './SalesforceOcapi.node.types' ;
109
1110import * as ocapi from '@fye/ocapi' ;
1211
13-
1412export 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}
0 commit comments