The minimal expected code is a function exported as default that should return the result of the worker’s script execution.
For example:
export default async function MyFunction() { // Do what you want return { status: 'DOWNLOAD_PROCEED', message: 'proceed', } }
To enhance the developer experience we have chosen to use TypeScript. The worker function takes two inputs, which are injected.
export default async function (context: PlatformContext, data: T)Promise<U> { // Do what you want return { status: 'DOWNLOAD_PROCEED', message: 'proceed', } }
Where T and U types stand for the data type (for example, BeforeDownloadRequest) and the expected returned response (like BeforeDownloadResponse for BeforeDownloadRequest).
You can give a name to your function for convenience. You can also use anonymous functions instead.
The code editor also supports arrow functions. The samples provided in the documentation uses arrow functions.