@oneblink/storage 3.2.3-beta.1 → 3.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { AttachmentUploadData, StorageConstructorOptions, UploadAssetOptions, UploadFormSubmissionOptions, UploadOptions, UploadEmailAttachmentOptions, UploadPDFConversionOptions } from './types';
1
+ import { AttachmentUploadData, StorageConstructorOptions, UploadAssetOptions, UploadFormSubmissionOptions, UploadOptions, UploadEmailAttachmentOptions, UploadPDFConversionOptions, UploadAiBuilderAttachmentOptions } from './types';
2
2
  import { SubmissionTypes } from '@oneblink/types';
3
3
  /**
4
4
  * Used to create an instance of the OneBlinkUploader, exposing methods to
@@ -285,6 +285,29 @@ export default class OneBlinkUploader {
285
285
  uploadPDFConversion({ onProgress, abortSignal, data, formId, }: UploadPDFConversionOptions): Promise<{
286
286
  s3: import("@oneblink/types/typescript/aws").S3Configuration;
287
287
  }>;
288
+ /**
289
+ * Upload an attachment for use with the AI builder.
290
+ *
291
+ * #### Example
292
+ *
293
+ * ```ts
294
+ * const abortController = new AbortController()
295
+ * const result = await uploader.uploadAiBuilderAttachment({
296
+ * onProgress: (progress) => {
297
+ * // ...
298
+ * },
299
+ * data: attachmentData,
300
+ * formId: 1,
301
+ * abortSignal: abortController.signal,
302
+ * })
303
+ * ```
304
+ *
305
+ * @param data The attachment data and options
306
+ * @returns The upload result
307
+ */
308
+ uploadAiBuilderAttachment({ onProgress, abortSignal, data, formId, contentType, fileName, }: UploadAiBuilderAttachmentOptions): Promise<{
309
+ s3: import("@oneblink/types/typescript/aws").S3Configuration;
310
+ }>;
288
311
  /**
289
312
  * Upload a volunteer asset file. Asset files are always public.
290
313
  *
@@ -361,6 +361,39 @@ class OneBlinkUploader {
361
361
  onProgress,
362
362
  });
363
363
  }
364
+ /**
365
+ * Upload an attachment for use with the AI builder.
366
+ *
367
+ * #### Example
368
+ *
369
+ * ```ts
370
+ * const abortController = new AbortController()
371
+ * const result = await uploader.uploadAiBuilderAttachment({
372
+ * onProgress: (progress) => {
373
+ * // ...
374
+ * },
375
+ * data: attachmentData,
376
+ * formId: 1,
377
+ * abortSignal: abortController.signal,
378
+ * })
379
+ * ```
380
+ *
381
+ * @param data The attachment data and options
382
+ * @returns The upload result
383
+ */
384
+ async uploadAiBuilderAttachment({ onProgress, abortSignal, data, formId, contentType, fileName, }) {
385
+ return await (0, uploadToS3_1.default)({
386
+ ...this,
387
+ contentType,
388
+ body: data,
389
+ key: `forms/${formId}/ai-builder/attachments`,
390
+ requestBodyHeader: {
391
+ filename: encodeURIComponent(fileName),
392
+ },
393
+ abortSignal,
394
+ onProgress,
395
+ });
396
+ }
364
397
  /**
365
398
  * Upload a volunteer asset file. Asset files are always public.
366
399
  *
@@ -1 +1 @@
1
- {"version":3,"file":"OneBlinkUploader.js","sourceRoot":"","sources":["../src/OneBlinkUploader.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AAWrC,8FAAqE;AACrE;;;GAGG;AACH,MAAqB,gBAAgB;IAKnC;;;;;;;;;;;;OAYG;IACH,YAAY,KAAgC;QAC1C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;QAC1B,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;IAC5C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,gBAAgB,CAAC,EACrB,UAAU,EACV,UAAU,EACV,MAAM,EACN,SAAS,EACT,gCAAgC,EAChC,KAAK,EACL,UAAU,EACV,UAAU,EACV,MAAM,EACN,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,WAAW,GAgBZ;QACC,MAAM,mBAAmB,GAAwC;YAC/D,UAAU;YACV,UAAU;YACV,MAAM;YACN,mBAAmB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,CAAC,mBAAmB,CAAC,EACxB,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,GACqB;QAC3B,OAAO,MAAM,IAAA,oBAAU,EAAC;YACtB,GAAG,IAAI;YACP,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,SAAS,MAAM,iBAAiB;YACrC,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,qBAAqB,CAAC,EAC1B,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,UAAU,GAKT;QACD,OAAO,MAAM,IAAA,oBAAU,EAEpB;YACD,GAAG,IAAI;YACP,WAAW;YACX,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,mBAAmB;YACxB,WAAW;YACX,UAAU;YACV,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;gBACtC,UAAU;aACX;YACD,QAAQ,EAAE,IAAI;SACf,CAAC,CAAA;IACJ,CAAC;CACF;AAjjBD,mCAijBC","sourcesContent":["import uploadToS3 from './uploadToS3'\nimport {\n AttachmentUploadData,\n StorageConstructorOptions,\n UploadAssetOptions,\n UploadFormSubmissionOptions,\n UploadOptions,\n UploadEmailAttachmentOptions,\n UploadPDFConversionOptions,\n} from './types'\nimport { SubmissionTypes } from '@oneblink/types'\nimport generateFormSubmissionTags from './generateFormSubmissionTags'\n/**\n * Used to create an instance of the OneBlinkUploader, exposing methods to\n * upload submissions and other types of files\n */\nexport default class OneBlinkUploader {\n apiOrigin: StorageConstructorOptions['apiOrigin']\n region: StorageConstructorOptions['region']\n getBearerToken: StorageConstructorOptions['getBearerToken']\n\n /**\n * #### Example\n *\n * ```typescript\n * import { OneBlinkUploader } from '@oneblink/uploads'\n *\n * const uploader = new OneBlinkUploader({\n * apiOrigin: 'https://auth-api.blinkm.io',\n * region: 'ap-southeast-2',\n * getBearerToken: () => getAccessToken(),\n * })\n * ```\n */\n constructor(props: StorageConstructorOptions) {\n this.apiOrigin = props.apiOrigin\n this.region = props.region\n this.getBearerToken = props.getBearerToken\n }\n\n /**\n * Upload a submission.\n *\n * #### Example\n *\n * ```ts\n * const result = await uploader.uploadSubmission({\n * submission: {\n * // ...\n * },\n * definition: {\n * // ...\n * },\n * formsAppId: 1,\n * onProgress: (progress) => {\n * // ...\n * },\n * })\n * ```\n *\n * @param data The submission upload data and options\n * @returns The upload result\n */\n async uploadSubmission({\n submission,\n definition,\n device,\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n formSubmissionDraftId,\n completionTimestamp,\n recaptchas = [],\n onProgress,\n abortSignal,\n }: UploadFormSubmissionOptions & {\n /**\n * The date and time (in ISO format) the form was completed I.e. when the\n * user clicked the submit button\n */\n completionTimestamp?: string\n /** The reCAPTCHA tokens to validate the submission */\n recaptchas?: {\n /** The site key that was used to generate the reCAPTCHA token */\n siteKey: string\n /** A reCAPTCHA token */\n token: string\n }[]\n /** The identifier of the draft to mark as submitted. */\n formSubmissionDraftId?: string\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n completionTimestamp,\n }\n const tags = generateFormSubmissionTags({\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n })\n\n return await uploadToS3<{\n submissionTimestamp: string\n submissionId: string\n pdfAccessToken?: string\n attachmentsAccessToken?: string\n preventPayment: boolean\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(newS3SubmissionData),\n key: `forms/${definition.id}/submissions`,\n tags,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n jobId,\n previousFormSubmissionApprovalId,\n recaptchas,\n formSubmissionDraftId,\n },\n })\n }\n\n /**\n * Upload an form submission attachment.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * formId: 1,\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * isPrivate: true,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The attachment upload data and options\n * @returns The upload result\n */\n async uploadAttachment({\n formId,\n fileName,\n contentType,\n isPrivate,\n data,\n username,\n onProgress,\n abortSignal,\n }: UploadOptions & {\n /** The identifier for the form that is being completed */\n formId: number\n /** The name of the file being uploaded */\n fileName: string\n /** A standard MIME type describing the format of the contents */\n contentType: string\n /** Set to `true` to prevent the file from being downloaded publicly */\n isPrivate: boolean\n /** The file data to upload */\n data: AttachmentUploadData\n /** A username to allow a single user to download the attachment file */\n username?: string\n }) {\n return await uploadToS3<{\n url: string\n attachmentDataId: string\n uploadedAt: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `forms/${formId}/attachments`,\n abortSignal,\n onProgress,\n isPublic: !isPrivate,\n contentDisposition: `attachment; filename*=UTF-8''${encodeURIComponent(fileName)}`,\n requestBodyHeader: {\n username: username ? encodeURIComponent(username) : undefined,\n fileName: encodeURIComponent(fileName),\n },\n })\n }\n\n /**\n * Upload a draft submission.\n *\n * #### Example\n *\n * ```ts\n * const result = await uploader.uploadDraftSubmission({\n * submission: {\n * // ...\n * },\n * definition: {\n * // ...\n * },\n * formsAppId: 1,\n * formSubmissionDraftId: '',\n * createdAt: new Date().toISOString(),\n * title: '',\n * onProgress: (progress) => {\n * // ...\n * },\n * })\n * ```\n *\n * @param data The submission upload data and options\n * @returns The upload result\n */\n async uploadFormSubmissionDraft({\n submission,\n definition,\n device,\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n formSubmissionDraftId,\n createdAt,\n title,\n lastElementUpdated,\n sectionState,\n onProgress,\n abortSignal,\n }: UploadFormSubmissionOptions & {\n /** The identifier of the draft that a new version should be created for. */\n formSubmissionDraftId: string\n /**\n * The date and time (in ISO format) when the draft data was saved by a\n * user.\n */\n createdAt: string\n /** The title input by a user to identify the draft. */\n title: string\n /** The identifier for the last element that was used before saving draft */\n lastElementUpdated?: SubmissionTypes.NewS3SubmissionData['lastElementUpdated']\n /** The open/closed state of collapsible sections before saving draft */\n sectionState?: SubmissionTypes.NewS3SubmissionData['sectionState']\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n lastElementUpdated,\n sectionState,\n }\n const tags = generateFormSubmissionTags({\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n })\n\n tags.append('formSubmissionDraftId', formSubmissionDraftId)\n\n return await uploadToS3<SubmissionTypes.FormSubmissionDraftVersion>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(newS3SubmissionData),\n key: 'form-submission-draft-versions',\n tags,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n formsAppId,\n formId: definition.id,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n jobId,\n previousFormSubmissionApprovalId,\n createdAt,\n title,\n formSubmissionDraftId,\n },\n })\n }\n\n /**\n * Upload an asset file. Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAsset({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * organisationId: 'abc123',\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n organisationId,\n }: UploadOptions &\n UploadAssetOptions & {\n /** The identifier for the organisation that owns the asset */\n organisationId: string\n }) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `organisations/${organisationId}/assets`,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName: encodeURIComponent(fileName),\n },\n isPublic: true,\n })\n }\n\n /**\n * Upload an asset file for a product service such as Product Notifications.\n * Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadProductAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n }: UploadOptions & UploadAssetOptions) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `administration/assets`,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName: encodeURIComponent(fileName),\n },\n isPublic: true,\n })\n }\n\n /**\n * Upload form prefill data.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadPrefillData({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: {\n * field1: 'abc',\n * field2: 123,\n * },\n * formId: 12,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The prefill upload data and options\n * @returns The upload result\n */\n async uploadPrefillData({\n formId,\n prefillData,\n onProgress,\n abortSignal,\n }: UploadOptions & {\n /** The identifier for the form that the prefill data is associated with */\n formId: number\n /** The prefill data to upload */\n prefillData: SubmissionTypes.NewS3SubmissionData['submission']\n }) {\n return await uploadToS3<{\n preFillFormDataId: string\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(prefillData),\n key: `forms/${formId}/pre-fill`,\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload an email attachment. Email attachments are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadEmailAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The email attachment data and options\n * @returns The upload result\n */\n async uploadEmailAttachment({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n }: UploadOptions & UploadEmailAttachmentOptions) {\n return await uploadToS3({\n ...this,\n contentType,\n body: data,\n key: 'email-attachments',\n abortSignal,\n onProgress,\n requestBodyHeader: {\n filename: encodeURIComponent(fileName),\n },\n isPublic: false,\n })\n }\n\n /**\n * Upload a PDF for conversion. PDF Conversions are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadPDFConversion({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: pdfData,\n * formId: 1,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The PDF data and options\n * @returns The upload result\n */\n async uploadPDFConversion({\n onProgress,\n abortSignal,\n data,\n formId,\n }: UploadPDFConversionOptions) {\n return await uploadToS3({\n ...this,\n contentType: 'application/pdf',\n body: data,\n key: `forms/${formId}/pdf-conversion`,\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload a volunteer asset file. Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadVolunteersAsset({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * formsAppId: 1,\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadVolunteersAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n formsAppId,\n }: UploadOptions &\n UploadAssetOptions & {\n /** The identifier for the volunteers app that owns the asset */\n formsAppId: number\n }) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: 'volunteers/assets',\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName: encodeURIComponent(fileName),\n formsAppId,\n },\n isPublic: true,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"OneBlinkUploader.js","sourceRoot":"","sources":["../src/OneBlinkUploader.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AAYrC,8FAAqE;AACrE;;;GAGG;AACH,MAAqB,gBAAgB;IAKnC;;;;;;;;;;;;OAYG;IACH,YAAY,KAAgC;QAC1C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;QAC1B,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;IAC5C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,gBAAgB,CAAC,EACrB,UAAU,EACV,UAAU,EACV,MAAM,EACN,SAAS,EACT,gCAAgC,EAChC,KAAK,EACL,UAAU,EACV,UAAU,EACV,MAAM,EACN,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,WAAW,GAgBZ;QACC,MAAM,mBAAmB,GAAwC;YAC/D,UAAU;YACV,UAAU;YACV,MAAM;YACN,mBAAmB;SACpB,CAAA;QACD,MAAM,IAAI,GAAG,IAAA,oCAA0B,EAAC;YACtC,SAAS;YACT,gCAAgC;YAChC,KAAK;SACN,CAAC,CAAA;QAEF,OAAO,MAAM,IAAA,oBAAU,EAMpB;YACD,GAAG,IAAI;YACP,WAAW,EAAE,kBAAkB;YAC/B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC;YACzC,GAAG,EAAE,SAAS,UAAU,CAAC,EAAE,cAAc;YACzC,IAAI;YACJ,WAAW;YACX,UAAU;YACV,iBAAiB,EAAE;gBACjB,UAAU;gBACV,UAAU;gBACV,MAAM;gBACN,YAAY;gBACZ,mBAAmB;gBACnB,KAAK;gBACL,gCAAgC;gBAChC,UAAU;gBACV,q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;YACP,WAAW;YACX,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,SAAS,MAAM,yBAAyB;YAC7C,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;aACvC;YACD,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,qBAAqB,CAAC,EAC1B,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,UAAU,GAKT;QACD,OAAO,MAAM,IAAA,oBAAU,EAEpB;YACD,GAAG,IAAI;YACP,WAAW;YACX,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,mBAAmB;YACxB,WAAW;YACX,UAAU;YACV,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;gBACtC,UAAU;aACX;YACD,QAAQ,EAAE,IAAI;SACf,CAAC,CAAA;IACJ,CAAC;CACF;AA1lBD,mCA0lBC","sourcesContent":["import uploadToS3 from './uploadToS3'\nimport {\n AttachmentUploadData,\n StorageConstructorOptions,\n UploadAssetOptions,\n UploadFormSubmissionOptions,\n UploadOptions,\n UploadEmailAttachmentOptions,\n UploadPDFConversionOptions,\n UploadAiBuilderAttachmentOptions,\n} from './types'\nimport { SubmissionTypes } from '@oneblink/types'\nimport generateFormSubmissionTags from './generateFormSubmissionTags'\n/**\n * Used to create an instance of the OneBlinkUploader, exposing methods to\n * upload submissions and other types of files\n */\nexport default class OneBlinkUploader {\n apiOrigin: StorageConstructorOptions['apiOrigin']\n region: StorageConstructorOptions['region']\n getBearerToken: StorageConstructorOptions['getBearerToken']\n\n /**\n * #### Example\n *\n * ```typescript\n * import { OneBlinkUploader } from '@oneblink/uploads'\n *\n * const uploader = new OneBlinkUploader({\n * apiOrigin: 'https://auth-api.blinkm.io',\n * region: 'ap-southeast-2',\n * getBearerToken: () => getAccessToken(),\n * })\n * ```\n */\n constructor(props: StorageConstructorOptions) {\n this.apiOrigin = props.apiOrigin\n this.region = props.region\n this.getBearerToken = props.getBearerToken\n }\n\n /**\n * Upload a submission.\n *\n * #### Example\n *\n * ```ts\n * const result = await uploader.uploadSubmission({\n * submission: {\n * // ...\n * },\n * definition: {\n * // ...\n * },\n * formsAppId: 1,\n * onProgress: (progress) => {\n * // ...\n * },\n * })\n * ```\n *\n * @param data The submission upload data and options\n * @returns The upload result\n */\n async uploadSubmission({\n submission,\n definition,\n device,\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n formSubmissionDraftId,\n completionTimestamp,\n recaptchas = [],\n onProgress,\n abortSignal,\n }: UploadFormSubmissionOptions & {\n /**\n * The date and time (in ISO format) the form was completed I.e. when the\n * user clicked the submit button\n */\n completionTimestamp?: string\n /** The reCAPTCHA tokens to validate the submission */\n recaptchas?: {\n /** The site key that was used to generate the reCAPTCHA token */\n siteKey: string\n /** A reCAPTCHA token */\n token: string\n }[]\n /** The identifier of the draft to mark as submitted. */\n formSubmissionDraftId?: string\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n completionTimestamp,\n }\n const tags = generateFormSubmissionTags({\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n })\n\n return await uploadToS3<{\n submissionTimestamp: string\n submissionId: string\n pdfAccessToken?: string\n attachmentsAccessToken?: string\n preventPayment: boolean\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(newS3SubmissionData),\n key: `forms/${definition.id}/submissions`,\n tags,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n jobId,\n previousFormSubmissionApprovalId,\n recaptchas,\n formSubmissionDraftId,\n },\n })\n }\n\n /**\n * Upload an form submission attachment.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * formId: 1,\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * isPrivate: true,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The attachment upload data and options\n * @returns The upload result\n */\n async uploadAttachment({\n formId,\n fileName,\n contentType,\n isPrivate,\n data,\n username,\n onProgress,\n abortSignal,\n }: UploadOptions & {\n /** The identifier for the form that is being completed */\n formId: number\n /** The name of the file being uploaded */\n fileName: string\n /** A standard MIME type describing the format of the contents */\n contentType: string\n /** Set to `true` to prevent the file from being downloaded publicly */\n isPrivate: boolean\n /** The file data to upload */\n data: AttachmentUploadData\n /** A username to allow a single user to download the attachment file */\n username?: string\n }) {\n return await uploadToS3<{\n url: string\n attachmentDataId: string\n uploadedAt: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `forms/${formId}/attachments`,\n abortSignal,\n onProgress,\n isPublic: !isPrivate,\n contentDisposition: `attachment; filename*=UTF-8''${encodeURIComponent(fileName)}`,\n requestBodyHeader: {\n username: username ? encodeURIComponent(username) : undefined,\n fileName: encodeURIComponent(fileName),\n },\n })\n }\n\n /**\n * Upload a draft submission.\n *\n * #### Example\n *\n * ```ts\n * const result = await uploader.uploadDraftSubmission({\n * submission: {\n * // ...\n * },\n * definition: {\n * // ...\n * },\n * formsAppId: 1,\n * formSubmissionDraftId: '',\n * createdAt: new Date().toISOString(),\n * title: '',\n * onProgress: (progress) => {\n * // ...\n * },\n * })\n * ```\n *\n * @param data The submission upload data and options\n * @returns The upload result\n */\n async uploadFormSubmissionDraft({\n submission,\n definition,\n device,\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n formsAppId,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n formSubmissionDraftId,\n createdAt,\n title,\n lastElementUpdated,\n sectionState,\n onProgress,\n abortSignal,\n }: UploadFormSubmissionOptions & {\n /** The identifier of the draft that a new version should be created for. */\n formSubmissionDraftId: string\n /**\n * The date and time (in ISO format) when the draft data was saved by a\n * user.\n */\n createdAt: string\n /** The title input by a user to identify the draft. */\n title: string\n /** The identifier for the last element that was used before saving draft */\n lastElementUpdated?: SubmissionTypes.NewS3SubmissionData['lastElementUpdated']\n /** The open/closed state of collapsible sections before saving draft */\n sectionState?: SubmissionTypes.NewS3SubmissionData['sectionState']\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n lastElementUpdated,\n sectionState,\n }\n const tags = generateFormSubmissionTags({\n userToken,\n previousFormSubmissionApprovalId,\n jobId,\n })\n\n tags.append('formSubmissionDraftId', formSubmissionDraftId)\n\n return await uploadToS3<SubmissionTypes.FormSubmissionDraftVersion>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(newS3SubmissionData),\n key: 'form-submission-draft-versions',\n tags,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n formsAppId,\n formId: definition.id,\n externalId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n jobId,\n previousFormSubmissionApprovalId,\n createdAt,\n title,\n formSubmissionDraftId,\n },\n })\n }\n\n /**\n * Upload an asset file. Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAsset({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * organisationId: 'abc123',\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n organisationId,\n }: UploadOptions &\n UploadAssetOptions & {\n /** The identifier for the organisation that owns the asset */\n organisationId: string\n }) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `organisations/${organisationId}/assets`,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName: encodeURIComponent(fileName),\n },\n isPublic: true,\n })\n }\n\n /**\n * Upload an asset file for a product service such as Product Notifications.\n * Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadProductAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n }: UploadOptions & UploadAssetOptions) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: `administration/assets`,\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName: encodeURIComponent(fileName),\n },\n isPublic: true,\n })\n }\n\n /**\n * Upload form prefill data.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadPrefillData({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: {\n * field1: 'abc',\n * field2: 123,\n * },\n * formId: 12,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The prefill upload data and options\n * @returns The upload result\n */\n async uploadPrefillData({\n formId,\n prefillData,\n onProgress,\n abortSignal,\n }: UploadOptions & {\n /** The identifier for the form that the prefill data is associated with */\n formId: number\n /** The prefill data to upload */\n prefillData: SubmissionTypes.NewS3SubmissionData['submission']\n }) {\n return await uploadToS3<{\n preFillFormDataId: string\n }>({\n ...this,\n contentType: 'application/json',\n body: JSON.stringify(prefillData),\n key: `forms/${formId}/pre-fill`,\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload an email attachment. Email attachments are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadEmailAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The email attachment data and options\n * @returns The upload result\n */\n async uploadEmailAttachment({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n }: UploadOptions & UploadEmailAttachmentOptions) {\n return await uploadToS3({\n ...this,\n contentType,\n body: data,\n key: 'email-attachments',\n abortSignal,\n onProgress,\n requestBodyHeader: {\n filename: encodeURIComponent(fileName),\n },\n isPublic: false,\n })\n }\n\n /**\n * Upload a PDF for conversion. PDF Conversions are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadPDFConversion({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: pdfData,\n * formId: 1,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The PDF data and options\n * @returns The upload result\n */\n async uploadPDFConversion({\n onProgress,\n abortSignal,\n data,\n formId,\n }: UploadPDFConversionOptions) {\n return await uploadToS3({\n ...this,\n contentType: 'application/pdf',\n body: data,\n key: `forms/${formId}/pdf-conversion`,\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload an attachment for use with the AI builder.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAiBuilderAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: attachmentData,\n * formId: 1,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The attachment data and options\n * @returns The upload result\n */\n async uploadAiBuilderAttachment({\n onProgress,\n abortSignal,\n data,\n formId,\n contentType,\n fileName,\n }: UploadAiBuilderAttachmentOptions) {\n return await uploadToS3({\n ...this,\n contentType,\n body: data,\n key: `forms/${formId}/ai-builder/attachments`,\n requestBodyHeader: {\n filename: encodeURIComponent(fileName),\n },\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload a volunteer asset file. Asset files are always public.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadVolunteersAsset({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: new Blob(['a string of data'], {\n * type: 'text/plain',\n * }),\n * fileName: 'file.txt',\n * contentType: 'text/plain',\n * abortSignal: abortController.signal,\n * formsAppId: 1,\n * })\n * ```\n *\n * @param data The asset upload data and options\n * @returns The upload result\n */\n async uploadVolunteersAsset({\n onProgress,\n abortSignal,\n data,\n contentType,\n fileName,\n formsAppId,\n }: UploadOptions &\n UploadAssetOptions & {\n /** The identifier for the volunteers app that owns the asset */\n formsAppId: number\n }) {\n return await uploadToS3<{\n url: string\n }>({\n ...this,\n contentType,\n body: data,\n key: 'volunteers/assets',\n abortSignal,\n onProgress,\n requestBodyHeader: {\n fileName: encodeURIComponent(fileName),\n formsAppId,\n },\n isPublic: true,\n })\n }\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -71,4 +71,14 @@ export type UploadPDFConversionOptions = UploadOptions & {
71
71
  /** The id of the Form that the PDF Conversion is occurring on */
72
72
  formId: number;
73
73
  };
74
+ export type UploadAiBuilderAttachmentOptions = UploadOptions & {
75
+ /** The file data to upload */
76
+ data: AttachmentUploadData;
77
+ /** A standard MIME type describing the format of the contents */
78
+ contentType: string;
79
+ /** The id of the Form that the AI Builder is being used with */
80
+ formId: number;
81
+ /** The name of the file being uploaded */
82
+ fileName: string;
83
+ };
74
84
  export type UploadEmailAttachmentOptions = UploadAssetOptions;
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PutObjectCommandInput } from '@aws-sdk/client-s3'\nimport { SubmissionTypes } from '@oneblink/types'\n\nexport type ProgressListenerEvent = { progress: number; total: number }\nexport type ProgressListener = (progress: ProgressListenerEvent) => void\n\n/** The properties to be passed to the Storage class constructors */\nexport type StorageConstructorOptions = {\n /** The API origin URL used to communicate with the OneBlink API */\n apiOrigin: string\n /** The AWS region to upload the submission to */\n region: string\n /**\n * A function that returns a promise resolving to a Bearer token. If the\n * promise resolves to a truthy value, the `authorization` header will be set\n * with the value.\n */\n getBearerToken: () => Promise<string | undefined>\n}\n\nexport type DownloadOptions = {\n /** An optional AbortSignal that can be used to abort the upload */\n abortSignal?: AbortSignal\n}\n\nexport type UploadOptions = DownloadOptions & {\n /** An optional progress listener for tracking the progress of the upload */\n onProgress?: ProgressListener\n}\n\nexport type AttachmentUploadData = NonNullable<PutObjectCommandInput['Body']>\n\nexport type UploadFormSubmissionOptions = UploadOptions & {\n /** The submission data */\n submission: SubmissionTypes.NewS3SubmissionData['submission']\n /** The form that is being submitted */\n definition: SubmissionTypes.NewS3SubmissionData['definition']\n /** The device the form is being submitted */\n device?: SubmissionTypes.NewS3SubmissionData['device']\n /** The identifier for the forms app that is being submitted from */\n formsAppId?: number\n /** An encrypted token that represents the user */\n userToken?: string\n /** The external identifier that represents the submission */\n externalId?: string\n /**\n * The identifier for the previous FormSubmissionApproval that lead to a\n * clarification request\n */\n previousFormSubmissionApprovalId?: string\n /** The identifier of the job that will be marked as submitted */\n jobId?: string\n /** The identifier of the task that will be marked as completed */\n taskId?: string\n /** The identifier of the task action that was used to complete the task */\n taskActionId?: string\n /**\n * The identifier of the task group instance that the completed task is\n * associated with\n */\n taskGroupInstanceId?: string\n}\n\nexport type UploadAssetOptions = UploadOptions & {\n /** The file data to upload */\n data: AttachmentUploadData\n /** A standard MIME type describing the format of the contents */\n contentType: string\n /** The name of the file being uploaded */\n fileName: string\n}\n\nexport type UploadPDFConversionOptions = UploadOptions & {\n /** The PDF File to upload */\n data: AttachmentUploadData\n /** The id of the Form that the PDF Conversion is occurring on */\n formId: number\n}\n\nexport type UploadEmailAttachmentOptions = UploadAssetOptions\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { PutObjectCommandInput } from '@aws-sdk/client-s3'\nimport { SubmissionTypes } from '@oneblink/types'\n\nexport type ProgressListenerEvent = { progress: number; total: number }\nexport type ProgressListener = (progress: ProgressListenerEvent) => void\n\n/** The properties to be passed to the Storage class constructors */\nexport type StorageConstructorOptions = {\n /** The API origin URL used to communicate with the OneBlink API */\n apiOrigin: string\n /** The AWS region to upload the submission to */\n region: string\n /**\n * A function that returns a promise resolving to a Bearer token. If the\n * promise resolves to a truthy value, the `authorization` header will be set\n * with the value.\n */\n getBearerToken: () => Promise<string | undefined>\n}\n\nexport type DownloadOptions = {\n /** An optional AbortSignal that can be used to abort the upload */\n abortSignal?: AbortSignal\n}\n\nexport type UploadOptions = DownloadOptions & {\n /** An optional progress listener for tracking the progress of the upload */\n onProgress?: ProgressListener\n}\n\nexport type AttachmentUploadData = NonNullable<PutObjectCommandInput['Body']>\n\nexport type UploadFormSubmissionOptions = UploadOptions & {\n /** The submission data */\n submission: SubmissionTypes.NewS3SubmissionData['submission']\n /** The form that is being submitted */\n definition: SubmissionTypes.NewS3SubmissionData['definition']\n /** The device the form is being submitted */\n device?: SubmissionTypes.NewS3SubmissionData['device']\n /** The identifier for the forms app that is being submitted from */\n formsAppId?: number\n /** An encrypted token that represents the user */\n userToken?: string\n /** The external identifier that represents the submission */\n externalId?: string\n /**\n * The identifier for the previous FormSubmissionApproval that lead to a\n * clarification request\n */\n previousFormSubmissionApprovalId?: string\n /** The identifier of the job that will be marked as submitted */\n jobId?: string\n /** The identifier of the task that will be marked as completed */\n taskId?: string\n /** The identifier of the task action that was used to complete the task */\n taskActionId?: string\n /**\n * The identifier of the task group instance that the completed task is\n * associated with\n */\n taskGroupInstanceId?: string\n}\n\nexport type UploadAssetOptions = UploadOptions & {\n /** The file data to upload */\n data: AttachmentUploadData\n /** A standard MIME type describing the format of the contents */\n contentType: string\n /** The name of the file being uploaded */\n fileName: string\n}\n\nexport type UploadPDFConversionOptions = UploadOptions & {\n /** The PDF File to upload */\n data: AttachmentUploadData\n /** The id of the Form that the PDF Conversion is occurring on */\n formId: number\n}\n\nexport type UploadAiBuilderAttachmentOptions = UploadOptions & {\n /** The file data to upload */\n data: AttachmentUploadData\n /** A standard MIME type describing the format of the contents */\n contentType: string\n /** The id of the Form that the AI Builder is being used with */\n formId: number\n /** The name of the file being uploaded */\n fileName: string\n}\n\nexport type UploadEmailAttachmentOptions = UploadAssetOptions\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/storage",
3
3
  "description": "SDK for managing storage files in the OneBlink ecosystem",
4
- "version": "3.2.3-beta.1",
4
+ "version": "3.3.0-beta.1",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/storage/issues"