@hasna/files 0.2.14 → 0.2.16

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/cli/index.js CHANGED
@@ -167615,7 +167615,7 @@ async function syncGoogleDriveSource(source) {
167615
167615
  const existing = getGoogleDriveImportedObject(source.id, item.drive_id, item.id);
167616
167616
  if (existing && !shouldImport(config9, item, existing, destination.source.id, destination.storage_type))
167617
167617
  continue;
167618
- const downloaded = await client2.downloadFile(toApiFile(item), config9.export_formats);
167618
+ const downloaded = await downloadOrArchiveGoogleDriveItem(client2, item, config9);
167619
167619
  const importedName = basename5(downloaded.filename);
167620
167620
  const importedPath = buildImportedPath(config9, item, importedName);
167621
167621
  const contentType = downloaded.mimeType || ($lookup(downloaded.filename) || item.mime || "application/octet-stream");
@@ -167888,6 +167888,59 @@ function appendDriveFileId(filename, fileId) {
167888
167888
  const base = ext ? filename.slice(0, -ext.length) : filename;
167889
167889
  return `${base} (${safePathSegment(fileId)})${ext}`;
167890
167890
  }
167891
+ function canDownloadDriveItem(item) {
167892
+ if (!item.mime.startsWith("application/vnd.google-apps."))
167893
+ return true;
167894
+ return [
167895
+ "application/vnd.google-apps.document",
167896
+ "application/vnd.google-apps.spreadsheet",
167897
+ "application/vnd.google-apps.presentation",
167898
+ "application/vnd.google-apps.drawing"
167899
+ ].includes(item.mime);
167900
+ }
167901
+ async function downloadOrArchiveGoogleDriveItem(client2, item, config9) {
167902
+ if (!canDownloadDriveItem(item))
167903
+ return createGoogleDriveMetadataArchive(item);
167904
+ try {
167905
+ return await client2.downloadFile(toApiFile(item), config9.export_formats);
167906
+ } catch (error) {
167907
+ if (shouldArchiveGoogleDriveDownloadError(item, error)) {
167908
+ return createGoogleDriveMetadataArchive(item, `Google Drive export failed: ${error.message}`);
167909
+ }
167910
+ throw error;
167911
+ }
167912
+ }
167913
+ function shouldArchiveGoogleDriveDownloadError(item, error) {
167914
+ if (!item.mime.startsWith("application/vnd.google-apps."))
167915
+ return false;
167916
+ const message = error.message ?? String(error);
167917
+ return /cannot be exported/i.test(message);
167918
+ }
167919
+ function createGoogleDriveMetadataArchive(item, reason = "Google Drive item is not exportable as file content through Drive export.") {
167920
+ const metadata = {
167921
+ archived_as: "google-drive-metadata",
167922
+ reason,
167923
+ id: item.id,
167924
+ name: item.name,
167925
+ mime: item.mime,
167926
+ drive_id: item.drive_id,
167927
+ drive_name: item.drive_name,
167928
+ is_shared_drive: item.is_shared_drive,
167929
+ parent_id: item.parent_id,
167930
+ path: item.path,
167931
+ size: item.size,
167932
+ modified_at: item.modified_at,
167933
+ version: item.version,
167934
+ hash: item.hash
167935
+ };
167936
+ const data = Buffer.from(JSON.stringify(metadata, null, 2) + `
167937
+ `);
167938
+ return {
167939
+ data: data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength),
167940
+ filename: `${item.name}.gdrive-metadata.json`,
167941
+ mimeType: "application/json"
167942
+ };
167943
+ }
167891
167944
  function toApiFile(item) {
167892
167945
  return {
167893
167946
  id: item.id,
package/dist/index.js CHANGED
@@ -164208,7 +164208,7 @@ async function syncGoogleDriveSource(source) {
164208
164208
  const existing = getGoogleDriveImportedObject(source.id, item.drive_id, item.id);
164209
164209
  if (existing && !shouldImport(config9, item, existing, destination.source.id, destination.storage_type))
164210
164210
  continue;
164211
- const downloaded = await client2.downloadFile(toApiFile(item), config9.export_formats);
164211
+ const downloaded = await downloadOrArchiveGoogleDriveItem(client2, item, config9);
164212
164212
  const importedName = basename5(downloaded.filename);
164213
164213
  const importedPath = buildImportedPath(config9, item, importedName);
164214
164214
  const contentType = downloaded.mimeType || ($lookup(downloaded.filename) || item.mime || "application/octet-stream");
@@ -164481,6 +164481,59 @@ function appendDriveFileId(filename, fileId) {
164481
164481
  const base = ext ? filename.slice(0, -ext.length) : filename;
164482
164482
  return `${base} (${safePathSegment(fileId)})${ext}`;
164483
164483
  }
164484
+ function canDownloadDriveItem(item) {
164485
+ if (!item.mime.startsWith("application/vnd.google-apps."))
164486
+ return true;
164487
+ return [
164488
+ "application/vnd.google-apps.document",
164489
+ "application/vnd.google-apps.spreadsheet",
164490
+ "application/vnd.google-apps.presentation",
164491
+ "application/vnd.google-apps.drawing"
164492
+ ].includes(item.mime);
164493
+ }
164494
+ async function downloadOrArchiveGoogleDriveItem(client2, item, config9) {
164495
+ if (!canDownloadDriveItem(item))
164496
+ return createGoogleDriveMetadataArchive(item);
164497
+ try {
164498
+ return await client2.downloadFile(toApiFile(item), config9.export_formats);
164499
+ } catch (error) {
164500
+ if (shouldArchiveGoogleDriveDownloadError(item, error)) {
164501
+ return createGoogleDriveMetadataArchive(item, `Google Drive export failed: ${error.message}`);
164502
+ }
164503
+ throw error;
164504
+ }
164505
+ }
164506
+ function shouldArchiveGoogleDriveDownloadError(item, error) {
164507
+ if (!item.mime.startsWith("application/vnd.google-apps."))
164508
+ return false;
164509
+ const message = error.message ?? String(error);
164510
+ return /cannot be exported/i.test(message);
164511
+ }
164512
+ function createGoogleDriveMetadataArchive(item, reason = "Google Drive item is not exportable as file content through Drive export.") {
164513
+ const metadata = {
164514
+ archived_as: "google-drive-metadata",
164515
+ reason,
164516
+ id: item.id,
164517
+ name: item.name,
164518
+ mime: item.mime,
164519
+ drive_id: item.drive_id,
164520
+ drive_name: item.drive_name,
164521
+ is_shared_drive: item.is_shared_drive,
164522
+ parent_id: item.parent_id,
164523
+ path: item.path,
164524
+ size: item.size,
164525
+ modified_at: item.modified_at,
164526
+ version: item.version,
164527
+ hash: item.hash
164528
+ };
164529
+ const data = Buffer.from(JSON.stringify(metadata, null, 2) + `
164530
+ `);
164531
+ return {
164532
+ data: data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength),
164533
+ filename: `${item.name}.gdrive-metadata.json`,
164534
+ mimeType: "application/json"
164535
+ };
164536
+ }
164484
164537
  function toApiFile(item) {
164485
164538
  return {
164486
164539
  id: item.id,
package/dist/mcp/index.js CHANGED
@@ -183139,7 +183139,7 @@ async function syncGoogleDriveSource(source) {
183139
183139
  const existing = getGoogleDriveImportedObject(source.id, item.drive_id, item.id);
183140
183140
  if (existing && !shouldImport(config9, item, existing, destination.source.id, destination.storage_type))
183141
183141
  continue;
183142
- const downloaded = await client2.downloadFile(toApiFile(item), config9.export_formats);
183142
+ const downloaded = await downloadOrArchiveGoogleDriveItem(client2, item, config9);
183143
183143
  const importedName = basename5(downloaded.filename);
183144
183144
  const importedPath = buildImportedPath(config9, item, importedName);
183145
183145
  const contentType = downloaded.mimeType || ($lookup(downloaded.filename) || item.mime || "application/octet-stream");
@@ -183412,6 +183412,59 @@ function appendDriveFileId(filename, fileId) {
183412
183412
  const base = ext ? filename.slice(0, -ext.length) : filename;
183413
183413
  return `${base} (${safePathSegment(fileId)})${ext}`;
183414
183414
  }
183415
+ function canDownloadDriveItem(item) {
183416
+ if (!item.mime.startsWith("application/vnd.google-apps."))
183417
+ return true;
183418
+ return [
183419
+ "application/vnd.google-apps.document",
183420
+ "application/vnd.google-apps.spreadsheet",
183421
+ "application/vnd.google-apps.presentation",
183422
+ "application/vnd.google-apps.drawing"
183423
+ ].includes(item.mime);
183424
+ }
183425
+ async function downloadOrArchiveGoogleDriveItem(client2, item, config9) {
183426
+ if (!canDownloadDriveItem(item))
183427
+ return createGoogleDriveMetadataArchive(item);
183428
+ try {
183429
+ return await client2.downloadFile(toApiFile(item), config9.export_formats);
183430
+ } catch (error) {
183431
+ if (shouldArchiveGoogleDriveDownloadError(item, error)) {
183432
+ return createGoogleDriveMetadataArchive(item, `Google Drive export failed: ${error.message}`);
183433
+ }
183434
+ throw error;
183435
+ }
183436
+ }
183437
+ function shouldArchiveGoogleDriveDownloadError(item, error) {
183438
+ if (!item.mime.startsWith("application/vnd.google-apps."))
183439
+ return false;
183440
+ const message = error.message ?? String(error);
183441
+ return /cannot be exported/i.test(message);
183442
+ }
183443
+ function createGoogleDriveMetadataArchive(item, reason = "Google Drive item is not exportable as file content through Drive export.") {
183444
+ const metadata = {
183445
+ archived_as: "google-drive-metadata",
183446
+ reason,
183447
+ id: item.id,
183448
+ name: item.name,
183449
+ mime: item.mime,
183450
+ drive_id: item.drive_id,
183451
+ drive_name: item.drive_name,
183452
+ is_shared_drive: item.is_shared_drive,
183453
+ parent_id: item.parent_id,
183454
+ path: item.path,
183455
+ size: item.size,
183456
+ modified_at: item.modified_at,
183457
+ version: item.version,
183458
+ hash: item.hash
183459
+ };
183460
+ const data = Buffer.from(JSON.stringify(metadata, null, 2) + `
183461
+ `);
183462
+ return {
183463
+ data: data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength),
183464
+ filename: `${item.name}.gdrive-metadata.json`,
183465
+ mimeType: "application/json"
183466
+ };
183467
+ }
183415
183468
  function toApiFile(item) {
183416
183469
  return {
183417
183470
  id: item.id,
@@ -163895,7 +163895,7 @@ async function syncGoogleDriveSource(source) {
163895
163895
  const existing = getGoogleDriveImportedObject(source.id, item.drive_id, item.id);
163896
163896
  if (existing && !shouldImport(config9, item, existing, destination.source.id, destination.storage_type))
163897
163897
  continue;
163898
- const downloaded = await client2.downloadFile(toApiFile(item), config9.export_formats);
163898
+ const downloaded = await downloadOrArchiveGoogleDriveItem(client2, item, config9);
163899
163899
  const importedName = basename5(downloaded.filename);
163900
163900
  const importedPath = buildImportedPath(config9, item, importedName);
163901
163901
  const contentType = downloaded.mimeType || ($lookup(downloaded.filename) || item.mime || "application/octet-stream");
@@ -164151,6 +164151,59 @@ function appendDriveFileId(filename, fileId) {
164151
164151
  const base = ext ? filename.slice(0, -ext.length) : filename;
164152
164152
  return `${base} (${safePathSegment(fileId)})${ext}`;
164153
164153
  }
164154
+ function canDownloadDriveItem(item) {
164155
+ if (!item.mime.startsWith("application/vnd.google-apps."))
164156
+ return true;
164157
+ return [
164158
+ "application/vnd.google-apps.document",
164159
+ "application/vnd.google-apps.spreadsheet",
164160
+ "application/vnd.google-apps.presentation",
164161
+ "application/vnd.google-apps.drawing"
164162
+ ].includes(item.mime);
164163
+ }
164164
+ async function downloadOrArchiveGoogleDriveItem(client2, item, config9) {
164165
+ if (!canDownloadDriveItem(item))
164166
+ return createGoogleDriveMetadataArchive(item);
164167
+ try {
164168
+ return await client2.downloadFile(toApiFile(item), config9.export_formats);
164169
+ } catch (error) {
164170
+ if (shouldArchiveGoogleDriveDownloadError(item, error)) {
164171
+ return createGoogleDriveMetadataArchive(item, `Google Drive export failed: ${error.message}`);
164172
+ }
164173
+ throw error;
164174
+ }
164175
+ }
164176
+ function shouldArchiveGoogleDriveDownloadError(item, error) {
164177
+ if (!item.mime.startsWith("application/vnd.google-apps."))
164178
+ return false;
164179
+ const message = error.message ?? String(error);
164180
+ return /cannot be exported/i.test(message);
164181
+ }
164182
+ function createGoogleDriveMetadataArchive(item, reason = "Google Drive item is not exportable as file content through Drive export.") {
164183
+ const metadata = {
164184
+ archived_as: "google-drive-metadata",
164185
+ reason,
164186
+ id: item.id,
164187
+ name: item.name,
164188
+ mime: item.mime,
164189
+ drive_id: item.drive_id,
164190
+ drive_name: item.drive_name,
164191
+ is_shared_drive: item.is_shared_drive,
164192
+ parent_id: item.parent_id,
164193
+ path: item.path,
164194
+ size: item.size,
164195
+ modified_at: item.modified_at,
164196
+ version: item.version,
164197
+ hash: item.hash
164198
+ };
164199
+ const data = Buffer.from(JSON.stringify(metadata, null, 2) + `
164200
+ `);
164201
+ return {
164202
+ data: data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength),
164203
+ filename: `${item.name}.gdrive-metadata.json`,
164204
+ mimeType: "application/json"
164205
+ };
164206
+ }
164154
164207
  function toApiFile(item) {
164155
164208
  return {
164156
164209
  id: item.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/files",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "Agent-first file management — index local folders and S3 buckets, sync Google Drive, tag, search, and retrieve files via CLI + MCP",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",