Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@
"name",
"output-dir",
"sandbox",
"shell-title",
"src"
"src",
"title"
],
"plugin": "@salesforce/plugin-templates"
},
Expand Down
10 changes: 5 additions & 5 deletions messages/uiEmbedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

- Generate an embedding wrapper LWC in the current directory:

<%= config.bin %> <%= command.id %> --name MyEmbeddingWrapper --src https://app.example.com --sandbox allow-forms --shell-title "Expense Report Embedding"
<%= config.bin %> <%= command.id %> --name MyEmbeddingWrapper --src https://app.example.com --sandbox allow-forms --title "Expense Report Embedding"

- Generate an embedding wrapper LWC in the "force-app/main/default/lwc" directory with multiple sandbox tokens:

<%= config.bin %> <%= command.id %> --name MyEmbeddingWrapper --src https://app.example.com --sandbox allow-forms --sandbox allow-scripts --shell-title "Expense Report Embedding" --output-dir force-app/main/default/lwc
<%= config.bin %> <%= command.id %> --name MyEmbeddingWrapper --src https://app.example.com --sandbox allow-forms --sandbox allow-scripts --title "Expense Report Embedding" --output-dir force-app/main/default/lwc

# summary

Generate a Lightning Web Component (LWC) bundle that wraps the <lightning-ui-embedding> base component.

# description

The generated LWC bundle consumes the first-party <lightning-ui-embedding> component, which is pre-wired with the three required attributes: the embedding URL (src), iframe sandbox tokens, and an accessible iframe title (shell-title).
The generated LWC bundle consumes the first-party <lightning-ui-embedding> component, which is pre-wired with the three required attributes: the embedding URL (--src), iframe sandbox tokens, and an accessible iframe title (--title).

The generated LWC bundle contains four files (.html, .js, .js-meta.xml, .css) in a directory named with the camelCased component name. The bundle must live under a parent folder named "lwc".

Expand Down Expand Up @@ -46,10 +46,10 @@ Iframe sandbox token. Specify this flag multiple times to set more than one toke

Each token is written into the space-separated "sandbox" attribute on <lightning-ui-embedding>. Only W3C-defined sandbox tokens are accepted.

# flags.shell-title.summary
# flags.title.summary

Accessible title for the embedded iframe.

# flags.shell-title.description
# flags.title.description

