|
1 | 1 | /* eslint-disable @typescript-eslint/no-non-null-assertion */ |
2 | 2 | import {ZodSchemaType, BaseConfigType, BaseSchema} from './schemas.js' |
3 | 3 | import {ExtensionInstance} from './extension-instance.js' |
| 4 | +import {adminLinkOverride} from './specifications/remote-overrides/admin_link.js' |
4 | 5 | import {blocks} from '../../constants.js' |
5 | 6 |
|
6 | 7 | import {Flag} from '../../utilities/developer-platform-client.js' |
@@ -56,7 +57,7 @@ export interface BuildAsset { |
56 | 57 | } |
57 | 58 |
|
58 | 59 | type BuildConfig = |
59 | | - | {mode: 'ui' | 'theme' | 'function' | 'tax_calculation' | 'none'} |
| 60 | + | {mode: 'ui' | 'theme' | 'function' | 'tax_calculation' | 'none' | 'copy_static_assets'} |
60 | 61 | | {mode: 'copy_files'; filePatterns: string[]; ignoredFilePatterns?: string[]} |
61 | 62 | /** |
62 | 63 | * Extension specification with all the needed properties and methods to load an extension. |
@@ -167,6 +168,11 @@ interface CreateExtensionSpecType<TConfiguration extends BaseConfigType = BaseCo |
167 | 168 | schema?: ZodSchemaType<TConfiguration> |
168 | 169 | } |
169 | 170 |
|
| 171 | +export type CreateContractOverrideExtensionSpecType<TConfiguration extends BaseConfigType = BaseConfigType> = Partial< |
| 172 | + CreateExtensionSpecType<TConfiguration> |
| 173 | +> & { |
| 174 | + transform?: (config: TConfiguration) => TConfiguration |
| 175 | +} |
170 | 176 | /** |
171 | 177 | * Create a new ui extension spec. |
172 | 178 | * |
@@ -269,21 +275,25 @@ export function createConfigExtensionSpecification<TConfiguration extends BaseCo |
269 | 275 | } |
270 | 276 |
|
271 | 277 | export function createContractBasedModuleSpecification<TConfiguration extends BaseConfigType = BaseConfigType>( |
272 | | - spec: Pick<CreateExtensionSpecType<TConfiguration>, 'identifier' | 'appModuleFeatures' | 'buildConfig'>, |
| 278 | + spec: Pick<CreateExtensionSpecType<TConfiguration>, 'identifier' | 'appModuleFeatures'> & |
| 279 | + CreateContractOverrideExtensionSpecType<TConfiguration>, |
273 | 280 | ) { |
| 281 | + const defaultDeployConfig = async (config: TConfiguration, directory: string) => { |
| 282 | + let parsedConfig = configWithoutFirstClassFields(config) |
| 283 | + if (spec.appModuleFeatures().includes('localization')) { |
| 284 | + const localization = await loadLocalesConfig(directory, spec.identifier) |
| 285 | + parsedConfig = {...parsedConfig, localization} |
| 286 | + } |
| 287 | + return parsedConfig |
| 288 | + } |
| 289 | + |
| 290 | + const schema = spec.transform ? zod.any({}).transform(spec.transform) : zod.any({}) |
| 291 | + |
274 | 292 | return createExtensionSpecification({ |
275 | | - identifier: spec.identifier, |
276 | | - schema: zod.any({}) as unknown as ZodSchemaType<TConfiguration>, |
277 | | - appModuleFeatures: spec.appModuleFeatures, |
| 293 | + ...spec, |
| 294 | + schema, |
278 | 295 | buildConfig: spec.buildConfig ?? {mode: 'none'}, |
279 | | - deployConfig: async (config, directory) => { |
280 | | - let parsedConfig = configWithoutFirstClassFields(config) |
281 | | - if (spec.appModuleFeatures().includes('localization')) { |
282 | | - const localization = await loadLocalesConfig(directory, spec.identifier) |
283 | | - parsedConfig = {...parsedConfig, localization} |
284 | | - } |
285 | | - return parsedConfig |
286 | | - }, |
| 296 | + deployConfig: spec.deployConfig ?? defaultDeployConfig, |
287 | 297 | }) |
288 | 298 | } |
289 | 299 |
|
@@ -401,3 +411,37 @@ export function configWithoutFirstClassFields(config: JsonMapType): JsonMapType |
401 | 411 | const {type, handle, uid, path, extensions, ...configWithoutFirstClassFields} = config |
402 | 412 | return configWithoutFirstClassFields |
403 | 413 | } |
| 414 | + |
| 415 | +/** |
| 416 | + * Specification overrides for remote specifications that need custom behavior. |
| 417 | + * These overrides are applied when creating contract-based module specifications |
| 418 | + * for extensions that are defined remotely but need local customization. |
| 419 | + * |
| 420 | + * Can include any method from ExtensionSpecification plus a schema. |
| 421 | + * All properties are optional - only provide what you want to override. |
| 422 | + */ |
| 423 | +export type SpecificationOverride<TConfiguration extends BaseConfigType = BaseConfigType> = Partial< |
| 424 | + ExtensionSpecification<TConfiguration> |
| 425 | +> & { |
| 426 | + schema?: ZodSchemaType<TConfiguration> |
| 427 | +} |
| 428 | + |
| 429 | +/** |
| 430 | + * Registry of specification overrides by identifier. |
| 431 | + * Add custom behavior for remote specifications here. |
| 432 | + */ |
| 433 | +export const SPECIFICATION_OVERRIDES: {[key: string]: SpecificationOverride} = { |
| 434 | + admin_link: adminLinkOverride as unknown as SpecificationOverride, |
| 435 | +} |
| 436 | + |
| 437 | +/** |
| 438 | + * Get the override configuration for a specific specification identifier. |
| 439 | + * |
| 440 | + * @param identifier - The specification identifier |
| 441 | + * @returns The override configuration if it exists, undefined otherwise |
| 442 | + */ |
| 443 | +export function getSpecificationOverride<TConfiguration extends BaseConfigType = BaseConfigType>( |
| 444 | + identifier: string, |
| 445 | +): SpecificationOverride<TConfiguration> | undefined { |
| 446 | + return SPECIFICATION_OVERRIDES[identifier] as SpecificationOverride<TConfiguration> | undefined |
| 447 | +} |
0 commit comments