@forge/bridge 5.8.0-next.8 → 5.8.0-next.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @forge/bridge
2
2
 
3
+ ## 5.8.0-next.9
4
+
5
+ ### Minor Changes
6
+
7
+ - 617c3d9: Add base64 support to upload bridge method
8
+
3
9
  ## 5.8.0-next.8
4
10
 
5
11
  ### Patch Changes
@@ -1,7 +1,7 @@
1
1
  export declare const objectStore: {
2
2
  upload: ({ functionKey, objects }: {
3
3
  functionKey: string;
4
- objects: Blob[];
4
+ objects: import("./types").UploadObject[];
5
5
  }) => Promise<import("./types").UploadResult[]>;
6
6
  download: ({ functionKey, keys }: {
7
7
  functionKey: string;
@@ -3,6 +3,11 @@ export declare type ObjectMetadata = {
3
3
  checksum: string;
4
4
  checksumType: string;
5
5
  };
6
+ export declare type Base64Object = {
7
+ data: string;
8
+ mimeType?: string;
9
+ };
10
+ export declare type UploadObject = Blob | Base64Object;
6
11
  export declare type FileMetadata = ObjectMetadata & {
7
12
  key: string;
8
13
  ttlSeconds?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/object-store/types.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,oBAAY,YAAY,GAAG,cAAc,GAAG;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,oBAAY,YAAY,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,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ACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,cAAc,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,mBAAmB,GAAG;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;CAC7B,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -1,6 +1,6 @@
1
- import type { UploadResult } from './types';
1
+ import type { UploadResult, UploadObject } from './types';
2
2
  export declare const upload: ({ functionKey, objects }: {
3
3
  functionKey: string;
4
- objects: Blob[];
4
+ objects: UploadObject[];
5
5
  }) => Promise<UploadResult[]>;
6
6
  //# sourceMappingURL=upload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/object-store/upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAuC,YAAY,EAAE,MAAM,SAAS,CAAC;AA+BjF,eAAO,MAAM,MAAM;iBAIJ,MAAM;aACV,IAAI,EAAE;MACb,QAAQ,YAAY,EAAE,CAkEzB,CAAC"}
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/object-store/upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAuC,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA4C/F,eAAO,MAAM,MAAM;iBAIJ,MAAM;aACV,YAAY,EAAE;MACrB,QAAQ,YAAY,EAAE,CAuFzB,CAAC"}
@@ -3,6 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.upload = void 0;
4
4
  const invoke_1 = require("../invoke");
5
5
  const errors_1 = require("../errors");
6
+ const base64ToBlob = (base64, mimeType) => {
7
+ const byteCharacters = atob(base64);
8
+ const byteNumbers = new Array(byteCharacters.length);
9
+ for (let i = 0; i < byteCharacters.length; i++) {
10
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
11
+ }
12
+ const byteArray = new Uint8Array(byteNumbers);
13
+ return new Blob([byteArray], { type: mimeType || 'application/octet-stream' });
14
+ };
6
15
  const getObjectMetadata = async (blob) => {
7
16
  const length = blob.size;
8
17
  const arrayBuffer = await blob.arrayBuffer();
@@ -23,7 +32,22 @@ const upload = async ({ functionKey, objects }) => {
23
32
  if (!Array.isArray(objects) || objects.length === 0) {
24
33
  throw new errors_1.BridgeAPIError('objects array is required and must not be empty');
25
34
  }
26
- const allObjectMetadata = await Promise.all(objects.map((obj) => getObjectMetadata(obj)));
35
+ const blobs = objects.map((obj, index) => {
36
+ if (obj instanceof Blob) {
37
+ return obj;
38
+ }
39
+ const isBase64Object = obj && typeof obj === 'object' && 'data' in obj && typeof obj.data === 'string';
40
+ if (!isBase64Object) {
41
+ throw new errors_1.BridgeAPIError(`Invalid object type at index ${index}. Only Blob or Base64Object (with data string and optional mimeType) are accepted.`);
42
+ }
43
+ try {
44
+ return base64ToBlob(obj.data, obj.mimeType);
45
+ }
46
+ catch (e) {
47
+ throw new errors_1.BridgeAPIError(`Invalid base64 data at index ${index}. The data string must be valid base64 encoded.`);
48
+ }
49
+ });
50
+ const allObjectMetadata = await Promise.all(blobs.map((blob) => getObjectMetadata(blob)));
27
51
  const presignedURLsToObjectMetadata = (await (0, invoke_1.invoke)(functionKey, {
28
52
  allObjectMetadata
29
53
  }));
@@ -31,7 +55,7 @@ const upload = async ({ functionKey, objects }) => {
31
55
  throw new errors_1.BridgeAPIError('Invalid response from functionKey');
32
56
  }
33
57
  const checksumToBlobMap = new Map();
34
- objects.forEach((blob, index) => {
58
+ blobs.forEach((blob, index) => {
35
59
  const metadata = allObjectMetadata[index];
36
60
  checksumToBlobMap.set(metadata.checksum, blob);
37
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/bridge",
3
- "version": "5.8.0-next.8",
3
+ "version": "5.8.0-next.9",
4
4
  "description": "Forge bridge API for custom UI apps",
5
5
  "author": "Atlassian",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",