Skip to content

Commit 22ae46c

Browse files
authored
fix: rules eval and template filtering (#118)
* fix: add rules eval command and template list filtering
1 parent 4a34a1a commit 22ae46c

File tree

9 files changed

+146
-121
lines changed

9 files changed

+146
-121
lines changed

command-snapshot.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@
7171
],
7272
"plugin": "@salesforce/plugin-orchestrator"
7373
},
74+
{
75+
"alias": [],
76+
"command": "orchestrator:rules:eval",
77+
"flagAliases": [],
78+
"flagChars": ["o", "r", "t", "v"],
79+
"flags": ["api-version", "flags-dir", "json", "rules", "target-org", "template-info", "variables"],
80+
"plugin": "@salesforce/plugin-orchestrator"
81+
},
7482
{
7583
"alias": [],
7684
"command": "orchestrator:template:create",
@@ -95,20 +103,12 @@
95103
"flags": ["api-version", "flags-dir", "json", "target-org", "template-id", "template-name"],
96104
"plugin": "@salesforce/plugin-orchestrator"
97105
},
98-
{
99-
"alias": [],
100-
"command": "orchestrator:template:eval",
101-
"flagAliases": [],
102-
"flagChars": ["d", "o", "r", "v"],
103-
"flags": ["api-version", "definition-file", "document-file", "flags-dir", "json", "target-org", "values-file"],
104-
"plugin": "@salesforce/plugin-orchestrator"
105-
},
106106
{
107107
"alias": [],
108108
"command": "orchestrator:template:list",
109109
"flagAliases": [],
110110
"flagChars": ["o"],
111-
"flags": ["api-version", "flags-dir", "json", "target-org"],
111+
"flags": ["all", "api-version", "flags-dir", "json", "target-org"],
112112
"plugin": "@salesforce/plugin-orchestrator"
113113
},
114114
{

messages/appframework.list.template.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ List all available templates in the target org.
66

77
Templates are reusable configurations that define the structure and settings for creating orchestrated apps. Use this command to discover available templates in your org before creating new apps.
88

9+
By default, this command only shows custom templates created in your org. Standard Salesforce-provided templates are filtered out to reduce noise. Use the --all flag to include all templates including the standard ones.
10+
911
Templates are displayed in a table format showing their name, label, ID, type, and other metadata. This information helps you choose the right template for your orchestrated app development.
1012

1113
You must have Data Cloud and Tableau Next enabled in your org and the AppFrameworkViewApp user permission to view templates. This command works with production orgs, sandboxes, and scratch orgs.
@@ -28,6 +30,14 @@ You must have Data Cloud and Tableau Next enabled in your org and the AppFramewo
2830

2931
<%= config.bin %> <%= command.id %> --target-org mySandbox --api-version 60.0
3032

33+
- List all templates including standard Salesforce templates:
34+
35+
<%= config.bin %> <%= command.id %> --all
36+
37+
- List all templates in a specific org:
38+
39+
<%= config.bin %> <%= command.id %> --target-org myOrg --all
40+
3141
# flags.target-org.summary
3242

3343
Login username or alias for the target org.
@@ -44,6 +54,14 @@ Override the API version used for API requests.
4454

4555
Override the API version used for orchestrator API requests. Use this flag to specify a particular API version when the default version doesn't work with your org's configuration.
4656

57+
# flags.all.summary
58+
59+
Show all templates including standard Salesforce templates.
60+
61+
# flags.all.description
62+
63+
By default, this command only shows custom templates created in your org. Use this flag to include the standard Salesforce-provided templates (those starting with 'sfdc_internal\_\_') in the results.
64+
4765
# templatesFound
4866

4967
Found %s templates:
@@ -52,6 +70,10 @@ Found %s templates:
5270

5371
No templates found.
5472

73+
# noCustomTemplatesFound
74+
75+
No custom templates found. Use --all to include standard Salesforce templates.
76+
5577
# fetchingTemplates
5678

5779
Fetching templates...
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# summary
2+
3+
Test JSON transformation rules using the jsonxform/transformation endpoint.
4+
5+
# description
6+
7+
Preview how transformation rules will modify JSON documents before deploying templates. This command uses a sample transformation to test the jsonxform/transformation endpoint with built-in User and Org context variables.
8+
9+
# flags.target-org.summary
10+
11+
Username or alias for the target org; overrides default target org.
12+
13+
# flags.target-org.description
14+
15+
The username or alias of the target org where the jsonxform/transformation endpoint will be called. This org provides the User and Org context variables used in the transformation.
16+
17+
# flags.api-version.summary
18+
19+
Override the api version used for api requests made by this command.
20+
21+
# flags.api-version.description
22+
23+
API version to use for the transformation request. Defaults to the org's configured API version.
24+
25+
# flags.template-info.summary
26+
27+
Path to Analytics template-info.json file.
28+
29+
# flags.template-info.description
30+
31+
Path to the template-info.json file containing the base JSON document structure that will be transformed.
32+
33+
# flags.variables.summary
34+
35+
Path to Analytics variables.json file.
36+
37+
# flags.variables.description
38+
39+
Path to the variables.json file containing variable definitions used in transformations.
40+
41+
# flags.rules.summary
42+
43+
Path to Analytics rules.json file.
44+
45+
# flags.rules.description
46+
47+
Path to the rules.json file containing transformation rules and macro definitions.
48+
49+
# examples
50+
51+
- Test JSON transformation with Analytics template files:
52+
<%= config.bin %> <%= command.id %> --template-info ./template-info.json --variables ./variables.json --rules ./rules.json --target-org myorg
53+
54+
- Test with specific API version:
55+
<%= config.bin %> <%= command.id %> --template-info ./template-info.json --variables ./variables.json --rules ./rules.json --target-org myorg --api-version 60.0

messages/orchestrator.template.eval.md

Lines changed: 0 additions & 58 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/plugin-orchestrator",
33
"description": "Plugin for working with SalesForce analytic apps, templates, assets and services.",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {
@@ -62,6 +62,9 @@
6262
"subtopics": {
6363
"app": {
6464
"external": true
65+
},
66+
"rules": {
67+
"external": true
6568
}
6669
}
6770
},
@@ -71,6 +74,9 @@
7174
"orchestrator:template": {
7275
"description": "Work with templates"
7376
},
77+
"orchestrator:rules": {
78+
"description": "Work with transformation rules"
79+
},
7480
"template": {
7581
"description": "description for template"
7682
}

src/commands/orchestrator/template/eval.ts renamed to src/commands/orchestrator/rules/eval.ts

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
1919
import { Messages, Connection } from '@salesforce/core';
2020

2121
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
22-
const messages = Messages.loadMessages('@salesforce/plugin-orchestrator', 'orchestrator.template.eval');
22+
const messages = Messages.loadMessages('@salesforce/plugin-orchestrator', 'orchestrator.rules.eval');
2323

2424
type TransformationPayload = {
2525
document: {
@@ -85,23 +85,23 @@ export default class TemplateEval extends SfCommand<TemplatePreviewResult> {
8585
summary: messages.getMessage('flags.api-version.summary'),
8686
description: messages.getMessage('flags.api-version.description'),
8787
}),
88-
'document-file': Flags.file({
89-
char: 'd',
90-
summary: messages.getMessage('flags.document-file.summary'),
91-
description: messages.getMessage('flags.document-file.description'),
88+
'template-info': Flags.file({
89+
char: 't',
90+
summary: messages.getMessage('flags.template-info.summary'),
91+
description: messages.getMessage('flags.template-info.description'),
9292
required: true,
9393
}),
94-
'values-file': Flags.file({
94+
variables: Flags.file({
9595
char: 'v',
96-
summary: messages.getMessage('flags.values-file.summary'),
97-
description: messages.getMessage('flags.values-file.description'),
98-
dependsOn: ['document-file'],
96+
summary: messages.getMessage('flags.variables.summary'),
97+
description: messages.getMessage('flags.variables.description'),
98+
required: true,
9999
}),
100-
'definition-file': Flags.file({
100+
rules: Flags.file({
101101
char: 'r',
102-
summary: messages.getMessage('flags.definition-file.summary'),
103-
description: messages.getMessage('flags.definition-file.description'),
104-
dependsOn: ['document-file'],
102+
summary: messages.getMessage('flags.rules.summary'),
103+
description: messages.getMessage('flags.rules.description'),
104+
required: true,
105105
}),
106106
};
107107

@@ -159,51 +159,41 @@ export default class TemplateEval extends SfCommand<TemplatePreviewResult> {
159159
}
160160
}
161161

162-
private async getTemplatePayload(flags: {
163-
'document-file': string;
164-
'values-file'?: string;
165-
'definition-file'?: string;
166-
}): Promise<{
162+
private async getTemplatePayload(flags: { 'template-info': string; variables: string; rules: string }): Promise<{
167163
template: TemplateInfo;
168164
payload: TransformationPayload;
169165
}> {
170-
return this.getDirectFilePayload(flags['document-file'], flags['values-file'], flags['definition-file']);
166+
return this.getDirectFilePayload(flags['template-info'], flags['variables'], flags['rules']);
171167
}
172168

173169
private async getDirectFilePayload(
174-
documentFile: string,
175-
valuesFile?: string,
176-
definitionFile?: string
170+
templateInfoFile: string,
171+
variablesFile: string,
172+
rulesFile: string
177173
): Promise<{
178174
template: TemplateInfo;
179175
payload: TransformationPayload;
180176
}> {
181-
this.log(`Loading document: ${documentFile}`);
182-
183-
// Read and parse the document file
184-
const documentContent = await fs.readFile(documentFile, 'utf8');
185-
const document = JSON.parse(documentContent) as unknown;
186-
187-
// Read values file if provided, otherwise use empty object
188-
let values = { Variables: { hello: 'world' } };
189-
if (valuesFile) {
190-
this.log(`Loading values: ${valuesFile}`);
191-
const valuesContent = await fs.readFile(valuesFile, 'utf8');
192-
values = JSON.parse(valuesContent) as typeof values;
193-
}
177+
this.log(`Loading template info: ${templateInfoFile}`);
194178

195-
// Read definition file if provided, otherwise use empty rules
196-
let definition = { rules: [] };
197-
if (definitionFile) {
198-
this.log(`Loading definition: ${definitionFile}`);
199-
const definitionContent = await fs.readFile(definitionFile, 'utf8');
200-
definition = JSON.parse(definitionContent) as typeof definition;
201-
}
179+
// Read and parse the template-info file
180+
const templateInfoContent = await fs.readFile(templateInfoFile, 'utf8');
181+
const document = JSON.parse(templateInfoContent) as unknown;
182+
183+
// Read variables file
184+
this.log(`Loading variables: ${variablesFile}`);
185+
const variablesContent = await fs.readFile(variablesFile, 'utf8');
186+
const values = JSON.parse(variablesContent) as { Variables: Record<string, unknown> };
187+
188+
// Read rules file
189+
this.log(`Loading rules: ${rulesFile}`);
190+
const rulesContent = await fs.readFile(rulesFile, 'utf8');
191+
const definition = JSON.parse(rulesContent) as { rules: unknown[] };
202192

203193
return {
204194
template: {
205195
name: 'Direct Files',
206-
path: documentFile,
196+
path: templateInfoFile,
207197
source: 'local' as const,
208198
},
209199
payload: {

src/commands/orchestrator/template/list.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export default class ListTemplate extends SfCommand<TemplateData[]> {
4141
summary: messages.getMessage('flags.api-version.summary'),
4242
description: messages.getMessage('flags.api-version.description'),
4343
}),
44+
all: Flags.boolean({
45+
summary: messages.getMessage('flags.all.summary'),
46+
description: messages.getMessage('flags.all.description'),
47+
default: false,
48+
}),
4449
};
4550

4651
public async run(): Promise<TemplateData[]> {
@@ -56,12 +61,18 @@ export default class ListTemplate extends SfCommand<TemplateData[]> {
5661
const rawTemplates = await appFrameworkTemplate.list();
5762
this.spinner.stop();
5863

59-
const templates = TemplateListUtil.processTemplates(rawTemplates);
64+
let templates = TemplateListUtil.processTemplates(rawTemplates);
65+
66+
// Filter out standard templates by default unless --all flag is used
67+
if (!flags.all) {
68+
templates = templates.filter((template) => !template.name?.startsWith('sfdc_internal__'));
69+
}
6070

6171
if (templates.length > 0) {
6272
TemplateDisplayUtil.displayTemplateList(this, templates);
6373
} else {
64-
this.log(messages.getMessage('noResultsFound'));
74+
const messageKey = flags.all ? 'noResultsFound' : 'noCustomTemplatesFound';
75+
this.log(messages.getMessage(messageKey));
6576
}
6677

6778
return templates;

0 commit comments

Comments
 (0)