Skip to content

Commit 9904f4e

Browse files
Merge pull request #763 from vlocityinc/alpha
Merging alpha to master
2 parents dbf1586 + 70272ce commit 9904f4e

File tree

7 files changed

+390
-219
lines changed

7 files changed

+390
-219
lines changed

javascript/lwcOmniOutRetrieve.js

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const path = require('path');
1010
*/
1111
module.exports = async function(vlocity, currentContextData, jobInfo, callback) {
1212
let listOfCustomLwc = [];
13+
let processedOmniScripts = new Set(); // Track processed OmniScripts to avoid duplicates
1314

1415
if(jobInfo.queries.length > 0) {
1516
for (const element of jobInfo.queries) {
@@ -18,31 +19,46 @@ module.exports = async function(vlocity, currentContextData, jobInfo, callback)
1819
}
1920
}
2021
}
21-
22+
jobInfo.currentStatus = jobInfo.currentStatus || {};
2223

23-
vlocity.jsForceConnection.query(query, function(err, result) {
24-
if (err) { return console.error(err); }
25-
async.eachSeries(result.records, function(record, seriesCallback) {
26-
27-
var body = {
28-
sClassName: 'Vlocity BuildJSONWithPrefill',
29-
sType: record[vlocity.namespace + '__Type__c'] || record['Type'],
30-
sSubType: record[vlocity.namespace + '__SubType__c'] || record['SubType'],
31-
sLang: record[vlocity.namespace + '__Language__c'] || record['Language']
32-
};
33-
34-
vlocity.jsForceConnection.apex.post('/' + vlocity.namespace + '/v1/GenericInvoke/', body, async function(err, prefilledJson) {
35-
if (err) { return console.error(err); }
24+
try {
25+
const result = await vlocity.jsForceConnection.query(query);
26+
27+
await async.eachSeries(result.records, async function(record) {
28+
try {
29+
// Use the new jsforce v3 approach for Apex REST calls
30+
const apexUrl = '/services/apexrest/' + vlocity.namespace + '/v1/GenericInvoke/';
31+
const prefilledJson = await vlocity.jsForceConnection.request({
32+
method: 'POST',
33+
url: apexUrl,
34+
body: JSON.stringify({
35+
sClassName: 'Vlocity BuildJSONWithPrefill',
36+
sType: record[vlocity.namespace + '__Type__c'] || record['Type'],
37+
sSubType: record[vlocity.namespace + '__SubType__c'] || record['SubType'],
38+
sLang: record[vlocity.namespace + '__Language__c'] || record['Language']
39+
}),
40+
headers: {
41+
'Content-Type': 'application/json'
42+
}
43+
});
3644

3745
if (!vlocity.isOmniStudioInstalled && (!record[vlocity.namespace + '__Type__c'] || !record[vlocity.namespace + '__SubType__c'] || !record[vlocity.namespace + '__Language__c']) ||
38-
vlocity.isOmniStudioInstalled && (! record['Type'] || ! record['SubType'] || ! record['Language'])
39-
) return;
46+
vlocity.isOmniStudioInstalled && (! record['Type'] || ! record['SubType'] || !record['Language'])
47+
) {
48+
return;
49+
}
50+
51+
let lwcname = vlocity.isOmniStudioInstalled ? (record['Type'] + record['SubType'] + record['Language']) : record[vlocity.namespace + '__Type__c']+record[vlocity.namespace + '__SubType__c']+record[vlocity.namespace + '__Language__c'];
52+
53+
// Skip if this OmniScript has already been processed
54+
if (processedOmniScripts.has(lwcname)) {
55+
return;
56+
}
4057

4158
vlocity.datapacksexpand.targetPath = jobInfo.projectPath + '/' + jobInfo.expansionPath;
4259

4360
listOfCustomLwc = await extractLwcDependencies(JSON.parse(prefilledJson) || {});
4461

45-
let lwcname = vlocity.isOmniStudioInstalled ? (record['Type'] + record['SubType'] + record['Language']) : record[vlocity.namespace + '__Type__c']+record[vlocity.namespace + '__SubType__c']+record[vlocity.namespace + '__Language__c'];
4662
// add the OmniScript itself
4763
const currentOmniScriptLwc = await fetchOmniOutContents(lwcname, vlocity);
4864
const parsedOmniScriptRes = await extractSources(currentOmniScriptLwc['compositeResponse'][1]['body']['records'], vlocity.namespace);
@@ -55,15 +71,23 @@ module.exports = async function(vlocity, currentContextData, jobInfo, callback)
5571
let parsedSources = await extractSources(retrieveLwcFile['compositeResponse'][1]['body']['records'], vlocity.namespace);
5672
await createFiles(parsedSources, vlocity, 'modules', `c/${element}`);
5773
}
74+
if (Object.keys(parsedOmniScriptRes).length > 0) {
75+
jobInfo.currentStatus[`${lwcname}`] = 'Success';
76+
}
77+
78+
// Mark this OmniScript as processed
79+
processedOmniScripts.add(lwcname);
5880

59-
seriesCallback();
60-
}, function(err, result) {
61-
seriesCallback();
62-
});
63-
}, function(err, result) {
64-
callback();
81+
} catch (err) {
82+
VlocityUtils.error('Error processing OmniScript:', err);
83+
}
6584
});
66-
});
85+
86+
callback();
87+
} catch (err) {
88+
VlocityUtils.error('Query error:', err);
89+
callback(err);
90+
}
6791
};
6892

