@finueva/drive 0.7.0 → 0.8.0

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
  # @finueva/drive
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8809e4e: Add getCurrentWorkspaceSources, listWorkspaceItems, and getWorkspaceUsage for authorized Files discovery. List recently modified items, actual incoming user/team grants, and trash with authenticated pagination, nullable genuine creation/modification/creator metadata, published version details, and retained mutation ETags. Read exact managed quota byte strings including unresolved reservations. Separate actual managed volumes from known provider kinds without fabricated connections or health. Existing SDK operations retain their contracts. The backend requires generated migration 0010 before these discovery routes are deployed.
8
+
3
9
  ## 0.7.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -78,13 +78,39 @@ const drive = createDriveServerClient({
78
78
 
79
79
  Create a client per request when using user authority. A fixed `credential` string is accepted for an explicitly scoped credential, but the SDK does not create, refresh, persist, or infer sessions, cookies, provider tokens, or service authority.
80
80
 
81
- The server client exposes all 24 Native Drive operations plus streaming `downloadItem`, but intentionally has no Blob-only `uploadFile` method. The package root and browser client add `uploadFile`, for 26 methods total.
81
+ The server client exposes all 27 normal-user Native Drive operations plus streaming `downloadItem`, but intentionally has no Blob-only `uploadFile` method. The package root and browser client add `uploadFile`, for 29 methods total.
82
+
83
+ ## Workspace Discovery
84
+
85
+ `getCurrentWorkspaceSources()` returns the actual managed volume separately from
86
+ known provider kinds. It does not invent external connections or provider health.
87
+
88
+ ```ts
89
+ const recent = await drive.listWorkspaceItems({ workspaceId, view: "recent", limit: 25 });
90
+ const shared = await drive.listWorkspaceItems({ workspaceId, view: "shared" });
91
+ const trash = await drive.listWorkspaceItems({ workspaceId, view: "trash" });
92
+ const usage = await drive.getWorkspaceUsage({ workspaceId });
93
+ ```
94
+
95
+ Recent means recorded modification time, not viewing activity. Historical unknown
96
+ timestamps and creator user IDs stay null; unknown modification times are excluded
97
+ from recent results until a real mutation. Shared lists actual incoming direct
98
+ user/team grants, not inherited descendants or all workspace-visible items. Trash
99
+ requires delete authority and retains current ETags for the existing mutation
100
+ methods. Continuations are encrypted, principal/root/filter-bound and short-lived;
101
+ restart on stale-page errors. Optional `kind` and `creatorUserId` filters apply on
102
+ the service before pagination. Quota reads require `usage:read` and return exact
103
+ decimal byte strings, clamped availability and unresolved-reservation evidence.
104
+ These source additions require backend migration `0010`, deployment and SDK release.
82
105
 
83
106
  ## Operations
84
107
 
85
108
  Methods use the Native API operation IDs:
86
109
 
87
110
  - `getCurrentWorkspace`
111
+ - `getCurrentWorkspaceSources`
112
+ - `listWorkspaceItems`
113
+ - `getWorkspaceUsage`
88
114
  - `getItem`
89
115
  - `searchWorkspaceItems`
90
116
  - `listFolderChildren`
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { $ as TrashItemInput, A as ListItemVersionsInput, C as FolderPage, D as GetUploadStatusInput, E as GetItemVersionInput, F as ManagedItemVersionPage, G as ProtectionClassification, I as ManagedItemVersionResource, J as RecordUploadPartInput, L as ManagedItemVersionRestoreResult, M as ManagedDownloadRestorePending, N as ManagedItemMetadata, O as ListFolderChildrenInput, P as ManagedItemVersion, Q as SearchWorkspaceItemsInput, R as ManagedLifecycleItem, S as FolderItem, T as GetItemInput, X as RestoreItemVersionInput, Y as RestoreItemInput, at as UploadFilePhase, c as CurrentWorkspace, ct as UploadPartDescriptor, d as DriveClient, dt as UploadStatus, et as UpdateItemInput, f as DriveClientConfig, ft as WorkspaceItemSearchItem, it as UploadFileInput, j as ManagedDownloadDescriptor, l as DeleteItemInput, lt as UploadPartResult, m as DriveCredentialProvider, n as CompleteUploadInput, nt as UploadCompletion, o as CreateUploadInput, ot as UploadFileProgress, pt as WorkspaceItemSearchPage, q as ReadyUpload, r as CreateDownloadInput, rt as UploadConfirmedPart, s as CreateUploadPartDescriptorInput, st as UploadFileProgressCallback, t as AbortUploadInput, u as DownloadItemResult, ut as UploadSession, w as GetCurrentWorkspaceInput, z as PendingUpload } from "./contract.js";
1
+ import { $ as RestoreItemVersionInput, A as ListFolderChildrenInput, B as ManagedItemVersionRestoreResult, C as FolderItem, D as GetItemVersionInput, E as GetItemInput, F as ManagedDownloadRestorePending, H as PendingUpload, I as ManagedItemMetadata, J as ProtectionClassification, L as ManagedItemVersion, M as ListItemVersionsInput, N as ListWorkspaceItemsInput, O as GetUploadStatusInput, P as ManagedDownloadDescriptor, Q as RestoreItemInput, R as ManagedItemVersionPage, T as GetCurrentWorkspaceInput, V as ManagedLifecycleItem, X as ReadyUpload, Z as RecordUploadPartInput, _t as WorkspaceItemSearchItem, at as UploadCompletion, c as CurrentWorkspace, ct as UploadFilePhase, d as DownloadItemResult, dt as UploadPartDescriptor, f as DriveClient, ft as UploadPartResult, gt as WorkspaceDiscoveryPage, h as DriveCredentialProvider, ht as WorkspaceDiscoveryItem, k as GetWorkspaceUsageInput, l as CurrentWorkspaceSources, lt as UploadFileProgress, mt as UploadStatus, n as CompleteUploadInput, nt as TrashItemInput, o as CreateUploadInput, ot as UploadConfirmedPart, p as DriveClientConfig, pt as UploadSession, r as CreateDownloadInput, rt as UpdateItemInput, s as CreateUploadPartDescriptorInput, st as UploadFileInput, t as AbortUploadInput, tt as SearchWorkspaceItemsInput, u as DeleteItemInput, ut as UploadFileProgressCallback, vt as WorkspaceItemSearchPage, w as FolderPage, yt as WorkspaceUsage, z as ManagedItemVersionResource } from "./contract.js";
2
2
  //#region src/client.d.ts
3
3
  declare function createDriveClient(config: DriveClientConfig): DriveClient;
4
4
  //#endregion
5
- export { type AbortUploadInput, type CompleteUploadInput, type CreateDownloadInput, type CreateUploadInput, type CreateUploadPartDescriptorInput, type CurrentWorkspace, type DeleteItemInput, type DownloadItemResult, type DriveClient, type DriveClientConfig, type DriveCredentialProvider, type FolderItem, type FolderPage, type GetCurrentWorkspaceInput, type GetItemInput, type GetItemVersionInput, type GetUploadStatusInput, type ListFolderChildrenInput, type ListItemVersionsInput, type ManagedDownloadDescriptor, type ManagedDownloadRestorePending, type ManagedItemMetadata, type ManagedItemVersion, type ManagedItemVersionPage, type ManagedItemVersionResource, type ManagedItemVersionRestoreResult, type ManagedLifecycleItem, type PendingUpload, type ProtectionClassification, type ReadyUpload, type RecordUploadPartInput, type RestoreItemInput, type RestoreItemVersionInput, type SearchWorkspaceItemsInput, type TrashItemInput, type UpdateItemInput, type UploadCompletion, type UploadConfirmedPart, type UploadFileInput, type UploadFilePhase, type UploadFileProgress, type UploadFileProgressCallback, type UploadPartDescriptor, type UploadPartResult, type UploadSession, type UploadStatus, type WorkspaceItemSearchItem, type WorkspaceItemSearchPage, createDriveClient };
5
+ export { type AbortUploadInput, type CompleteUploadInput, type CreateDownloadInput, type CreateUploadInput, type CreateUploadPartDescriptorInput, type CurrentWorkspace, type CurrentWorkspaceSources, type DeleteItemInput, type DownloadItemResult, type DriveClient, type DriveClientConfig, type DriveCredentialProvider, type FolderItem, type FolderPage, type GetCurrentWorkspaceInput, type GetItemInput, type GetItemVersionInput, type GetUploadStatusInput, type GetWorkspaceUsageInput, type ListFolderChildrenInput, type ListItemVersionsInput, type ListWorkspaceItemsInput, type ManagedDownloadDescriptor, type ManagedDownloadRestorePending, type ManagedItemMetadata, type ManagedItemVersion, type ManagedItemVersionPage, type ManagedItemVersionResource, type ManagedItemVersionRestoreResult, type ManagedLifecycleItem, type PendingUpload, type ProtectionClassification, type ReadyUpload, type RecordUploadPartInput, type RestoreItemInput, type RestoreItemVersionInput, type SearchWorkspaceItemsInput, type TrashItemInput, type UpdateItemInput, type UploadCompletion, type UploadConfirmedPart, type UploadFileInput, type UploadFilePhase, type UploadFileProgress, type UploadFileProgressCallback, type UploadPartDescriptor, type UploadPartResult, type UploadSession, type UploadStatus, type WorkspaceDiscoveryItem, type WorkspaceDiscoveryPage, type WorkspaceItemSearchItem, type WorkspaceItemSearchPage, type WorkspaceUsage, createDriveClient };
package/dist/client.js CHANGED
@@ -327,6 +327,101 @@ const MAX_UPLOAD_BYTE_LENGTH$1 = 33554432e4;
327
327
  const UPLOAD_PART_BYTE_LENGTH$2 = 32 * 1024 * 1024;
328
328
  const CONTENT_DIGEST$1 = /^sha256:[0-9a-f]{64}$/;
329
329
  const UTF8 = new TextEncoder();
