@@ -108,6 +108,7 @@ async function createSubscriptionWithPolling(
108108 resourcesReady : boolean
109109} > {
110110 const nonBlocking = startupResourcePolling . nonBlocking === true
111+ // biome-ignore lint/style/noNonNullAssertion: QueueName is validated in initSnsSqs before calling this function
111112 const queueName = creationConfig . queue . QueueName !
112113
113114 const onTopicReady = async ( ) => {
@@ -124,6 +125,8 @@ async function createSubscriptionWithPolling(
124125 extraParams ?. onResourcesReady ?.( {
125126 topicArn : result . topicArn ,
126127 queueUrl : result . queueUrl ,
128+ subscriptionArn : result . subscriptionArn ,
129+ queueName,
127130 } )
128131 } catch ( err ) {
129132 const error = isError ( err ) ? err : new Error ( String ( err ) )
@@ -207,7 +210,12 @@ export type InitSnsSqsExtraParams = ExtraParams & {
207210 * Callback invoked when resources become available in non-blocking mode.
208211 * Only called when startupResourcePolling.nonBlocking is true and resources were not immediately available.
209212 */
210- onResourcesReady ?: ( result : { topicArn : string ; queueUrl : string } ) => void
213+ onResourcesReady ?: ( result : {
214+ topicArn : string
215+ queueUrl : string
216+ subscriptionArn : string
217+ queueName : string
218+ } ) => void
211219 /**
212220 * Callback invoked when background resource polling or subscription creation fails in non-blocking mode.
213221 * This can happen due to polling timeout or subscription creation failure.
@@ -273,9 +281,17 @@ export async function initSnsSqs(
273281 isStartupResourcePollingEnabled ( startupResourcePolling ) &&
274282 ! isCreateTopicCommand ( topicResolutionOptions )
275283 ) {
284+ // Validate that we have either topicArn or topicName to build the ARN
285+ if ( ! topicResolutionOptions . topicArn && ! topicResolutionOptions . topicName ) {
286+ throw new Error (
287+ 'When startup resource polling is enabled and topic is not being created, either topicArn or topicName must be provided in locatorConfig to identify the topic to poll for' ,
288+ )
289+ }
290+
291+ // biome-ignore lint/style/noNonNullAssertion: Validated above that at least one of topicArn or topicName is present
276292 const topicArnToWaitFor =
277293 topicResolutionOptions . topicArn ??
278- ( await buildTopicArn ( stsClient , topicResolutionOptions . topicName ?? '' ) )
294+ ( await buildTopicArn ( stsClient , topicResolutionOptions . topicName ! ) )
279295
280296 return await createSubscriptionWithPolling (
281297 sqsClient ,
@@ -321,13 +337,23 @@ export async function initSnsSqs(
321337 if ( isStartupResourcePollingEnabled ( startupResourcePolling ) ) {
322338 const nonBlocking = startupResourcePolling . nonBlocking === true
323339
340+ // Extract queueName early for use in callbacks
341+ const splitUrl = queueUrl . split ( '/' )
342+ // biome-ignore lint/style/noNonNullAssertion: It's ok
343+ const queueName = splitUrl [ splitUrl . length - 1 ] !
344+
324345 // Track availability for non-blocking mode coordination
325346 let topicAvailable = false
326347 let queueAvailable = false
327348
328349 const notifyIfBothReady = ( ) => {
329350 if ( nonBlocking && topicAvailable && queueAvailable ) {
330- extraParams ?. onResourcesReady ?.( { topicArn : subscriptionTopicArn , queueUrl } )
351+ extraParams ?. onResourcesReady ?.( {
352+ topicArn : subscriptionTopicArn ,
353+ queueUrl,
354+ subscriptionArn : locatorConfig . subscriptionArn ! ,
355+ queueName,
356+ } )
331357 }
332358 }
333359
@@ -354,10 +380,6 @@ export async function initSnsSqs(
354380 // If non-blocking and topic wasn't immediately available, return early
355381 // Background polling will continue and call notifyIfBothReady when topic is available
356382 if ( nonBlocking && topicResult === undefined ) {
357- const splitUrl = queueUrl . split ( '/' )
358- // biome-ignore lint/style/noNonNullAssertion: It's ok
359- const queueName = splitUrl [ splitUrl . length - 1 ] !
360-
361383 // Also start polling for queue in background so we can notify when both are ready
362384 pollForQueue (
363385 sqsClient ,
@@ -419,10 +441,6 @@ export async function initSnsSqs(
419441
420442 // If non-blocking and queue wasn't immediately available, return early
421443 if ( nonBlocking && queueResult === undefined ) {
422- const splitUrl = queueUrl . split ( '/' )
423- // biome-ignore lint/style/noNonNullAssertion: It's ok
424- const queueName = splitUrl [ splitUrl . length - 1 ] !
425-
426444 return {
427445 subscriptionArn : locatorConfig . subscriptionArn ,
428446 topicArn : subscriptionTopicArn ,
0 commit comments