import identity = require ( "oci-identity" ) ; import common = require ( "oci-common" ) ; import email = require ( "oci-email" ) ; const provider = new common . ConfigFileAuthenticationDetailsProvider ( ) ; const args = process . argv . slice ( 2 ) ; if ( args . length !== 4 ) { console . error ( "Unexpected number of arguments received. Consult the script header comments for expected arguments" ) ; process . exit ( - 1 ) ; } const compartmentId = args [ 0 ] ; const targetCompartmentId = args [ 1 ] ; const senderEmailAddress = args [ 2 ] ; const suppressionEmailAddress = args [ 3 ] ; const emailClient = new email . EmailClient ( { authenticationDetailsProvider : provider } ) ; const identityClient = new identity . IdentityClient ( { authenticationDetailsProvider : provider } ) ; async function delay ( s ) { return new Promise ( resolve => setTimeout ( resolve , s * 1000 ) ) ; } async function createEmailSender ( compartmentId , senderEmailAddress ) { const request = { createSenderDetails : { compartmentId : compartmentId , emailAddress : senderEmailAddress } } ; const response = await emailClient . createSender ( request ) ; await delay ( 240 ) ; console . log ( "Created Sender: " , response ) ; return response ; } async function updateEmailSender ( sender ) { const request = { senderId : sender . sender . id ! , updateSenderDetails : { freeformTags : { department : "Finance" } } } ; const response = await emailClient . updateSender ( request ) ; console . log ( "Updated Sender with freeformTags: " , response . sender . freeformTags ) ; return response ; } async function changeSenderCompartment ( sender ) { const request = { senderId : sender . sender . id ! , changeSenderCompartmentDetails : { compartmentId : targetCompartmentId } } ; const response = await emailClient . changeSenderCompartment ( request ) ; console . log ( `Change sender compartment to: ${ targetCompartmentId }` ) ; return response ; } async function listAllSender ( compartmentId , emailAddress ) { const request = { compartmentId : compartmentId } ; if ( emailAddress ) { request [ "emailAddress" ] = emailAddress ; } const senders = await common . paginatedRecordsWithLimit ( request , req => emailClient . listSenders ( request ) ) ; console . log ( "Listing all senders: " ) ; senders . forEach ( sender => { console . log ( "Sender: " , sender ) ; } ) ; return ; } async function createSuppresion ( compartmentId , emailAddress ) { const request = { createSuppressionDetails : { compartmentId : compartmentId , emailAddress : emailAddress } } ; const response = await emailClient . createSuppression ( request ) ; console . log ( "Created suppression: " , response . suppression ) ; return response ; } async function listAllSuppressions ( compartmentId , emailAddress ) { const request = { compartmentId : compartmentId } ; if ( emailAddress ) { request [ "emailAddress" ] = emailAddress ; } const suppressions = await common . paginatedRecordsWithLimit ( request , req => emailClient . listSuppressions ( request ) ) ; console . log ( "List suppressions: " ) ; suppressions . forEach ( suppression => { console . log ( "Suppression: " , suppression ) ; } ) ; } async function deleteSender ( sender ) { const request = { senderId : sender . sender . id ! } ; await emailClient . deleteSender ( request ) ; console . log ( "Deleted Sender." ) ; return ; } async function deleteSuppression ( suppression ) { const request = { suppressionId : suppression . suppression . id ! } ; await emailClient . deleteSuppression ( request ) ; console . log ( "Deleted Supression." ) ; return ; } async function createSmtpCredential ( ) { const request = { userId : provider . getUser ( ) , createSmtpCredentialDetails : { description : "New Credentials" } } ; const smptCredential = await identityClient . createSmtpCredential ( request ) ; console . log ( "Created smptCredential: " , smptCredential ) ; return smptCredential ; } async function updateSmtpCredential ( smptCredential ) { const request = { userId : provider . getUser ( ) , smtpCredentialId : smptCredential . smtpCredential . id ! , updateSmtpCredentialDetails : { description : "Updated Credentials" } } ; const updatedSmtpCredential = await identityClient . updateSmtpCredential ( request ) ; console . log ( "Updated SMTP Credential: " , updatedSmtpCredential . smtpCredentialSummary ) ; return ; } async function listSmtpCredentials ( ) { const request = { userId : provider . getUser ( ) } ; const smtpCredentialsResponse = await identityClient . listSmtpCredentials ( request ) ; console . log ( "SMTP Credentials for user: " , smtpCredentialsResponse ) ; return ; } async function deleteSmtpCredential ( smptCredential ) { const request = { userId : provider . getUser ( ) , smtpCredentialId : smptCredential . smtpCredential . id ! } ; await identityClient . deleteSmtpCredential ( request ) ; console . log ( "Deleted SMTP Credential" ) ; return ; } ( async ( ) => { const sender = await createEmailSender ( compartmentId , senderEmailAddress ) ; await updateEmailSender ( sender ) ; await changeSenderCompartment ( sender ) ; await listAllSender ( compartmentId , "" ) ; await listAllSender ( compartmentId , senderEmailAddress ) ; const suppression = await createSuppresion ( compartmentId , suppressionEmailAddress ) ; await listAllSuppressions ( compartmentId , "" ) ; await listAllSuppressions ( compartmentId , suppressionEmailAddress ) ; await deleteSender ( sender ) ; await deleteSuppression ( suppression ) ; const smtpCredential = await createSmtpCredential ( ) ; await updateSmtpCredential ( smtpCredential ) ; await listSmtpCredentials ( ) ; await deleteSmtpCredential ( smtpCredential ) ; } ) ( ) ;