@oneblink/storage 6.1.0 → 7.0.0-beta.2

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, UploadAiBuilderAttachmentOptions } from './types.js';
1
+ import { AttachmentUploadData, StorageConstructorOptions, UploadAssetOptions, UploadFormSubmissionOptions, UploadOptions, UploadEmailAttachmentOptions, UploadCustomPDFOptions, UploadAiBuilderAttachmentOptions, UploadAiEnvironmentStylingAttachmentOptions } from './types.js';
2
2
  import { SubmissionTypes } from '@oneblink/types';
3
3
  /**
4
4
  * Used to create an instance of the OneBlinkUploader, exposing methods to
@@ -281,42 +281,41 @@ export default class OneBlinkUploader {
281
281
  s3: import("@oneblink/types/typescript/aws.js").S3Configuration;
282
282
  }>;
283
283
  /**
284
- * Upload a PDF for conversion. PDF Conversions are always private.
284
+ * Upload an attachment for use with the AI builder.
285
285
  *
286
286
  * #### Example
287
287
  *
288
288
  * ```ts
289
289
  * const abortController = new AbortController()
290
- * const result = await uploader.uploadPDFConversion({
290
+ * const result = await uploader.uploadAiBuilderAttachment({
291
291
  * onProgress: (progress) => {
292
292
  * // ...
293
293
  * },
294
- * data: pdfData,
294
+ * data: attachmentData,
295
295
  * formId: 1,
296
296
  * abortSignal: abortController.signal,
297
297
  * })
298
298
  * ```
299
299
  *
300
- * @param data The PDF data and options
300
+ * @param data The attachment data and options
301
301
  * @returns The upload result
302
302
  */
303
- uploadPDFConversion({ onProgress, abortSignal, data, formId, }: UploadPDFConversionOptions): Promise<import("./http-handlers/types.js").OneBlinkResponse<{
304
- pdfConversionId: string;
305
- pdfConversionJobId: number;
306
- }>>;
303
+ uploadAiBuilderAttachment({ onProgress, abortSignal, data, formId, contentType, fileName, }: UploadAiBuilderAttachmentOptions): Promise<{
304
+ s3: import("@oneblink/types/typescript/aws.js").S3Configuration;
305
+ }>;
307
306
  /**
308
- * Upload an attachment for use with the AI builder.
307
+ * Upload an attachment for use with the AI environment styling.
309
308
  *
310
309
  * #### Example
311
310
  *
312
311
  * ```ts
313
312
  * const abortController = new AbortController()
314
- * const result = await uploader.uploadAiBuilderAttachment({
313
+ * const result = await uploader.uploadAiEnvironmentStylingAttachment({
315
314
  * onProgress: (progress) => {
316
315
  * // ...
317
316
  * },
318
317
  * data: attachmentData,
319
- * formId: 1,
318
+ * formsAppEnvironmentId: 1,
320
319
  * abortSignal: abortController.signal,
321
320
  * })
322
321
  * ```
@@ -324,7 +323,7 @@ export default class OneBlinkUploader {
324
323
  * @param data The attachment data and options
325
324
  * @returns The upload result
326
325
  */
327
- uploadAiBuilderAttachment({ onProgress, abortSignal, data, formId, contentType, fileName, }: UploadAiBuilderAttachmentOptions): Promise<{
326
+ uploadAiEnvironmentStylingAttachment({ onProgress, abortSignal, data, formsAppEnvironmentId, contentType, fileName, }: UploadAiEnvironmentStylingAttachmentOptions): Promise<{
328
327
  s3: import("@oneblink/types/typescript/aws.js").S3Configuration;
329
328
  }>;
330
329
  /**
@@ -348,7 +347,7 @@ export default class OneBlinkUploader {
348
347
  * @param data The PDF data and options
349
348
  * @returns The upload result
350
349
  */
351
- uploadFormCustomPDF({ onProgress, abortSignal, data, formId, }: UploadPDFConversionOptions): Promise<{
350
+ uploadFormCustomPDF({ onProgress, abortSignal, data, formId, }: UploadCustomPDFOptions): Promise<{
352
351
  s3: import("@oneblink/types/typescript/aws.js").S3Configuration;
353
352
  }>;
354
353
  }
@@ -349,48 +349,51 @@ export default class OneBlinkUploader {
349
349
  });
350
350
  }
