Skip to content

Commit

Permalink
Merge pull request #17 from wildbit/feature/override-base-uri
Browse files Browse the repository at this point in the history
Feature/override base uri
  • Loading branch information
derekrushforth authored Nov 14, 2019
2 parents 5d7e352 + f7ce56f commit 199949b
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postmark-cli",
"version": "1.1.2",
"version": "1.2.2",
"description": "A CLI tool for managing templates, sending emails, and fetching servers on Postmark.",
"main": "./dist/index.js",
"dependencies": {
Expand Down
9 changes: 8 additions & 1 deletion src/commands/email/raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const builder = {
type: 'string',
hidden: true,
},
'request-host': {
type: 'string',
hidden: true,
},
from: {
type: 'string',
describe:
Expand Down Expand Up @@ -54,10 +58,13 @@ const exec = (args: RawEmailArguments): Promise<void> => {
* Execute send command in shell
*/
const sendCommand = (serverToken: string, args: RawEmailArguments): void => {
const { from, to, subject, html, text } = args
const { from, to, subject, html, text, requestHost } = args
const command: CommandResponse = new CommandResponse()
command.initResponse('Sending an email')
const client = new ServerClient(serverToken)
if (requestHost !== undefined && requestHost !== '') {
client.clientOptions.requestHost = requestHost
}

sendEmail(client, from, to, subject, html, text)
.then(response => {
Expand Down
9 changes: 8 additions & 1 deletion src/commands/email/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const builder = {
type: 'string',
hidden: true,
},
'request-host': {
type: 'string',
hidden: true,
},
id: {
type: 'string',
describe: 'Template ID. Required if a template alias is not specified.',
Expand Down Expand Up @@ -56,10 +60,13 @@ const exec = (args: TemplatedEmailArguments) => {
* Execute templated email send command in shell
*/
const sendCommand = (serverToken: string, args: TemplatedEmailArguments) => {
const { id, alias, from, to, model } = args
const { id, alias, from, to, model, requestHost } = args
const command: CommandResponse = new CommandResponse()
command.initResponse('Sending an email')
const client = new ServerClient(serverToken)
if (requestHost !== undefined && requestHost !== '') {
client.clientOptions.requestHost = requestHost
}

sendEmailWithTemplate(client, id, alias, from, to, model)
.then((response: any) => {
Expand Down
9 changes: 8 additions & 1 deletion src/commands/servers/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export const builder = {
type: 'string',
hidden: true,
},
'request-host': {
type: 'string',
hidden: true,
},
count: {
type: 'number',
describe: 'Number of servers to return',
Expand Down Expand Up @@ -55,10 +59,13 @@ const exec = (args: ServerListArguments): Promise<void> => {
* Get list of servers
*/
const listCommand = (accountToken: string, args: ServerListArguments): void => {
const { count, offset, name, showTokens } = args
const { count, offset, name, showTokens, requestHost } = args
const command: CommandResponse = new CommandResponse()
command.initResponse('Fetching servers...')
const client = new AccountClient(accountToken)
if (requestHost !== undefined && requestHost !== '') {
client.clientOptions.requestHost = requestHost
}

getServers(client, count, offset, name)
.then(response => {
Expand Down
25 changes: 18 additions & 7 deletions src/commands/templates/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export const builder = {
type: 'string',
hidden: true,
},
'request-host': {
type: 'string',
hidden: true,
},
overwrite: {
type: 'boolean',
alias: 'o',
Expand All @@ -45,23 +49,28 @@ const exec = (args: TemplatePullArguments) => {
* Begin pulling the templates
*/
const pull = (serverToken: string, args: TemplatePullArguments) => {
const { outputdirectory, overwrite } = args
const { outputdirectory, overwrite, requestHost } = args

// Check if directory exists
if (existsSync(untildify(outputdirectory)) && !overwrite) {
return overwritePrompt(serverToken, outputdirectory)
return overwritePrompt(serverToken, outputdirectory, requestHost)
}

return fetchTemplateList({
sourceServer: serverToken,
outputDir: outputdirectory,
requestHost: requestHost,
})
}

/**
* Ask user to confirm overwrite
*/
const overwritePrompt = (serverToken: string, outputdirectory: string) => {
const overwritePrompt = (
serverToken: string,
outputdirectory: string,
requestHost: string
) => {
return prompt([
{
type: 'confirm',
Expand All @@ -74,6 +83,7 @@ const overwritePrompt = (serverToken: string, outputdirectory: string) => {
return fetchTemplateList({
sourceServer: serverToken,
outputDir: outputdirectory,
requestHost: requestHost,
})
}
})
Expand All @@ -83,9 +93,12 @@ const overwritePrompt = (serverToken: string, outputdirectory: string) => {
* Fetch template list from PM
*/
const fetchTemplateList = (options: TemplateListOptions) => {
const { sourceServer, outputDir } = options
const { sourceServer, outputDir, requestHost } = options
const spinner = ora('Pulling templates from Postmark...').start()
const client = new ServerClient(sourceServer)
if (requestHost !== undefined && requestHost !== '') {
client.clientOptions.requestHost = requestHost
}

client
.getTemplates()
Expand Down Expand Up @@ -129,9 +142,7 @@ const processTemplates = (options: ProcessTemplatesOptions) => {
if (!template.Alias) {
requestCount++
log(
`Template named "${
template.Name
}" will not be downloaded because it is missing an alias.`,
`Template named "${template.Name}" will not be downloaded because it is missing an alias.`,
{ warn: true }
)

Expand Down
9 changes: 8 additions & 1 deletion src/commands/templates/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const builder = {
type: 'string',
hidden: true,
},
'request-host': {
type: 'string',
hidden: true,
},
force: {
type: 'boolean',
describe: 'Disable confirmation before pushing templates',
Expand Down Expand Up @@ -70,10 +74,13 @@ const validateDirectory = (
* Begin pushing the templates
*/
const push = (serverToken: string, args: TemplatePushArguments) => {
const { templatesdirectory, force } = args
const { templatesdirectory, force, requestHost } = args
const spinner = ora('Fetching templates...').start()
const manifest = createManifest(templatesdirectory)
const client = new ServerClient(serverToken)
if (requestHost !== undefined && requestHost !== '') {
client.clientOptions.requestHost = requestHost
}

// Make sure manifest isn't empty
if (manifest.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions src/types/Email.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
interface EmailArguments {
serverToken: string
requestHost: string
from: string
to: string
}
Expand Down
1 change: 1 addition & 0 deletions src/types/Server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface ServerListArguments {
accountToken: string
requestHost: string
count: number
offset: number
name: string
Expand Down
3 changes: 3 additions & 0 deletions src/types/Template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@ export interface ProcessTemplatesOptions {

export interface TemplateListOptions {
sourceServer: string
requestHost: string
outputDir: string
}

export interface TemplatePullArguments {
serverToken: string
requestHost: string
outputdirectory: string
overwrite: boolean
}

export interface TemplatePushArguments {
serverToken: string
requestHost: string
templatesdirectory: string
force: boolean
}
Expand Down

0 comments on commit 199949b

Please sign in to comment.