330
+ function isWorkspaceUsage(value) {
331
+ if (!isExactRecord(value, [
332
+ "workspaceId",
333
+ "provider",
334
+ "usedBytes",
335
+ "reservedBytes",
336
+ "limitBytes",
337
+ "availableBytes",
338
+ "accounting",
339
+ "reservedBytesIncludeUnresolvedUploads",
340
+ "unresolvedReservedBytes",
341
+ "warnings"
342
+ ]) || typeof value.workspaceId !== "string" || !WORKSPACE_ID$1.test(value.workspaceId) || value.provider !== "managed" || value.accounting !== "current-versions-and-reservations" || value.reservedBytesIncludeUnresolvedUploads !== true || !Array.isArray(value.warnings) || value.warnings.length > 1 || value.warnings.some((warning) => warning !== "unresolved-archive-ownership") || ![
343
+ value.usedBytes,
344
+ value.reservedBytes,
345
+ value.limitBytes,
346
+ value.availableBytes,
347
+ value.unresolvedReservedBytes
348
+ ].every((bytes) => typeof bytes === "string" && /^(0|[1-9][0-9]{0,18})$/.test(bytes))) return false;
349
+ const available = BigInt(value.limitBytes) - BigInt(value.usedBytes) - BigInt(value.reservedBytes);
350
+ const valid = BigInt(value.availableBytes) === (available > 0n ? available : 0n) && BigInt(value.unresolvedReservedBytes) <= BigInt(value.reservedBytes) && (value.unresolvedReservedBytes === "0" || value.warnings.length === 1);
351
+ if (valid) Object.freeze(value.warnings);
352
+ return valid;
353
+ }
354
+ function isWorkspaceDiscoveryPage(value) {
355
+ if (!isExactRecord(value, ["items", "nextCursor"]) || !Array.isArray(value.items) || value.items.length > 50 || !(value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length > 0 && value.nextCursor.length <= 2048 && /^[A-Za-z0-9_.-]+$/.test(value.nextCursor)) || value.items.length === 0 && value.nextCursor !== null) return false;
356
+ const ids = new Set();
357
+ const valid = value.items.every((item) => {
358
+ if (!isExactRecord(item, [
359
+ "workspaceId",
360
+ "itemId",
361
+ "parentId",
362
+ "type",
363
+ "name",
364
+ "lifecycleState",
365
+ "revision",
366
+ "currentVersion",
367
+ "volumeId",
368
+ "provider",
369
+ "createdAtEpochMilliseconds",
370
+ "modifiedAtEpochMilliseconds",
371
+ "creatorUserId",
372
+ "etag",
373
+ "trashedAtEpochMilliseconds",
374
+ "purgeAfterEpochMilliseconds"
375
+ ]) || item.lifecycleState !== "active" && item.lifecycleState !== "trashed" || typeof item.volumeId !== "string" || !VOLUME_ID.test(item.volumeId) || item.provider !== "managed" || item.creatorUserId !== null && (typeof item.creatorUserId !== "string" || !AUTH_ID$1.test(item.creatorUserId)) || ![
376
+ item.createdAtEpochMilliseconds,
377
+ item.modifiedAtEpochMilliseconds,
378
+ item.trashedAtEpochMilliseconds,
379
+ item.purgeAfterEpochMilliseconds
380
+ ].every((date) => date === null || isSafeInteger$1(date))) return false;
381
+ const metadata = {
382
+ workspaceId: item.workspaceId,
383
+ itemId: item.itemId,
384
+ parentId: item.parentId,
385
+ type: item.type,
386
+ name: item.name,
387
+ lifecycleState: "active",
388
+ revision: item.revision,
389
+ currentVersion: item.currentVersion
390
+ };
391
+ if (typeof metadata.workspaceId !== "string" || !WORKSPACE_ID$1.test(metadata.workspaceId) || typeof metadata.itemId !== "string" || !ITEM_ID$1.test(metadata.itemId) || metadata.parentId === null || metadata.parentId === metadata.itemId || !isManagedItemMetadata(metadata, metadata.workspaceId, metadata.itemId) || item.etag !== `"drive.item.v1.${metadata.revision}"` || ids.has(metadata.itemId)) return false;
392
+ if (item.lifecycleState === "active" ? item.trashedAtEpochMilliseconds !== null || item.purgeAfterEpochMilliseconds !== null : !isSafeInteger$1(item.trashedAtEpochMilliseconds) || !isSafeInteger$1(item.purgeAfterEpochMilliseconds) || item.purgeAfterEpochMilliseconds <= item.trashedAtEpochMilliseconds) return false;
393
+ ids.add(metadata.itemId);
394
+ return true;
395
+ });
396
+ if (valid) {
397
+ for (const item of value.items) Object.freeze(item);
398
+ Object.freeze(value.items);
399
+ Object.freeze(value);
400
+ }
401
+ return valid;
402
+ }
403
+ function isCurrentWorkspaceSources(value) {
404
+ if (!isExactRecord(value, [
405
+ "workspace",
406
+ "volumes",
407
+ "knownProviders",
408
+ "externalConnectionsSupported"
409
+ ]) || !isCurrentWorkspace(value.workspace) || !Array.isArray(value.volumes) || value.volumes.length !== 1 || !Array.isArray(value.knownProviders) || value.externalConnectionsSupported !== false) return false;
410
+ const volume = value.volumes[0];
411
+ const providers = [
412
+ "managed",
413
+ "google-drive",
414
+ "onedrive",
415
+ "dropbox",
416
+ "s3-compatible"
417
+ ];
418
+ return isExactRecord(volume, [
419
+ "volumeId",
420
+ "rootItemId",
421
+ "provider",
422
+ "name"
423
+ ]) && volume.volumeId === value.workspace.rootVolumeId && volume.rootItemId === value.workspace.rootItemId && volume.provider === "managed" && volume.name === "Files" && value.knownProviders.length === providers.length && value.knownProviders.every((provider, index) => provider === providers[index]);
424
+ }
330
425
  function isCurrentWorkspace(value) {
331
426
  if (!isExactRecord(value, [
332
427
  "workspaceId",
@@ -846,6 +941,29 @@ function validateCurrentWorkspaceInput(value) {
846
941
  const signal = validateSignal(captureRecord(value === void 0 ? {} : value, [], ["signal"]).signal);
847
942
  return signal === void 0 ? {} : { signal };
848
943
  }
944
+ function validateWorkspaceDiscoveryInput(value, list) {
945
+ const input = captureRecord(value, ["workspaceId"], list ? [
946
+ "signal",
947
+ "view",
948
+ "kind",
949
+ "creatorUserId",
950
+ "limit",
951
+ "cursor"
952
+ ] : ["signal"]);
953
+ const signal = validateSignal(input.signal);
954
+ if (typeof input.workspaceId !== "string" || !WORKSPACE_ID.test(input.workspaceId) || input.view !== void 0 && input.view !== "recent" && input.view !== "shared" && input.view !== "trash" || input.kind !== void 0 && input.kind !== "file" && input.kind !== "folder" || input.creatorUserId !== void 0 && (typeof input.creatorUserId !== "string" || !AUTH_ID.test(input.creatorUserId)) || input.limit !== void 0 && (typeof input.limit !== "number" || !Number.isInteger(input.limit) || input.limit < 1 || input.limit > 50) || input.cursor !== void 0 && (typeof input.cursor !== "string" || input.cursor.length < 1 || input.cursor.length > 2048 || !/^[A-Za-z0-9_.-]+$/.test(input.cursor))) throw new DriveError("invalid_input");
955
+ return {
956
+ workspaceId: input.workspaceId,
957
+ signal,
958
+ query: {
959
+ ...input.view === void 0 ? {} : { view: input.view },
960
+ ...input.kind === void 0 ? {} : { kind: input.kind },
961
+ ...input.creatorUserId === void 0 ? {} : { creatorUserId: input.creatorUserId },
962
+ ...input.limit === void 0 ? {} : { limit: input.limit },
963
+ ...input.cursor === void 0 ? {} : { cursor: input.cursor }
964
+ }
965
+ };
966
+ }
849
967
  function validateResourceInput(value) {
850
968
  const input = captureRecord(value, ["workspaceId", "itemId"], ["signal"]);
851
969
  const workspaceId = input.workspaceId;
@@ -2022,6 +2140,9 @@ const DOWNLOAD_ERROR_CODES = Object.freeze([
2022
2140
  function createDriveOperations(runtime) {
2023
2141
  return Object.freeze({
2024
2142
  getCurrentWorkspace: (input) => getCurrentWorkspace(runtime, input),
2143
+ listWorkspaceItems: (input) => listWorkspaceItems(runtime, input),
2144
+ getWorkspaceUsage: (input) => getWorkspaceUsage(runtime, input),
2145
+ getCurrentWorkspaceSources: (input) => getCurrentWorkspaceSources(runtime, input),
2025
2146
  getItem: (input) => getItem(runtime, input),
2026
2147
  searchWorkspaceItems: (input) => searchWorkspaceItems(runtime, input),
2027
2148
  listFolderChildren: (input) => listFolderChildren(runtime, input),
@@ -2220,6 +2341,29 @@ function streamWithOperationLifetime(source, expectedLength, signal) {
2220
2341
  }
2221
2342
  });
2222
2343
  }
2344
+ async function getCurrentWorkspaceSources(runtime, input) {
2345
+ return execute(runtime, validateCurrentWorkspaceInput(input).signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/current/sources", {
2346
+ ...operationOptions("getCurrentWorkspaceSources", { params: {} }),
2347
+ ...requestOptions
2348
+ }), [200], isCurrentWorkspaceSources, false, CURRENT_WORKSPACE_ERROR_CODES);
2349
+ }
2350
+ async function listWorkspaceItems(runtime, input) {
2351
+ const validated = validateWorkspaceDiscoveryInput(input, true);
2352
+ return execute(runtime, validated.signal, null, (api, options) => api.GET("/api/v1/workspaces/{workspaceId}/items", {
2353
+ ...operationOptions("listWorkspaceItems", { params: {
2354
+ path: { workspaceId: validated.workspaceId },
2355
+ query: validated.query
2356
+ } }),
2357
+ ...options
2358
+ }), [200], (value) => isWorkspaceDiscoveryPage(value) && value.items.length <= (validated.query.limit ?? 25) && value.items.every((item, index, items) => item.workspaceId === validated.workspaceId && item.lifecycleState === (validated.query.view === "trash" ? "trashed" : "active") && ((validated.query.view ?? "recent") !== "recent" || item.modifiedAtEpochMilliseconds !== null) && (validated.query.kind === void 0 || item.type === validated.query.kind) && (validated.query.creatorUserId === void 0 || item.creatorUserId === validated.query.creatorUserId) && (index === 0 || ((validated.query.view ?? "recent") === "recent" ? items[index - 1].modifiedAtEpochMilliseconds > item.modifiedAtEpochMilliseconds || items[index - 1].modifiedAtEpochMilliseconds === item.modifiedAtEpochMilliseconds && items[index - 1].itemId < item.itemId : items[index - 1].itemId < item.itemId))), false, SEARCH_WORKSPACE_ITEMS_ERROR_CODES);
2359
+ }
2360
+ async function getWorkspaceUsage(runtime, input) {
2361
+ const validated = validateWorkspaceDiscoveryInput(input, false);
2362
+ return execute(runtime, validated.signal, null, (api, options) => api.GET("/api/v1/workspaces/{workspaceId}/usage", {
2363
+ ...operationOptions("getWorkspaceUsage", { params: { path: { workspaceId: validated.workspaceId } } }),
2364
+ ...options
2365
+ }), [200], (value) => isWorkspaceUsage(value) && value.workspaceId === validated.workspaceId, false, SEARCH_WORKSPACE_ITEMS_ERROR_CODES);
2366
+ }
2223
2367
  async function getCurrentWorkspace(runtime, input) {
2224
2368
  return execute(runtime, validateCurrentWorkspaceInput(input).signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/current", {
2225
2369
  ...operationOptions("getCurrentWorkspace", { params: {} }),
@@ -355,6 +355,312 @@ interface operations {
355
355
  };
356
356
  };
357
357
  };
358
+ getCurrentWorkspaceSources: {
359
+ parameters: {
360
+ query?: never;
361
+ header?: never;
362
+ path?: never;
363
+ cookie?: never;
364
+ };
365
+ requestBody?: never;
366
+ responses: {
367
+ /** @description One canonical managed volume. Known providers are not connections or health evidence. */
368
+ 200: {
369
+ headers: {
370
+ [name: string]: unknown;
371
+ };
372
+ content: {
373
+ "application/json": {
374
+ /** @enum {boolean} */
375
+ externalConnectionsSupported: false;
376
+ knownProviders: ("managed" | "google-drive" | "onedrive" | "dropbox" | "s3-compatible")[];
377
+ volumes: {
378
+ /** @enum {string} */
379
+ name: "Files";
380
+ /** @enum {string} */
381
+ provider: "managed";
382
+ rootItemId: string;
383
+ volumeId: string;
384
+ }[];
385
+ workspace: {
386
+ rootItemId: string;
387
+ rootVolumeId: string;
388
+ workspaceId: string;
389
+ workspaceReference: {
390
+ /** @enum {string} */
391
+ type: "personal";
392
+ userId: string;
393
+ } | {
394
+ organizationId: string;
395
+ /** @enum {string} */
396
+ type: "organization";
397
+ };
398
+ };
399
+ };
400
+ };
401
+ };
402
+ /** @description A valid Drive user bearer credential is required. */
403
+ 401: {
404
+ headers: {
405
+ [name: string]: unknown;
406
+ };
407
+ content: {
408
+ "application/json": {
409
+ error: {
410
+ /** @enum {string} */
411
+ code: "authentication_required";
412
+ details: Record<string, never>;
413
+ /** @enum {string} */
414
+ message: "Authentication is required.";
415
+ requestId: string;
416
+ };
417
+ };
418
+ };
419
+ };
420
+ /** @description Managed storage is disabled. */
421
+ 403: {
422
+ headers: {
423
+ [name: string]: unknown;
424
+ };
425
+ content: {
426
+ "application/json": {
427
+ error: {
428
+ /** @enum {string} */
429
+ code: "permission_denied";
430
+ details: Record<string, never>;
431
+ /** @enum {string} */
432
+ message: "The requested action is not permitted.";
433
+ requestId: string;
434
+ };
435
+ };
436
+ };
437
+ };
438
+ /** @description The current workspace is not provisioned or accessible. */
439
+ 404: {
440
+ headers: {
441
+ [name: string]: unknown;
442
+ };
443
+ content: {
444
+ "application/json": {
445
+ error: {
446
+ /** @enum {string} */
447
+ code: "resource_not_found";
448
+ details: Record<string, never>;
449
+ /** @enum {string} */
450
+ message: "The requested resource was not found.";
451
+ requestId: string;
452
+ };
453
+ };
454
+ };
455
+ };
456
+ /** @description Unsupported query input. */
457
+ 422: {
458
+ headers: {
459
+ [name: string]: unknown;
460
+ };
461
+ content: {
462
+ "application/json": {
463
+ error: {
464
+ /** @enum {string} */
465
+ code: "invalid_request";
466
+ details: Record<string, never>;
467
+ /** @enum {string} */
468
+ message: "The request is invalid.";
469
+ requestId: string;
470
+ };
471
+ };
472
+ };
473
+ };
474
+ /** @description Identity authority, D1, or canonical managed root is unavailable. */
475
+ 503: {
476
+ headers: {
477
+ [name: string]: unknown;
478
+ };
479
+ content: {
480
+ "application/json": {
481
+ error: {
482
+ /** @enum {string} */
483
+ code: "identity_authority_unavailable";
484
+ details: Record<string, never>;
485
+ /** @enum {string} */
486
+ message: "Authentication is temporarily unavailable.";
487
+ requestId: string;
488
+ };
489
+ } | {
490
+ error: {
491
+ /** @enum {string} */
492
+ code: "service_unavailable";
493
+ details: Record<string, never>;
494
+ /** @enum {string} */
495
+ message: "The service is temporarily unavailable.";
496
+ requestId: string;
497
+ };
498
+ };
499
+ };
500
+ };
501
+ };
502
+ };
503
+ listWorkspaceItems: {
504
+ parameters: {
505
+ query?: {
506
+ view?: "recent" | "shared" | "trash";
507
+ kind?: "file" | "folder";
508
+ creatorUserId?: string;
509
+ limit?: number;
510
+ cursor?: string;
511
+ };
512
+ header?: never;
513
+ path: {
514
+ workspaceId: string;
515
+ };
516
+ cookie?: never;
517
+ };
518
+ requestBody?: never;
519
+ responses: {
520
+ /** @description Authorized items and an authenticated continuation; no total count. */
521
+ 200: {
522
+ headers: {
523
+ [name: string]: unknown;
524
+ };
525
+ content: {
526
+ "application/json": {
527
+ items: {
528
+ createdAtEpochMilliseconds: number | null;
529
+ creatorUserId: string | null;
530
+ currentVersion: {
531
+ byteLength: number;
532
+ mediaType: string;
533
+ /** @enum {string} */
534
+ protectionClassification: "ordinary" | "opaque-encrypted";
535
+ /** @enum {string} */
536
+ state: "current";
537
+ versionId: string;
538
+ } | null;
539
+ etag: string;
540
+ itemId: string;
541
+ /** @enum {string} */
542
+ lifecycleState: "active" | "trashed";
543
+ modifiedAtEpochMilliseconds: number | null;
544
+ name: string;
545
+ parentId: string | null;
546
+ /** @enum {string} */
547
+ provider: "managed";
548
+ purgeAfterEpochMilliseconds: number | null;
549
+ revision: number;
550
+ trashedAtEpochMilliseconds: number | null;
551
+ /** @enum {string} */
552
+ type: "file" | "folder";
553
+ volumeId: string;
554
+ workspaceId: string;
555
+ }[];
556
+ nextCursor: string | null;
557
+ };
558
+ };
559
+ };
560
+ /** @description Authentication required. */
561
+ 401: {
562
+ headers: {
563
+ [name: string]: unknown;
564
+ };
565
+ content: {
566
+ "application/json": {
567
+ error: {
568
+ /** @enum {string} */
569
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
570
+ details: Record<string, never>;
571
+ message: string;
572
+ requestId: string;
573
+ };
574
+ };
575
+ };
576
+ };
577
+ /** @description The action is not permitted. */
578
+ 403: {
579
+ headers: {
580
+ [name: string]: unknown;
581
+ };
582
+ content: {
583
+ "application/json": {
584
+ error: {
585
+ /** @enum {string} */
586
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
587
+ details: Record<string, never>;
588
+ message: string;
589
+ requestId: string;
590
+ };
591
+ };
592
+ };
593
+ };
594
+ /** @description Workspace not found. */
595
+ 404: {
596
+ headers: {
597
+ [name: string]: unknown;
598
+ };
599
+ content: {
600
+ "application/json": {
601
+ error: {
602
+ /** @enum {string} */
603
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
604
+ details: Record<string, never>;
605
+ message: string;
606
+ requestId: string;
607
+ };
608
+ };
609
+ };
610
+ };
611
+ /** @description The selected authority or page changed; restart the query. */
612
+ 409: {
613
+ headers: {
614
+ [name: string]: unknown;
615
+ };
616
+ content: {
617
+ "application/json": {
618
+ error: {
619
+ /** @enum {string} */
620
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
621
+ details: Record<string, never>;
622
+ message: string;
623
+ requestId: string;
624
+ };
625
+ };
626
+ };
627
+ };
628
+ /** @description Invalid request or cursor. */
629
+ 422: {
630
+ headers: {
631
+ [name: string]: unknown;
632
+ };
633
+ content: {
634
+ "application/json": {
635
+ error: {
636
+ /** @enum {string} */
637
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
638
+ details: Record<string, never>;
639
+ message: string;
640
+ requestId: string;
641
+ };
642
+ };
643
+ };
644
+ };
645
+ /** @description Authoritative state is unavailable. */
646
+ 503: {
647
+ headers: {
648
+ [name: string]: unknown;
649
+ };
650
+ content: {
651
+ "application/json": {
652
+ error: {
653
+ /** @enum {string} */
654
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
655
+ details: Record<string, never>;
656
+ message: string;
657
+ requestId: string;
658
+ };
659
+ };
660
+ };
661
+ };
662
+ };
663
+ };
358
664
  getItem: {
359
665
  parameters: {
360
666
  query?: never;
@@ -4562,6 +4868,144 @@ interface operations {
4562
4868
  };
4563
4869
  };
4564
4870
  };
4871
+ getWorkspaceUsage: {
4872
+ parameters: {
4873
+ query?: never;
4874
+ header?: never;
4875
+ path: {
4876
+ workspaceId: string;
4877
+ };
4878
+ cookie?: never;
4879
+ };
4880
+ requestBody?: never;
4881
+ responses: {
4882
+ /** @description Current committed and retained reserved bytes, not physical archive usage. */
4883
+ 200: {
4884
+ headers: {
4885
+ [name: string]: unknown;
4886
+ };
4887
+ content: {
4888
+ "application/json": {
4889
+ /** @enum {string} */
4890
+ accounting: "current-versions-and-reservations";
4891
+ availableBytes: string;
4892
+ limitBytes: string;
4893
+ /** @enum {string} */
4894
+ provider: "managed";
4895
+ reservedBytes: string;
4896
+ /** @enum {boolean} */
4897
+ reservedBytesIncludeUnresolvedUploads: true;
4898
+ unresolvedReservedBytes: string;
4899
+ usedBytes: string;
4900
+ warnings: "unresolved-archive-ownership"[];
4901
+ workspaceId: string;
4902
+ };
4903
+ };
4904
+ };
4905
+ /** @description Authentication required. */
4906
+ 401: {
4907
+ headers: {
4908
+ [name: string]: unknown;
4909
+ };
4910
+ content: {
4911
+ "application/json": {
4912
+ error: {
4913
+ /** @enum {string} */
4914
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
4915
+ details: Record<string, never>;
4916
+ message: string;
4917
+ requestId: string;
4918
+ };
4919
+ };
4920
+ };
4921
+ };
4922
+ /** @description The action is not permitted. */
4923
+ 403: {
4924
+ headers: {
4925
+ [name: string]: unknown;
4926
+ };
4927
+ content: {
4928
+ "application/json": {
4929
+ error: {
4930
+ /** @enum {string} */
4931
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
4932
+ details: Record<string, never>;
4933
+ message: string;
4934
+ requestId: string;
4935
+ };
4936
+ };
4937
+ };
4938
+ };
4939
+ /** @description Workspace not found. */
4940
+ 404: {
4941
+ headers: {
4942
+ [name: string]: unknown;
4943
+ };
4944
+ content: {
4945
+ "application/json": {
4946
+ error: {
4947
+ /** @enum {string} */
4948
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
4949
+ details: Record<string, never>;
4950
+ message: string;
4951
+ requestId: string;
4952
+ };
4953
+ };
4954
+ };
4955
+ };
4956
+ /** @description The selected authority or page changed; restart the query. */
4957
+ 409: {
4958
+ headers: {
4959
+ [name: string]: unknown;
4960
+ };
4961
+ content: {
4962
+ "application/json": {
4963
+ error: {
4964
+ /** @enum {string} */
4965
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
4966
+ details: Record<string, never>;
4967
+ message: string;
4968
+ requestId: string;
4969
+ };
4970
+ };
4971
+ };
4972
+ };
4973
+ /** @description Invalid request or cursor. */
4974
+ 422: {
4975
+ headers: {
4976
+ [name: string]: unknown;
4977
+ };
4978
+ content: {
4979
+ "application/json": {
4980
+ error: {
4981
+ /** @enum {string} */
4982
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
4983
+ details: Record<string, never>;
4984
+ message: string;
4985
+ requestId: string;
4986
+ };
4987
+ };
4988
+ };
4989
+ };
4990
+ /** @description Authoritative state is unavailable. */
4991
+ 503: {
4992
+ headers: {
4993
+ [name: string]: unknown;
4994
+ };
4995
+ content: {
4996
+ "application/json": {
4997
+ error: {
4998
+ /** @enum {string} */
4999
+ code: "authentication_required" | "identity_authority_unavailable" | "permission_denied" | "resource_not_found" | "invalid_request" | "invalid_pagination_cursor" | "precondition_failed" | "service_unavailable";
5000
+ details: Record<string, never>;
5001
+ message: string;
5002
+ requestId: string;
5003
+ };
5004
+ };
5005
+ };
5006
+ };
5007
+ };
5008
+ };
4565
5009
  }
4566
5010
  //#endregion
4567
5011
  //#region src/types.d.ts
@@ -4610,6 +5054,35 @@ type CreateDownloadPath = operations["createDownload"]["parameters"]["path"];
4610
5054
  type CreateDownloadQuery = NonNullable<operations["createDownload"]["parameters"]["query"]>;
4611
5055
  type CreateDownloadHeaders = operations["createDownload"]["parameters"]["header"];
4612
5056
  type GeneratedCurrentWorkspace = JsonResponse<"getCurrentWorkspace", 200>;
5057
+ type GeneratedDiscoveryPage = JsonResponse<"listWorkspaceItems", 200>;
5058
+ type WorkspaceDiscoveryItem = Readonly<Omit<GeneratedDiscoveryPage["items"][number], "currentVersion"> & {
5059
+ readonly currentVersion: ManagedItemMetadata["currentVersion"];
5060
+ }>;
5061
+ type WorkspaceDiscoveryPage = Readonly<{
5062
+ items: readonly WorkspaceDiscoveryItem[];
5063
+ nextCursor: string | null;
5064
+ }>;
5065
+ type GeneratedWorkspaceUsage = JsonResponse<"getWorkspaceUsage", 200>;
5066
+ type WorkspaceUsage = Readonly<Omit<GeneratedWorkspaceUsage, "warnings"> & {
5067
+ readonly warnings: readonly GeneratedWorkspaceUsage["warnings"][number][];
5068
+ }>;
5069
+ interface GetWorkspaceUsageInput {
5070
+ readonly workspaceId: string;
5071
+ readonly signal?: AbortSignal;
5072
+ }
5073
+ interface ListWorkspaceItemsInput extends GetWorkspaceUsageInput {
5074
+ readonly view?: "recent" | "shared" | "trash";
5075
+ readonly kind?: "file" | "folder";
5076
+ readonly creatorUserId?: string;
5077
+ readonly limit?: number;
5078
+ readonly cursor?: string;
5079
+ }
5080
+ type GeneratedCurrentWorkspaceSources = JsonResponse<"getCurrentWorkspaceSources", 200>;
5081
+ type CurrentWorkspaceSources = Readonly<Omit<GeneratedCurrentWorkspaceSources, "workspace" | "volumes" | "knownProviders"> & {
5082
+ readonly workspace: CurrentWorkspace;
5083
+ readonly volumes: readonly Readonly<GeneratedCurrentWorkspaceSources["volumes"][number]>[];
5084
+ readonly knownProviders: readonly GeneratedCurrentWorkspaceSources["knownProviders"][number][];
5085
+ }>;
4613
5086
  type CurrentWorkspace = Readonly<Omit<GeneratedCurrentWorkspace, "workspaceReference"> & {
4614
5087
  readonly workspaceReference: Readonly<GeneratedCurrentWorkspace["workspaceReference"]>;
4615
5088
  }>;
@@ -4817,6 +5290,9 @@ interface GetCurrentWorkspaceInput {
4817
5290
  readonly signal?: AbortSignal;
4818
5291
  }
4819
5292
  interface DriveOperations {
5293
+ listWorkspaceItems(input: ListWorkspaceItemsInput): Promise<DriveOperationResult<WorkspaceDiscoveryPage, 200>>;
5294
+ getWorkspaceUsage(input: GetWorkspaceUsageInput): Promise<DriveOperationResult<WorkspaceUsage, 200>>;
5295
+ getCurrentWorkspaceSources(input?: GetCurrentWorkspaceInput): Promise<DriveOperationResult<CurrentWorkspaceSources, 200>>;
4820
5296
  getCurrentWorkspace(input?: GetCurrentWorkspaceInput): Promise<DriveOperationResult<CurrentWorkspace, 200>>;
4821
5297
  getItem(input: GetItemInput): Promise<DriveOperationResult<ManagedItemMetadata, 200>>;
4822
5298
  searchWorkspaceItems(input: SearchWorkspaceItemsInput): Promise<DriveOperationResult<WorkspaceItemSearchPage, 200>>;
@@ -4848,4 +5324,4 @@ interface DriveClient extends DriveOperations {
4848
5324
  uploadFile(input: UploadFileInput): Promise<DriveOperationResult<UploadCompletion, 200 | 202>>;
4849
5325
  }
4850
5326
  //#endregion
4851
- export { TrashItemInput as $, ListItemVersionsInput as A, PermissionAction as B, FolderPage as C, GetUploadStatusInput as D, GetItemVersionInput as E, ManagedItemVersionPage as F, ProtectionClassification as G, PermissionGrantee as H, ManagedItemVersionResource as I, RecordUploadPartInput as J, ReadEffectiveItemPermissionsInput as K, ManagedItemVersionRestoreResult as L, ManagedDownloadRestorePending as M, ManagedItemMetadata as N, ListFolderChildrenInput as O, ManagedItemVersion as P, SearchWorkspaceItemsInput as Q, ManagedLifecycleItem as R, FolderItem as S, GetItemInput as T, PermissionMutation as U, PermissionGrant as V, PermissionPage as W, RestoreItemVersionInput as X, RestoreItemInput as Y, RevokeItemPermissionInput as Z, DriveResponseValidators as _, CreateItemPermissionInput as a, UploadFilePhase as at, EffectivePermissionAction as b, CurrentWorkspace as c, UploadPartDescriptor as ct, DriveClient as d, UploadStatus as dt, UpdateItemInput as et, DriveClientConfig as f, WorkspaceItemSearchItem as ft, DriveOperations as g, DriveOperationResult as h, CreateFolderInput as i, UploadFileInput as it, ManagedDownloadDescriptor as j, ListItemPermissionsInput as k, DeleteItemInput as l, UploadPartResult as lt, DriveCredentialProvider as m, operations as mt, CompleteUploadInput as n, UploadCompletion as nt, CreateUploadInput as o, UploadFileProgress as ot, DriveCredentialContext as p, WorkspaceItemSearchPage as pt, ReadyUpload as q, CreateDownloadInput as r, UploadConfirmedPart as rt, CreateUploadPartDescriptorInput as s, UploadFileProgressCallback as st, AbortUploadInput as t, UpdateItemPermissionInput as tt, DownloadItemResult as u, UploadSession as ut, DriveServerClient as v, GetCurrentWorkspaceInput as w, EffectivePermissionResponse as x, DriveServerClientConfig as y, PendingUpload as z };
5327
+ export { RestoreItemVersionInput as $, ListFolderChildrenInput as A, ManagedItemVersionRestoreResult as B, FolderItem as C, GetItemVersionInput as D, GetItemInput as E, ManagedDownloadRestorePending as F, PermissionGrantee as G, PendingUpload as H, ManagedItemMetadata as I, ProtectionClassification as J, PermissionMutation as K, ManagedItemVersion as L, ListItemVersionsInput as M, ListWorkspaceItemsInput as N, GetUploadStatusInput as O, ManagedDownloadDescriptor as P, RestoreItemInput as Q, ManagedItemVersionPage as R, EffectivePermissionResponse as S, GetCurrentWorkspaceInput as T, PermissionAction as U, ManagedLifecycleItem as V, PermissionGrant as W, ReadyUpload as X, ReadEffectiveItemPermissionsInput as Y, RecordUploadPartInput as Z, DriveOperations as _, WorkspaceItemSearchItem as _t, CreateItemPermissionInput as a, UploadCompletion as at, DriveServerClientConfig as b, operations as bt, CurrentWorkspace as c, UploadFilePhase as ct, DownloadItemResult as d, UploadPartDescriptor as dt, RevokeItemPermissionInput as et, DriveClient as f, UploadPartResult as ft, DriveOperationResult as g, WorkspaceDiscoveryPage as gt, DriveCredentialProvider as h, WorkspaceDiscoveryItem as ht, CreateFolderInput as i, UpdateItemPermissionInput as it, ListItemPermissionsInput as j, GetWorkspaceUsageInput as k, CurrentWorkspaceSources as l, UploadFileProgress as lt, DriveCredentialContext as m, UploadStatus as mt, CompleteUploadInput as n, TrashItemInput as nt, CreateUploadInput as o, UploadConfirmedPart as ot, DriveClientConfig as p, UploadSession as pt, PermissionPage as q, CreateDownloadInput as r, UpdateItemInput as rt, CreateUploadPartDescriptorInput as s, UploadFileInput as st, AbortUploadInput as t, SearchWorkspaceItemsInput as tt, DeleteItemInput as u, UploadFileProgressCallback as ut, DriveResponseValidators as v, WorkspaceItemSearchPage as vt, FolderPage as w, EffectivePermissionAction as x, DriveServerClient as y, WorkspaceUsage as yt, ManagedItemVersionResource as z };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as TrashItemInput, A as ListItemVersionsInput, B as PermissionAction, C as FolderPage, D as GetUploadStatusInput, E as GetItemVersionInput, F as ManagedItemVersionPage, G as ProtectionClassification, H as PermissionGrantee, I as ManagedItemVersionResource, J as RecordUploadPartInput, K as ReadEffectiveItemPermissionsInput, L as ManagedItemVersionRestoreResult, M as ManagedDownloadRestorePending, N as ManagedItemMetadata, O as ListFolderChildrenInput, P as ManagedItemVersion, Q as SearchWorkspaceItemsInput, R as ManagedLifecycleItem, S as FolderItem, T as GetItemInput, U as PermissionMutation, V as PermissionGrant, X as RestoreItemVersionInput, Y as RestoreItemInput, Z as RevokeItemPermissionInput, _ as DriveResponseValidators, a as CreateItemPermissionInput, at as UploadFilePhase, b as EffectivePermissionAction, c as CurrentWorkspace, ct as UploadPartDescriptor, d as DriveClient, dt as UploadStatus, et as UpdateItemInput, f as DriveClientConfig, ft as WorkspaceItemSearchItem, g as DriveOperations, h as DriveOperationResult, i as CreateFolderInput, it as UploadFileInput, j as ManagedDownloadDescriptor, k as ListItemPermissionsInput, l as DeleteItemInput, lt as UploadPartResult, m as DriveCredentialProvider, n as CompleteUploadInput, nt as UploadCompletion, o as CreateUploadInput, ot as UploadFileProgress, pt as WorkspaceItemSearchPage, q as ReadyUpload, r as CreateDownloadInput, rt as UploadConfirmedPart, s as CreateUploadPartDescriptorInput, st as UploadFileProgressCallback, t as AbortUploadInput, tt as UpdateItemPermissionInput, u as DownloadItemResult, ut as UploadSession, w as GetCurrentWorkspaceInput, z as PendingUpload } from "./contract.js";
1
+ import { $ as RestoreItemVersionInput, A as ListFolderChildrenInput, B as ManagedItemVersionRestoreResult, C as FolderItem, D as GetItemVersionInput, E as GetItemInput, F as ManagedDownloadRestorePending, G as PermissionGrantee, H as PendingUpload, I as ManagedItemMetadata, J as ProtectionClassification, K as PermissionMutation, L as ManagedItemVersion, M as ListItemVersionsInput, N as ListWorkspaceItemsInput, O as GetUploadStatusInput, P as ManagedDownloadDescriptor, Q as RestoreItemInput, R as ManagedItemVersionPage, T as GetCurrentWorkspaceInput, U as PermissionAction, V as ManagedLifecycleItem, W as PermissionGrant, X as ReadyUpload, Y as ReadEffectiveItemPermissionsInput, Z as RecordUploadPartInput, _ as DriveOperations, _t as WorkspaceItemSearchItem, a as CreateItemPermissionInput, at as UploadCompletion, c as CurrentWorkspace, ct as UploadFilePhase, d as DownloadItemResult, dt as UploadPartDescriptor, et as RevokeItemPermissionInput, f as DriveClient, ft as UploadPartResult, g as DriveOperationResult, gt as WorkspaceDiscoveryPage, h as DriveCredentialProvider, ht as WorkspaceDiscoveryItem, i as CreateFolderInput, it as UpdateItemPermissionInput, j as ListItemPermissionsInput, k as GetWorkspaceUsageInput, l as CurrentWorkspaceSources, lt as UploadFileProgress, mt as UploadStatus, n as CompleteUploadInput, nt as TrashItemInput, o as CreateUploadInput, ot as UploadConfirmedPart, p as DriveClientConfig, pt as UploadSession, r as CreateDownloadInput, rt as UpdateItemInput, s as CreateUploadPartDescriptorInput, st as UploadFileInput, t as AbortUploadInput, tt as SearchWorkspaceItemsInput, u as DeleteItemInput, ut as UploadFileProgressCallback, v as DriveResponseValidators, vt as WorkspaceItemSearchPage, w as FolderPage, x as EffectivePermissionAction, yt as WorkspaceUsage, z as ManagedItemVersionResource } from "./contract.js";
2
2
  import { createDriveClient } from "./client.js";
3
3
  import { DRIVE_API_ERROR_CODES, DRIVE_API_ERROR_MESSAGES, DriveApiErrorCode, DriveError, DriveErrorCode, DriveSdkErrorCode } from "./core.js";
4
- export { type AbortUploadInput, type CompleteUploadInput, type CreateDownloadInput, type CreateFolderInput, type CreateItemPermissionInput, type CreateUploadInput, type CreateUploadPartDescriptorInput, type CurrentWorkspace, DRIVE_API_ERROR_CODES, DRIVE_API_ERROR_MESSAGES, type DeleteItemInput, type DownloadItemResult, type DriveApiErrorCode, type DriveClient, type DriveClientConfig, type DriveCredentialProvider, DriveError, type DriveErrorCode, type DriveOperationResult, type DriveOperations, type DriveResponseValidators, type DriveSdkErrorCode, type EffectivePermissionAction, type FolderItem, type FolderPage, type GetCurrentWorkspaceInput, type GetItemInput, type GetItemVersionInput, type GetUploadStatusInput, type ListFolderChildrenInput, type ListItemPermissionsInput, type ListItemVersionsInput, type ManagedDownloadDescriptor, type ManagedDownloadRestorePending, type ManagedItemMetadata, type ManagedItemVersion, type ManagedItemVersionPage, type ManagedItemVersionResource, type ManagedItemVersionRestoreResult, type ManagedLifecycleItem, type PendingUpload, type PermissionAction, type PermissionGrant, type PermissionGrantee, type PermissionMutation, type ProtectionClassification, type ReadEffectiveItemPermissionsInput, type ReadyUpload, type RecordUploadPartInput, type RestoreItemInput, type RestoreItemVersionInput, type RevokeItemPermissionInput, type SearchWorkspaceItemsInput, type TrashItemInput, type UpdateItemInput, type UpdateItemPermissionInput, type UploadCompletion, type UploadConfirmedPart, type UploadFileInput, type UploadFilePhase, type UploadFileProgress, type UploadFileProgressCallback, type UploadPartDescriptor, type UploadPartResult, type UploadSession, type UploadStatus, type WorkspaceItemSearchItem, type WorkspaceItemSearchPage, createDriveClient };
4
+ export { type AbortUploadInput, type CompleteUploadInput, type CreateDownloadInput, type CreateFolderInput, type CreateItemPermissionInput, type CreateUploadInput, type CreateUploadPartDescriptorInput, type CurrentWorkspace, type CurrentWorkspaceSources, DRIVE_API_ERROR_CODES, DRIVE_API_ERROR_MESSAGES, type DeleteItemInput, type DownloadItemResult, type DriveApiErrorCode, type DriveClient, type DriveClientConfig, type DriveCredentialProvider, DriveError, type DriveErrorCode, type DriveOperationResult, type DriveOperations, type DriveResponseValidators, type DriveSdkErrorCode, type EffectivePermissionAction, type FolderItem, type FolderPage, type GetCurrentWorkspaceInput, type GetItemInput, type GetItemVersionInput, type GetUploadStatusInput, type GetWorkspaceUsageInput, type ListFolderChildrenInput, type ListItemPermissionsInput, type ListItemVersionsInput, type ListWorkspaceItemsInput, type ManagedDownloadDescriptor, type ManagedDownloadRestorePending, type ManagedItemMetadata, type ManagedItemVersion, type ManagedItemVersionPage, type ManagedItemVersionResource, type ManagedItemVersionRestoreResult, type ManagedLifecycleItem, type PendingUpload, type PermissionAction, type PermissionGrant, type PermissionGrantee, type PermissionMutation, type ProtectionClassification, type ReadEffectiveItemPermissionsInput, type ReadyUpload, type RecordUploadPartInput, type RestoreItemInput, type RestoreItemVersionInput, type RevokeItemPermissionInput, type SearchWorkspaceItemsInput, type TrashItemInput, type UpdateItemInput, type UpdateItemPermissionInput, type UploadCompletion, type UploadConfirmedPart, type UploadFileInput, type UploadFilePhase, type UploadFileProgress, type UploadFileProgressCallback, type UploadPartDescriptor, type UploadPartResult, type UploadSession, type UploadStatus, type WorkspaceDiscoveryItem, type WorkspaceDiscoveryPage, type WorkspaceItemSearchItem, type WorkspaceItemSearchPage, type WorkspaceUsage, createDriveClient };
package/dist/index.js CHANGED
@@ -327,6 +327,101 @@ const MAX_UPLOAD_BYTE_LENGTH$1 = 33554432e4;
327
327
  const UPLOAD_PART_BYTE_LENGTH$2 = 32 * 1024 * 1024;
328
328
  const CONTENT_DIGEST$1 = /^sha256:[0-9a-f]{64}$/;
329
329
  const UTF8 = new TextEncoder();
330
+ function isWorkspaceUsage(value) {
331
+ if (!isExactRecord(value, [
332
+ "workspaceId",
333
+ "provider",
334
+ "usedBytes",
335
+ "reservedBytes",
336
+ "limitBytes",
337
+ "availableBytes",
338
+ "accounting",
339
+ "reservedBytesIncludeUnresolvedUploads",
340
+ "unresolvedReservedBytes",
341
+ "warnings"
342
+ ]) || typeof value.workspaceId !== "string" || !WORKSPACE_ID$1.test(value.workspaceId) || value.provider !== "managed" || value.accounting !== "current-versions-and-reservations" || value.reservedBytesIncludeUnresolvedUploads !== true || !Array.isArray(value.warnings) || value.warnings.length > 1 || value.warnings.some((warning) => warning !== "unresolved-archive-ownership") || ![
343
+ value.usedBytes,
344
+ value.reservedBytes,
345
+ value.limitBytes,
346
+ value.availableBytes,
347
+ value.unresolvedReservedBytes
348
+ ].every((bytes) => typeof bytes === "string" && /^(0|[1-9][0-9]{0,18})$/.test(bytes))) return false;
349
+ const available = BigInt(value.limitBytes) - BigInt(value.usedBytes) - BigInt(value.reservedBytes);
350
+ const valid = BigInt(value.availableBytes) === (available > 0n ? available : 0n) && BigInt(value.unresolvedReservedBytes) <= BigInt(value.reservedBytes) && (value.unresolvedReservedBytes === "0" || value.warnings.length === 1);
351
+ if (valid) Object.freeze(value.warnings);
352
+ return valid;
353
+ }
354
+ function isWorkspaceDiscoveryPage(value) {
355
+ if (!isExactRecord(value, ["items", "nextCursor"]) || !Array.isArray(value.items) || value.items.length > 50 || !(value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length > 0 && value.nextCursor.length <= 2048 && /^[A-Za-z0-9_.-]+$/.test(value.nextCursor)) || value.items.length === 0 && value.nextCursor !== null) return false;
356
+ const ids = new Set();
357
+ const valid = value.items.every((item) => {
358
+ if (!isExactRecord(item, [
359
+ "workspaceId",
360
+ "itemId",
361
+ "parentId",
362
+ "type",
363
+ "name",
364
+ "lifecycleState",
365
+ "revision",
366
+ "currentVersion",
367
+ "volumeId",
368
+ "provider",
369
+ "createdAtEpochMilliseconds",
370
+ "modifiedAtEpochMilliseconds",
371
+ "creatorUserId",
372
+ "etag",
373
+ "trashedAtEpochMilliseconds",
374
+ "purgeAfterEpochMilliseconds"
375
+ ]) || item.lifecycleState !== "active" && item.lifecycleState !== "trashed" || typeof item.volumeId !== "string" || !VOLUME_ID.test(item.volumeId) || item.provider !== "managed" || item.creatorUserId !== null && (typeof item.creatorUserId !== "string" || !AUTH_ID$1.test(item.creatorUserId)) || ![
376
+ item.createdAtEpochMilliseconds,
377
+ item.modifiedAtEpochMilliseconds,
378
+ item.trashedAtEpochMilliseconds,
379
+ item.purgeAfterEpochMilliseconds
380
+ ].every((date) => date === null || isSafeInteger$1(date))) return false;
381
+ const metadata = {
382
+ workspaceId: item.workspaceId,
383
+ itemId: item.itemId,
384
+ parentId: item.parentId,
385
+ type: item.type,
386
+ name: item.name,
387
+ lifecycleState: "active",
388
+ revision: item.revision,
389
+ currentVersion: item.currentVersion
390
+ };
391
+ if (typeof metadata.workspaceId !== "string" || !WORKSPACE_ID$1.test(metadata.workspaceId) || typeof metadata.itemId !== "string" || !ITEM_ID$1.test(metadata.itemId) || metadata.parentId === null || metadata.parentId === metadata.itemId || !isManagedItemMetadata(metadata, metadata.workspaceId, metadata.itemId) || item.etag !== `"drive.item.v1.${metadata.revision}"` || ids.has(metadata.itemId)) return false;
392
+ if (item.lifecycleState === "active" ? item.trashedAtEpochMilliseconds !== null || item.purgeAfterEpochMilliseconds !== null : !isSafeInteger$1(item.trashedAtEpochMilliseconds) || !isSafeInteger$1(item.purgeAfterEpochMilliseconds) || item.purgeAfterEpochMilliseconds <= item.trashedAtEpochMilliseconds) return false;
393
+ ids.add(metadata.itemId);
394
+ return true;
395
+ });
396
+ if (valid) {
397
+ for (const item of value.items) Object.freeze(item);
398
+ Object.freeze(value.items);
399
+ Object.freeze(value);
400
+ }
401
+ return valid;
402
+ }
403
+ function isCurrentWorkspaceSources(value) {
404
+ if (!isExactRecord(value, [
405
+ "workspace",
406
+ "volumes",
407
+ "knownProviders",
408
+ "externalConnectionsSupported"
409
+ ]) || !isCurrentWorkspace(value.workspace) || !Array.isArray(value.volumes) || value.volumes.length !== 1 || !Array.isArray(value.knownProviders) || value.externalConnectionsSupported !== false) return false;
410
+ const volume = value.volumes[0];
411
+ const providers = [
412
+ "managed",
413
+ "google-drive",
414
+ "onedrive",
415
+ "dropbox",
416
+ "s3-compatible"
417
+ ];
418
+ return isExactRecord(volume, [
419
+ "volumeId",
420
+ "rootItemId",
421
+ "provider",
422
+ "name"
423
+ ]) && volume.volumeId === value.workspace.rootVolumeId && volume.rootItemId === value.workspace.rootItemId && volume.provider === "managed" && volume.name === "Files" && value.knownProviders.length === providers.length && value.knownProviders.every((provider, index) => provider === providers[index]);
424
+ }
330
425
  function isCurrentWorkspace(value) {
331
426
  if (!isExactRecord(value, [
332
427
  "workspaceId",
@@ -846,6 +941,29 @@ function validateCurrentWorkspaceInput(value) {
846
941
  const signal = validateSignal(captureRecord(value === void 0 ? {} : value, [], ["signal"]).signal);
847
942
  return signal === void 0 ? {} : { signal };
848
943
  }
944
+ function validateWorkspaceDiscoveryInput(value, list) {
945
+ const input = captureRecord(value, ["workspaceId"], list ? [
946
+ "signal",
947
+ "view",
948
+ "kind",
949
+ "creatorUserId",
950
+ "limit",
951
+ "cursor"
952
+ ] : ["signal"]);
953
+ const signal = validateSignal(input.signal);
954
+ if (typeof input.workspaceId !== "string" || !WORKSPACE_ID.test(input.workspaceId) || input.view !== void 0 && input.view !== "recent" && input.view !== "shared" && input.view !== "trash" || input.kind !== void 0 && input.kind !== "file" && input.kind !== "folder" || input.creatorUserId !== void 0 && (typeof input.creatorUserId !== "string" || !AUTH_ID.test(input.creatorUserId)) || input.limit !== void 0 && (typeof input.limit !== "number" || !Number.isInteger(input.limit) || input.limit < 1 || input.limit > 50) || input.cursor !== void 0 && (typeof input.cursor !== "string" || input.cursor.length < 1 || input.cursor.length > 2048 || !/^[A-Za-z0-9_.-]+$/.test(input.cursor))) throw new DriveError("invalid_input");
955
+ return {
956
+ workspaceId: input.workspaceId,
957
+ signal,
958
+ query: {
959
+ ...input.view === void 0 ? {} : { view: input.view },
960
+ ...input.kind === void 0 ? {} : { kind: input.kind },
961
+ ...input.creatorUserId === void 0 ? {} : { creatorUserId: input.creatorUserId },
962
+ ...input.limit === void 0 ? {} : { limit: input.limit },
963
+ ...input.cursor === void 0 ? {} : { cursor: input.cursor }
964
+ }
965
+ };
966
+ }
849
967
  function validateResourceInput(value) {
850
968
  const input = captureRecord(value, ["workspaceId", "itemId"], ["signal"]);
851
969
  const workspaceId = input.workspaceId;
@@ -2022,6 +2140,9 @@ const DOWNLOAD_ERROR_CODES = Object.freeze([
2022
2140
  function createDriveOperations(runtime) {
2023
2141
  return Object.freeze({
2024
2142
  getCurrentWorkspace: (input) => getCurrentWorkspace(runtime, input),
2143
+ listWorkspaceItems: (input) => listWorkspaceItems(runtime, input),
2144
+ getWorkspaceUsage: (input) => getWorkspaceUsage(runtime, input),
2145
+ getCurrentWorkspaceSources: (input) => getCurrentWorkspaceSources(runtime, input),
2025
2146
  getItem: (input) => getItem(runtime, input),
2026
2147
  searchWorkspaceItems: (input) => searchWorkspaceItems(runtime, input),
2027
2148
  listFolderChildren: (input) => listFolderChildren(runtime, input),
@@ -2220,6 +2341,29 @@ function streamWithOperationLifetime(source, expectedLength, signal) {
2220
2341
  }
2221
2342
  });
2222
2343
  }
2344
+ async function getCurrentWorkspaceSources(runtime, input) {
2345
+ return execute(runtime, validateCurrentWorkspaceInput(input).signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/current/sources", {
2346
+ ...operationOptions("getCurrentWorkspaceSources", { params: {} }),
2347
+ ...requestOptions
2348
+ }), [200], isCurrentWorkspaceSources, false, CURRENT_WORKSPACE_ERROR_CODES);
2349
+ }
2350
+ async function listWorkspaceItems(runtime, input) {
2351
+ const validated = validateWorkspaceDiscoveryInput(input, true);
2352
+ return execute(runtime, validated.signal, null, (api, options) => api.GET("/api/v1/workspaces/{workspaceId}/items", {
2353
+ ...operationOptions("listWorkspaceItems", { params: {
2354
+ path: { workspaceId: validated.workspaceId },
2355
+ query: validated.query
2356
+ } }),
2357
+ ...options
2358
+ }), [200], (value) => isWorkspaceDiscoveryPage(value) && value.items.length <= (validated.query.limit ?? 25) && value.items.every((item, index, items) => item.workspaceId === validated.workspaceId && item.lifecycleState === (validated.query.view === "trash" ? "trashed" : "active") && ((validated.query.view ?? "recent") !== "recent" || item.modifiedAtEpochMilliseconds !== null) && (validated.query.kind === void 0 || item.type === validated.query.kind) && (validated.query.creatorUserId === void 0 || item.creatorUserId === validated.query.creatorUserId) && (index === 0 || ((validated.query.view ?? "recent") === "recent" ? items[index - 1].modifiedAtEpochMilliseconds > item.modifiedAtEpochMilliseconds || items[index - 1].modifiedAtEpochMilliseconds === item.modifiedAtEpochMilliseconds && items[index - 1].itemId < item.itemId : items[index - 1].itemId < item.itemId))), false, SEARCH_WORKSPACE_ITEMS_ERROR_CODES);
2359
+ }
2360
+ async function getWorkspaceUsage(runtime, input) {
2361
+ const validated = validateWorkspaceDiscoveryInput(input, false);
2362
+ return execute(runtime, validated.signal, null, (api, options) => api.GET("/api/v1/workspaces/{workspaceId}/usage", {
2363
+ ...operationOptions("getWorkspaceUsage", { params: { path: { workspaceId: validated.workspaceId } } }),
2364
+ ...options
2365
+ }), [200], (value) => isWorkspaceUsage(value) && value.workspaceId === validated.workspaceId, false, SEARCH_WORKSPACE_ITEMS_ERROR_CODES);
2366
+ }
2223
2367
  async function getCurrentWorkspace(runtime, input) {
2224
2368
  return execute(runtime, validateCurrentWorkspaceInput(input).signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/current", {
2225
2369
  ...operationOptions("getCurrentWorkspace", { params: {} }),
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as TrashItemInput, A as ListItemVersionsInput, C as FolderPage, D as GetUploadStatusInput, E as GetItemVersionInput, F as ManagedItemVersionPage, G as ProtectionClassification, I as ManagedItemVersionResource, J as RecordUploadPartInput, L as ManagedItemVersionRestoreResult, M as ManagedDownloadRestorePending, N as ManagedItemMetadata, O as ListFolderChildrenInput, P as ManagedItemVersion, Q as SearchWorkspaceItemsInput, R as ManagedLifecycleItem, S as FolderItem, T as GetItemInput, X as RestoreItemVersionInput, Y as RestoreItemInput, c as CurrentWorkspace, ct as UploadPartDescriptor, dt as UploadStatus, et as UpdateItemInput, ft as WorkspaceItemSearchItem, h as DriveOperationResult, j as ManagedDownloadDescriptor, l as DeleteItemInput, lt as UploadPartResult, m as DriveCredentialProvider, mt as operations, n as CompleteUploadInput, nt as UploadCompletion, o as CreateUploadInput, pt as WorkspaceItemSearchPage, q as ReadyUpload, r as CreateDownloadInput, rt as UploadConfirmedPart, s as CreateUploadPartDescriptorInput, t as AbortUploadInput, u as DownloadItemResult, ut as UploadSession, v as DriveServerClient, w as GetCurrentWorkspaceInput, y as DriveServerClientConfig, z as PendingUpload } from "./contract.js";
1
+ import { $ as RestoreItemVersionInput, A as ListFolderChildrenInput, B as ManagedItemVersionRestoreResult, C as FolderItem, D as GetItemVersionInput, E as GetItemInput, F as ManagedDownloadRestorePending, H as PendingUpload, I as ManagedItemMetadata, J as ProtectionClassification, L as ManagedItemVersion, M as ListItemVersionsInput, N as ListWorkspaceItemsInput, O as GetUploadStatusInput, P as ManagedDownloadDescriptor, Q as RestoreItemInput, R as ManagedItemVersionPage, T as GetCurrentWorkspaceInput, V as ManagedLifecycleItem, X as ReadyUpload, Z as RecordUploadPartInput, _t as WorkspaceItemSearchItem, at as UploadCompletion, b as DriveServerClientConfig, bt as operations, c as CurrentWorkspace, d as DownloadItemResult, dt as UploadPartDescriptor, ft as UploadPartResult, g as DriveOperationResult, gt as WorkspaceDiscoveryPage, h as DriveCredentialProvider, ht as WorkspaceDiscoveryItem, k as GetWorkspaceUsageInput, l as CurrentWorkspaceSources, mt as UploadStatus, n as CompleteUploadInput, nt as TrashItemInput, o as CreateUploadInput, ot as UploadConfirmedPart, pt as UploadSession, r as CreateDownloadInput, rt as UpdateItemInput, s as CreateUploadPartDescriptorInput, t as AbortUploadInput, tt as SearchWorkspaceItemsInput, u as DeleteItemInput, vt as WorkspaceItemSearchPage, w as FolderPage, y as DriveServerClient, yt as WorkspaceUsage, z as ManagedItemVersionResource } from "./contract.js";
2
2
  //#region src/internal/provisioning.d.ts
3
3
  type Operation = operations["provisionManagedWorkspace"];
4
4
  type ProvisionWorkspaceCommand = Operation["requestBody"]["content"]["application/json"];
@@ -20,4 +20,4 @@ declare function createDriveProvisioningClient(config: DriveProvisioningClientCo
20
20
  //#region src/server.d.ts
21
21
  declare function createDriveServerClient(config: DriveServerClientConfig): DriveServerClient;
22
22
  //#endregion
23
- export { type AbortUploadInput, type CompleteUploadInput, type CreateDownloadInput, type CreateUploadInput, type CreateUploadPartDescriptorInput, type CurrentWorkspace, type DeleteItemInput, type DownloadItemResult, type DriveProvisioningClient, type DriveProvisioningClientConfig, type DriveServerClient, type DriveServerClientConfig, type FolderItem, type FolderPage, type GetCurrentWorkspaceInput, type GetItemInput, type GetItemVersionInput, type GetUploadStatusInput, type ListFolderChildrenInput, type ListItemVersionsInput, type ManagedDownloadDescriptor, type ManagedDownloadRestorePending, type ManagedItemMetadata, type ManagedItemVersion, type ManagedItemVersionPage, type ManagedItemVersionResource, type ManagedItemVersionRestoreResult, type ManagedLifecycleItem, type PendingUpload, type ProtectionClassification, type ProvisionWorkspaceCommand, type ProvisionWorkspaceResult, type ReadyUpload, type RecordUploadPartInput, type RestoreItemInput, type RestoreItemVersionInput, type SearchWorkspaceItemsInput, type TrashItemInput, type UpdateItemInput, type UploadCompletion, type UploadConfirmedPart, type UploadPartDescriptor, type UploadPartResult, type UploadSession, type UploadStatus, type WorkspaceItemSearchItem, type WorkspaceItemSearchPage, createDriveProvisioningClient, createDriveServerClient };
23
+ export { type AbortUploadInput, type CompleteUploadInput, type CreateDownloadInput, type CreateUploadInput, type CreateUploadPartDescriptorInput, type CurrentWorkspace, type CurrentWorkspaceSources, type DeleteItemInput, type DownloadItemResult, type DriveProvisioningClient, type DriveProvisioningClientConfig, type DriveServerClient, type DriveServerClientConfig, type FolderItem, type FolderPage, type GetCurrentWorkspaceInput, type GetItemInput, type GetItemVersionInput, type GetUploadStatusInput, type GetWorkspaceUsageInput, type ListFolderChildrenInput, type ListItemVersionsInput, type ListWorkspaceItemsInput, type ManagedDownloadDescriptor, type ManagedDownloadRestorePending, type ManagedItemMetadata, type ManagedItemVersion, type ManagedItemVersionPage, type ManagedItemVersionResource, type ManagedItemVersionRestoreResult, type ManagedLifecycleItem, type PendingUpload, type ProtectionClassification, type ProvisionWorkspaceCommand, type ProvisionWorkspaceResult, type ReadyUpload, type RecordUploadPartInput, type RestoreItemInput, type RestoreItemVersionInput, type SearchWorkspaceItemsInput, type TrashItemInput, type UpdateItemInput, type UploadCompletion, type UploadConfirmedPart, type UploadPartDescriptor, type UploadPartResult, type UploadSession, type UploadStatus, type WorkspaceDiscoveryItem, type WorkspaceDiscoveryPage, type WorkspaceItemSearchItem, type WorkspaceItemSearchPage, type WorkspaceUsage, createDriveProvisioningClient, createDriveServerClient };
package/dist/server.js CHANGED
@@ -327,6 +327,101 @@ const MAX_UPLOAD_BYTE_LENGTH$1 = 33554432e4;
327
327
  const UPLOAD_PART_BYTE_LENGTH$1 = 32 * 1024 * 1024;
328
328
  const CONTENT_DIGEST$1 = /^sha256:[0-9a-f]{64}$/;
329
329
  const UTF8 = new TextEncoder();
330
+ function isWorkspaceUsage(value) {
331
+ if (!isExactRecord(value, [
332
+ "workspaceId",
333
+ "provider",
334
+ "usedBytes",
335
+ "reservedBytes",
336
+ "limitBytes",
337
+ "availableBytes",
338
+ "accounting",
339
+ "reservedBytesIncludeUnresolvedUploads",
340
+ "unresolvedReservedBytes",
341
+ "warnings"
342
+ ]) || typeof value.workspaceId !== "string" || !WORKSPACE_ID$1.test(value.workspaceId) || value.provider !== "managed" || value.accounting !== "current-versions-and-reservations" || value.reservedBytesIncludeUnresolvedUploads !== true || !Array.isArray(value.warnings) || value.warnings.length > 1 || value.warnings.some((warning) => warning !== "unresolved-archive-ownership") || ![
343
+ value.usedBytes,
344
+ value.reservedBytes,
345
+ value.limitBytes,
346
+ value.availableBytes,
347
+ value.unresolvedReservedBytes
348
+ ].every((bytes) => typeof bytes === "string" && /^(0|[1-9][0-9]{0,18})$/.test(bytes))) return false;
349
+ const available = BigInt(value.limitBytes) - BigInt(value.usedBytes) - BigInt(value.reservedBytes);
350
+ const valid = BigInt(value.availableBytes) === (available > 0n ? available : 0n) && BigInt(value.unresolvedReservedBytes) <= BigInt(value.reservedBytes) && (value.unresolvedReservedBytes === "0" || value.warnings.length === 1);
351
+ if (valid) Object.freeze(value.warnings);
352
+ return valid;
353
+ }
354
+ function isWorkspaceDiscoveryPage(value) {
355
+ if (!isExactRecord(value, ["items", "nextCursor"]) || !Array.isArray(value.items) || value.items.length > 50 || !(value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length > 0 && value.nextCursor.length <= 2048 && /^[A-Za-z0-9_.-]+$/.test(value.nextCursor)) || value.items.length === 0 && value.nextCursor !== null) return false;
356
+ const ids = new Set();
357
+ const valid = value.items.every((item) => {
358
+ if (!isExactRecord(item, [
359
+ "workspaceId",
360
+ "itemId",
361
+ "parentId",
362
+ "type",
363
+ "name",
364
+ "lifecycleState",
365
+ "revision",
366
+ "currentVersion",
367
+ "volumeId",
368
+ "provider",
369
+ "createdAtEpochMilliseconds",
370
+ "modifiedAtEpochMilliseconds",
371
+ "creatorUserId",
372
+ "etag",
373
+ "trashedAtEpochMilliseconds",
374
+ "purgeAfterEpochMilliseconds"
375
+ ]) || item.lifecycleState !== "active" && item.lifecycleState !== "trashed" || typeof item.volumeId !== "string" || !VOLUME_ID.test(item.volumeId) || item.provider !== "managed" || item.creatorUserId !== null && (typeof item.creatorUserId !== "string" || !AUTH_ID$1.test(item.creatorUserId)) || ![
376
+ item.createdAtEpochMilliseconds,
377
+ item.modifiedAtEpochMilliseconds,
378
+ item.trashedAtEpochMilliseconds,
379
+ item.purgeAfterEpochMilliseconds
380
+ ].every((date) => date === null || isSafeInteger$1(date))) return false;
381
+ const metadata = {
382
+ workspaceId: item.workspaceId,
383
+ itemId: item.itemId,
384
+ parentId: item.parentId,
385
+ type: item.type,
386
+ name: item.name,
387
+ lifecycleState: "active",
388
+ revision: item.revision,
389
+ currentVersion: item.currentVersion
390
+ };
391
+ if (typeof metadata.workspaceId !== "string" || !WORKSPACE_ID$1.test(metadata.workspaceId) || typeof metadata.itemId !== "string" || !ITEM_ID$1.test(metadata.itemId) || metadata.parentId === null || metadata.parentId === metadata.itemId || !isManagedItemMetadata(metadata, metadata.workspaceId, metadata.itemId) || item.etag !== `"drive.item.v1.${metadata.revision}"` || ids.has(metadata.itemId)) return false;
392
+ if (item.lifecycleState === "active" ? item.trashedAtEpochMilliseconds !== null || item.purgeAfterEpochMilliseconds !== null : !isSafeInteger$1(item.trashedAtEpochMilliseconds) || !isSafeInteger$1(item.purgeAfterEpochMilliseconds) || item.purgeAfterEpochMilliseconds <= item.trashedAtEpochMilliseconds) return false;
393
+ ids.add(metadata.itemId);
394
+ return true;
395
+ });
396
+ if (valid) {
397
+ for (const item of value.items) Object.freeze(item);
398
+ Object.freeze(value.items);
399
+ Object.freeze(value);
400
+ }
401
+ return valid;
402
+ }
403
+ function isCurrentWorkspaceSources(value) {
404
+ if (!isExactRecord(value, [
405
+ "workspace",
406
+ "volumes",
407
+ "knownProviders",
408
+ "externalConnectionsSupported"
409
+ ]) || !isCurrentWorkspace(value.workspace) || !Array.isArray(value.volumes) || value.volumes.length !== 1 || !Array.isArray(value.knownProviders) || value.externalConnectionsSupported !== false) return false;
410
+ const volume = value.volumes[0];
411
+ const providers = [
412
+ "managed",
413
+ "google-drive",
414
+ "onedrive",
415
+ "dropbox",
416
+ "s3-compatible"
417
+ ];
418
+ return isExactRecord(volume, [
419
+ "volumeId",
420
+ "rootItemId",
421
+ "provider",
422
+ "name"
423
+ ]) && volume.volumeId === value.workspace.rootVolumeId && volume.rootItemId === value.workspace.rootItemId && volume.provider === "managed" && volume.name === "Files" && value.knownProviders.length === providers.length && value.knownProviders.every((provider, index) => provider === providers[index]);
424
+ }
330
425
  function isCurrentWorkspace(value) {
331
426
  if (!isExactRecord(value, [
332
427
  "workspaceId",
@@ -846,6 +941,29 @@ function validateCurrentWorkspaceInput(value) {
846
941
  const signal = validateSignal(captureRecord(value === void 0 ? {} : value, [], ["signal"]).signal);
847
942
  return signal === void 0 ? {} : { signal };
848
943
  }
944
+ function validateWorkspaceDiscoveryInput(value, list) {
945
+ const input = captureRecord(value, ["workspaceId"], list ? [
946
+ "signal",
947
+ "view",
948
+ "kind",
949
+ "creatorUserId",
950
+ "limit",
951
+ "cursor"
952
+ ] : ["signal"]);
953
+ const signal = validateSignal(input.signal);
954
+ if (typeof input.workspaceId !== "string" || !WORKSPACE_ID.test(input.workspaceId) || input.view !== void 0 && input.view !== "recent" && input.view !== "shared" && input.view !== "trash" || input.kind !== void 0 && input.kind !== "file" && input.kind !== "folder" || input.creatorUserId !== void 0 && (typeof input.creatorUserId !== "string" || !AUTH_ID.test(input.creatorUserId)) || input.limit !== void 0 && (typeof input.limit !== "number" || !Number.isInteger(input.limit) || input.limit < 1 || input.limit > 50) || input.cursor !== void 0 && (typeof input.cursor !== "string" || input.cursor.length < 1 || input.cursor.length > 2048 || !/^[A-Za-z0-9_.-]+$/.test(input.cursor))) throw new DriveError("invalid_input");
955
+ return {
956
+ workspaceId: input.workspaceId,
957
+ signal,
958
+ query: {
959
+ ...input.view === void 0 ? {} : { view: input.view },
960
+ ...input.kind === void 0 ? {} : { kind: input.kind },
961
+ ...input.creatorUserId === void 0 ? {} : { creatorUserId: input.creatorUserId },
962
+ ...input.limit === void 0 ? {} : { limit: input.limit },
963
+ ...input.cursor === void 0 ? {} : { cursor: input.cursor }
964
+ }
965
+ };
966
+ }
849
967
  function validateResourceInput(value) {
850
968
  const input = captureRecord(value, ["workspaceId", "itemId"], ["signal"]);
851
969
  const workspaceId = input.workspaceId;
@@ -1983,6 +2101,9 @@ function createDriveClientInternal(config) {
1983
2101
  function createDriveOperations(runtime) {
1984
2102
  return Object.freeze({
1985
2103
  getCurrentWorkspace: (input) => getCurrentWorkspace(runtime, input),
2104
+ listWorkspaceItems: (input) => listWorkspaceItems(runtime, input),
2105
+ getWorkspaceUsage: (input) => getWorkspaceUsage(runtime, input),
2106
+ getCurrentWorkspaceSources: (input) => getCurrentWorkspaceSources(runtime, input),
1986
2107
  getItem: (input) => getItem(runtime, input),
1987
2108
  searchWorkspaceItems: (input) => searchWorkspaceItems(runtime, input),
1988
2109
  listFolderChildren: (input) => listFolderChildren(runtime, input),
@@ -2181,6 +2302,29 @@ function streamWithOperationLifetime(source, expectedLength, signal) {
2181
2302
  }
2182
2303
  });
2183
2304
  }
2305
+ async function getCurrentWorkspaceSources(runtime, input) {
2306
+ return execute(runtime, validateCurrentWorkspaceInput(input).signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/current/sources", {
2307
+ ...operationOptions("getCurrentWorkspaceSources", { params: {} }),
2308
+ ...requestOptions
2309
+ }), [200], isCurrentWorkspaceSources, false, CURRENT_WORKSPACE_ERROR_CODES);
2310
+ }
2311
+ async function listWorkspaceItems(runtime, input) {
2312
+ const validated = validateWorkspaceDiscoveryInput(input, true);
2313
+ return execute(runtime, validated.signal, null, (api, options) => api.GET("/api/v1/workspaces/{workspaceId}/items", {
2314
+ ...operationOptions("listWorkspaceItems", { params: {
2315
+ path: { workspaceId: validated.workspaceId },
2316
+ query: validated.query
2317
+ } }),
2318
+ ...options
2319
+ }), [200], (value) => isWorkspaceDiscoveryPage(value) && value.items.length <= (validated.query.limit ?? 25) && value.items.every((item, index, items) => item.workspaceId === validated.workspaceId && item.lifecycleState === (validated.query.view === "trash" ? "trashed" : "active") && ((validated.query.view ?? "recent") !== "recent" || item.modifiedAtEpochMilliseconds !== null) && (validated.query.kind === void 0 || item.type === validated.query.kind) && (validated.query.creatorUserId === void 0 || item.creatorUserId === validated.query.creatorUserId) && (index === 0 || ((validated.query.view ?? "recent") === "recent" ? items[index - 1].modifiedAtEpochMilliseconds > item.modifiedAtEpochMilliseconds || items[index - 1].modifiedAtEpochMilliseconds === item.modifiedAtEpochMilliseconds && items[index - 1].itemId < item.itemId : items[index - 1].itemId < item.itemId))), false, SEARCH_WORKSPACE_ITEMS_ERROR_CODES);
2320
+ }
2321
+ async function getWorkspaceUsage(runtime, input) {
2322
+ const validated = validateWorkspaceDiscoveryInput(input, false);
2323
+ return execute(runtime, validated.signal, null, (api, options) => api.GET("/api/v1/workspaces/{workspaceId}/usage", {
2324
+ ...operationOptions("getWorkspaceUsage", { params: { path: { workspaceId: validated.workspaceId } } }),
2325
+ ...options
2326
+ }), [200], (value) => isWorkspaceUsage(value) && value.workspaceId === validated.workspaceId, false, SEARCH_WORKSPACE_ITEMS_ERROR_CODES);
2327
+ }
2184
2328
  async function getCurrentWorkspace(runtime, input) {
2185
2329
  return execute(runtime, validateCurrentWorkspaceInput(input).signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/current", {
2186
2330
  ...operationOptions("getCurrentWorkspace", { params: {} }),
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as TrashItemInput, A as ListItemVersionsInput, B as PermissionAction, C as FolderPage, D as GetUploadStatusInput, E as GetItemVersionInput, F as ManagedItemVersionPage, G as ProtectionClassification, H as PermissionGrantee, I as ManagedItemVersionResource, J as RecordUploadPartInput, K as ReadEffectiveItemPermissionsInput, L as ManagedItemVersionRestoreResult, M as ManagedDownloadRestorePending, N as ManagedItemMetadata, O as ListFolderChildrenInput, P as ManagedItemVersion, Q as SearchWorkspaceItemsInput, R as ManagedLifecycleItem, S as FolderItem, T as GetItemInput, U as PermissionMutation, V as PermissionGrant, W as PermissionPage, X as RestoreItemVersionInput, Y as RestoreItemInput, Z as RevokeItemPermissionInput, _ as DriveResponseValidators, a as CreateItemPermissionInput, at as UploadFilePhase, b as EffectivePermissionAction, c as CurrentWorkspace, ct as UploadPartDescriptor, d as DriveClient, dt as UploadStatus, et as UpdateItemInput, f as DriveClientConfig, ft as WorkspaceItemSearchItem, g as DriveOperations, h as DriveOperationResult, i as CreateFolderInput, it as UploadFileInput, j as ManagedDownloadDescriptor, k as ListItemPermissionsInput, l as DeleteItemInput, lt as UploadPartResult, m as DriveCredentialProvider, n as CompleteUploadInput, nt as UploadCompletion, o as CreateUploadInput, ot as UploadFileProgress, p as DriveCredentialContext, pt as WorkspaceItemSearchPage, q as ReadyUpload, r as CreateDownloadInput, rt as UploadConfirmedPart, s as CreateUploadPartDescriptorInput, st as UploadFileProgressCallback, t as AbortUploadInput, tt as UpdateItemPermissionInput, u as DownloadItemResult, ut as UploadSession, v as DriveServerClient, w as GetCurrentWorkspaceInput, x as EffectivePermissionResponse, y as DriveServerClientConfig, z as PendingUpload } from "./contract.js";
2
- export { AbortUploadInput, CompleteUploadInput, CreateDownloadInput, CreateFolderInput, CreateItemPermissionInput, CreateUploadInput, CreateUploadPartDescriptorInput, CurrentWorkspace, DeleteItemInput, DownloadItemResult, DriveClient, DriveClientConfig, DriveCredentialContext, DriveCredentialProvider, DriveOperationResult, DriveOperations, DriveResponseValidators, DriveServerClient, DriveServerClientConfig, EffectivePermissionAction, EffectivePermissionResponse, FolderItem, FolderPage, GetCurrentWorkspaceInput, GetItemInput, GetItemVersionInput, GetUploadStatusInput, ListFolderChildrenInput, ListItemPermissionsInput, ListItemVersionsInput, ManagedDownloadDescriptor, ManagedDownloadRestorePending, ManagedItemMetadata, ManagedItemVersion, ManagedItemVersionPage, ManagedItemVersionResource, ManagedItemVersionRestoreResult, ManagedLifecycleItem, PendingUpload, PermissionAction, PermissionGrant, PermissionGrantee, PermissionMutation, PermissionPage, ProtectionClassification, ReadEffectiveItemPermissionsInput, ReadyUpload, RecordUploadPartInput, RestoreItemInput, RestoreItemVersionInput, RevokeItemPermissionInput, SearchWorkspaceItemsInput, TrashItemInput, UpdateItemInput, UpdateItemPermissionInput, UploadCompletion, UploadConfirmedPart, UploadFileInput, UploadFilePhase, UploadFileProgress, UploadFileProgressCallback, UploadPartDescriptor, UploadPartResult, UploadSession, UploadStatus, WorkspaceItemSearchItem, WorkspaceItemSearchPage };
1
+ import { $ as RestoreItemVersionInput, A as ListFolderChildrenInput, B as ManagedItemVersionRestoreResult, C as FolderItem, D as GetItemVersionInput, E as GetItemInput, F as ManagedDownloadRestorePending, G as PermissionGrantee, H as PendingUpload, I as ManagedItemMetadata, J as ProtectionClassification, K as PermissionMutation, L as ManagedItemVersion, M as ListItemVersionsInput, N as ListWorkspaceItemsInput, O as GetUploadStatusInput, P as ManagedDownloadDescriptor, Q as RestoreItemInput, R as ManagedItemVersionPage, S as EffectivePermissionResponse, T as GetCurrentWorkspaceInput, U as PermissionAction, V as ManagedLifecycleItem, W as PermissionGrant, X as ReadyUpload, Y as ReadEffectiveItemPermissionsInput, Z as RecordUploadPartInput, _ as DriveOperations, _t as WorkspaceItemSearchItem, a as CreateItemPermissionInput, at as UploadCompletion, b as DriveServerClientConfig, c as CurrentWorkspace, ct as UploadFilePhase, d as DownloadItemResult, dt as UploadPartDescriptor, et as RevokeItemPermissionInput, f as DriveClient, ft as UploadPartResult, g as DriveOperationResult, gt as WorkspaceDiscoveryPage, h as DriveCredentialProvider, ht as WorkspaceDiscoveryItem, i as CreateFolderInput, it as UpdateItemPermissionInput, j as ListItemPermissionsInput, k as GetWorkspaceUsageInput, l as CurrentWorkspaceSources, lt as UploadFileProgress, m as DriveCredentialContext, mt as UploadStatus, n as CompleteUploadInput, nt as TrashItemInput, o as CreateUploadInput, ot as UploadConfirmedPart, p as DriveClientConfig, pt as UploadSession, q as PermissionPage, r as CreateDownloadInput, rt as UpdateItemInput, s as CreateUploadPartDescriptorInput, st as UploadFileInput, t as AbortUploadInput, tt as SearchWorkspaceItemsInput, u as DeleteItemInput, ut as UploadFileProgressCallback, v as DriveResponseValidators, vt as WorkspaceItemSearchPage, w as FolderPage, x as EffectivePermissionAction, y as DriveServerClient, yt as WorkspaceUsage, z as ManagedItemVersionResource } from "./contract.js";
2
+ export { AbortUploadInput, CompleteUploadInput, CreateDownloadInput, CreateFolderInput, CreateItemPermissionInput, CreateUploadInput, CreateUploadPartDescriptorInput, CurrentWorkspace, CurrentWorkspaceSources, DeleteItemInput, DownloadItemResult, DriveClient, DriveClientConfig, DriveCredentialContext, DriveCredentialProvider, DriveOperationResult, DriveOperations, DriveResponseValidators, DriveServerClient, DriveServerClientConfig, EffectivePermissionAction, EffectivePermissionResponse, FolderItem, FolderPage, GetCurrentWorkspaceInput, GetItemInput, GetItemVersionInput, GetUploadStatusInput, GetWorkspaceUsageInput, ListFolderChildrenInput, ListItemPermissionsInput, ListItemVersionsInput, ListWorkspaceItemsInput, ManagedDownloadDescriptor, ManagedDownloadRestorePending, ManagedItemMetadata, ManagedItemVersion, ManagedItemVersionPage, ManagedItemVersionResource, ManagedItemVersionRestoreResult, ManagedLifecycleItem, PendingUpload, PermissionAction, PermissionGrant, PermissionGrantee, PermissionMutation, PermissionPage, ProtectionClassification, ReadEffectiveItemPermissionsInput, ReadyUpload, RecordUploadPartInput, RestoreItemInput, RestoreItemVersionInput, RevokeItemPermissionInput, SearchWorkspaceItemsInput, TrashItemInput, UpdateItemInput, UpdateItemPermissionInput, UploadCompletion, UploadConfirmedPart, UploadFileInput, UploadFilePhase, UploadFileProgress, UploadFileProgressCallback, UploadPartDescriptor, UploadPartResult, UploadSession, UploadStatus, WorkspaceDiscoveryItem, WorkspaceDiscoveryPage, WorkspaceItemSearchItem, WorkspaceItemSearchPage, WorkspaceUsage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finueva/drive",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Public browser, Worker, and Node client for Finueva Drive",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",