-
Notifications
You must be signed in to change notification settings - Fork 258
[Feature] Allow Flow action extension runtime_urls to be relative
#7715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EliasJRH
wants to merge
9
commits into
extend_deploy_config
Choose a base branch
from
relative_dev_flow_action_urls
base: extend_deploy_config
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
487d5bd
Allow for relative urls in Flow action extensions during development
EliasJRH 67fd91d
Allow flow action deployments to use relative urls
EliasJRH 563c8dd
Have runtime urls be properly resolved with app url at dev and deploy…
EliasJRH 26c25d2
Remove unused validation function
EliasJRH 3b29450
Expand deploy config url resolution test
EliasJRH 4b9e23b
Add and use custom Flow action url validation
EliasJRH 569fe8d
Tighten URL validation
EliasJRH d7f6e39
Tigheten URL resolver function
EliasJRH e9e8ed7
Add changeset
EliasJRH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@shopify/app': minor | ||
| --- | ||
|
|
||
| Allow Flow action extension URLs to be as relative paths and resolved against the application URL during dev and deploy |
164 changes: 164 additions & 0 deletions
164
packages/app/src/cli/models/extensions/specifications/flow_action.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import {placeholderAppConfiguration, testFlowActionExtension} from '../../app/app.test-data.js' | ||
| import {ExtensionInstance} from '../extension-instance.js' | ||
| import {BaseConfigType} from '../schemas.js' | ||
| import {ApplicationURLs} from '../../../services/dev/urls.js' | ||
| import {beforeEach, describe, expect, test} from 'vitest' | ||
|
|
||
| type FlowActionConfig = BaseConfigType & { | ||
| type: 'flow_action' | ||
| handle: string | ||
| name: string | ||
| runtime_url: string | ||
| validation_url?: string | ||
| config_page_url?: string | ||
| config_page_preview_url?: string | ||
| } | ||
|
|
||
| const tunnelUrls: ApplicationURLs = { | ||
| applicationUrl: 'https://my-tunnel.example.com', | ||
| redirectUrlWhitelist: [], | ||
| } | ||
|
|
||
| const urlFields = ['runtime_url', 'validation_url', 'config_page_url', 'config_page_preview_url'] as const | ||
|
|
||
| describe('FlowActionExtension', () => { | ||
| let extension: ExtensionInstance<FlowActionConfig> | ||
|
|
||
| const config: FlowActionConfig = { | ||
| type: 'flow_action', | ||
| handle: 'place-bid', | ||
| name: 'Place auction bid', | ||
| description: 'Place a bid on an auction', | ||
| runtime_url: '/api/execute', | ||
| validation_url: '/api/validate', | ||
| config_page_url: '/config', | ||
| config_page_preview_url: '/config/preview', | ||
| } | ||
|
|
||
| beforeEach(async () => { | ||
| extension = (await testFlowActionExtension()) as ExtensionInstance<FlowActionConfig> | ||
| extension.configuration = {...config} | ||
| }) | ||
|
|
||
| test('accepts an absolute https runtime_url', () => { | ||
| // When | ||
| const parsed = extension.specification.parseConfigurationObject({ | ||
| ...config, | ||
| runtime_url: 'https://example.com/api/execute', | ||
| }) | ||
|
|
||
| // Then | ||
| expect(parsed.state).toBe('ok') | ||
| }) | ||
|
|
||
| test('accepts a relative runtime_url starting with /', () => { | ||
| // When | ||
| const parsed = extension.specification.parseConfigurationObject(config) | ||
|
|
||
| // Then | ||
| expect(parsed.state).toBe('ok') | ||
| }) | ||
|
|
||
| test('rejects a non-https absolute runtime_url', () => { | ||
| // When | ||
| const parsed = extension.specification.parseConfigurationObject({ | ||
| ...config, | ||
| runtime_url: 'http://example.com/api/execute', | ||
| }) | ||
|
|
||
| // Then | ||
| expect(parsed.state).toBe('error') | ||
| }) | ||
|
|
||
| test.each(urlFields)('rejects a relative %s containing a newline', (field) => { | ||
| // When | ||
| const parsed = extension.specification.parseConfigurationObject({ | ||
| ...config, | ||
| [field]: `/${field}\nmalicious-header: value`, | ||
| }) | ||
|
|
||
| // Then | ||
| expect(parsed.state).toBe('error') | ||
| }) | ||
|
|
||
| test('preserves absolute URLs and prepends the app URL to relative URLs in the deploy configuration', async () => { | ||
| // Given | ||
| extension.configuration = { | ||
| ...extension.configuration, | ||
| runtime_url: '/api/execute', | ||
| validation_url: 'https://my-app.example.com/api/validate', | ||
| config_page_url: '/config', | ||
| config_page_preview_url: 'https://my-app.example.com/config/preview', | ||
| } | ||
|
|
||
| // When | ||
| const got = await extension.deployConfig({ | ||
| apiKey: 'api-key', | ||
| appConfiguration: { | ||
| ...placeholderAppConfiguration, | ||
| application_url: 'https://my-app.example.com', | ||
| }, | ||
| }) | ||
|
|
||
| // Then | ||
| expect(got).toEqual({ | ||
| title: extension.configuration.name, | ||
| description: extension.configuration.description, | ||
| url: 'https://my-app.example.com/api/execute', | ||
| fields: [], | ||
| validation_url: 'https://my-app.example.com/api/validate', | ||
| custom_configuration_page_url: 'https://my-app.example.com/config', | ||
| custom_configuration_page_preview_url: 'https://my-app.example.com/config/preview', | ||
| schema_patch: '', | ||
| return_type_ref: undefined, | ||
| }) | ||
| }) | ||
|
|
||
| test.each(urlFields)('throws when deploying a relative %s without an app URL', async (field) => { | ||
| // Given | ||
| extension.configuration = { | ||
| ...extension.configuration, | ||
| runtime_url: 'https://my-prod-host.example.com/api/execute', | ||
| validation_url: 'https://my-prod-host.example.com/api/validate', | ||
| config_page_url: 'https://my-prod-host.example.com/config', | ||
| config_page_preview_url: 'https://my-prod-host.example.com/config/preview', | ||
| } | ||
| extension.configuration[field] = `/${field}` | ||
|
|
||
| // When/Then | ||
| await expect( | ||
| extension.deployConfig({ | ||
| apiKey: 'api-key', | ||
| appConfiguration: placeholderAppConfiguration, | ||
| }), | ||
| ).rejects.toThrow( | ||
| `Flow action ${field} is a relative URL, but no application_url is configured. Set application_url in your app configuration or use an absolute HTTPS URL.`, | ||
| ) | ||
| }) | ||
|
|
||
| test('prepends the dev application URL to relative URL fields', () => { | ||
| // When | ||
| extension.patchWithAppDevURLs(tunnelUrls) | ||
|
|
||
| // Then | ||
| expect(extension.configuration.runtime_url).toBe('https://my-tunnel.example.com/api/execute') | ||
| expect(extension.configuration.validation_url).toBe('https://my-tunnel.example.com/api/validate') | ||
| expect(extension.configuration.config_page_url).toBe('https://my-tunnel.example.com/config') | ||
| expect(extension.configuration.config_page_preview_url).toBe('https://my-tunnel.example.com/config/preview') | ||
| }) | ||
|
|
||
| test('leaves absolute dev URLs untouched', () => { | ||
| // Given | ||
| extension.configuration.runtime_url = 'https://my-prod-host.example.com/api/execute' | ||
| extension.configuration.validation_url = undefined | ||
| extension.configuration.config_page_url = undefined | ||
| extension.configuration.config_page_preview_url = undefined | ||
|
|
||
| // When | ||
| extension.patchWithAppDevURLs(tunnelUrls) | ||
|
|
||
| // Then | ||
| expect(extension.configuration.runtime_url).toBe('https://my-prod-host.example.com/api/execute') | ||
| expect(extension.configuration.validation_url).toBeUndefined() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming behaviour - this only happens for
app dev, notapp deploy?