From ee5cce253b16820f8c9751e2c25703b752135439 Mon Sep 17 00:00:00 2001 From: Nihal Bhatnagar Date: Thu, 12 Dec 2024 21:45:24 -0500 Subject: [PATCH 1/2] Fixes attachment uploads --- etc/api.report.api.md | 4 +++- packages/api/src/object/Attachment.ts | 3 ++- packages/client/src/createClient.test.ts | 1 - packages/client/src/object/AttachmentUpload.ts | 11 +++-------- packages/client/src/util/toDataValue.ts | 2 +- packages/client/src/util/toDataValueQueries.ts | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/etc/api.report.api.md b/etc/api.report.api.md index eca1ab2ed..54052178d 100644 --- a/etc/api.report.api.md +++ b/etc/api.report.api.md @@ -205,7 +205,9 @@ export interface Attachment { } // @public -export interface AttachmentUpload extends Blob { +export interface AttachmentUpload { + // (undocumented) + readonly data: Blob; // (undocumented) readonly name: string; } diff --git a/packages/api/src/object/Attachment.ts b/packages/api/src/object/Attachment.ts index 78f56e0e9..e8316dccd 100644 --- a/packages/api/src/object/Attachment.ts +++ b/packages/api/src/object/Attachment.ts @@ -29,8 +29,9 @@ export interface Attachment { * This interface should also accept the File object from * the W3C FileApi https://www.w3.org/TR/FileAPI/#file-section */ -export interface AttachmentUpload extends Blob { +export interface AttachmentUpload { readonly name: string; + readonly data: Blob; } export interface AttachmentMetadata { diff --git a/packages/client/src/createClient.test.ts b/packages/client/src/createClient.test.ts index a0500a304..09a7739d9 100644 --- a/packages/client/src/createClient.test.ts +++ b/packages/client/src/createClient.test.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { __EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks } from "@osdk/api/unstable"; import { Task } from "@osdk/client.test.ontology"; import * as SharedClientContext from "@osdk/shared.client.impl"; import { mockFetchResponse, MockOntology } from "@osdk/shared.test"; diff --git a/packages/client/src/object/AttachmentUpload.ts b/packages/client/src/object/AttachmentUpload.ts index 50b778146..4dc747ee5 100644 --- a/packages/client/src/object/AttachmentUpload.ts +++ b/packages/client/src/object/AttachmentUpload.ts @@ -17,18 +17,13 @@ import type { AttachmentUpload } from "@osdk/api"; export function isAttachmentUpload(o: any): o is AttachmentUpload { - return o instanceof Blob && "name" in o; + return Object.hasOwn(o, "name") && Object.hasOwn(o, "data") + && o.data instanceof Blob; } export function createAttachmentUpload( data: Blob, name: string, ): AttachmentUpload { - const attachmentUpload = Object.create(data, { - name: { value: name }, - size: { value: data.size }, - type: { value: data.type }, - }); - - return attachmentUpload as AttachmentUpload; + return { data, name }; } diff --git a/packages/client/src/util/toDataValue.ts b/packages/client/src/util/toDataValue.ts index 84f9145cd..240df99b9 100644 --- a/packages/client/src/util/toDataValue.ts +++ b/packages/client/src/util/toDataValue.ts @@ -51,7 +51,7 @@ export async function toDataValue( if (isAttachmentUpload(value)) { const attachment = await OntologiesV2.Attachments.upload( client, - value, + value.data, { filename: value.name, }, diff --git a/packages/client/src/util/toDataValueQueries.ts b/packages/client/src/util/toDataValueQueries.ts index ae8b4ada7..9c1911c69 100644 --- a/packages/client/src/util/toDataValueQueries.ts +++ b/packages/client/src/util/toDataValueQueries.ts @@ -52,7 +52,7 @@ export async function toDataValueQueries( if (isAttachmentUpload(value)) { const attachment = await OntologiesV2.Attachments.upload( client, - value, + value.data, { filename: value.name, }, From ea51368c04c43fa04b4c38c468deaf208ec46e84 Mon Sep 17 00:00:00 2001 From: Nihal Bhatnagar Date: Fri, 13 Dec 2024 15:19:04 -0500 Subject: [PATCH 2/2] Update attachments --- .changeset/fluffy-horses-enjoy.md | 6 ++++++ packages/client/src/object/AttachmentUpload.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/fluffy-horses-enjoy.md diff --git a/.changeset/fluffy-horses-enjoy.md b/.changeset/fluffy-horses-enjoy.md new file mode 100644 index 000000000..9ed297817 --- /dev/null +++ b/.changeset/fluffy-horses-enjoy.md @@ -0,0 +1,6 @@ +--- +"@osdk/client": patch +"@osdk/api": patch +--- + +Fixes attachment upload inputs sending incorrect in browser contexts diff --git a/packages/client/src/object/AttachmentUpload.ts b/packages/client/src/object/AttachmentUpload.ts index 4dc747ee5..9fb4f1a5d 100644 --- a/packages/client/src/object/AttachmentUpload.ts +++ b/packages/client/src/object/AttachmentUpload.ts @@ -17,7 +17,7 @@ import type { AttachmentUpload } from "@osdk/api"; export function isAttachmentUpload(o: any): o is AttachmentUpload { - return Object.hasOwn(o, "name") && Object.hasOwn(o, "data") + return typeof o === `object` && "name" in o && "data" in o && o.data instanceof Blob; }