Written to the "shell-title" attribute on <lightning-ui-embedding> and used as the iframe's accessible name (announced by screen readers).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"@salesforce/core": "^9.1.9",
"@salesforce/sf-plugins-core": "^13.0.4",
"@salesforce/templates": "^66.14.0"
"@salesforce/templates": "^66.15.0"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^6.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/template/generate/ui-embedding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export default class UIEmbedding extends SfCommand<CreateOutput> {
multiple: true,
required: true,
})(),
'shell-title': Flags.string({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I don't have context, but this is a breaking change, would you consider adding an alias: 'shell-title' and deprecateAliases:true properties to this flag definition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillieRuemmele, since this hasn’t reached GA yet, will it still cause a breaking change?

summary: messages.getMessage('flags.shell-title.summary'),
description: messages.getMessage('flags.shell-title.description'),
title: Flags.string({
summary: messages.getMessage('flags.title.summary'),
description: messages.getMessage('flags.title.description'),
required: true,
}),
'output-dir': outputDirFlagLightning,
Expand All @@ -78,7 +78,7 @@ export default class UIEmbedding extends SfCommand<CreateOutput> {
componentname: flags.name,
src: flags.src,
sandbox: flags.sandbox.join(' '),
shellTitle: flags['shell-title'],
title: flags.title,
outputdir: flags['output-dir'],
apiversion: flags['api-version'],
internal: flags.internal,
Expand Down
28 changes: 14 additions & 14 deletions test/commands/template/generate/ui-embedding/index.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ describe('template generate ui-embedding:', () => {

it('should scaffold an embedding LWC bundle with all four files', () => {
execCmd(
`template generate ui-embedding --name ${name} --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`,
`template generate ui-embedding --name ${name} --src ${src} --sandbox allow-forms --title "${shellTitle}" --output-dir ${lwcDir()}`,
{ ensureExitCode: 0 }
);
assert.file(bundleFiles(name));
});

it('should emit a <lightning-ui-embedding> element in the generated html', () => {
execCmd(
`template generate ui-embedding --name ${name} --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`,
`template generate ui-embedding --name ${name} --src ${src} --sandbox allow-forms --title "${shellTitle}" --output-dir ${lwcDir()}`,
{ ensureExitCode: 0 }
);
const camel = name.charAt(0).toLowerCase() + name.slice(1);
Expand All @@ -62,7 +62,7 @@ describe('template generate ui-embedding:', () => {

it('should join multiple --sandbox tokens into a single space-separated attribute', () => {
execCmd(
`template generate ui-embedding --name MultiSandbox --src ${src} --sandbox allow-forms --sandbox allow-scripts --shell-title "${shellTitle}" --output-dir ${lwcDir()}`,
`template generate ui-embedding --name MultiSandbox --src ${src} --sandbox allow-forms --sandbox allow-scripts --title "${shellTitle}" --output-dir ${lwcDir()}`,
{ ensureExitCode: 0 }
);
assert.fileContent(
Expand All @@ -73,45 +73,45 @@ describe('template generate ui-embedding:', () => {

it('should bind the src URL into the generated js as a reactive property', () => {
execCmd(
`template generate ui-embedding --name SrcBinding --src ${src} --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`,
`template generate ui-embedding --name SrcBinding --src ${src} --sandbox allow-forms --title "${shellTitle}" --output-dir ${lwcDir()}`,
{ ensureExitCode: 0 }
);
assert.fileContent(path.join(lwcDir(), 'srcBinding', 'srcBinding.js'), src);
});

it('should accept http URLs on localhost for local development', () => {
execCmd(
`template generate ui-embedding --name LocalDev --src http://localhost:3000 --sandbox allow-forms --shell-title "${shellTitle}" --output-dir ${lwcDir()}`,
`template generate ui-embedding --name LocalDev --src http://localhost:3000 --sandbox allow-forms --title "${shellTitle}" --output-dir ${lwcDir()}`,
{ ensureExitCode: 0 }
);
assert.fileContent(path.join(lwcDir(), 'localDev', 'localDev.js'), 'http://localhost:3000');
});
});

describe('ui-embedding failures', () => {
const baseFlags = '--name Foo --sandbox allow-forms --shell-title "Demo"';
const baseFlags = '--name Foo --sandbox allow-forms --title "Demo"';

it('should throw missing --name error', () => {
const stderr = execCmd(
'template generate ui-embedding --src https://app.example.com --sandbox allow-forms --shell-title "Demo"'
'template generate ui-embedding --src https://app.example.com --sandbox allow-forms --title "Demo"'
).shellOutput.stderr;
expect(stderr).to.contain('Missing required flag');
});

it('should throw missing --src error', () => {
const stderr = execCmd('template generate ui-embedding --name Foo --sandbox allow-forms --shell-title "Demo"')
const stderr = execCmd('template generate ui-embedding --name Foo --sandbox allow-forms --title "Demo"')
.shellOutput.stderr;
expect(stderr).to.contain('Missing required flag');
});

it('should throw missing --sandbox error', () => {
const stderr = execCmd(
'template generate ui-embedding --name Foo --src https://app.example.com --shell-title "Demo"'
'template generate ui-embedding --name Foo --src https://app.example.com --title "Demo"'
).shellOutput.stderr;
expect(stderr).to.contain('Missing required flag');
});

it('should throw missing --shell-title error (no fallback to --name)', () => {
it('should throw missing --title error (no fallback to --name)', () => {
const stderr = execCmd(
'template generate ui-embedding --name Foo --src https://app.example.com --sandbox allow-forms'
).shellOutput.stderr;
Expand All @@ -120,21 +120,21 @@ describe('template generate ui-embedding:', () => {

it('should reject http src on a non-localhost host', () => {
const stderr = execCmd(
`template generate ui-embedding --name Foo --src http://attacker.com --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}`
`template generate ui-embedding --name Foo --src http://attacker.com --sandbox allow-forms --title "Demo" --output-dir ${lwcDir()}`
).shellOutput.stderr;
expect(stderr).to.contain('HTTPS URL');
});

it('should reject non-http(s) protocols', () => {
const stderr = execCmd(
`template generate ui-embedding --name Foo --src ftp://example.com --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}`
`template generate ui-embedding --name Foo --src ftp://example.com --sandbox allow-forms --title "Demo" --output-dir ${lwcDir()}`
).shellOutput.stderr;
expect(stderr).to.contain('HTTPS URL');
});

it('should reject malformed --src input', () => {
const stderr = execCmd(
`template generate ui-embedding --name Foo --src not-a-url --sandbox allow-forms --shell-title "Demo" --output-dir ${lwcDir()}`
`template generate ui-embedding --name Foo --src not-a-url --sandbox allow-forms --title "Demo" --output-dir ${lwcDir()}`
).shellOutput.stderr;
expect(stderr).to.contain('HTTPS URL');
});
Expand All @@ -149,7 +149,7 @@ describe('template generate ui-embedding:', () => {

it('should throw missing lwc parent folder error when output-dir is not under lwc/', () => {
const stderr = execCmd(
`template generate ui-embedding --name Foo --src https://app.example.com --sandbox allow-forms --shell-title "Demo" --output-dir ${path.join(
`template generate ui-embedding --name Foo --src https://app.example.com --sandbox allow-forms --title "Demo" --output-dir ${path.join(
session.project.dir,
'somewhere-else'
)}`
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1436,10 +1436,10 @@
cli-progress "^3.12.0"
terminal-link "^3.0.0"

"@salesforce/templates@^66.14.0":
version "66.14.0"
resolved "https://registry.yarnpkg.com/@salesforce/templates/-/templates-66.14.0.tgz#9ce7e15419094841116500922129554164b28366"
integrity sha512-4tmVFM3/9GefMXmhAoVA43qC4Zq6ir3rWQ8fEJimGizCo6qjsNs9gn1e3nQKldXSgXlt1T6SB0tgnMgsZnp2og==
"@salesforce/templates@^66.15.0":
version "66.15.0"
resolved "https://registry.yarnpkg.com/@salesforce/templates/-/templates-66.15.0.tgz#2b64727feaac1cc947fd8f7eff87f22cc2d9cdb3"
integrity sha512-wOFos8lh/xsswuRs7z3o6D8pCtmScC0LJ0Jzbzz6SxZGxYKoI09NpgXwvCOzZkLRqyCYNUknQi0UplOP2PaIOw==
dependencies:
"@salesforce/kit" "^4.0.0"
ejs "^3.1.10"
Expand Down
Loading