ampsalesfunnels-functions
Set with helper functions for the implementation of Netlify functions.
Functions
- printEnv(additionalAMPSFVars, additionalNetlifyVars) ⇒
void
Print values of important Netlify provided built-in environment variables, and environment variables used by AMPSalesFunnels.
- isProductionBasedOnHostname() ⇒
boolean
Is site in production mode? Based on the host name.
- getEnv(envName)
Get the value of the given environment variable, depending on production parameter. If production is true get PRODUCTION_
with fallback to . If production is false get SANDBOX_ with fallback to . If variable does not exist
throw exception.
- prepareFunction(event, context, dirname, additionalAMPSFVars, additionalNetlifyVars) ⇒
void
Prepare a Netlify function for execution.
- getAMPRedirectToFunctionResult(url) ⇒
*
Get a Netlify function result object that will do an AMP redirect to an url.
- getEmptyFunctionResult() ⇒
Object
Get a Netlify 200 function result with empty JSON body.
- getMessageFunctionResult(message) ⇒
Object
Get a Netlify 200 function result with message.
- getObjectFunctionResult(obj) ⇒
*
Get a Netlify 200 function result with body.
- getErrorFunctionResult(statusCode, error) ⇒
Object
Get a Netlify function error result object.
- sendEmailWithMailgen(nodemailerTransporter, from, to, name, sku, dirname) ⇒
Promise.<void>
Send email using nodemailer with body generated using mailgen.
- makeQueryString(params) ⇒
string
Convert a dictionary object into a query string with URI encoded values
- ifttt_event(key, eventname, value1, value2, value3)
Log an event to IFTTT.
- log_event(production, eventname, valueA, valueB)
Log an event to available providers.
- log_event_error(production, functionFilename, name, email, message)
Log an error event to available providers.
- log_event_information(production, functionFilename, name, email, message)
Log an information event to available providers.
- log_event_interest(production, name, email, sku, price)
Log an interested in sku event to available providers.
- log_event_sale(production, name, email, sku, price)
Log a sale of sku event to available providers.
- getPayPalBaseUrl(production) ⇒
string
Get the PayPal base URL.
- getPayPalMerchantEmail(production) ⇒
string
Get the PayPal merchant email address.
- getPayPalIpnNotificationUrl(production) ⇒
string
Get the PayPal IPN notification URL.
- getPayPalProductUrl(sku, formData, customData, siteUrl, returnPage, cancelPage, logoUrl, dirname, production) ⇒
string
Get the PayPal url to do the checkout for a product.
- payPalIpnValidate(ipnMessage, production) ⇒
Promise.<void>
Validate the contents of a PayPal IPN message with PayPal.
Throws an exception if the IPN message is INVALID.
- payPalIpnToOrder(body) ⇒
*
Convert PayPal IPN message to an order object. The field custom in the order contains the order form fields.
printEnv(additionalAMPSFVars, additionalNetlifyVars) ⇒ void
Print values of important Netlify provided built-in environment variables, and environment variables used by AMPSalesFunnels.
Kind: global function
Param | Type | Description |
---|
additionalAMPSFVars | Array.<string> | additional AMPSalesFunnels specific environment variables to print |
additionalNetlifyVars | Array.<string> | additional Netlify specific environment variables to print |
isProductionBasedOnHostname() ⇒ boolean
Is site in production mode? Based on the host name.
Kind: global function
getEnv(envName)
Get the value of the given environment variable, depending on production parameter. If production is true get PRODUCTION_
with fallback to . If production is false get SANDBOX_ with fallback to . If variable does not exist
throw exception.
Kind: global function
prepareFunction(event, context, dirname, additionalAMPSFVars, additionalNetlifyVars) ⇒ void
Prepare a Netlify function for execution.
Kind: global function
Param | Type | Description |
---|
event | APIGatewayProxyEvent | |
context | any | |
dirname | string | path to the directory containing the function |
additionalAMPSFVars | Array.<string> | additional AMPSalesFunnels specific environment variables to print |
additionalNetlifyVars | Array.<string> | additional Netlify specific environment variables to print |
getAMPRedirectToFunctionResult(url) ⇒ *
Get a Netlify function result object that will do an AMP redirect to an url.
Kind: global function
Param | Type | Description |
---|
url | string | url to redirect to |
getEmptyFunctionResult() ⇒ Object
Get a Netlify 200 function result with empty JSON body.
Kind: global function
getMessageFunctionResult(message) ⇒ Object
Get a Netlify 200 function result with message.
Kind: global function
Param | Type | Description |
---|
message | string | the message to return in body: { "message": message } |
getObjectFunctionResult(obj) ⇒ *
Get a Netlify 200 function result with body.
Kind: global function
Param | Type | Description |
---|
obj | * | the obj to return in body: { ... } |
getErrorFunctionResult(statusCode, error) ⇒ Object
Get a Netlify function error result object.
Kind: global function
Param | Type | Description |
---|
statusCode | number | status code |
error | Error | string | the error object (or a string), error message wil be returned in body: { "error": "message" } |
sendEmailWithMailgen(nodemailerTransporter, from, to, name, sku, dirname) ⇒ Promise.<void>
Send email using nodemailer with body generated using mailgen.
Kind: global function
Param | Type | Description |
---|
nodemailerTransporter | Transporter | the nodemailer transporter to use |
from | string | email address of the sender |
to | string | email address to send the mail to |
name | string | name of the customer |
sku | string | unique identifier for the product (stock-keeping unit) |
dirname | string | path to the directory containing the mailgen files |
makeQueryString(params) ⇒ string
Convert a dictionary object into a query string with URI encoded values
Kind: global function
Returns: string
-
the query string
Param | Type | Description |
---|
params | Object.<string, string> | dictionary object with name-value pairs |
ifttt_event(key, eventname, value1, value2, value3)
Log an event to IFTTT.
Kind: global function
Category: IFTTT
Param | Type | Description |
---|
key | string | IFTTT key, available at https://ifttt.com/maker_webhooks/settings (after /use/) |
eventname | string | the name of the event to report |
value1 | string | first value |
value2 | string | second value |
value3 | string | third value |
log_event(production, eventname, valueA, valueB)
Log an event to available providers.
Kind: global function
Category: IFTTT
Param | Type | Description |
---|
production | boolean | true if production; false if sandbox |
eventname | string | the name of the event to report, can be ERROR, LOG, INTERESTED, SALE, ... |
valueA | string | first value |
valueB | string | second value |
log_event_error(production, functionFilename, name, email, message)
Log an error event to available providers.
Kind: global function
Category: IFTTT
Param | Type | Description |
---|
production | boolean | true if production; false if sandbox |
functionFilename | string | filename of the function |
name | string | name of user |
email | string | email of user |
message | string | error message |
log_event_information(production, functionFilename, name, email, message)
Log an information event to available providers.
Kind: global function
Category: IFTTT
Param | Type | Description |
---|
production | boolean | true if production; false if sandbox |
functionFilename | string | filename of the function |
name | string | name of user |
email | string | email of user |
message | string | message to log |
log_event_interest(production, name, email, sku, price)
Log an interested in sku event to available providers.
Kind: global function
Category: IFTTT
Param | Type | Default | Description |
---|
production | boolean | | true if production; false if sandbox |
name | string | | name of user |
email | string | | email of user |
sku | string | "unknown" | sku of the product user is interested in |
price | string | "unknown" | price of sku |
log_event_sale(production, name, email, sku, price)
Log a sale of sku event to available providers.
Kind: global function
Category: IFTTT
Param | Type | Default | Description |
---|
production | boolean | | true if production; false if sandbox |
name | string | | name of user |
email | string | | email of user |
sku | string | "unknown" | sku of the product user is interested in |
price | string | "unknown" | price of sku |
getPayPalBaseUrl(production) ⇒ string
Get the PayPal base URL.
Kind: global function
Returns: string
-
The PayPal base URL https://www.sandbox.paypal.com or https://www.paypal.com'
Category: PayPal
Param | Type | Description |
---|
production | boolean | in production mode if true; in sandbox mode if false |
getPayPalMerchantEmail(production) ⇒ string
Get the PayPal merchant email address.
Kind: global function
Returns: string
-
email address of merchant
Category: PayPal
Param | Type | Description |
---|
production | boolean | in production mode if true; in sandbox mode if false |
getPayPalIpnNotificationUrl(production) ⇒ string
Get the PayPal IPN notification URL.
Kind: global function
Returns: string
-
The IPN notification URL
Category: PayPal
Param | Type | Description |
---|
production | boolean | in production mode if true; in sandbox mode if false |
getPayPalProductUrl(sku, formData, customData, siteUrl, returnPage, cancelPage, logoUrl, dirname, production) ⇒ string
Get the PayPal url to do the checkout for a product.
Kind: global function
Returns: string
-
- production url if in production mode, sandbox url otherwise
**Category**: PayPal
Param | Type | Description |
---|
sku | string | unique identifier for the product (stock-keeping unit) |
formData | object | form data as posted on the salesfunnel page |
customData | object | custom data to add to the PayPal URL |
siteUrl | string | url of the site hosting the salesfunnel page |
returnPage | string | relative url of page to go to when PayPal checkout completed, e.g. salesfunnel-thanks.html page) |
cancelPage | string | relative url of page to go to when PayPal flow is canceled (salesfunnel page) |
logoUrl | string | relative url to a 150x50 product log image used in PayPal checkout |
dirname | string | path to the directory containing the products.json file |
production | boolean | in production mode if true; in sandbox mode if false |
payPalIpnValidate(ipnMessage, production) ⇒ Promise.<void>
Validate the contents of a PayPal IPN message with PayPal.
Throws an exception if the IPN message is INVALID.
Kind: global function
Returns: Promise.<void>
-
- a Promise than can be awaited
**Category**: PayPal
Param | Type | Description |
---|
ipnMessage | string | the body of the PayPal IPN message |
production | boolean | in production mode if true; in sandbox mode if false |
payPalIpnToOrder(body) ⇒ *
Convert PayPal IPN message to an order object. The field custom in the order contains the order form fields.
Kind: global function
Returns: *
-
an order object with all IPN fields
Category: PayPal
Param | Type | Description |
---|
body | string | POST body as PayPal sends to IPN endpoint |
===
© 2021 Dellariva Solutions