@cooperation/vc-storage 1.0.4 → 1.0.6

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.
@@ -215,9 +215,25 @@ export class GoogleDriveStorage {
215
215
  }));
216
216
  // Find the latest file based on the timestamp in the file name
217
217
  const latestFile = fileContents.reduce((latest, current) => {
218
- // Assuming the file name is formatted as `${uuid}_${type}_${timestamp}.json`
219
- const latestTimestamp = latest ? parseInt(latest.name.split('_')[2].split('.')[0], 10) : 0;
220
- const currentTimestamp = parseInt(current.name.split('_')[2].split('.')[0], 10);
218
+ // Check if the file name has the expected structure
219
+ const nameParts = current.name.split('_');
220
+ let currentTimestampStr;
221
+ if (nameParts.length === 3) {
222
+ // Structure with UUID: `${uuid}_${type}_${timestamp}.json`
223
+ currentTimestampStr = nameParts[2];
224
+ }
225
+ else if (nameParts.length === 2) {
226
+ // Structure without UUID: `${type}_${timestamp}.json`
227
+ currentTimestampStr = nameParts[1];
228
+ }
229
+ else {
230
+ // Log warning and skip this file if the structure is not as expected
231
+ console.warn(`Unexpected file name format: ${current.name}`);
232
+ return latest;
233
+ }
234
+ // Parse the timestamp from the file name
235
+ const latestTimestamp = latest ? parseInt(latest.name.split('_').pop().split('.')[0], 10) : 0;
236
+ const currentTimestamp = parseInt(currentTimestampStr.split('.')[0], 10);
221
237
  return currentTimestamp > latestTimestamp ? current : latest;
222
238
  }, null);
223
239
  // Return the content of the latest file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cooperation/vc-storage",
3
3
  "type": "module",
4
- "version": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "description": "Sign and store your verifiable credentials.",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -16,7 +16,7 @@
16
16
  "author": "cooperation",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
- "@cooperation/vc-storage": "^1.0.3",
19
+ "@cooperation/vc-storage": "1.0.5",
20
20
  "@digitalbazaar/did-method-key": "^5.2.0",
21
21
  "@digitalbazaar/ed25519-signature-2020": "^5.3.0",
22
22
  "@digitalbazaar/ed25519-verification-key-2020": "^4.1.0",