@oneblink/storage 4.0.0-beta.2 → 4.0.0
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.
- package/dist/OneBlinkUploader.d.ts +14 -0
- package/dist/OneBlinkUploader.js +14 -0
- package/dist/OneBlinkUploader.js.map +1 -1
- package/dist/generateS3Client.js +1 -0
- package/dist/generateS3Client.js.map +1 -1
- package/dist/http-handlers/FetchHandler.d.ts +1 -0
- package/dist/http-handlers/FetchHandler.js +2 -0
- package/dist/http-handlers/FetchHandler.js.map +1 -1
- package/dist/http-handlers/NodeJsHandler.d.ts +1 -0
- package/dist/http-handlers/NodeJsHandler.js +2 -0
- package/dist/http-handlers/NodeJsHandler.js.map +1 -1
- package/dist/http-handlers/types.d.ts +6 -0
- package/dist/http-handlers/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -210,6 +210,13 @@ export default class OneBlinkUploader {
|
|
|
210
210
|
/**
|
|
211
211
|
* Upload form prefill data.
|
|
212
212
|
*
|
|
213
|
+
* Note: This function requires a JWT created from a Developer Key with the
|
|
214
|
+
* `Upload Form Prefill Data' permission set to 'On'. The [OneBlink NodeJS
|
|
215
|
+
* SDK](https://github.com/oneblink/sdk-node-js) handles this for you with the
|
|
216
|
+
* [generateFormUrl](https://oneblink.github.io/sdk-node-js/classes/oneblink.Forms.html#generateFormUrl)
|
|
217
|
+
* function, and as such it is recommended you use that instead for uploading
|
|
218
|
+
* prefill data.
|
|
219
|
+
*
|
|
213
220
|
* #### Example
|
|
214
221
|
*
|
|
215
222
|
* ```ts
|
|
@@ -241,6 +248,13 @@ export default class OneBlinkUploader {
|
|
|
241
248
|
/**
|
|
242
249
|
* Upload an email attachment. Email attachments are always private.
|
|
243
250
|
*
|
|
251
|
+
* Note: This function requires a JWT created from a Developer Key with the
|
|
252
|
+
* `Upload Attachments' permission set to 'On'. The [OneBlink NodeJS
|
|
253
|
+
* SDK](https://github.com/oneblink/sdk-node-js) handles this for you with the
|
|
254
|
+
* [uploadEmailAttachment](https://oneblink.github.io/sdk-node-js/classes/oneblink.Forms.html#uploadEmailAttachment)
|
|
255
|
+
* function, and as such it is recommended you use that instead for uploading
|
|
256
|
+
* email attachments.
|
|
257
|
+
*
|
|
244
258
|
* #### Example
|
|
245
259
|
*
|
|
246
260
|
* ```ts
|
package/dist/OneBlinkUploader.js
CHANGED
|
@@ -263,6 +263,13 @@ export default class OneBlinkUploader {
|
|
|
263
263
|
/**
|
|
264
264
|
* Upload form prefill data.
|
|
265
265
|
*
|
|
266
|
+
* Note: This function requires a JWT created from a Developer Key with the
|
|
267
|
+
* `Upload Form Prefill Data' permission set to 'On'. The [OneBlink NodeJS
|
|
268
|
+
* SDK](https://github.com/oneblink/sdk-node-js) handles this for you with the
|
|
269
|
+
* [generateFormUrl](https://oneblink.github.io/sdk-node-js/classes/oneblink.Forms.html#generateFormUrl)
|
|
270
|
+
* function, and as such it is recommended you use that instead for uploading
|
|
271
|
+
* prefill data.
|
|
272
|
+
*
|
|
266
273
|
* #### Example
|
|
267
274
|
*
|
|
268
275
|
* ```ts
|
|
@@ -296,6 +303,13 @@ export default class OneBlinkUploader {
|
|
|
296
303
|
/**
|
|
297
304
|
* Upload an email attachment. Email attachments are always private.
|
|
298
305
|
*
|
|
306
|
+
* Note: This function requires a JWT created from a Developer Key with the
|
|
307
|
+
* `Upload Attachments' permission set to 'On'. The [OneBlink NodeJS
|
|
308
|
+
* SDK](https://github.com/oneblink/sdk-node-js) handles this for you with the
|
|
309
|
+
* [uploadEmailAttachment](https://oneblink.github.io/sdk-node-js/classes/oneblink.Forms.html#uploadEmailAttachment)
|
|
310
|
+
* function, and as such it is recommended you use that instead for uploading
|
|
311
|
+
* email attachments.
|
|
312
|
+
*
|
|
299
313
|
* #### Example
|
|
300
314
|
*
|
|
301
315
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OneBlinkUploader.js","sourceRoot":"","sources":["../src/OneBlinkUploader.ts"],"names":[],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V,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,UAAU,CAEpB;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","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 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 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,\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"]}
|
|
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,qBAAqB,EACrB,mBAA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UploadData,\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 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 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,\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 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 * 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 ...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/generateS3Client.js
CHANGED
|
@@ -25,6 +25,7 @@ export function generateS3Client({ region, apiOrigin, getBearerToken, requestBod
|
|
|
25
25
|
maxAttempts: RETRY_ATTEMPTS,
|
|
26
26
|
requestHandler: oneBlinkRequestHandler,
|
|
27
27
|
credentials: {},
|
|
28
|
+
requestChecksumCalculation: oneBlinkHttpHandler.requestChecksumCalculation,
|
|
28
29
|
// Sign requests with our own Authorization header instead
|
|
29
30
|
// of letting AWS SDK attempt to generate credentials
|
|
30
31
|
signer: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateS3Client.js","sourceRoot":"","sources":["../src/generateS3Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAG7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAGpE,MAAM,cAAc,GAAG,CAAC,CAAA;AAExB,MAAM,UAAU,gBAAgB,CAAI,EAClC,MAAM,EACN,SAAS,EACT,cAAc,EACd,iBAAiB,GAGlB;IACC,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAA;IACpD,MAAM,sBAAsB,GAAG,IAAI,sBAAsB,CACvD,mBAAmB,EACnB,iBAAiB,CAClB,CAAA;IAED,4DAA4D;IAC5D,iEAAiE;IACjE,8DAA8D;IAC9D,mEAAmE;IACnE,oEAAoE;IACpE,kEAAkE;IAClE,gEAAgE;IAChE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;IAC9B,GAAG,CAAC,QAAQ,GAAG,UAAU,CAAA;IACzB,MAAM,CAAC,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxD,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEpC,OAAO;QACL,MAAM;QACN,sBAAsB;QACtB,QAAQ,EAAE,IAAI,QAAQ,CAAC;YACrB,QAAQ,EAAE,GAAG,CAAC,IAAI;YAClB,MAAM;YACN,WAAW,EAAE,cAAc;YAC3B,cAAc,EAAE,sBAAsB;YACtC,WAAW,EAAE,EAA2B;YACxC,0DAA0D;YAC1D,qDAAqD;YACrD,MAAM,EAAE;gBACN,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;oBACtB,MAAM,KAAK,GAAG,MAAM,cAAc,EAAE,CAAA;oBACpC,IAAI,KAAK,EAAE,CAAC;wBACV,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,GAAG,KAAK,CAAA;oBACtD,CAAC;oBAED,OAAO,OAAO,CAAA;gBAChB,CAAC;aACF;SACF,CAAC;KACH,CAAA;AACH,CAAC","sourcesContent":["import { S3Client } from '@aws-sdk/client-s3'\nimport { AwsCredentialIdentity } from '@smithy/types'\nimport { StorageConstructorOptions } from './types.js'\nimport { getOneBlinkHttpHandler } from './http-handlers/index.js'\nimport { OneBlinkRequestHandler } from './OneBlinkRequestHandler.js'\nimport { RequestBodyHeader } from './http-handlers/types.js'\n\nconst RETRY_ATTEMPTS = 3\n\nexport function generateS3Client<T>({\n region,\n apiOrigin,\n getBearerToken,\n requestBodyHeader,\n}: StorageConstructorOptions & {\n requestBodyHeader?: RequestBodyHeader\n}) {\n const oneBlinkHttpHandler = getOneBlinkHttpHandler()\n const oneBlinkRequestHandler = new OneBlinkRequestHandler<T>(\n oneBlinkHttpHandler,\n requestBodyHeader,\n )\n\n // The endpoint we use instead of the the AWS S3 endpoint is\n // formatted internally by the AWS S3 SDK. It will add the Bucket\n // parameter below as the subdomain to the URL (as long as the\n // bucket does not contain a `.`). The logic below allows the final\n // URL used to upload the object to be the origin that is passed in.\n // The suffix on the end is important as it will allow us to route\n // traffic to S3 via lambda at edge instead of going to our API.\n const url = new URL(apiOrigin)\n url.pathname = '/storage'\n const [bucket, ...domainParts] = url.hostname.split('.')\n url.hostname = domainParts.join('.')\n\n return {\n bucket,\n oneBlinkRequestHandler,\n s3Client: new S3Client({\n endpoint: url.href,\n region,\n maxAttempts: RETRY_ATTEMPTS,\n requestHandler: oneBlinkRequestHandler,\n credentials: {} as AwsCredentialIdentity,\n // Sign requests with our own Authorization header instead\n // of letting AWS SDK attempt to generate credentials\n signer: {\n sign: async (request) => {\n const token = await getBearerToken()\n if (token) {\n request.headers['authorization'] = 'Bearer ' + token\n }\n\n return request\n },\n },\n }),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"generateS3Client.js","sourceRoot":"","sources":["../src/generateS3Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAG7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAGpE,MAAM,cAAc,GAAG,CAAC,CAAA;AAExB,MAAM,UAAU,gBAAgB,CAAI,EAClC,MAAM,EACN,SAAS,EACT,cAAc,EACd,iBAAiB,GAGlB;IACC,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAA;IACpD,MAAM,sBAAsB,GAAG,IAAI,sBAAsB,CACvD,mBAAmB,EACnB,iBAAiB,CAClB,CAAA;IAED,4DAA4D;IAC5D,iEAAiE;IACjE,8DAA8D;IAC9D,mEAAmE;IACnE,oEAAoE;IACpE,kEAAkE;IAClE,gEAAgE;IAChE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;IAC9B,GAAG,CAAC,QAAQ,GAAG,UAAU,CAAA;IACzB,MAAM,CAAC,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxD,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEpC,OAAO;QACL,MAAM;QACN,sBAAsB;QACtB,QAAQ,EAAE,IAAI,QAAQ,CAAC;YACrB,QAAQ,EAAE,GAAG,CAAC,IAAI;YAClB,MAAM;YACN,WAAW,EAAE,cAAc;YAC3B,cAAc,EAAE,sBAAsB;YACtC,WAAW,EAAE,EAA2B;YACxC,0BAA0B,EACxB,mBAAmB,CAAC,0BAA0B;YAChD,0DAA0D;YAC1D,qDAAqD;YACrD,MAAM,EAAE;gBACN,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;oBACtB,MAAM,KAAK,GAAG,MAAM,cAAc,EAAE,CAAA;oBACpC,IAAI,KAAK,EAAE,CAAC;wBACV,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,GAAG,KAAK,CAAA;oBACtD,CAAC;oBAED,OAAO,OAAO,CAAA;gBAChB,CAAC;aACF;SACF,CAAC;KACH,CAAA;AACH,CAAC","sourcesContent":["import { S3Client } from '@aws-sdk/client-s3'\nimport { AwsCredentialIdentity } from '@smithy/types'\nimport { StorageConstructorOptions } from './types.js'\nimport { getOneBlinkHttpHandler } from './http-handlers/index.js'\nimport { OneBlinkRequestHandler } from './OneBlinkRequestHandler.js'\nimport { RequestBodyHeader } from './http-handlers/types.js'\n\nconst RETRY_ATTEMPTS = 3\n\nexport function generateS3Client<T>({\n region,\n apiOrigin,\n getBearerToken,\n requestBodyHeader,\n}: StorageConstructorOptions & {\n requestBodyHeader?: RequestBodyHeader\n}) {\n const oneBlinkHttpHandler = getOneBlinkHttpHandler()\n const oneBlinkRequestHandler = new OneBlinkRequestHandler<T>(\n oneBlinkHttpHandler,\n requestBodyHeader,\n )\n\n // The endpoint we use instead of the the AWS S3 endpoint is\n // formatted internally by the AWS S3 SDK. It will add the Bucket\n // parameter below as the subdomain to the URL (as long as the\n // bucket does not contain a `.`). The logic below allows the final\n // URL used to upload the object to be the origin that is passed in.\n // The suffix on the end is important as it will allow us to route\n // traffic to S3 via lambda at edge instead of going to our API.\n const url = new URL(apiOrigin)\n url.pathname = '/storage'\n const [bucket, ...domainParts] = url.hostname.split('.')\n url.hostname = domainParts.join('.')\n\n return {\n bucket,\n oneBlinkRequestHandler,\n s3Client: new S3Client({\n endpoint: url.href,\n region,\n maxAttempts: RETRY_ATTEMPTS,\n requestHandler: oneBlinkRequestHandler,\n credentials: {} as AwsCredentialIdentity,\n requestChecksumCalculation:\n oneBlinkHttpHandler.requestChecksumCalculation,\n // Sign requests with our own Authorization header instead\n // of letting AWS SDK attempt to generate credentials\n signer: {\n sign: async (request) => {\n const token = await getBearerToken()\n if (token) {\n request.headers['authorization'] = 'Bearer ' + token\n }\n\n return request\n },\n },\n }),\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { HttpHandlerOptions } from '@smithy/types';
|
|
|
3
3
|
import { IOneBlinkHttpHandler } from './types.js';
|
|
4
4
|
import { GetObjectCommandOutput } from '@aws-sdk/client-s3';
|
|
5
5
|
export declare class OneBlinkFetchHandler implements IOneBlinkHttpHandler {
|
|
6
|
+
requestChecksumCalculation: "WHEN_REQUIRED";
|
|
6
7
|
handleRequest(request: HttpRequest, options?: HttpHandlerOptions): Promise<HttpResponse>;
|
|
7
8
|
handleFailResponse(response: HttpResponse): Promise<{
|
|
8
9
|
statusCode: number;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums';
|
|
1
2
|
export class OneBlinkFetchHandler {
|
|
3
|
+
requestChecksumCalculation = RequestChecksumCalculation.WHEN_REQUIRED;
|
|
2
4
|
async handleRequest(request, options) {
|
|
3
5
|
const { FetchHttpHandler } = await import('@smithy/fetch-http-handler');
|
|
4
6
|
const fetchHttpHandler = new FetchHttpHandler();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchHandler.js","sourceRoot":"","sources":["../../src/http-handlers/FetchHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FetchHandler.js","sourceRoot":"","sources":["../../src/http-handlers/FetchHandler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAA;AAEnF,MAAM,OAAO,oBAAoB;IAC/B,0BAA0B,GAAG,0BAA0B,CAAC,aAAa,CAAA;IAErE,KAAK,CAAC,aAAa,CAAC,OAAoB,EAAE,OAA4B;QACpE,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,4BAA4B,CAAC,CAAA;QACvE,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA;QAC/C,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACpE,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,QAAsB;QAC7C,MAAM,aAAa,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAEjD,QAAQ,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACzC,KAAK,iCAAiC,CAAC;YACvC,KAAK,kBAAkB,CAAC,CAAC,CAAC;gBACxB,OAAO;oBACL,UAAU,EAAE,QAAQ,CAAC,UAAU;oBAC/B,OAAO,EAAE,CAAC,MAAM,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO;iBAC9C,CAAA;YACH,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO;oBACL,UAAU,EAAE,QAAQ,CAAC,UAAU;oBAC/B,OAAO,EAAE,MAAM,aAAa,CAAC,IAAI,EAAE;iBACpC,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iCAAiC,CACrC,sBAA8C;QAE9C,IACE,sBAAsB,CAAC,IAAI,YAAY,IAAI;YAC3C,CAAC,MAAM,CAAC,cAAc;gBACpB,sBAAsB,CAAC,IAAI,YAAY,MAAM,CAAC,cAAc,CAAC,EAC/D,CAAC;YACD,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAM,CAAA;QACtE,CAAC;IACH,CAAC;IAED,wBAAwB;QACtB,MAAM,aAAa,GACjB,MAAM,CAAC,SAAS;YAChB,YAAY,IAAI,MAAM,CAAC,SAAS;YAChC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU;YAC7B,OAAO,MAAM,CAAC,SAAS,CAAC,UAAU,KAAK,QAAQ;YAC/C,eAAe,IAAI,MAAM,CAAC,SAAS,CAAC,UAAU;YAC5C,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,aAAa;YAC3C,CAAC,CAAC,SAAS,CAAA;QACf,QAAQ,aAAa,EAAE,CAAC;YACtB,KAAK,IAAI;gBACP,OAAO,EAAE,CAAA;YACX,KAAK,IAAI;gBACP,OAAO,CAAC,CAAA;YACV,KAAK,SAAS,CAAC;YACf,KAAK,IAAI,CAAC;YACV,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,CAAC,CAAA;YACV,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\nimport { IOneBlinkHttpHandler } from './types.js'\nimport { GetObjectCommandOutput } from '@aws-sdk/client-s3'\nimport { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums'\n\nexport class OneBlinkFetchHandler implements IOneBlinkHttpHandler {\n requestChecksumCalculation = RequestChecksumCalculation.WHEN_REQUIRED\n\n async handleRequest(request: HttpRequest, options?: HttpHandlerOptions) {\n const { FetchHttpHandler } = await import('@smithy/fetch-http-handler')\n const fetchHttpHandler = new FetchHttpHandler()\n const { response } = await fetchHttpHandler.handle(request, options)\n return response\n }\n\n async handleFailResponse(response: HttpResponse) {\n const fetchResponse = new Response(response.body)\n\n switch (response.headers['content-type']) {\n case 'application/json; charset=utf-8':\n case 'application/json': {\n return {\n statusCode: response.statusCode,\n message: (await fetchResponse.json()).message,\n }\n }\n default: {\n return {\n statusCode: response.statusCode,\n message: await fetchResponse.text(),\n }\n }\n }\n }\n\n async parseGetObjectCommandOutputAsJson<T>(\n getObjectCommandOutput: GetObjectCommandOutput,\n ): Promise<T | undefined> {\n if (\n getObjectCommandOutput.Body instanceof Blob ||\n (window.ReadableStream &&\n getObjectCommandOutput.Body instanceof window.ReadableStream)\n ) {\n return (await new Response(getObjectCommandOutput.Body).json()) as T\n }\n }\n\n determineUploadQueueSize() {\n const effectiveType =\n window.navigator &&\n 'connection' in window.navigator &&\n !!window.navigator.connection &&\n typeof window.navigator.connection === 'object' &&\n 'effectiveType' in window.navigator.connection\n ? window.navigator.connection.effectiveType\n : undefined\n switch (effectiveType) {\n case '4g':\n return 10\n case '3g':\n return 2\n case 'slow-2g':\n case '2g':\n default: {\n return 1\n }\n }\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { HttpHandlerOptions } from '@smithy/types';
|
|
|
3
3
|
import { IOneBlinkHttpHandler } from './types.js';
|
|
4
4
|
import { GetObjectCommandOutput } from '@aws-sdk/client-s3';
|
|
5
5
|
export declare class OneBlinkNodeJsHandler implements IOneBlinkHttpHandler {
|
|
6
|
+
requestChecksumCalculation: "WHEN_SUPPORTED";
|
|
6
7
|
handleRequest(request: HttpRequest, options?: HttpHandlerOptions | undefined): Promise<HttpResponse>;
|
|
7
8
|
handleFailResponse(response: HttpResponse): Promise<{
|
|
8
9
|
statusCode: number;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums';
|
|
1
2
|
export class OneBlinkNodeJsHandler {
|
|
3
|
+
requestChecksumCalculation = RequestChecksumCalculation.WHEN_SUPPORTED;
|
|
2
4
|
async handleRequest(request, options) {
|
|
3
5
|
const { NodeHttpHandler } = await import('@smithy/node-http-handler');
|
|
4
6
|
const nodeHttpHandler = new NodeHttpHandler();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeJsHandler.js","sourceRoot":"","sources":["../../src/http-handlers/NodeJsHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NodeJsHandler.js","sourceRoot":"","sources":["../../src/http-handlers/NodeJsHandler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAA;AAEnF,MAAM,OAAO,qBAAqB;IAChC,0BAA0B,GAAG,0BAA0B,CAAC,cAAc,CAAA;IAEtE,KAAK,CAAC,aAAa,CACjB,OAAoB,EACpB,OAAwC;QAExC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAA;QACrE,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QAC7C,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACnE,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,QAAsB;QAC7C,QAAQ,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACzC,KAAK,iCAAiC,CAAC;YACvC,KAAK,kBAAkB,CAAC,CAAC,CAAC;gBACxB,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;gBAC3C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AC,QAAQ,CAAC,CAAA;QAC3C,IAAI,sBAAsB,CAAC,IAAI,YAAY,QAAQ,EAAE,CAAC;YACpD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAA;YAClD,OAAO,CAAC,MAAM,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAM,CAAA;QACjE,CAAC;IACH,CAAC;IAED,wBAAwB;QACtB,OAAO,EAAE,CAAA;IACX,CAAC;CACF","sourcesContent":["import { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\nimport { IOneBlinkHttpHandler, FailResponse } from './types.js'\nimport { GetObjectCommandOutput } from '@aws-sdk/client-s3'\nimport { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums'\n\nexport class OneBlinkNodeJsHandler implements IOneBlinkHttpHandler {\n requestChecksumCalculation = RequestChecksumCalculation.WHEN_SUPPORTED\n\n async handleRequest(\n request: HttpRequest,\n options?: HttpHandlerOptions | undefined,\n ) {\n const { NodeHttpHandler } = await import('@smithy/node-http-handler')\n const nodeHttpHandler = new NodeHttpHandler()\n const { response } = await nodeHttpHandler.handle(request, options)\n return response\n }\n\n async handleFailResponse(response: HttpResponse) {\n switch (response.headers['content-type']) {\n case 'application/json; charset=utf-8':\n case 'application/json': {\n const { Readable } = await import('stream')\n if (response.body instanceof Readable) {\n const consumers = await import('stream/consumers')\n return {\n statusCode: response.statusCode,\n message: ((await consumers.json(response.body)) as FailResponse)\n .message,\n }\n }\n\n if (typeof response.body === 'string') {\n return {\n statusCode: response.statusCode,\n message: JSON.parse(response.body).message,\n }\n }\n break\n }\n default: {\n const { Readable } = await import('stream')\n if (response.body instanceof Readable) {\n const consumers = await import('stream/consumers')\n return {\n statusCode: response.statusCode,\n message: await consumers.text(response.body),\n }\n }\n\n if (typeof response.body === 'string') {\n return {\n statusCode: response.statusCode,\n message: response.body,\n }\n }\n break\n }\n }\n }\n\n async parseGetObjectCommandOutputAsJson<T>(\n getObjectCommandOutput: GetObjectCommandOutput,\n ): Promise<T | undefined> {\n const { Readable } = await import('stream')\n if (getObjectCommandOutput.Body instanceof Readable) {\n const consumers = await import('stream/consumers')\n return (await consumers.json(getObjectCommandOutput.Body)) as T\n }\n }\n\n determineUploadQueueSize() {\n return 10\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GetObjectCommandOutput } from '@aws-sdk/client-s3';
|
|
2
|
+
import { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums';
|
|
2
3
|
import { AWSTypes } from '@oneblink/types';
|
|
3
4
|
import { HttpRequest, HttpResponse } from '@smithy/protocol-http';
|
|
4
5
|
import { HttpHandlerOptions } from '@smithy/types';
|
|
@@ -11,6 +12,11 @@ export type FailResponse = {
|
|
|
11
12
|
message: string;
|
|
12
13
|
};
|
|
13
14
|
export interface IOneBlinkHttpHandler {
|
|
15
|
+
/**
|
|
16
|
+
* Need this to avoid this [issue with the AWS
|
|
17
|
+
* SDK](https://github.com/aws/aws-sdk-js-v3/issues/6810)
|
|
18
|
+
*/
|
|
19
|
+
requestChecksumCalculation: RequestChecksumCalculation;
|
|
14
20
|
handleRequest: (request: HttpRequest, options?: HttpHandlerOptions) => Promise<HttpResponse>;
|
|
15
21
|
parseGetObjectCommandOutputAsJson: <T>(getObjectCommandOutput: GetObjectCommandOutput) => Promise<T | undefined>;
|
|
16
22
|
handleFailResponse: (response: HttpResponse) => Promise<FailResponse | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/http-handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["import { GetObjectCommandOutput } from '@aws-sdk/client-s3'\nimport { AWSTypes } from '@oneblink/types'\nimport { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\n\nexport type RequestBodyHeader = Record<string, unknown>\n\nexport type OneBlinkResponse<T> = T & {\n s3: AWSTypes.S3Configuration\n}\nexport type FailResponse = {\n statusCode: number\n message: string\n}\n\nexport interface IOneBlinkHttpHandler {\n handleRequest: (\n request: HttpRequest,\n options?: HttpHandlerOptions,\n ) => Promise<HttpResponse>\n parseGetObjectCommandOutputAsJson: <T>(\n getObjectCommandOutput: GetObjectCommandOutput,\n ) => Promise<T | undefined>\n handleFailResponse: (\n response: HttpResponse,\n ) => Promise<FailResponse | undefined>\n determineUploadQueueSize: () => number\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/http-handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["import { GetObjectCommandOutput } from '@aws-sdk/client-s3'\nimport { RequestChecksumCalculation } from '@aws-sdk/middleware-flexible-checksums'\nimport { AWSTypes } from '@oneblink/types'\nimport { HttpRequest, HttpResponse } from '@smithy/protocol-http'\nimport { HttpHandlerOptions } from '@smithy/types'\n\nexport type RequestBodyHeader = Record<string, unknown>\n\nexport type OneBlinkResponse<T> = T & {\n s3: AWSTypes.S3Configuration\n}\nexport type FailResponse = {\n statusCode: number\n message: string\n}\n\nexport interface IOneBlinkHttpHandler {\n /**\n * Need this to avoid this [issue with the AWS\n * SDK](https://github.com/aws/aws-sdk-js-v3/issues/6810)\n */\n requestChecksumCalculation: RequestChecksumCalculation\n handleRequest: (\n request: HttpRequest,\n options?: HttpHandlerOptions,\n ) => Promise<HttpResponse>\n parseGetObjectCommandOutputAsJson: <T>(\n getObjectCommandOutput: GetObjectCommandOutput,\n ) => Promise<T | undefined>\n handleFailResponse: (\n response: HttpResponse,\n ) => Promise<FailResponse | undefined>\n determineUploadQueueSize: () => number\n}\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": "4.0.0
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/oneblink/storage/issues"
|