diff --git a/CHANGELOG.md b/CHANGELOG.md index 9526859..bf814bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- `OneBlinkUploader.uploadAiEnvironmentStylingAttachment()` + ### Removed - **[BREAKING]** `OneBlinkUploader.uploadPDFConversion()` diff --git a/src/OneBlinkUploader.ts b/src/OneBlinkUploader.ts index 6dfd01a..a8f7ef7 100644 --- a/src/OneBlinkUploader.ts +++ b/src/OneBlinkUploader.ts @@ -8,6 +8,7 @@ import { UploadEmailAttachmentOptions, UploadCustomPDFOptions, UploadAiBuilderAttachmentOptions, + UploadAiEnvironmentStylingAttachmentOptions, } from './types.js' import { SubmissionTypes } from '@oneblink/types' import generateFormSubmissionTags from './generateFormSubmissionTags.js' @@ -555,6 +556,47 @@ export default class OneBlinkUploader { }) } + /** + * Upload an attachment for use with the AI environment styling. + * + * #### Example + * + * ```ts + * const abortController = new AbortController() + * const result = await uploader.uploadAiEnvironmentStylingAttachment({ + * onProgress: (progress) => { + * // ... + * }, + * data: attachmentData, + * formsAppEnvironmentId: 1, + * abortSignal: abortController.signal, + * }) + * ``` + * + * @param data The attachment data and options + * @returns The upload result + */ + async uploadAiEnvironmentStylingAttachment({ + onProgress, + abortSignal, + data, + formsAppEnvironmentId, + contentType, + fileName, + }: UploadAiEnvironmentStylingAttachmentOptions) { + return await uploadToS3({ + ...this, + contentType, + body: data, + key: `forms-app-environments/${formsAppEnvironmentId}/ai-builder/attachments`, + requestBodyHeader: { + fileName: encodeURIComponent(fileName), + }, + abortSignal, + onProgress, + }) + } + /** * Upload a PDF for a form to be used as a custom PDF in workflow events. * Custom PDFs are always private. diff --git a/src/types.ts b/src/types.ts index 0848def..e5d6111 100644 --- a/src/types.ts +++ b/src/types.ts @@ -90,4 +90,18 @@ export type UploadAiBuilderAttachmentOptions = UploadOptions & { fileName: string } +export type UploadAiEnvironmentStylingAttachmentOptions = UploadOptions & { + /** The file data to upload */ + data: AttachmentUploadData + /** A standard MIME type describing the format of the contents */ + contentType: string + /** + * The id of the Forms App Environment that the AI Environment Styling is + * being used with + */ + formsAppEnvironmentId: number + /** The name of the file being uploaded */ + fileName: string +} + export type UploadEmailAttachmentOptions = UploadAssetOptions