Skip to content

Commit c07b233

Browse files
committed
Change how Webhook Subscription UID is generated
1 parent 73c7be2 commit c07b233

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

packages/app/src/cli/models/extensions/extension-instance.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,24 @@ describe('draftMessages', async () => {
531531
expect(extensionInstance.uid).toBe(nonRandomUUID(extensionInstance.handle))
532532
})
533533

534-
test('returns non-random UUID based on handle when strategy is dynamic', async () => {
534+
test('returns a custom string when strategy is dynamic and it is a webhook subscription extension without filters', async () => {
535535
// Given
536536
const extensionInstance = await testSingleWebhookSubscriptionExtension()
537+
// Then
538+
expect(extensionInstance.uid).toBe('orders/delete::undefined::https://my-app.com/webhooks')
539+
})
537540

541+
test('returns a custom string when strategy is dynamic and it is a webhook subscription extension with filters', async () => {
542+
// Given
543+
const extensionInstance = await testSingleWebhookSubscriptionExtension({
544+
config: {
545+
topic: 'orders/delete',
546+
uri: 'https://my-app.com/webhooks',
547+
filter: '123',
548+
},
549+
})
538550
// Then
539-
expect(extensionInstance.uid).toBe(nonRandomUUID(extensionInstance.handle))
551+
expect(extensionInstance.uid).toBe('orders/delete::123::https://my-app.com/webhooks')
540552
})
541553
})
542554
})

packages/app/src/cli/models/extensions/extension-instance.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22

3-
import {BaseConfigType, MAX_EXTENSION_HANDLE_LENGTH} from './schemas.js'
3+
import {BaseConfigType, MAX_EXTENSION_HANDLE_LENGTH, MAX_UID_LENGTH} from './schemas.js'
44
import {FunctionConfigType} from './specifications/function.js'
55
import {ExtensionFeature, ExtensionSpecification} from './specification.js'
66
import {SingleWebhookSubscriptionType} from './specifications/app_config_webhook_schemas/webhooks_schema.js'
@@ -508,7 +508,19 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
508508
case 'uuid':
509509
return this.configuration.uid ?? nonRandomUUID(this.handle)
510510
case 'dynamic':
511-
return nonRandomUUID(this.handle)
511+
// NOTE: This is a temporary special case for webhook subscriptions.
512+
// We're directly checking for webhook properties and casting the configuration
513+
// instead of using a proper dynamic strategy implementation.
514+
// To remove this special case:
515+
// 1. Implement a proper dynamic UID strategy for webhooks in the server-side specification
516+
// 2. Update the CLI to use that strategy instead of this hardcoded logic
517+
// Related issues: PR #559094 in old Core repo
518+
if ('topic' in this.configuration && 'uri' in this.configuration) {
519+
const subscription = this.configuration as unknown as SingleWebhookSubscriptionType
520+
return `${subscription.topic}::${subscription.filter}::${subscription.uri}`.substring(0, MAX_UID_LENGTH)
521+
} else {
522+
return nonRandomUUID(JSON.stringify(this.configuration))
523+
}
512524
}
513525
}
514526
}

packages/app/src/cli/models/extensions/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {zod} from '@shopify/cli-kit/node/schema'
22

33
export const MAX_EXTENSION_HANDLE_LENGTH = 50
4+
export const MAX_UID_LENGTH = 250
45

56
// eslint-disable-next-line @typescript-eslint/no-explicit-any
67
export type ZodSchemaType<T> = zod.ZodType<T, any, any>

0 commit comments

Comments
 (0)