Pluga developer platform toolbox
npm install pluga-plgIf you are using the storageService (>= 0.2.0), define the following in the environment:
AWS_S3_BUCKET=bucket-name
AWS_REGION=region
AWS_ACCESS_KEY_ID=access-key
AWS_SECRET_ACCESS_KEY=secret-keyThere are specific types of errors that are handled differently within the Pluga platform. Details about the supported error types and how they can be used in your code are described below:
AuthError
Authentication error, usually requires manual action from the client. Should be used in cases where an authentication issue prevents the integration from functioning. plg.errors.authError(message: String)Error
Generic error type. Errors of this type put the event in a failed state. Should be used when an integration issue requires manual correction by the client. plg.errors.error(message: String)RateLimitError
Errors of this type allow Pluga to process the events automatically at a later time. Should be used when a resource becomes unavailable due to usage limits, for example. You must provide the necessary time (in seconds) for the resource to become available again.
plg.errors.rateLimitError(message: String, remaining: Integer(seconds))TransientError
Temporary or transient errors that may occur due to instabilities, outages, etc., and do not require any manual action for proper functioning. Events with this type of error are automatically reprocessed by the Pluga platform.
plg.errors.transientError(message: String)The files.remote module provides integration with Amazon S3 for file management.
async upload
Send a local file to a S3 bucket.
plg.files.remote.upload({ fileKey: String, filePath: String })
| Name | Type | Required | Description |
|---|---|---|---|
| fileKey | string | Yes | The unique key (name) for the file in the S3 bucket |
| filePath | string | Yes | The local path of the file to upload |
{
"fileKey": "string"
}| type | When it occurs | Example message |
|---|---|---|
Error |
Local path does not exist | - |
Error |
Internal errors in the AWS SDK | - |
async download
Download a file from an Amazon S3 bucket and save it to a local path.
plg.files.remote.download({
fileKey: String,
pathToWrite: String
sizeLimit: Number
})
| Name | Type | Required | Description |
|---|---|---|---|
| fileKey | string | Yes | The unique key (name) for the file in the S3 bucket |
| pathToWrite | string | Yes | Local path where the downloaded file will be saved |
| sizeLimit | number | No | Optional maximum allowed file size in bytes. If exceeded, the download will fail |
{
"success": true
}| type | When it occurs | Example message |
|---|---|---|
Error |
Local path does not exist | - |
Error |
Internal errors in the AWS SDK | - |
Error |
File exceeds size limit specified in the sizeLimit param |
File size limit exceeded. File size: ${fileSize} bytes, limit: ${sizeLimit} bytes. |
async getSignedUrl
Generate a temporary signed URL to download a file from S3.
plg.files.remote.getSignedUrl({
fileKey: String,
expiresIn: Number
})
| Name | Type | Required | Description |
|---|---|---|---|
| fileKey | string | Yes | The unique key (name) for the file in the S3 bucket |
| expiresIn | number | No | Optional expiration time in seconds. Default: 1800 (30 minutes) |
If the file exists:
{
"fileKey": "string",
"signedUrl": "string",
"expiresIn": "number"
}If file does not exists returns null
| type | When it occurs | Example message |
|---|---|---|
Error |
Internal errors in the AWS SDK | - |
async fileExists
Checks if a file exists in S3 bucket.
plg.files.remote.fileExists({
fileKey: String
})
| Name | Type | Required | Description |
|---|---|---|---|
| fileKey | string | Yes | The unique key (name) for the file in the S3 bucket |
true // if the file exists
false // if the file does not exist| type | When it occurs | Example message |
|---|---|---|
Error |
Internal errors in the AWS SDK, except for 404, which is treated as false | - |
The files.local module enables local file handling.
async downloadStream
Download a file from a URL as a stream and save it locally.
plg.files.local.downloadStream({
pathToWrite: String,
downloadRequestParams: {
downloadUrl: String,
headers?: Object,
},
callbacks?: {
onData?: Function,
onEnd?: Function,
},
})| Name | Type | Required | Description |
|---|---|---|---|
| pathToWrite | string | Yes | Local path where the downloaded file will be saved. |
| downloadRequestParams | object | Yes | Object containing the download URL and optional HTTP headers. |
| downloadRequestParams.downloadUrl | string | Yes | Public URL used to download the file. |
| downloadRequestParams.headers | object | No | Optional HTTP headers to be sent with the download request. |
| callbacks | object | No | Optional callbacks executed during the download lifecycle. |
| callbacks.onData | function | No | Executed for each received data chunk. Receives (dataChunk, currentDownloadedBytesCount). |
| callbacks.onEnd | function | No | Executed when the download finishes. If it returns a value, the promise resolves with that value. |
{
"success": true
}- Note: If
onEndCallbackreturns a value, the promise resolves with that value instead
| Type | When it occurs | Example |
|---|---|---|
Error |
Local path to write does not exist or is not writable | β |
Error |
Download URL provided is not public or request fails | β |
onDataCallback |
Error thrown inside callbacks.onData |
{ "type": "onDataCallback", "error": <original error> } |
onEndCallback |
Error thrown inside callbacks.onEnd |
{ "type": "onEndCallback", "error": <original error> } |
StreamPipelineError |
Stream pipeline fails (connection drop, timeout, write error, etc.) | { "type": "StreamPipelineError", "error": <original error> } |