-
Notifications
You must be signed in to change notification settings - Fork 228
Migrate app_access spec to deployConfig + transformRemoteToLocal #6912
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
base: rcb/contract-app-home
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import {validateUrl} from '../../app/validation/common.js' | ||
| import {TransformationConfig, createConfigExtensionSpecification} from '../specification.js' | ||
| import {configWithoutFirstClassFields, createConfigExtensionSpecification} from '../specification.js' | ||
| import {BaseSchemaWithoutHandle} from '../schemas.js' | ||
| import {normalizeDelimitedString} from '@shopify/cli-kit/common/string' | ||
| import {zod} from '@shopify/cli-kit/node/schema' | ||
|
|
@@ -33,19 +33,37 @@ const AppAccessSchema = BaseSchemaWithoutHandle.extend({ | |
|
|
||
| export const AppAccessSpecIdentifier = 'app_access' | ||
|
|
||
| const AppAccessTransformConfig: TransformationConfig = { | ||
| access: 'access', | ||
| scopes: 'access_scopes.scopes', | ||
| required_scopes: 'access_scopes.required_scopes', | ||
| optional_scopes: 'access_scopes.optional_scopes', | ||
| use_legacy_install_flow: 'access_scopes.use_legacy_install_flow', | ||
| redirect_url_allowlist: 'auth.redirect_urls', | ||
| } | ||
|
|
||
| const appAccessSpec = createConfigExtensionSpecification({ | ||
| identifier: AppAccessSpecIdentifier, | ||
| schema: AppAccessSchema, | ||
| transformConfig: AppAccessTransformConfig, | ||
| deployConfig: async (config) => { | ||
| const {name, ...rest} = configWithoutFirstClassFields(config) | ||
| return rest | ||
| }, | ||
| transformRemoteToLocal: (remoteContent: object) => { | ||
| const remote = remoteContent as {[key: string]: unknown} | ||
| const result: {[key: string]: unknown} = {} | ||
|
|
||
| if (remote.access !== undefined) { | ||
| result.access = remote.access | ||
| } | ||
|
|
||
| const accessScopes: {[key: string]: unknown} = {} | ||
| if (remote.scopes !== undefined) accessScopes.scopes = remote.scopes | ||
| if (remote.required_scopes !== undefined) accessScopes.required_scopes = remote.required_scopes | ||
| if (remote.optional_scopes !== undefined) accessScopes.optional_scopes = remote.optional_scopes | ||
| if (remote.use_legacy_install_flow !== undefined) | ||
| accessScopes.use_legacy_install_flow = remote.use_legacy_install_flow | ||
| if (Object.keys(accessScopes).length > 0) { | ||
| result.access_scopes = accessScopes | ||
| } | ||
|
|
||
| if (remote.redirect_url_allowlist !== undefined) { | ||
| result.auth = {redirect_urls: remote.redirect_url_allowlist} | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Reverse transform currently only maps |
||
|
|
||
| return result | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }, | ||
| getDevSessionUpdateMessages: async (config) => { | ||
| const hasAccessModule = config.access_scopes !== undefined | ||
| const isLegacyInstallFlow = config.access_scopes?.use_legacy_install_flow === true | ||
|
|
||
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.
authis required in schema but can be omitted bytransformRemoteToLocalAppAccessSchemadefinesauthas a required object (no.optional()), buttransformRemoteToLocalonly setsresult.authwhenremote.redirect_url_allowlist !== undefined. If the platform returns remote content withoutredirect_url_allowlist(or returnsnull), the transform returns an object missingauth, which can fail schema validation/parsing downstream and potentially break CLI flows that ingest remote module content.