6993
/**
@@ -169,7 +193,7 @@ const extractSources = async (items, namespace) => {
169193
let parsed = [];
170194

171195
if(items?.length > 0) {
172-
items.map(async (i) => {
196+
for (const i of items) {
173197
let path = i['FilePath'].replace('lwc', '');
174198

175199
if(path.startsWith("dc")) {
@@ -179,11 +203,11 @@ const extractSources = async (items, namespace) => {
179203
}
180204

181205
if (i['Source'] === "(hidden)") {
182-
console.log('Skipping path');
206+
VlocityUtils.log('Skipping path');
183207
} else {
184208
parsed[path] = await parseSource(i['Source'], namespace);
185209
}
186-
});
210+
}
187211
}
188212

189213
resolve(parsed);
@@ -216,7 +240,7 @@ const createFiles = async(files, vlocity, parentFolder = 'modules', childFolder
216240
try {
217241
for (const key in files) {
218242
if (files.hasOwnProperty(key)) {
219-
console.log(`${key}: `);
243+
VlocityUtils.log(`${key}: `);
220244

221245
const filename = path.basename(key) || null;
222246
const fileTypeName = filename.split('.') || null;
@@ -227,6 +251,6 @@ const createFiles = async(files, vlocity, parentFolder = 'modules', childFolder
227251
}
228252
}
229253
} catch (error) {
230-
console.error(`Got an error trying to write to a file: ${error.message}`);
254+
VlocityUtils.error(`Got an error trying to write to a file: ${error.message}`);
231255
}
232-
}
256+
}

javascript/omniOutRetrieve.js

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,77 @@
1-
var async = require('async');
2-
var path = require('path');
1+
const async = require('async');
2+
const path = require('path');
33

4-
module.exports = function(vlocity, currentContextData, jobInfo, callback) {
4+
/**
5+
* Download off-platform OmniScript
6+
* @param {*} vlocity
7+
* @param {*} currentContextData
8+
* @param {*} jobInfo
9+
* @param {*} callback
10+
*/
11+
module.exports = async function(vlocity, currentContextData, jobInfo, callback) {
12+
let query = vlocity.omnistudio.updateQuery('Select %vlocity_namespace%__Type__c, %vlocity_namespace%__Language__c, %vlocity_namespace%__SubType__c from %vlocity_namespace%__OmniScript__c WHERE %vlocity_namespace%__IsActive__c = true AND %vlocity_namespace%__IsProcedure__c = false').replace(/%vlocity_namespace%/g, vlocity.namespace);
13+
let processedOmniScripts = new Set(); // Track processed OmniScripts to avoid duplicates
514

6-
var query = vlocity.omnistudio.updateQuery('Select %vlocity_namespace%__Type__c, %vlocity_namespace%__Language__c, %vlocity_namespace%__SubType__c from %vlocity_namespace%__OmniScript__c WHERE %vlocity_namespace%__IsActive__c = true AND %vlocity_namespace%__IsProcedure__c = false').replace(/%vlocity_namespace%/g, vlocity.namespace);
15+
if(jobInfo.queries.length > 0) {
16+
for (const element of jobInfo.queries) {
17+
if(element.VlocityDataPackType === 'OmniScript') {
18+
query = vlocity.omnistudio.updateQuery(element.query).replace(/%vlocity_namespace%/g, vlocity.namespace);
19+
}
20+
}
21+
}
22+
jobInfo.currentStatus = jobInfo.currentStatus || {};
723

8-
vlocity.jsForceConnection.query(query, function(err, result) {
9-
if (err) { return console.error(err); }
10-
async.eachSeries(result.records, function(record, seriesCallback) {
11-
12-
var body = {
13-
sClassName: 'Vlocity BuildJSONWithPrefill',
14-
sType: record[vlocity.namespace + '__Type__c'] || record['Type'],
15-
sSubType: record[vlocity.namespace + '__SubType__c'] || record['SubType'],
16-
sLang: record[vlocity.namespace + '__Language__c'] || record['Language']
17-
};
18-
19-
vlocity.jsForceConnection.apex.post('/' + vlocity.namespace + '/v1/GenericInvoke/', body, function(err, prefilledJson) {
20-
if (err) { return console.error(err); }
24+
try {
25+
const result = await vlocity.jsForceConnection.query(query);
26+
27+
await async.eachSeries(result.records, async function(record) {
28+
try {
29+
// Use the new jsforce v3 approach for Apex REST calls
30+
const apexUrl = '/services/apexrest/' + vlocity.namespace + '/v1/GenericInvoke/';
31+
const prefilledJson = await vlocity.jsForceConnection.request({
32+
method: 'POST',
33+
url: apexUrl,
34+
body: JSON.stringify({
35+
sClassName: 'Vlocity BuildJSONWithPrefill',
36+
sType: record[vlocity.namespace + '__Type__c'] || record['Type'],
37+
sSubType: record[vlocity.namespace + '__SubType__c'] || record['SubType'],
38+
sLang: record[vlocity.namespace + '__Language__c'] || record['Language']
39+
}),
40+
headers: {
41+
'Content-Type': 'application/json'
42+
}
43+
});
2144

2245
if (!vlocity.isOmniStudioInstalled && (!record[vlocity.namespace + '__Type__c'] || !record[vlocity.namespace + '__SubType__c'] || !record[vlocity.namespace + '__Language__c']) ||
23-
vlocity.isOmniStudioInstalled && (! record['Type'] || ! record['SubType'] || ! record['Language'])
24-
) return;
46+
vlocity.isOmniStudioInstalled && (! record['Type'] || ! record['SubType'] || !record['Language'])
47+
) {
48+
return;
49+
}
2550

26-
var filename = vlocity.isOmniStudioInstalled ? (record['Type'] + record['SubType'] + record['Language']) : record[vlocity.namespace + '__Type__c']+record[vlocity.namespace + '__SubType__c']+record[vlocity.namespace + '__Language__c'];
51+
const filename = vlocity.isOmniStudioInstalled ? (record['Type'] + record['SubType'] + record['Language']) : record[vlocity.namespace + '__Type__c']+record[vlocity.namespace + '__SubType__c']+record[vlocity.namespace + '__Language__c'];
52+
53+
// Skip if this OmniScript has already been processed
54+
if (processedOmniScripts.has(filename)) {
55+
return;
56+
}
57+
2758
vlocity.datapacksexpand.targetPath = jobInfo.projectPath + '/' + jobInfo.expansionPath;
28-
var file = vlocity.datapacksexpand.writeFile('OmniOut', 'OmniOut', filename, 'json', prefilledJson, false);
59+
const file = vlocity.datapacksexpand.writeFile('OmniOut', 'OmniOut', filename, 'json', prefilledJson, false);
2960

3061
VlocityUtils.success('Created file:', path.join(vlocity.datapacksexpand.targetPath, 'OmniOut', 'OmniOut', filename));
31-
seriesCallback();
32-
}, function(err, result) {
33-
seriesCallback();
34-
});
35-
}, function(err, result) {
36-
callback();
62+
jobInfo.currentStatus[`${filename}`] = 'Success';
63+
64+
// Mark this OmniScript as processed
65+
processedOmniScripts.add(filename);
66+
67+
} catch (err) {
68+
VlocityUtils.error('Error processing OmniScript:', err);
69+
}
3770
});
38-
});
71+
72+
callback();
73+
} catch (err) {
74+
VlocityUtils.error('Query error:', err);
75+
callback(err);
76+
}
3977
};

0 commit comments

Comments
 (0)