@cooperation/vc-storage 1.0.15 → 1.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,10 +22,10 @@ export class GoogleDriveStorage {
22
22
  try {
23
23
  const res = await fetch(url, {
24
24
  method,
25
- headers: new Headers({
25
+ headers: {
26
26
  Authorization: `Bearer ${this.accessToken}`,
27
27
  ...headers,
28
- }),
28
+ },
29
29
  body,
30
30
  });
31
31
  // Check the Content-Type to ensure it's JSON before parsing
@@ -426,4 +426,22 @@ export class GoogleDriveStorage {
426
426
  return null;
427
427
  }
428
428
  }
429
+ async update(fileId, data) {
430
+ const fileMetadata = {
431
+ name: data.fileName,
432
+ mimeType: data.mimeType,
433
+ };
434
+ let uploadUrl = `https://www.googleapis.com/upload/drive/v3/files/${fileId}?uploadType=multipart`;
435
+ const formData = new FormData();
436
+ formData.append('metadata', new Blob([JSON.stringify(fileMetadata)], { type: 'application/json' }));
437
+ formData.append('file', new Blob([data.body], { type: fileMetadata.mimeType }));
438
+ const updatedFile = await this.fetcher({
439
+ method: 'PATCH',
440
+ headers: {},
441
+ body: JSON.stringify(formData),
442
+ url: `${uploadUrl}&fields=id,parents`,
443
+ });
444
+ console.log('File updated:', updatedFile);
445
+ return updatedFile;
446
+ }
429
447
  }
@@ -84,5 +84,6 @@ export declare class GoogleDriveStorage {
84
84
  * @returns
85
85
  */
86
86
  delete(id: string): Promise<any>;
87
+ update(fileId: string, data: any): Promise<any>;
87
88
  }
88
89
  export {};
@@ -10,11 +10,7 @@ export declare const getVCWithRecommendations: ({ vcId, storage }: {
10
10
  vcId: string;
11
11
  storage: GoogleDriveStorage;
12
12
  }) => Promise<{
13
- vc: {
14
- name: string;
15
- data: any;
16
- id: string;
17
- };
13
+ vc: any;
18
14
  recommendations: any[];
19
15
  relationsFileId: any;
20
16
  }>;
@@ -3,14 +3,15 @@ export const getVCWithRecommendations = async ({ vcId, storage }) => {
3
3
  const files = await storage.findFilesUnderFolder(vcFolderId);
4
4
  const relationsFile = files.find((f) => f.name === 'RELATIONS');
5
5
  const relationsContent = await storage.retrieve(relationsFile.id);
6
- const relationsData = relationsContent.data;
6
+ const relationsData = JSON.parse(relationsContent.data.body);
7
7
  const [vcFileId, recommendationIds] = [relationsData.vc_id, relationsData.recommendations];
8
8
  const vc = await storage.retrieve(vcFileId);
9
+ const vcData = JSON.parse(vc.data.body);
9
10
  const recommendations = await Promise.all(recommendationIds.map(async (rec) => {
10
11
  const recFile = await storage.retrieve(rec);
11
12
  return recFile;
12
13
  }));
13
- return { vc: vc, recommendations, relationsFileId: relationsFile.id };
14
+ return { vc: vcData, recommendations, relationsFileId: relationsFile.id };
14
15
  };
15
16
  /**
16
17
  * Save data to Google Drive in the specified folder type.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cooperation/vc-storage",
3
3
  "type": "module",
4
- "version": "1.0.15",
4
+ "version": "1.0.17",
5
5
  "description": "Sign and store your verifiable credentials.",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/types/index.d.ts",