Skip to content

Commit

Permalink
Merge pull request #4465 from Shopify/support-non-config-contract-mod…
Browse files Browse the repository at this point in the history
…ules

Add support for contract-based app modules
  • Loading branch information
isaacroldan authored Sep 20, 2024
2 parents 0e2831c + c0478b4 commit 1c26162
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {loadLocalExtensionsSpecifications} from './load-specifications.js'
import {createContractBasedModuleSpecification} from './specification.js'
import {AppSchema} from '../app/app.js'
import {describe, test, expect, beforeAll} from 'vitest'

Expand Down Expand Up @@ -26,3 +27,20 @@ describe('allLocalSpecs', () => {
expect(got.length).not.toEqual(0)
})
})

describe('createContractBasedModuleSpecification', () => {
test('creates a specification with the given identifier', () => {
// When
const got = createContractBasedModuleSpecification('test', ['bundling'])

// Then
expect(got).toMatchObject(
expect.objectContaining({
identifier: 'test',
experience: 'extension',
uidStrategy: 'uuid',
}),
)
expect(got.appModuleFeatures()).toEqual(['bundling'])
})
})
14 changes: 14 additions & 0 deletions packages/app/src/cli/models/extensions/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ export function createContractBasedConfigModuleSpecification<TKey extends string
})
}

export function createContractBasedModuleSpecification<TConfiguration extends BaseConfigType = BaseConfigType>(
identifier: string,
appModuleFeatures?: ExtensionFeature[],
) {
return createExtensionSpecification({
identifier,
schema: zod.any({}) as unknown as ZodSchemaType<TConfiguration>,
appModuleFeatures: () => appModuleFeatures ?? [],
deployConfig: async (config, _) => {
return config
},
})
}

function resolveAppConfigTransform(transformConfig?: TransformationConfig | CustomTransformationConfig) {
if (!transformConfig) return (content: object) => defaultAppConfigTransform(content as {[key: string]: unknown})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
import {MarketingActivityExtensionSchema} from './marketing_activity_schemas/marketing_activity_schema.js'
import {createExtensionSpecification} from '../specification.js'
import {randomUUID} from '@shopify/cli-kit/node/crypto'
import {createContractBasedModuleSpecification} from '../specification.js'

const spec = createExtensionSpecification({
identifier: 'marketing_activity',
schema: MarketingActivityExtensionSchema,
appModuleFeatures: (_) => ['bundling'],
deployConfig: async (config, _) => {
return {
title: config.title,
description: config.description,
api_path: config.api_path,
tactic: config.tactic,
marketing_channel: config.marketing_channel,
referring_domain: config.referring_domain,
is_automation: config.is_automation,
use_external_editor: config.use_external_editor,
preview_data: config.preview_data,
fields: config.fields.map((field) => ({
...field,
// NOTE: we're not using this id anywhere, generating it to satisfy the schema
// decided not to remove it from the schema for now to minimize the risk of breaking changes
id: randomUUID(),
})),
}
},
})
const spec = createContractBasedModuleSpecification('marketing_activity')

export default spec

0 comments on commit 1c26162

Please sign in to comment.