import PubSub from '@google-cloud/pubsub' ; export const createClient = ( credentials ? ) => { return new PubSub . v1 . SubscriberClient ( { credentials } ) ; } ; export const buildSubscriptionName = ( envName , purpose ) => { return `${ envName }-${ purpose }` ; } ; export const createSubscription = async ( client , projectID , topic , subscriptionName ) => { const formattedName = client . subscriptionPath ( projectID , subscriptionName ) ; const formattedTopic = client . topicPath ( projectID , topic ) ; const request = { name : formattedName , topic : formattedTopic , } ; const [ subscriptionInfo ] = await client . createSubscription ( request ) ; return subscriptionInfo ; } ; export const deleteSubscription = async ( client , projectID , subscriptionName ) => { const formattedName = client . subscriptionPath ( projectID , subscriptionName ) ; await client . deleteSubscription ( { subscription : formattedName } ) ; return true ; } ; export const createStreamingPull = ( client , projectID , subscriptionName , handler ) => { const stream = client . streamingPull ( ) . on ( 'data' , handler ) ; const formattedName = client . subscriptionPath ( projectID , subscriptionName ) ; const request = { subscription : formattedName , streamAckDeadlineSeconds : 10 , } ; stream . write ( request ) ; } ;