- SQS
SQS utility to send messages to SQS
- createFormData ⇒
FormData
Creates and populates a FormData object from key-value pairs.
- getGroupMembersEndpoint ⇒
string
Generates the IMS groups endpoint URL.
- getImsOrgsApiPath ⇒
string
Generates the IMS organizations endpoint URL.
- extractIdAndAuthSource ⇒
Object
Extracts the orgId and authSource from the IMS Org ID.
- emailAddressIsAllowed ⇒
boolean
Validates whether the given email address is allowed.
- createClient(log, dbClient, docClient) ⇒
Object
Creates a client object for interacting with DynamoDB.
- createResponse(body, [status], [headers]) ⇒
Response
Creates a response with a JSON body if the content-type is JSON. Defaults to 200 status. If a header is already defined and has a different content-type, it is handled accordingly.
- isArray(value) ⇒
boolean
Determines if the given parameter is an array.
- isBoolean(value) ⇒
boolean
Determines case-insensitively if the given value is a boolean or a string representation of a boolean.
- isInteger(value) ⇒
boolean
Checks if the given value is an integer.
- isNumber(value) ⇒
boolean
Determines if the given value is a number.
- isObject(value) ⇒
boolean
Checks if the given parameter is an object and not an array or null.
- isNonEmptyObject(value) ⇒
boolean
Checks if the given value is an object and contains properties of its own.
- deepEqual(x, y) ⇒
boolean
Deeply compares two objects or arrays for equality. Supports nested objects and arrays. Does not support circular references. Does not compare functions.
- isString(value) ⇒
boolean
Determines if the given parameter is a string.
- hasText(str) ⇒
boolean
Checks if the given string is not empty.
- isValidDate(value) ⇒
boolean
Checks whether the given object is a valid JavaScript Date.
- isIsoDate(str) ⇒
boolean
Validates whether the given string is a JavaScript ISO date string in Zulu (UTC) timezone. Used for persisting system dates, which must be independent of any user timezone.
- isIsoTimeOffsetsDate(str) ⇒
boolean
Validates whether the given string is a JavaScript ISO date string following UTC time offsets format.
- isValidUrl(urlString) ⇒
boolean
Validates whether the given string is a valid URL with http or https protocol.
- toBoolean(value) ⇒
boolean
Converts a given value to a boolean. Throws an error if the value is not a boolean.
- arrayEquals(a, b) ⇒
boolean
Compares two arrays for equality. Supports primitive array item types only.
- dateAfterDays(days, [dateString]) ⇒
Date
Calculates the date after a specified number of days from the current date.
- resolveSecretsName(opts, ctx, defaultPath) ⇒
string
Resolves the name of the secret based on the function version.
- resolveCustomerSecretsName(baseURL, ctx) ⇒
string
Resolves the name of the customer secrets based on the baseURL.
- generateCSVFile(data) ⇒
Buffer
Generates a CSV file from the provided JSON data.
Each key-value pair in the JSON objects corresponds to a column and its value in the CSV. The output is a UTF-8 encoded Buffer that represents the CSV file content.
- logWrapper(fn) ⇒
function
A higher-order function that wraps a given function and enhances logging by appending a
jobId
to log messages when available. This improves traceability of logs associated with specific jobs or processes.The wrapper checks if a
log
object exists in thecontext
and whether themessage
contains ajobId
. If found, log methods (e.g.,info
,error
, etc.) will prepend thejobId
to all log statements wherecontext.contextualLog
is used. If nojobId
is found, logging will remain unchanged.- s3Wrapper(fn) ⇒
function
Adds an S3Client instance and bucket to the context.
- sqsEventAdapter(fn) ⇒
function
Wrapper to turn an SQS record into a function param Inspired by https://github.com/adobe/helix-admin/blob/main/src/index.js#L108-L133
- createSubsegment(parentSegment, hostname) ⇒
Object
Creates a subsegment for a given hostname based on whether the parent segment is traced or not.
- setTraceHeaders(request, parentSegment, subSegment)
Sets the AWS X-Ray trace headers on the request object.
- setSubSegmentFlagsByStatusCode(subSegment, status)
Adds flags to the given subsegment based on the status code of the response.
- addFetchRequestDataToSegment(segment, request, [response])
Adds request and response data to the given segment for AWS X-Ray tracing.
- handleSubSegmentError(subSegment, request, error)
Adds error data to the given segment for AWS X-Ray tracing.
- tracingFetch(url, options) ⇒
Promise.<Response>
Performs a fetch request and adds AWS X-Ray tracing, including request/response tracking.
- prependSchema(url) ⇒
string
Prepends 'https://' schema to the URL if it's not already present.
- stripPort(url) ⇒
string
Strips the port number from the end of the URL.
- stripTrailingDot(url) ⇒
string
Strips the trailing dot from the end of the URL.
- stripTrailingSlash(url) ⇒
string
Strips the trailing slash from the end of the URL if the path is '/'.
- stripWWW(url) ⇒
string
Strips 'www.' from the beginning of the URL if present.
- composeBaseURL(domain) ⇒
string
Composes a base URL by applying a series of transformations to the given domain.
SQS utility to send messages to SQS
Kind: global class
- SQS
- new SQS(region, log)
- .sendMessage(queueUrl, message, messageGroupId) ⇒
Promise.<void>
Param | Type | Description |
---|---|---|
region | string |
AWS region |
log | object |
log object |
Send a message to an SQS queue. For FIFO queues, messageGroupId is required.
Kind: instance method of SQS
Param | Type | Description |
---|---|---|
queueUrl | string |
The URL of the SQS queue. |
message | object |
The message body to send. |
messageGroupId | string |
(Optional) The message group ID for FIFO queues. |
Creates and populates a FormData object from key-value pairs.
Kind: global constant
Returns: FormData
- A populated FormData object.
Param | Type | Description |
---|---|---|
fields | Object |
Object containing key-value pairs to append to FormData. |
Generates the IMS groups endpoint URL.
Kind: global constant
Returns: string
- /ims/organizations/$/groups/${string}/members
- The IMS groups endpoint URL.
Param | Type | Description |
---|---|---|
imsOrgId | string |
The IMS host. |
groupId | string |
The IMS client ID. |
Generates the IMS organizations endpoint URL.
Kind: global constant
Returns: string
- /ims/organizations/$/v2
- The IMS organizations endpoint URL.
Param | Type | Description |
---|---|---|
imsOrgId | string |
The IMS host. |
Extracts the orgId and authSource from the IMS Org ID.
Kind: global constant
Returns: Object
- - The orgId and authSource.
Param | Type | Description |
---|---|---|
imsOrgId | string |
The IMS Org ID. |
Validates whether the given email address is allowed.
Kind: global constant
Returns: boolean
- - True if the email address is allowed, false otherwise.
Param | Type | Description |
---|---|---|
string |
The email address to validate. |
Creates a client object for interacting with DynamoDB.
Kind: global function
Returns: Object
- A client object with methods to interact with DynamoDB.
Param | Type | Description |
---|---|---|
log | Object |
The logging object, defaults to console. |
dbClient | DynamoDB |
The AWS SDK DynamoDB client instance. |
docClient | DynamoDBDocument |
The AWS SDK DynamoDB Document client instance. |
Creates a response with a JSON body if the content-type is JSON. Defaults to 200 status. If a header is already defined and has a different content-type, it is handled accordingly.
Kind: global function
Returns: Response
- Response.
Param | Type | Default | Description |
---|---|---|---|
body | object |
Response body. | |
[status] | number |
200 |
Optional status code. |
[headers] | object |
{} |
Optional headers. |
Determines if the given parameter is an array.
Kind: global function
Returns: boolean
- True if the parameter is an array, false otherwise.
Param | Type | Description |
---|---|---|
value | * |
The value to check. |
Determines case-insensitively if the given value is a boolean or a string representation of a boolean.
Kind: global function
Returns: boolean
- True if the value is a boolean or a string representation of a boolean.
Param | Type | Description |
---|---|---|
value | * |
The value to check. |
Checks if the given value is an integer.
Kind: global function
Returns: boolean
- True if the value is an integer, false otherwise.
Param | Type | Description |
---|---|---|
value | * |
The value to check. |
Determines if the given value is a number.
Kind: global function
Returns: boolean
- True if the value is a finite number, false otherwise.
Param | Type | Description |
---|---|---|
value | * |
The value to check. |
Checks if the given parameter is an object and not an array or null.
Kind: global function
Returns: boolean
- True if the parameter is an object, false otherwise.
Param | Type | Description |
---|---|---|
value | * |
The value to check. |
Checks if the given value is an object and contains properties of its own.
Kind: global function
Returns: boolean
- True if the value is a non-empty object, false otherwise.
Param | Type | Description |
---|---|---|
value | * |
The value to check. |
Deeply compares two objects or arrays for equality. Supports nested objects and arrays. Does not support circular references. Does not compare functions.
Kind: global function
Returns: boolean
- True if the objects or arrays are equal, false otherwise.
Param | Type | Description |
---|---|---|
x | unknown |
The first object or array to compare. |
y | unknown |
The second object or array to compare. |
Determines if the given parameter is a string.
Kind: global function
Returns: boolean
- True if the parameter is a string, false otherwise.
Param | Type | Description |
---|---|---|
value | * |
The value to check. |
Checks if the given string is not empty.
Kind: global function
Returns: boolean
- True if the string is not empty, false otherwise.
Param | Type | Description |
---|---|---|
str | * |
The string to check. |
Checks whether the given object is a valid JavaScript Date.
Kind: global function
Returns: boolean
- True if the given object is a valid Date object, false otherwise.
Param | Type | Description |
---|---|---|
value | * |
The value to check. |
Validates whether the given string is a JavaScript ISO date string in Zulu (UTC) timezone. Used for persisting system dates, which must be independent of any user timezone.
Kind: global function
Returns: boolean
- True if the given string validates successfully.
Param | Type | Description |
---|---|---|
str | string |
The string to validate. |
Validates whether the given string is a JavaScript ISO date string following UTC time offsets format.
Kind: global function
Returns: boolean
- True if the given string validates successfully.
Param | Type | Description |
---|---|---|
str | string |
The string to validate. |
Validates whether the given string is a valid URL with http or https protocol.
Kind: global function
Returns: boolean
- True if the given string validates successfully.
Param | Type | Description |
---|---|---|
urlString | string |
The string to validate. |
Converts a given value to a boolean. Throws an error if the value is not a boolean.
Kind: global function
Returns: boolean
- The converted boolean value.
Throws:
Error
If the value is not a boolean or a boolean-like string.
Param | Type | Description |
---|---|---|
value | * |
The value to convert. |
Compares two arrays for equality. Supports primitive array item types only.
Kind: global function
Returns: boolean
- True if the arrays are equal, false otherwise.
Param | Type | Description |
---|---|---|
a | Array |
The first array to compare. |
b | Array |
The second array to compare. |
Calculates the date after a specified number of days from the current date.
Kind: global function
Returns: Date
- A new Date object representing the calculated date after the specified days.
Throws:
TypeError
If the provided 'days' parameter is not a number.RangeError
If the calculated date is outside the valid JavaScript date range.
Param | Type | Description |
---|---|---|
days | number |
The number of days to add to the current date. |
[dateString] | string |
The reference date in string format. |
Example
// Get the date 7 days from now
const sevenDaysLater = dateAfterDays(7);
console.log(sevenDaysLater); // Outputs a Date object representing the date 7 days from now
Resolves the name of the secret based on the function version.
Kind: global function
Returns: string
- - The resolved secret name.
Param | Type | Description |
---|---|---|
opts | Object |
The options object, not used in this implementation. |
ctx | Object |
The context object containing the function version. |
defaultPath | string |
The default path for the secret. |
Resolves the name of the customer secrets based on the baseURL.
Kind: global function
Returns: string
- - The resolved secret name.
Param | Type | Description |
---|---|---|
baseURL | string |
The base URL to resolve the customer secrets name from. |
ctx | Object |
The context object containing the function version. |
Generates a CSV file from the provided JSON data.
Each key-value pair in the JSON objects corresponds to a column and its value in the CSV. The output is a UTF-8 encoded Buffer that represents the CSV file content.
Kind: global function
Returns: Buffer
- A Buffer containing the CSV formatted data, encoded in UTF-8.
Param | Type | Description |
---|---|---|
data | Array.<Object> |
An array of JSON objects to be converted into CSV format. |
A higher-order function that wraps a given function and enhances logging by appending
a jobId
to log messages when available. This improves traceability of logs associated
with specific jobs or processes.
The wrapper checks if a log
object exists in the context
and whether the message
contains a jobId
. If found, log methods (e.g., info
, error
, etc.) will prepend the
jobId
to all log statements where context.contextualLog
is used. If no jobId
is found,
logging will remain unchanged.
Kind: global function
Returns: function
- - A wrapped function that enhances
logging and returns the result of the original function.
context.contextualLog
will include logging methods with jobId
prefixed, or fall back
to the existing log
object if no jobId
is provided.
Param | Type | Description |
---|---|---|
fn | function |
The original function to be wrapped, called with the provided message and context after logging enhancement. |
Adds an S3Client instance and bucket to the context.
Kind: global function
Param | Type |
---|---|
fn | UniversalAction |
Wrapper to turn an SQS record into a function param Inspired by https://github.com/adobe/helix-admin/blob/main/src/index.js#L108-L133
Kind: global function
Param | Type |
---|---|
fn | UniversalAction |
Creates a subsegment for a given hostname based on whether the parent segment is traced or not.
Kind: global function
Returns: Object
- The created subsegment.
Param | Type | Description |
---|---|---|
parentSegment | Object |
The parent X-Ray segment. |
hostname | string |
The hostname to associate with the subsegment. |
Sets the AWS X-Ray trace headers on the request object.
Kind: global function
Param | Type | Description |
---|---|---|
request | Request |
The request object on which headers are set. |
parentSegment | Object |
The parent X-Ray segment. |
subSegment | Object |
The subsegment to include in the headers. |
Adds flags to the given subsegment based on the status code of the response.
Kind: global function
Param | Type | Description |
---|---|---|
subSegment | Object |
The X-Ray subsegment to which flags are added. |
status | number |
The status code of the response. |
Adds request and response data to the given segment for AWS X-Ray tracing.
Kind: global function
Param | Type | Description |
---|---|---|
segment | Object |
The X-Ray segment to which request and response data are added. |
request | Request |
The original request object. |
[response] | Response |
The response object (if available). |
Adds error data to the given segment for AWS X-Ray tracing.
Kind: global function
Param | Type | Description |
---|---|---|
subSegment | Object |
The X-Ray subsegment to which error data is added. |
request | Request |
The original request object. |
error | Error |
The error object. |
Performs a fetch request and adds AWS X-Ray tracing, including request/response tracking.
Kind: global function
Returns: Promise.<Response>
- The response from the fetch request.
Param | Type | Description |
---|---|---|
url | string |
The URL for the request. |
options | Object |
Options to be passed to the fetch call. |
Prepends 'https://' schema to the URL if it's not already present.
Kind: global function
Returns: string
- - The URL with 'https://' schema prepended.
Param | Type | Description |
---|---|---|
url | string |
The URL to modify. |
Strips the port number from the end of the URL.
Kind: global function
Returns: string
- - The URL with the port removed.
Param | Type | Description |
---|---|---|
url | string |
The URL to modify. |
Strips the trailing dot from the end of the URL.
Kind: global function
Returns: string
- - The URL with the trailing dot removed.
Param | Type | Description |
---|---|---|
url | string |
The URL to modify. |
Strips the trailing slash from the end of the URL if the path is '/'.
Kind: global function
Returns: string
- - The URL with the trailing slash removed.
Param | Type | Description |
---|---|---|
url | string |
The URL to modify. |
Strips 'www.' from the beginning of the URL if present.
Kind: global function
Returns: string
- - The URL with 'www.' removed.
Param | Type | Description |
---|---|---|
url | string |
The URL to modify. |
Composes a base URL by applying a series of transformations to the given domain.
Kind: global function
Returns: string
- - The composed base URL.
Param | Type | Description |
---|---|---|
domain | string |
The domain to compose the base URL from. |