@trycourier/cli
Advanced tools
Comparing version 1.2.1 to 1.3.2
@@ -23,5 +23,5 @@ import React, { useEffect, useState } from 'react'; | ||
}, []); | ||
return React.createElement(React.Fragment, null, | ||
return (React.createElement(React.Fragment, null, | ||
React.createElement(Request, { request: request, response: resp }), | ||
React.createElement(Response, { response: resp })); | ||
React.createElement(Response, { response: resp }))); | ||
}; |
@@ -5,3 +5,3 @@ import React from 'react'; | ||
instructions?: string; | ||
example?: string; | ||
example?: string | string[]; | ||
options?: { | ||
@@ -8,0 +8,0 @@ option: string; |
@@ -42,6 +42,8 @@ import React from 'react'; | ||
: null, | ||
v.example ? (React.createElement(Text, { color: "cyan" }, | ||
v.example && Array.isArray(v.example) ? (v.example.map((e, i) => (React.createElement(Text, { color: "cyan", key: i }, | ||
' ', | ||
e)))) : v.example ? (React.createElement(Text, { color: "cyan" }, | ||
' ', | ||
v.example)) : null)); | ||
}))); | ||
}; |
@@ -32,3 +32,3 @@ import React, { useEffect, useState } from 'react'; | ||
} | ||
let content = { | ||
let contentElemental = { | ||
title: undefined, | ||
@@ -38,9 +38,9 @@ body: undefined, | ||
if (params.title) { | ||
content.title = params.title; | ||
contentElemental.title = params.title; | ||
} | ||
if (params.body) { | ||
content.body = params.body; | ||
contentElemental.body = params.body; | ||
} | ||
else if (params.message) { | ||
content.body = params.message; | ||
contentElemental.body = params.message; | ||
} | ||
@@ -66,25 +66,43 @@ let routing = { | ||
} | ||
const { _, user, list, audience, email, tel, apn, fcm, title, body, elemental, mock, ...data } = params; | ||
return { | ||
message: { | ||
to: to.length === 1 ? to[0] : to, | ||
content, | ||
routing: routing.channels.length ? routing : undefined, | ||
data: data ? data : undefined, | ||
}, | ||
}; | ||
const { _, user, list, audience, email, tel, apn, fcm, title, body, message, template, channel, channels, all, elemental, mock, ...data } = params; | ||
if (params.template) { | ||
return { | ||
type: 'template', | ||
message: { | ||
to: to.length === 1 ? to[0] : to, | ||
template: params.template, | ||
routing: routing.channels.length ? routing : undefined, | ||
data: data ? data : undefined, | ||
}, | ||
}; | ||
} | ||
else { | ||
return { | ||
type: 'elemental', | ||
message: { | ||
to: to.length === 1 ? to[0] : to, | ||
content: contentElemental, | ||
routing: routing.channels.length ? routing : undefined, | ||
data: data ? data : undefined, | ||
}, | ||
}; | ||
} | ||
}; | ||
export default ({ params }) => { | ||
const [resp, setResp] = useState(); | ||
const payload = constructPayload(params); | ||
if (!params.body && !params.template && !params.elemental) { | ||
return (React.createElement(UhOh, { text: "You must specify a message body, template, or Elemental file path." })); | ||
} | ||
let payload = constructPayload(params); | ||
if (!payload.message.to) { | ||
return React.createElement(UhOh, { text: "You must specify a recipient." }); | ||
} | ||
if (!params.elemental && | ||
if (payload.type === 'elemental' && | ||
!params.elemental && | ||
(!payload.message.content.body || !payload.message.content.body?.length)) { | ||
return React.createElement(UhOh, { text: "You must specify a body for the message." }); | ||
throw new Error('You must specify a body for the message.'); | ||
} | ||
if (params.elemental) { | ||
if (params.elemental && payload.type === 'elemental') { | ||
if (!fs.existsSync(params.elemental)) { | ||
return React.createElement(UhOh, { text: "Invalid file path to Elemental document." }); | ||
throw new Error('Invalid file path to Elemental document.'); | ||
} | ||
@@ -96,3 +114,5 @@ payload.message.content = JSON.parse(fs.readFileSync(params.elemental, 'utf8')); | ||
url: '/send', | ||
body: payload, | ||
body: { | ||
message: payload.message, | ||
}, | ||
}; | ||
@@ -110,4 +130,3 @@ useEffect(() => { | ||
React.createElement(Text, null, " Elemental")), | ||
React.createElement(Box, null, | ||
React.createElement(Elemental, { elemental: payload.message.content })))) : null, | ||
React.createElement(Box, null, payload.type === 'elemental' ? (React.createElement(Elemental, { elemental: payload.message.content })) : null))) : null, | ||
React.createElement(React.Fragment, null, | ||
@@ -114,0 +133,0 @@ React.createElement(Request, { request: request, response: resp }), |
@@ -34,5 +34,5 @@ import React, { useEffect, useState } from 'react'; | ||
}, []); | ||
return React.createElement(React.Fragment, null, | ||
return (React.createElement(React.Fragment, null, | ||
React.createElement(Request, { request: request, response: resp }), | ||
React.createElement(Response, { response: resp })); | ||
React.createElement(Response, { response: resp }))); | ||
}; |
@@ -32,5 +32,5 @@ import React, { useEffect, useState } from 'react'; | ||
}, []); | ||
return React.createElement(React.Fragment, null, | ||
return (React.createElement(React.Fragment, null, | ||
React.createElement(Request, { request: request, response: resp }), | ||
React.createElement(Response, { response: resp })); | ||
React.createElement(Response, { response: resp }))); | ||
}; |
@@ -6,2 +6,3 @@ import React from 'react'; | ||
export default (props) => { | ||
const url = `${process.env['COURIER_DOMAIN'] || 'https://api.courier.com'}${props.request.url}`; | ||
return (React.createElement(Box, { flexDirection: "column" }, | ||
@@ -13,4 +14,3 @@ React.createElement(Box, { borderStyle: "bold", borderColor: "blue" }, | ||
' ', | ||
"https://api.courier.com", | ||
props.request.url)), | ||
url)), | ||
props.request.body ? (typeof props.request.body === 'string' ? (React.createElement(Text, null, props.request.body)) : (React.createElement(Text, null, JSON.stringify(props.request.body, undefined, ' ')))) : null, | ||
@@ -17,0 +17,0 @@ !props.request.body ? React.createElement(Text, { color: "gray" }, "No request body") : null, |
@@ -5,3 +5,3 @@ import React from 'react'; | ||
instructions?: string; | ||
example?: string; | ||
example?: string | string[]; | ||
options?: { | ||
@@ -8,0 +8,0 @@ option: string; |
@@ -22,3 +22,3 @@ import React from 'react'; | ||
mappings.set('send', { | ||
instructions: 'Send a notification to a user, list, or audience', | ||
instructions: 'Send a notification to a user, list, or audience. Unrecognized parameters will be sent as message data.', | ||
options: [ | ||
@@ -66,2 +66,6 @@ { | ||
{ | ||
option: '--template <template ID or alias>', | ||
value: 'ID or alias of a template stored in Courier', | ||
}, | ||
{ | ||
option: '--channels <channel>', | ||
@@ -75,3 +79,6 @@ value: 'comma-delimted list of channels to send to', | ||
], | ||
example: `courier send --tel 555-867-5309 --body "Hey Jenny\\!"`, | ||
example: [ | ||
`courier send --tel 555-867-5309 --body "Hey Jenny\\!"`, | ||
`courier send --user user123 --template my-template-id --foo bar`, | ||
], | ||
component: params => { | ||
@@ -78,0 +85,0 @@ return React.createElement(Send, { params: params }); |
{ | ||
"name": "@trycourier/cli", | ||
"version": "1.2.1", | ||
"version": "1.3.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "bin": { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
44905
1183
7