351
351
  /**
352
- * Upload a PDF for conversion. PDF Conversions are always private.
352
+ * Upload an attachment for use with the AI builder.
353
353
  *
354
354
  * #### Example
355
355
  *
356
356
  * ```ts
357
357
  * const abortController = new AbortController()
358
- * const result = await uploader.uploadPDFConversion({
358
+ * const result = await uploader.uploadAiBuilderAttachment({
359
359
  * onProgress: (progress) => {
360
360
  * // ...
361
361
  * },
362
- * data: pdfData,
362
+ * data: attachmentData,
363
363
  * formId: 1,
364
364
  * abortSignal: abortController.signal,
365
365
  * })
366
366
  * ```
367
367
  *
368
- * @param data The PDF data and options
368
+ * @param data The attachment data and options
369
369
  * @returns The upload result
370
370
  */
371
- async uploadPDFConversion({ onProgress, abortSignal, data, formId, }) {
371
+ async uploadAiBuilderAttachment({ onProgress, abortSignal, data, formId, contentType, fileName, }) {
372
372
  return await uploadToS3({
373
373
  ...this,
374
- contentType: 'application/pdf',
374
+ contentType,
375
375
  body: data,
376
- key: `forms/${formId}/pdf-conversion`,
376
+ key: `forms/${formId}/ai-builder/attachments`,
377
+ requestBodyHeader: {
378
+ fileName: encodeURIComponent(fileName),
379
+ },
377
380
  abortSignal,
378
381
  onProgress,
379
382
  });
380
383
  }
381
384
  /**
382
- * Upload an attachment for use with the AI builder.
385
+ * Upload an attachment for use with the AI environment styling.
383
386
  *
384
387
  * #### Example
385
388
  *
386
389
  * ```ts
387
390
  * const abortController = new AbortController()
388
- * const result = await uploader.uploadAiBuilderAttachment({
391
+ * const result = await uploader.uploadAiEnvironmentStylingAttachment({
389
392
  * onProgress: (progress) => {
390
393
  * // ...
391
394
  * },
392
395
  * data: attachmentData,
393
- * formId: 1,
396
+ * formsAppEnvironmentId: 1,
394
397
  * abortSignal: abortController.signal,
395
398
  * })
396
399
  * ```
@@ -398,12 +401,12 @@ export default class OneBlinkUploader {
398
401
  * @param data The attachment data and options
399
402
  * @returns The upload result
400
403
  */
401
- async uploadAiBuilderAttachment({ onProgress, abortSignal, data, formId, contentType, fileName, }) {
404
+ async uploadAiEnvironmentStylingAttachment({ onProgress, abortSignal, data, formsAppEnvironmentId, contentType, fileName, }) {
402
405
  return await uploadToS3({
403
406
  ...this,
404
407
  contentType,
405
408
  body: data,
406
- key: `forms/${formId}/ai-builder/attachments`,
409
+ key: `forms-app-environments/${formsAppEnvironmentId}/ai-builder/attachments`,
407
410
  requestBodyHeader: {
408
411
  fileName: encodeURIComponent(fileName),
409
412
  },
@@ -1 +1 @@
1
- {"version":3,"file":"OneBlinkUploader.js","sourceRoot":"","sources":["../src/OneBlinkUploader.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAA;AAYxC,OAAO,0BAA0B,MAAM,iCAAiC,CAAA;AACxE;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,SAAS,CAAwC;IACjD,MAAM,CAAqC;IAC3C,cAAc,CAA6C;IAE3D;;;;;;;;;;;;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,uBAAuB,EACvB,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,0BAA0B,CAAC;YACtC,SAAS;YACT,gCAAgC;YAChC,KAAK;SACN,CAAC,CAAA;QAEF,OAAO,MAAM,UAAU,CAMpB;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,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AAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,SAAS,MAAM,iBAAiB;YACrC,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,yBAAyB,CAAC,EAC9B,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,EACN,WAAW,EACX,QAAQ,GACyB;QACjC,OAAO,MAAM,UAAU,CAAC;YACtB,GAAG,IAAI;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;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,mBAAmB,CAAC,EACxB,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,GACqB;QAC3B,OAAO,MAAM,UAAU,CAAC;YACtB,GAAG,IAAI;YACP,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,SAAS,MAAM,aAAa;YACjC,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import uploadToS3 from './uploadToS3.js'\nimport {\n AttachmentUploadData,\n StorageConstructorOptions,\n UploadAssetOptions,\n UploadFormSubmissionOptions,\n UploadOptions,\n UploadEmailAttachmentOptions,\n UploadPDFConversionOptions,\n UploadAiBuilderAttachmentOptions,\n} from './types.js'\nimport { SubmissionTypes } from '@oneblink/types'\nimport generateFormSubmissionTags from './generateFormSubmissionTags.js'\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 taskCompletionTimestamp,\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 taskCompletionTimestamp,\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 previousElapsedDurationSeconds,\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 /** The previously elapsed duration in seconds before saving draft */\n previousElapsedDurationSeconds?: SubmissionTypes.NewS3SubmissionData['previousElapsedDurationSeconds']\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n lastElementUpdated,\n sectionState,\n previousElapsedDurationSeconds,\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: encodeURIComponent(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 * Note: This function requires a JWT created from a Developer Key with the\n * `Upload Form Prefill Data' permission set to 'On'. The [OneBlink NodeJS\n * SDK](https://github.com/oneblink/sdk-node-js) handles this for you with the\n * [generateFormUrl](https://oneblink.github.io/sdk-node-js/classes/oneblink.Forms.html#generateFormUrl)\n * function, and as such it is recommended you use that instead for uploading\n * 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 username,\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 /** A username to allow a single user to download the prefill data */\n username?: string\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 requestBodyHeader: {\n username: username ? encodeURIComponent(username) : undefined,\n },\n })\n }\n\n /**\n * Upload an email attachment. Email attachments are always private.\n *\n * Note: This function requires a JWT created from a Developer Key with the\n * `Upload Attachments' permission set to 'On'. The [OneBlink NodeJS\n * SDK](https://github.com/oneblink/sdk-node-js) handles this for you with the\n * [uploadEmailAttachment](https://oneblink.github.io/sdk-node-js/classes/oneblink.Forms.html#uploadEmailAttachment)\n * function, and as such it is recommended you use that instead for uploading\n * email attachments.\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 pdfConversionId: string\n pdfConversionJobId: number\n }>({\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 PDF for a form to be used as a custom PDF in workflow events.\n * Custom PDFs are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadFormCustomPDF({\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 uploadFormCustomPDF({\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}/custom-pdf`,\n abortSignal,\n onProgress,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"OneBlinkUploader.js","sourceRoot":"","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BACjB,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;aACvC;YACD,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,oCAAoC,CAAC,EACzC,UAAU,EACV,WAAW,EACX,IAAI,EACJ,qBAAqB,EACrB,WAAW,EACX,QAAQ,GACoC;QAC5C,OAAO,MAAM,UAAU,CAAC;YACtB,GAAG,IAAI;YACP,WAAW;YACX,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,0BAA0B,qBAAqB,yBAAyB;YAC7E,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC;aACvC;YACD,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,mBAAmB,CAAC,EACxB,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,GACiB;QACvB,OAAO,MAAM,UAAU,CAAC;YACtB,GAAG,IAAI;YACP,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,SAAS,MAAM,aAAa;YACjC,WAAW;YACX,UAAU;SACX,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import uploadToS3 from './uploadToS3.js'\nimport {\n AttachmentUploadData,\n StorageConstructorOptions,\n UploadAssetOptions,\n UploadFormSubmissionOptions,\n UploadOptions,\n UploadEmailAttachmentOptions,\n UploadCustomPDFOptions,\n UploadAiBuilderAttachmentOptions,\n UploadAiEnvironmentStylingAttachmentOptions,\n} from './types.js'\nimport { SubmissionTypes } from '@oneblink/types'\nimport generateFormSubmissionTags from './generateFormSubmissionTags.js'\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 taskCompletionTimestamp,\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 taskCompletionTimestamp,\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 previousElapsedDurationSeconds,\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 /** The previously elapsed duration in seconds before saving draft */\n previousElapsedDurationSeconds?: SubmissionTypes.NewS3SubmissionData['previousElapsedDurationSeconds']\n }) {\n const newS3SubmissionData: SubmissionTypes.NewS3SubmissionData = {\n submission,\n definition,\n device,\n lastElementUpdated,\n sectionState,\n previousElapsedDurationSeconds,\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: encodeURIComponent(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 * Note: This function requires a JWT created from a Developer Key with the\n * `Upload Form Prefill Data' permission set to 'On'. The [OneBlink NodeJS\n * SDK](https://github.com/oneblink/sdk-node-js) handles this for you with the\n * [generateFormUrl](https://oneblink.github.io/sdk-node-js/classes/oneblink.Forms.html#generateFormUrl)\n * function, and as such it is recommended you use that instead for uploading\n * 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 username,\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 /** A username to allow a single user to download the prefill data */\n username?: string\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 requestBodyHeader: {\n username: username ? encodeURIComponent(username) : undefined,\n },\n })\n }\n\n /**\n * Upload an email attachment. Email attachments are always private.\n *\n * Note: This function requires a JWT created from a Developer Key with the\n * `Upload Attachments' permission set to 'On'. The [OneBlink NodeJS\n * SDK](https://github.com/oneblink/sdk-node-js) handles this for you with the\n * [uploadEmailAttachment](https://oneblink.github.io/sdk-node-js/classes/oneblink.Forms.html#uploadEmailAttachment)\n * function, and as such it is recommended you use that instead for uploading\n * email attachments.\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 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 an attachment for use with the AI environment styling.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadAiEnvironmentStylingAttachment({\n * onProgress: (progress) => {\n * // ...\n * },\n * data: attachmentData,\n * formsAppEnvironmentId: 1,\n * abortSignal: abortController.signal,\n * })\n * ```\n *\n * @param data The attachment data and options\n * @returns The upload result\n */\n async uploadAiEnvironmentStylingAttachment({\n onProgress,\n abortSignal,\n data,\n formsAppEnvironmentId,\n contentType,\n fileName,\n }: UploadAiEnvironmentStylingAttachmentOptions) {\n return await uploadToS3({\n ...this,\n contentType,\n body: data,\n key: `forms-app-environments/${formsAppEnvironmentId}/ai-builder/attachments`,\n requestBodyHeader: {\n fileName: encodeURIComponent(fileName),\n },\n abortSignal,\n onProgress,\n })\n }\n\n /**\n * Upload a PDF for a form to be used as a custom PDF in workflow events.\n * Custom PDFs are always private.\n *\n * #### Example\n *\n * ```ts\n * const abortController = new AbortController()\n * const result = await uploader.uploadFormCustomPDF({\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 uploadFormCustomPDF({\n onProgress,\n abortSignal,\n data,\n formId,\n }: UploadCustomPDFOptions) {\n return await uploadToS3({\n ...this,\n contentType: 'application/pdf',\n body: data,\n key: `forms/${formId}/custom-pdf`,\n abortSignal,\n onProgress,\n })\n }\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -67,7 +67,7 @@ export type UploadAssetOptions = UploadOptions & {
67
67
  /** The name of the file being uploaded */
68
68
  fileName: string;
69
69
  };
70
- export type UploadPDFConversionOptions = UploadOptions & {
70
+ export type UploadCustomPDFOptions = UploadOptions & {
71
71
  /** The PDF File to upload */
72
72
  data: AttachmentUploadData;
73
73
  /** The id of the Form that the PDF Conversion is occurring on */
@@ -83,4 +83,17 @@ export type UploadAiBuilderAttachmentOptions = UploadOptions & {
83
83
  /** The name of the file being uploaded */
84
84
  fileName: string;
85
85
  };
86
+ export type UploadAiEnvironmentStylingAttachmentOptions = UploadOptions & {
87
+ /** The file data to upload */
88
+ data: AttachmentUploadData;
89
+ /** A standard MIME type describing the format of the contents */
90
+ contentType: string;
91
+ /**
92
+ * The id of the Forms App Environment that the AI Environment Styling is
93
+ * being used with
94
+ */
95
+ formsAppEnvironmentId: number;
96
+ /** The name of the file being uploaded */
97
+ fileName: string;
98
+ };
86
99
  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 /** The date and time (in ISO format) the task was completed */\n taskCompletionTimestamp?: 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"]}
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 /** The date and time (in ISO format) the task was completed */\n taskCompletionTimestamp?: 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 UploadCustomPDFOptions = 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 UploadAiEnvironmentStylingAttachmentOptions = 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 /**\n * The id of the Forms App Environment that the AI Environment Styling is\n * being used with\n */\n formsAppEnvironmentId: 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": "6.1.0",
4
+ "version": "7.0.0-beta.2",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/storage/issues"