@finueva/drive 0.21.1 → 0.22.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.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 784bfcd: Recognize explicit item ownership and add owner-only internal file sharing with current organization members. Organization storage membership no longer implies access to another user's files.
8
+
3
9
  ## 0.21.1
4
10
 
5
11
  ### Patch Changes
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- const e=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`recipient_unavailable`,`registration_conflict`,`rate_limited`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_pagination_cursor`,`invalid_idempotency_key`,`precondition_failed`,`range_not_satisfiable`,`idempotency_conflict`,`quota_exceeded`,`upload_recovery_required`,`service_unavailable`,`internal_error`]),t=Object.freeze([`upload_admission_saturated`,`upload_admission_stalled`,`ownership_unchanged`,`ownership_successor_not_member`,`ownership_restricted_items`,`ownership_subtree_too_large`,`external_sharing_disabled`,`unspecified`]);function n(e){return typeof e==`string`&&t.includes(e)}const r=Object.freeze({authentication_required:`Authentication is required.`,identity_authority_unavailable:`Authentication is temporarily unavailable.`,recipient_unavailable:`The recipient is unavailable.`,registration_conflict:`The recipient could not be confirmed.`,rate_limited:`Too many requests.`,permission_denied:`The requested action is not permitted.`,resource_not_found:`The requested resource was not found.`,invalid_request:`The request is invalid.`,invalid_pagination_cursor:`The pagination cursor is invalid.`,invalid_idempotency_key:`The idempotency key is invalid.`,precondition_failed:`The request precondition failed.`,range_not_satisfiable:`The requested byte range is not satisfiable.`,idempotency_conflict:`The idempotency key conflicts with an earlier request.`,quota_exceeded:`The workspace storage quota would be exceeded.`,upload_recovery_required:`The upload requires recovery before it can continue.`,service_unavailable:`The service is temporarily unavailable.`,internal_error:`The request could not be completed.`}),i=Object.freeze({invalid_input:`The Drive SDK input is invalid.`,credential_unavailable:`A Drive credential could not be obtained.`,network_error:`The Drive request could not reach the service.`,timeout:`The Drive request timed out.`,aborted:`The Drive request was aborted.`,invalid_response:`Drive returned an invalid response.`});var a=class extends Error{code;status;requestId;details;constructor(e,t={}){super(e in r?r[e]:i[e]),this.name=`DriveError`,this.code=e,this.status=t.status??null,this.requestId=t.requestId??null,this.details=Object.freeze(n(t.reason)?{reason:t.reason}:{})}};const o=/^[A-Za-z0-9_-]{16,128}$/,s=/^"drive\.permission-collection\.v1\.(0|[1-9][0-9]*)"$/,c=/^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/,l=/^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/,u=/^"drive\.item\.v1\.(0|[1-9][0-9]*)"$/;async function d(e,t,n,r,i,o,s){let c=te(e.headers.get(`x-request-id`));if(c===null)throw y(e),new a(`invalid_response`,{status:e.status});if(!r.includes(e.status))throw await g(e,c,t,n,o,s);if(e.status===304){let t=e.headers.get(`content-length`),n=e.headers.get(`etag`),r=e.status;if(e.body!==null||t!==null&&t!==`0`||e.headers.has(`content-type`)||n===null||!/^"[\x21\x23-\x7e]{1,1022}"$/.test(n)||!i(void 0,r,e.headers))throw y(e),new a(`invalid_response`,{status:r,requestId:c});return Object.freeze({data:void 0,status:r,requestId:c,validators:Object.freeze({etag:n})})}let{value:l}=await v(e,262144,e.status,c,t),u=e.status;if(!i(l,u,e.headers))throw new a(`invalid_response`,{status:u,requestId:c});return Object.freeze({data:l,status:u,requestId:c,validators:re(e.headers)})}async function f(e,t,n,r,i){let o=te(e.headers.get(`x-request-id`));if(o===null)throw y(e),new a(`invalid_response`,{status:e.status});if(!r.includes(e.status))throw await g(e,o,t,n,!1,i);let s=e.headers.get(`content-length`);if(e.body!==null||s!==null&&s!==`0`||e.headers.has(`content-type`))throw y(e),new a(`invalid_response`,{status:e.status,requestId:o});return Object.freeze({data:void 0,status:e.status,requestId:o,validators:Object.freeze({})})}function p(e){let t=s.exec(e);if(!t)return;let n=Number(t[1]);return Number.isSafeInteger(n)?n:void 0}function m(e){let t=c.exec(e);if(!t)return;let n=Number(t[1]),r=Number(t[2]);return Number.isSafeInteger(n)&&Number.isSafeInteger(r)?[n,r]:void 0}function h(e){let t=u.exec(e);if(!t)return;let n=Number(t[1]);return Number.isSafeInteger(n)?n:void 0}async function g(t,i,s,c,l,u){let d;try{d=await v(t,16384,t.status,i,s)}catch(e){return e instanceof a&&e.code===`aborted`?e:new a(`invalid_response`,{status:t.status,requestId:i})}let f=d.value;if(!b(f,[`error`])||!b(f.error,[`code`,`message`,`requestId`,`details`]))return new a(`invalid_response`,{status:t.status,requestId:i});let p=f.error,m=p.details,h=b(m,[`reason`])?m.reason:void 0;return typeof p.code!=`string`||!e.includes(p.code)||p.message!==r[p.code]||!o.test(String(p.requestId))||p.requestId!==i||!(b(m,[])||n(h))||!_(p.code,t.status,c,l,u)||d.text!==JSON.stringify(f)?new a(`invalid_response`,{status:t.status,requestId:i}):new a(p.code,{status:t.status,requestId:p.requestId,...n(h)?{reason:h}:{}})}function _(e,t,n,r,i){return i&&!i.includes(e)||e===`quota_exceeded`&&!r?!1:{authentication_required:[401],identity_authority_unavailable:[503],recipient_unavailable:[404],registration_conflict:[409],rate_limited:[429],permission_denied:[403],resource_not_found:[404],invalid_request:[422],invalid_pagination_cursor:[422],invalid_idempotency_key:[422],precondition_failed:n===null?[]:[n],range_not_satisfiable:[416],idempotency_conflict:[409],quota_exceeded:[409],upload_recovery_required:[409],service_unavailable:[503],internal_error:[500]}[e].includes(t)}async function v(e,t,n,r,i){if(!e.body)throw new a(`invalid_response`,{status:n,requestId:r});let o=e.body.getReader(),s=new TextDecoder(`utf-8`,{fatal:!0}),c=0,l=0,u=``,d=e.headers.get(`content-length`);if(d!==null&&(!/^(?:0|[1-9][0-9]*)$/.test(d)||Number(d)>t))throw o.cancel().catch(()=>{}),new a(`invalid_response`,{status:n,requestId:r});let f=new AbortController,p=setTimeout(()=>f.abort(),5e3);try{for(;;){if(i?.aborted)throw new a(`aborted`);let{done:e,value:d}=await ee(o,i,f.signal);if(e)break;if(l+=1,c+=d.byteLength,l>256||c>t)throw new a(`invalid_response`,{status:n,requestId:r});u+=s.decode(d,{stream:!0})}return u+=s.decode(),{value:JSON.parse(u),text:u}}catch(e){throw e instanceof a?e.code===`aborted`||i?.aborted?new a(`aborted`):e:new a(`invalid_response`,{status:n,requestId:r})}finally{clearTimeout(p),o.cancel().catch(()=>{})}}async function ee(e,t,n){if(t?.aborted)throw new a(`aborted`);if(n.aborted)throw new a(`invalid_response`);let r=()=>{},i=()=>{},o=new Promise((e,n)=>{if(!t)return;let i=()=>n(new a(`aborted`));t.addEventListener(`abort`,i,{once:!0}),r=()=>t.removeEventListener(`abort`,i)}),s=new Promise((e,t)=>{let r=()=>t(new a(`invalid_response`));n.addEventListener(`abort`,r,{once:!0}),i=()=>n.removeEventListener(`abort`,r)});try{return await Promise.race([e.read(),o,s])}finally{r(),i()}}function y(e){e.body?.cancel().catch(()=>{})}function te(e){return e!==null&&o.test(e)?e:null}const ne=/^"drive\.sharing-policy\.v1\.(0|[1-9][0-9]{0,15})"$/;function re(e){let t=e.get(`etag`),n=e.get(`drive-permission-collection-etag`),r=e.get(`drive-permission-grant-etag`);return Object.freeze({...t!==null&&(l.test(t)||ne.test(t)||h(t)!==void 0)?{etag:t}:{},...n!==null&&p(n)!==void 0?{permissionCollectionEtag:n}:{},...r!==null&&m(r)!==void 0?{permissionGrantEtag:r}:{}})}function b(e,t){return typeof e!=`object`||!e||Array.isArray(e)?!1:Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}const x=/^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,S=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,C=/^drive\.volume\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ie=/^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,w=/^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,T=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,E=/^drive\.retrieval\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,D=/^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/,O=/^[A-Za-z0-9_-]{1,128}$/,k=/^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/,ae=/^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/,A=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:read`,`items:update`]),oe=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:manage`,`items:permissions:read`,`items:update`]),se=33554432e4,ce=32*1024*1024,le=/^sha256:[0-9a-f]{64}$/,ue=new TextEncoder;function de(e){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>50||e.nextCursor!==null&&(typeof e.nextCursor!=`string`||e.nextCursor.length<1||e.nextCursor.length>2048||!/^[A-Za-z0-9_.-]+$/.test(e.nextCursor))||e.items.length===0&&e.nextCursor!==null)return!1;let t=``;for(let n of e.items){if(!P(n,[`workspaceId`,`itemId`])||typeof n.workspaceId!=`string`||!S.test(n.workspaceId)||typeof n.itemId!=`string`||!x.test(n.itemId))return!1;let e=`${n.workspaceId}/${n.itemId}`;if(t&&t>=e)return!1;t=e}return!0}function fe(e){if(!P(e,[`workspaceId`,`provider`,`usedBytes`,`reservedBytes`,`limitBytes`,`availableBytes`,`accounting`,`reservedBytesIncludeUnresolvedUploads`,`unresolvedReservedBytes`,`warnings`])||typeof e.workspaceId!=`string`||!S.test(e.workspaceId)||e.provider!==`managed`||e.accounting!==`current-versions-and-reservations`||e.reservedBytesIncludeUnresolvedUploads!==!0||!Array.isArray(e.warnings)||e.warnings.length>1||e.warnings.some(e=>e!==`unresolved-archive-ownership`)||![e.usedBytes,e.reservedBytes,e.limitBytes,e.availableBytes,e.unresolvedReservedBytes].every(e=>typeof e==`string`&&/^(0|[1-9][0-9]{0,18})$/.test(e)))return!1;let t=BigInt(e.limitBytes)-BigInt(e.usedBytes)-BigInt(e.reservedBytes),n=BigInt(e.availableBytes)===(t>0n?t:0n)&&BigInt(e.unresolvedReservedBytes)<=BigInt(e.reservedBytes)&&(e.unresolvedReservedBytes===`0`||e.warnings.length===1);return n&&Object.freeze(e.warnings),n}function pe(e){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>50||!(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length>0&&e.nextCursor.length<=2048&&/^[A-Za-z0-9_.-]+$/.test(e.nextCursor))||e.items.length===0&&e.nextCursor!==null)return!1;let t=new Set,n=e.items.every(e=>{if(!P(e,[`workspaceId`,`itemId`,`parentId`,`type`,`name`,`lifecycleState`,`revision`,`currentVersion`,`volumeId`,`provider`,`createdAtEpochMilliseconds`,`modifiedAtEpochMilliseconds`,`creatorUserId`,`etag`,`trashedAtEpochMilliseconds`,`purgeAfterEpochMilliseconds`])||e.lifecycleState!==`active`&&e.lifecycleState!==`trashed`||typeof e.volumeId!=`string`||!C.test(e.volumeId)||e.provider!==`managed`||e.creatorUserId!==null&&(typeof e.creatorUserId!=`string`||!O.test(e.creatorUserId))||![e.createdAtEpochMilliseconds,e.modifiedAtEpochMilliseconds,e.trashedAtEpochMilliseconds,e.purgeAfterEpochMilliseconds].every(e=>e===null||N(e)))return!1;let n={workspaceId:e.workspaceId,itemId:e.itemId,parentId:e.parentId,type:e.type,name:e.name,lifecycleState:`active`,revision:e.revision,currentVersion:e.currentVersion};return typeof n.workspaceId!=`string`||!S.test(n.workspaceId)||typeof n.itemId!=`string`||!x.test(n.itemId)||n.parentId===null||n.parentId===n.itemId||!Ee(n,n.workspaceId,n.itemId)||e.etag!==`"drive.item.v1.${n.revision}"`||t.has(n.itemId)||(e.lifecycleState===`active`?e.trashedAtEpochMilliseconds!==null||e.purgeAfterEpochMilliseconds!==null:!N(e.trashedAtEpochMilliseconds)||!N(e.purgeAfterEpochMilliseconds)||e.purgeAfterEpochMilliseconds<=e.trashedAtEpochMilliseconds)?!1:(t.add(n.itemId),!0)});if(n){for(let t of e.items)Object.freeze(t);Object.freeze(e.items),Object.freeze(e)}return n}const me=[`ownerUserId`,`ownership`,`visibility`,`archived`,`activeVisitorGrantCount`];function he(e,t,n){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items))return!1;let r=[],i=``;for(let a of e.items){if(!a||typeof a!=`object`||Array.isArray(a))return!1;let e=a,{ownerUserId:o,ownership:s,visibility:c,archived:l,activeVisitorGrantCount:u,...d}=e;if(!me.every(t=>Object.hasOwn(e,t))||o!==t||s!==`assigned`&&s!==`creator`||s===`creator`&&d.creatorUserId!==t||c!==`workspace`&&c!==`restricted`||typeof l!=`boolean`||n===`active`&&l||!N(u)||d.lifecycleState!==n||typeof d.itemId!=`string`||d.itemId<=i)return!1;i=d.itemId,r.push(d)}if(!pe({items:r,nextCursor:e.nextCursor}))return!1;for(let t of e.items)Object.freeze(t);return Object.freeze(e.items),Object.freeze(e),!0}function ge(e,t,n,r){return!P(e,[`workspaceId`,`volumeId`,`itemId`,`kind`,`revision`,`previousOwnerUserId`,`ownerUserId`,`transferredItemCount`,`revokedVisitorGrantCount`])||e.workspaceId!==t||e.itemId!==n||typeof e.volumeId!=`string`||!C.test(e.volumeId)||e.kind!==`file`&&e.kind!==`folder`||!N(e.revision)||e.revision<1||e.previousOwnerUserId!==null&&(typeof e.previousOwnerUserId!=`string`||!O.test(e.previousOwnerUserId))||e.previousOwnerUserId===r||e.ownerUserId!==r||!N(e.transferredItemCount)||e.transferredItemCount<1||!N(e.revokedVisitorGrantCount)?!1:(Object.freeze(e),!0)}function _e(e,t,n){return!P(e,[`workspaceId`,`volumeId`,`itemId`,`parentItemId`,`kind`,`name`,`state`,`revision`,`trashedAtEpochMilliseconds`,`purgeAfterEpochMilliseconds`,`retentionHold`])||e.workspaceId!==t||e.itemId!==n||typeof e.volumeId!=`string`||!C.test(e.volumeId)||typeof e.parentItemId!=`string`||!x.test(e.parentItemId)||e.parentItemId===n||e.kind!==`file`&&e.kind!==`folder`||!M(e.name)||e.state!==`trashed`||!N(e.revision)||e.revision<1||!N(e.trashedAtEpochMilliseconds)||!N(e.purgeAfterEpochMilliseconds)||e.purgeAfterEpochMilliseconds<=e.trashedAtEpochMilliseconds||e.retentionHold!==!0?!1:(Object.freeze(e),!0)}function ve(e){if(!P(e,[`workspace`,`volumes`,`knownProviders`,`externalConnectionsSupported`])||!ye(e.workspace)||!Array.isArray(e.volumes)||e.volumes.length!==1||!Array.isArray(e.knownProviders)||e.externalConnectionsSupported!==!1)return!1;let t=e.volumes[0],n=[`managed`,`google-drive`,`onedrive`,`dropbox`,`s3-compatible`];return P(t,[`volumeId`,`rootItemId`,`provider`,`name`])&&t.volumeId===e.workspace.rootVolumeId&&t.rootItemId===e.workspace.rootItemId&&t.provider===`managed`&&t.name===`Files`&&e.knownProviders.length===n.length&&e.knownProviders.every((e,t)=>e===n[t])}function ye(e){if(!P(e,[`workspaceId`,`rootVolumeId`,`rootItemId`,`workspaceReference`])||typeof e.workspaceId!=`string`||!S.test(e.workspaceId)||typeof e.rootVolumeId!=`string`||!C.test(e.rootVolumeId)||typeof e.rootItemId!=`string`||!x.test(e.rootItemId))return!1;let t=e.workspaceReference;return P(t,[`type`,`userId`])&&t.type===`personal`&&typeof t.userId==`string`&&O.test(t.userId)||P(t,[`type`,`organizationId`])&&t.type===`organization`&&typeof t.organizationId==`string`&&O.test(t.organizationId)}function be(e){return!P(e,[`mode`,`method`,`url`,`headers`,`expiresAtEpochMilliseconds`,`response`])||e.mode!==`presigned-single`||e.method!==`GET`&&e.method!==`HEAD`||typeof e.url!=`string`||!ot(e.url)||!N(e.expiresAtEpochMilliseconds)||!st(e.headers,[`if-match`],e.url)&&!st(e.headers,[`if-match`,`range`],e.url)||typeof e.headers[`if-match`]!=`string`||!at(e.headers[`if-match`])||e.headers.range!==void 0&&(typeof e.headers.range!=`string`||!/^bytes=(?:0|[1-9][0-9]*)-(?:0|[1-9][0-9]*)$/.test(e.headers.range))||!P(e.response,[`status`,`versionId`,`byteLength`,`contentLength`,`contentType`,`contentDisposition`,`etag`,`acceptRanges`,`contentRange`])||e.response.status!==200&&e.response.status!==206||typeof e.response.versionId!=`string`||!T.test(e.response.versionId)||!N(e.response.byteLength)||!N(e.response.contentLength)||typeof e.response.contentType!=`string`||!/^[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?\/[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?$/.test(e.response.contentType)||typeof e.response.contentDisposition!=`string`||e.response.contentDisposition.length>2048||!/^[\x20-\x7e]+$/.test(e.response.contentDisposition)||e.response.etag!==e.headers[`if-match`]||e.response.acceptRanges!==`bytes`||e.response.contentRange!==null&&typeof e.response.contentRange!=`string`||!xe(e)?!1:(Object.freeze(e.headers),Object.freeze(e.response),Object.freeze(e),!0)}function xe(e){let t=e.response;if(t.contentLength>t.byteLength||e.method===`HEAD`&&t.status!==200||!t.contentDisposition.startsWith(`attachment; filename="`))return!1;if(t.status===200)return e.headers.range===void 0&&t.contentRange===null&&t.contentLength===t.byteLength;if(e.method!==`GET`||e.headers.range===void 0||t.contentRange===null)return!1;let n=/^bytes=(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$/.exec(e.headers.range),r=/^bytes (0|[1-9][0-9]*)-(0|[1-9][0-9]*)\/(0|[1-9][0-9]*)$/.exec(t.contentRange);if(!n||!r)return!1;let i=Number(n[1]),a=Number(n[2]),o=Number(r[1]),s=Number(r[2]),c=Number(r[3]);return[i,a,o,s,c].every(N)&&i===o&&a===s&&c===t.byteLength&&i<=a&&a<c&&t.contentLength===a-i+1}function Se(e){return P(e,[`mode`,`operationId`,`versionId`,`state`,`pollAfterSeconds`])&&e.mode===`restore-pending`&&typeof e.operationId==`string`&&E.test(e.operationId)&&typeof e.versionId==`string`&&T.test(e.versionId)&&(e.state===`pending`||e.state===`restoring`)&&N(e.pollAfterSeconds)&&e.pollAfterSeconds>=1&&e.pollAfterSeconds<=60}function Ce(e,t,n){return P(e,[`items`,`nextCursor`])&&Array.isArray(e.items)&&e.items.length<=50&&e.items.every(we)&&(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&D.test(e.nextCursor))?e.items.every(e=>e.workspaceId===t&&e.parentItemId===n)&&it(e.items,e=>e.itemId):!1}function we(e){return P(e,[`workspaceId`,`volumeId`,`itemId`,`parentItemId`,`kind`,`name`,`visibility`,`revision`])&&typeof e.workspaceId==`string`&&S.test(e.workspaceId)&&typeof e.volumeId==`string`&&C.test(e.volumeId)&&typeof e.itemId==`string`&&x.test(e.itemId)&&typeof e.parentItemId==`string`&&x.test(e.parentItemId)&&(e.kind===`file`||e.kind===`folder`)&&M(e.name)&&(e.visibility===`workspace`||e.visibility===`restricted`)&&N(e.revision)}function Te(e,t,n,r){return!P(e,[`workspaceId`,`volumeId`,`itemId`,`parentItemId`,`kind`,`name`,`state`,`revision`,`purgeAfterEpochMilliseconds`])||e.workspaceId!==t||e.itemId!==n||typeof e.volumeId!=`string`||!C.test(e.volumeId)||typeof e.parentItemId!=`string`||!x.test(e.parentItemId)||e.kind!==`file`&&e.kind!==`folder`||!M(e.name)||e.state!==r||!N(e.revision)||(e.state===`active`?e.purgeAfterEpochMilliseconds!==null:!N(e.purgeAfterEpochMilliseconds))?!1:(Object.freeze(e),!0)}function Ee(e,t,n){return!P(e,[`workspaceId`,`itemId`,`parentId`,`type`,`name`,`lifecycleState`,`revision`,`currentVersion`])||e.workspaceId!==t||e.itemId!==n||!(e.parentId===null||typeof e.parentId==`string`&&x.test(e.parentId))||e.type!==`file`&&e.type!==`folder`||!M(e.name)||e.lifecycleState!==`active`||!N(e.revision)||(e.type===`folder`?e.currentVersion!==null:!Oe(e.currentVersion))?!1:(e.currentVersion!==null&&Object.freeze(e.currentVersion),Object.freeze(e),!0)}function De(e,t,n,r){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>r||!e.items.every(e=>ke(e,t,n))||!(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&D.test(e.nextCursor))||e.items.length===0&&e.nextCursor!==null||new Set(e.items.map(e=>e.itemId)).size!==e.items.length||!Ae(e.items))return!1;for(let t of e.items)t.currentVersion!==null&&Object.freeze(t.currentVersion),Object.freeze(t);return Object.freeze(e.items),Object.freeze(e),!0}function j(e,t){let n=e.get(`etag`);return n!==null&&h(n)===t}function Oe(e){return P(e,[`versionId`,`state`,`byteLength`,`mediaType`,`protectionClassification`])&&typeof e.versionId==`string`&&T.test(e.versionId)&&e.state===`current`&&N(e.byteLength)&&tt(e.mediaType)&&(e.protectionClassification===`ordinary`||e.protectionClassification===`opaque-encrypted`)}function ke(e,t,n){return P(e,[`workspaceId`,`volumeId`,`provider`,`itemId`,`parentId`,`type`,`name`,`lifecycleState`,`revision`,`currentVersion`])&&e.workspaceId===t&&typeof e.volumeId==`string`&&C.test(e.volumeId)&&e.provider===`managed`&&typeof e.itemId==`string`&&x.test(e.itemId)&&(e.parentId===null||typeof e.parentId==`string`&&x.test(e.parentId))&&(e.type===`file`||e.type===`folder`)&&M(e.name)&&e.name.startsWith(n)&&e.lifecycleState===`active`&&N(e.revision)&&(e.type===`folder`?e.currentVersion===null:Oe(e.currentVersion))}function Ae(e){for(let t=1;t<e.length;t+=1){let n=e[t-1],r=e[t],i=je(n.name,r.name);if(i>0||i===0&&n.itemId>=r.itemId)return!1}return!0}function je(e,t){let n=ue.encode(e),r=ue.encode(t),i=Math.min(n.length,r.length);for(let e=0;e<i;e+=1)if(n[e]!==r[e])return n[e]-r[e];return n.length-r.length}function Me(e,t){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>t||!e.items.every(Ge)||!(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&D.test(e.nextCursor))||e.nextCursor!==null&&e.items.length===0||!it(e.items,e=>e.versionId))return!1;for(let t of e.items)Object.freeze(t);return Object.freeze(e.items),Object.freeze(e),!0}function Ne(e,t){return!P(e,[`itemRevision`,`currentVersionId`])||!N(e.itemRevision)||e.currentVersionId!==t?!1:(Object.freeze(e),!0)}function Pe(e,t,n,r=ae){if(!(P(e,[`items`,`nextCursor`,`collectionRevision`,`collectionEtag`])&&Array.isArray(e.items)&&e.items.length<=50&&e.items.every(Xe)&&(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&D.test(e.nextCursor))&&N(e.collectionRevision)&&typeof e.collectionEtag==`string`&&p(e.collectionEtag)===e.collectionRevision))return!1;let i=t.get(`drive-permission-collection-etag`),a=t.get(`etag`),o=e.collectionRevision;return N(o)?i===e.collectionEtag&&a!==null&&r.test(a)&&e.items.every(e=>{let t=m(e.etag);return t===void 0||e.etag!==et(t[0],e.revision)?!1:e.source===`direct`?e.sourceItemId===n&&t[0]===o:e.sourceItemId!==n})&&it(e.items,e=>`${e.sourceItemId}\0${e.grantId}`):!1}function Fe(e,t,n){if(!P(e,[`items`,`nextCursor`,`collectionRevision`,`collectionEtag`])||!Array.isArray(e.items)||e.items.length>50)return!1;let r=[];for(let t of e.items){if(!P(t,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`,`etag`,`recipient`]))return!1;let{recipient:e,...n}=t;if(!Xe(n)||e!==null&&(!P(e,[`userId`,`name`,`email`,`resolvedAt`,`expiresAt`])||n.grantee.type!==`user`||e.userId!==n.grantee.userId||typeof e.name!=`string`||e.name.length<1||ue.encode(e.name).byteLength>1024||typeof e.email!=`string`||e.email.length<3||ue.encode(e.email).byteLength>320||!e.email.includes(`@`)||!N(e.resolvedAt)||!N(e.expiresAt)||e.expiresAt!==e.resolvedAt+864e5))return!1;r.push(n)}return Pe({...e,items:r},t,n,/^"drive\.sharing-people\.v1\.[0-9a-f]{64}"$/)}function Ie(e,t,n){if(!P(e,[`outcome`,`grant`,`collectionRevision`])||e.outcome!==`committed`&&e.outcome!==`replayed`||!N(e.collectionRevision))return!1;let r=e.grant;return P(r,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`])&&r.source===`direct`&&typeof r.sourceItemId==`string`&&r.sourceItemId===t&&typeof r.grantId==`string`&&ie.test(r.grantId)&&(n===void 0||r.grantId===n)&&Ze(r.grantee)&&Qe(r.actions)&&[`active`,`expired`,`revoked`].includes(String(r.availability))&&(r.expiresAtEpochMilliseconds===null||N(r.expiresAtEpochMilliseconds))&&N(r.revision)}function Le(e,t){if(!P(e,[`actions`])||!Array.isArray(e.actions)||e.actions.length!==7)return!1;for(let n=0;n<e.actions.length;n+=1){let r=e.actions[n];if(r===void 0||!P(r,[`action`,`allowed`,`basis`,`sourceItemId`,`grantId`])||r.action!==oe[n]||typeof r.allowed!=`boolean`||!(r.basis===null||[`workspace_visibility`,`restricted_administrator_bypass`,`direct_grant`,`inherited_grant`].includes(String(r.basis)))||!(r.sourceItemId===null||typeof r.sourceItemId==`string`&&x.test(r.sourceItemId))||!(r.grantId===null||typeof r.grantId==`string`&&ie.test(r.grantId))||!$e(r,t))return!1}return!0}function Re(e,t,n=!1,r){if(!P(e,[`itemId`,`versionId`,`uploadId`,`mode`,`partByteLength`,`partCount`,`revision`,`expiresAtEpochMilliseconds`],[`singleUpload`])||typeof e.itemId!=`string`||!x.test(e.itemId)||typeof e.versionId!=`string`||!T.test(e.versionId)||typeof e.uploadId!=`string`||!w.test(e.uploadId)||e.mode!==`presigned-multipart`&&e.mode!==`server-mediated-zero-byte`&&e.mode!==`presigned-single`||e.partByteLength!==ce||!N(e.partCount)||e.partCount>1e4||e.partCount!==Math.ceil(t/ce)||(t===0?e.mode!==`server-mediated-zero-byte`:e.mode!==`presigned-multipart`&&e.mode!==`presigned-single`)||!N(e.revision)||!N(e.expiresAtEpochMilliseconds)||e.expiresAtEpochMilliseconds<=Date.now())return!1;if(e.mode===`presigned-single`){if(t<1||t>8*1024*1024||!r||!P(e.singleUpload,[`state`,`descriptor`])||![`uploading`,`completing`,`ready`].includes(String(e.singleUpload.state)))return!1;let i=e.singleUpload.descriptor;if(i!==null){if(e.singleUpload.state!==`uploading`||!P(i,[`url`,`method`,`headers`,`expectedByteLength`,`expiresAtEpochMilliseconds`])||!nt(i.url,n)||i.method!==`PUT`||!st(i.headers,[`content-md5`,`content-type`,`if-none-match`],i.url)||i.headers[`content-md5`]!==r||i.headers[`if-none-match`]!==`*`||typeof i.headers[`content-type`]!=`string`||i.expectedByteLength!==t||!N(i.expiresAtEpochMilliseconds)||i.expiresAtEpochMilliseconds>e.expiresAtEpochMilliseconds)return!1;Object.freeze(i.headers),Object.freeze(i)}Object.freeze(e.singleUpload)}else if(e.singleUpload!==void 0)return!1;return Object.freeze(e),!0}function ze(e,t,n){if(!P(e,[`itemId`,`versionId`,`uploadId`,`mode`,`lifecycle`,`revision`,`partPolicy`,`confirmedParts`,`nextAfterPartNumber`,`expiresAtEpochMilliseconds`,`ready`],[`verification`])||typeof e.itemId!=`string`||!x.test(e.itemId)||typeof e.versionId!=`string`||!T.test(e.versionId)||typeof e.uploadId!=`string`||!w.test(e.uploadId)||e.mode!==`presigned-multipart`&&e.mode!==`server-mediated-zero-byte`&&e.mode!==`presigned-single`||![`initiating`,`recovery-required`,`uploading`,`completing`,`provider-completed`,`verifying`,`failed`,`ready`,`aborting`,`aborted`].includes(String(e.lifecycle))||!N(e.revision)||!P(e.partPolicy,[`partByteLength`,`partCount`,`maxParts`])||e.partPolicy.partByteLength!==ce||!N(e.partPolicy.partCount)||e.partPolicy.partCount>1e4||e.partPolicy.maxParts!==1e4||e.mode===`presigned-single`&&e.partPolicy.partCount!==1||(e.mode===`server-mediated-zero-byte`?e.partPolicy.partCount!==0:e.partPolicy.partCount<1)||!Array.isArray(e.confirmedParts)||e.confirmedParts.length>n||!N(e.expiresAtEpochMilliseconds))return!1;let r=t;if(e.verification!==void 0){let t=e.verification;if(!P(t,[`state`,`verifiedByteLength`,`totalByteLength`,`revision`])||![`pending`,`verified`,`failed`].includes(String(t.state))||!N(t.verifiedByteLength)||!N(t.totalByteLength)||t.totalByteLength>se||t.verifiedByteLength>t.totalByteLength||!N(t.revision)||t.state===`verified`&&t.verifiedByteLength!==t.totalByteLength)return!1;Object.freeze(t)}if([`verifying`,`failed`].includes(String(e.lifecycle))&&e.verification===void 0)return!1;for(let t of e.confirmedParts){if(!P(t,[`partNumber`,`checksumSha256`])||!N(t.partNumber)||t.partNumber<=r||t.partNumber>e.partPolicy.partCount||!We(t.checksumSha256))return!1;r=t.partNumber}if(!(e.nextAfterPartNumber===null||N(e.nextAfterPartNumber)&&e.confirmedParts.length===n&&e.nextAfterPartNumber===r)||e.mode===`server-mediated-zero-byte`&&(e.confirmedParts.length!==0||e.nextAfterPartNumber!==null)||e.lifecycle===`ready`!=(e.ready!==null)||e.ready!==null&&(!He(e.ready,{uploadId:e.uploadId})||e.ready.itemId!==e.itemId||e.ready.versionId!==e.versionId||!P(e.verification,[`state`,`verifiedByteLength`,`totalByteLength`,`revision`])||e.verification.state!==`verified`||e.verification.totalByteLength!==e.ready.byteLength))return!1;Object.freeze(e.partPolicy);for(let t of e.confirmedParts)Object.freeze(t);return Object.freeze(e.confirmedParts),Object.freeze(e),!0}function Be(e,t,n,r){return!P(e,[`url`,`method`,`headers`,`partNumber`,`expectedByteLength`,`expiresAtEpochMilliseconds`])||!nt(e.url,n)||e.method!==`PUT`||!r||!st(e.headers,[`content-md5`],e.url)||e.headers[`content-md5`]!==r||e.partNumber!==t||!N(e.expectedByteLength)||e.expectedByteLength<1||e.expectedByteLength>ce||!N(e.expiresAtEpochMilliseconds)||e.expiresAtEpochMilliseconds<=Date.now()?!1:(Object.freeze(e.headers),Object.freeze(e),!0)}function Ve(e,t,n){return!P(e,[`partNumber`,`revision`])||e.partNumber!==t||e.revision!==n+1||!N(e.revision)?!1:(Object.freeze(e),!0)}function He(e,t){return!P(e,[`itemId`,`versionId`,`uploadId`,`byteLength`,`callerDeclaredContentDigest`,`displayFilename`,`mediaType`,`state`])||typeof e.itemId!=`string`||!x.test(e.itemId)||typeof e.versionId!=`string`||!T.test(e.versionId)||e.uploadId!==t.uploadId||!N(e.byteLength)||e.byteLength<0||e.byteLength>se||typeof e.callerDeclaredContentDigest!=`string`||!le.test(e.callerDeclaredContentDigest)||!M(e.displayFilename)||!tt(e.mediaType)||e.state!==`ready`||t.byteLength!==void 0&&e.byteLength!==t.byteLength||t.callerDeclaredContentDigest!==void 0&&e.callerDeclaredContentDigest!==t.callerDeclaredContentDigest||t.displayFilename!==void 0&&e.displayFilename!==t.displayFilename||t.mediaType!==void 0&&e.mediaType!==t.mediaType?!1:(Object.freeze(e),!0)}function Ue(e,t){return!P(e,[`itemId`,`versionId`,`uploadId`,`state`,`verifiedByteLength`,`totalByteLength`,`verificationRevision`])||typeof e.itemId!=`string`||!x.test(e.itemId)||typeof e.versionId!=`string`||!T.test(e.versionId)||e.uploadId!==t||e.state!==`verifying`||!N(e.verifiedByteLength)||!N(e.totalByteLength)||e.totalByteLength>se||e.verifiedByteLength>e.totalByteLength||!N(e.verificationRevision)?!1:(Object.freeze(e),!0)}function We(e){return typeof e==`string`&&/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/.test(e)}function Ge(e){let t=P(e,qe)&&Je(e);return t&&Object.freeze(e),t}function Ke(e,t,n,r){let i=P(e,[...qe,`workspaceId`,`itemId`])&&e.workspaceId===t&&e.itemId===n&&e.versionId===r&&Je(e);return i&&Object.freeze(e),i}const qe=Object.freeze([`versionId`,`state`,`revision`,`byteLength`,`contentDigest`,`mediaType`,`displayFilename`,`protectionClassification`,`archiveState`]);function Je(e){return typeof e.versionId==`string`&&T.test(e.versionId)&&(e.state===`current`||e.state===`superseded`)&&N(e.revision)&&N(e.byteLength)&&typeof e.contentDigest==`string`&&le.test(e.contentDigest)&&tt(e.mediaType)&&M(e.displayFilename)&&(e.protectionClassification===`ordinary`||e.protectionClassification===`opaque-encrypted`)&&[`available`,`cold`,`restoring`,`unavailable`,`corrupt`].includes(String(e.archiveState))}function Ye(e){let t=e.get(`drive-permission-collection-etag`),n=e.get(`drive-permission-grant-etag`),r=t===null?void 0:p(t);if(r===void 0)return!1;if(n===null)return!0;let i=m(n);return i!==void 0&&i[0]===r}function Xe(e){return P(e,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`,`etag`])&&(e.source===`direct`||e.source===`inherited`)&&typeof e.sourceItemId==`string`&&x.test(e.sourceItemId)&&typeof e.grantId==`string`&&ie.test(e.grantId)&&Ze(e.grantee)&&Qe(e.actions)&&[`active`,`expired`,`revoked`].includes(String(e.availability))&&(e.expiresAtEpochMilliseconds===null||N(e.expiresAtEpochMilliseconds))&&N(e.revision)&&typeof e.etag==`string`&&k.test(e.etag)}function Ze(e){return P(e,[`type`,`userId`])&&e.type===`user`&&typeof e.userId==`string`&&O.test(e.userId)||P(e,[`type`,`teamId`])&&e.type===`team`&&typeof e.teamId==`string`&&O.test(e.teamId)}function Qe(e){return Array.isArray(e)&&e.length>=1&&e.length<=6&&new Set(e).size===e.length&&e.every(e=>A.includes(e))&&e.every((t,n)=>n===0||A.indexOf(t)>A.indexOf(e[n-1]))}function $e(e,t){return e.allowed?e.basis===`workspace_visibility`||e.basis===`restricted_administrator_bypass`?e.sourceItemId===null&&e.grantId===null:e.basis===`direct_grant`?e.sourceItemId===t&&typeof e.grantId==`string`:e.basis===`inherited_grant`&&typeof e.sourceItemId==`string`&&e.sourceItemId!==t&&typeof e.grantId==`string`:e.basis===null&&e.sourceItemId===null&&e.grantId===null}function et(e,t){return`"drive.permission-grant.v1.${e}.${t}"`}function M(e){if(typeof e!=`string`||e.length===0||e.length>510||e.normalize(`NFC`)!==e||e.endsWith(`.`)||e.endsWith(` `)||rt(e))return!1;let t=0,n=0;for(let r of e){let e=r.codePointAt(0);if(e===void 0||e===47||e===92||e<=31||e>=127&&e<=159||e===8232||e===8233||e>=55296&&e<=57343||(t+=1,n+=e<=127?1:e<=2047?2:e<=65535?3:4,t>255||n>255))return!1}return!0}function tt(e){return typeof e==`string`&&e.length<=255&&/^[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?\/[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?$/.test(e)}function nt(e,t){if(typeof e!=`string`||e.length<1||e.length>8192||e!==e.trim())return!1;try{let n=new URL(e),r=n.hostname===`localhost`||n.hostname===`127.0.0.1`||n.hostname===`[::1]`;return(n.protocol===`https:`||n.protocol===`http:`&&t&&r)&&n.username===``&&n.password===``&&n.hash===``&&n.host!==``}catch{return!1}}function rt(e){let t=e.split(`.`,1)[0].toUpperCase();return e===`.`||e===`..`||[`CON`,`PRN`,`AUX`,`NUL`,`CLOCK$`,`CONIN$`,`CONOUT$`].includes(t)||/^COM[1-9]$/.test(t)||/^LPT[1-9]$/.test(t)}function it(e,t){return e.every((n,r)=>r===0||t(e[r-1])<t(n))}function N(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function at(e){return/^"[\x21\x23-\x7e]{1,1022}"$/.test(e)}function ot(e){try{let t=new URL(e),n=t.protocol===`http:`&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname);return(t.protocol===`https:`||n)&&!t.username&&!t.password&&!t.hash}catch{return!1}}function P(e,t,n=[]){return typeof e!=`object`||!e||Array.isArray(e)?!1:Object.keys(e).every(e=>t.includes(e)||n.includes(e))&&t.every(t=>Object.hasOwn(e,t))}function st(e,t,n){if(P(e,t))return!0;let r=[`x-amz-server-side-encryption-customer-algorithm`,`x-amz-server-side-encryption-customer-key`,`x-amz-server-side-encryption-customer-key-md5`];if(!P(e,[...t,...r])||typeof n!=`string`)return!1;try{let t=new URL(n),i=t.searchParams.get(`X-Amz-SignedHeaders`)?.split(`;`)??[];return t.protocol===`https:`&&r.every(e=>i.includes(e))&&e[r[0]]===`AES256`&&typeof e[r[1]]==`string`&&/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/.test(e[r[1]])&&typeof e[r[2]]==`string`&&/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(e[r[2]])}catch{return!1}}const ct=/^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,F=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,lt=/^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ut=/^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,dt=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ft=/^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/,pt=/^[A-Za-z0-9_-]{1,128}$/,mt=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:read`,`items:update`]),ht=/^[A-Za-z0-9_-]{16,128}$/,gt=/^sha256:[0-9a-f]{64}$/,_t=/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/,vt=33554432e4;function yt(e){let t=V(B(e===void 0?{}:e,[],[`signal`]).signal);return t===void 0?{}:{signal:t}}function bt(e){let t=B(e===void 0?{}:e,[],[`signal`,`limit`,`cursor`,`mediaTypes`]),n=V(t.signal),r=St(t.mediaTypes);if(t.limit!==void 0&&(typeof t.limit!=`number`||!Number.isInteger(t.limit)||t.limit<1||t.limit>50)||t.cursor!==void 0&&(typeof t.cursor!=`string`||t.cursor.length<1||t.cursor.length>2048||!/^[A-Za-z0-9_.-]+$/.test(t.cursor)))throw new a(`invalid_input`);return{signal:n,query:{...t.limit===void 0?{}:{limit:t.limit},...t.cursor===void 0?{}:{cursor:t.cursor},...r===void 0?{}:{mediaTypes:r}}}}function xt(e,t){let n=B(e,[`workspaceId`],t?[`signal`,`view`,`kind`,`creatorUserId`,`mediaTypes`,`limit`,`cursor`]:[`signal`]),r=V(n.signal),i=St(n.mediaTypes);if(i!==void 0&&n.kind===`folder`||typeof n.workspaceId!=`string`||!F.test(n.workspaceId)||n.view!==void 0&&n.view!==`recent`&&n.view!==`shared`&&n.view!==`trash`||n.kind!==void 0&&n.kind!==`file`&&n.kind!==`folder`||n.creatorUserId!==void 0&&(typeof n.creatorUserId!=`string`||!pt.test(n.creatorUserId))||n.limit!==void 0&&(typeof n.limit!=`number`||!Number.isInteger(n.limit)||n.limit<1||n.limit>50)||n.cursor!==void 0&&(typeof n.cursor!=`string`||n.cursor.length<1||n.cursor.length>2048||!/^[A-Za-z0-9_.-]+$/.test(n.cursor)))throw new a(`invalid_input`);return{workspaceId:n.workspaceId,signal:r,query:{...n.view===void 0?{}:{view:n.view},...n.kind===void 0?{}:{kind:n.kind},...n.creatorUserId===void 0?{}:{creatorUserId:n.creatorUserId},...i===void 0?{}:{mediaTypes:i},...n.limit===void 0?{}:{limit:n.limit},...n.cursor===void 0?{}:{cursor:n.cursor}}}}function St(e){if(e!==void 0&&(!Array.isArray(e)||e.length<1||e.length>32||new Set(e).size!==e.length||e.some(e=>typeof e!=`string`||!/^[a-z0-9][a-z0-9!#$&^_.+-]{0,63}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,127}$/.test(e))||e.join(`,`).length>2048))throw new a(`invalid_input`);return e===void 0?void 0:[...e].sort().join(`,`)}function I(e){let t=B(e,[`workspaceId`,`itemId`],[`signal`]),n=t.workspaceId,r=t.itemId,i=V(t.signal);if(typeof n!=`string`||!F.test(n)||typeof r!=`string`||!ct.test(r))throw new a(`invalid_input`);return{workspaceId:n,itemId:r,...i===void 0?{}:{signal:i}}}function Ct(e){let t=B(e,[`workspaceId`,`itemId`,`versionId`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.versionId!=`string`||!dt.test(t.versionId))throw new a(`invalid_input`);return{...n,versionId:t.versionId}}function wt(e){let t=B(e,[`workspaceId`,`itemId`,`idempotencyKey`],[`versionId`,`method`,`range`,`ifMatch`,`ifNoneMatch`,`ifRange`,`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),r=t.method??`GET`;if(!H(t.idempotencyKey)||t.versionId!==void 0&&(typeof t.versionId!=`string`||!dt.test(t.versionId))||r!==`GET`&&r!==`HEAD`||t.range!==void 0&&(typeof t.range!=`string`||t.range.length>128||!/^bytes=(?:[0-9]+-[0-9]*|-[0-9]+)$/.test(t.range))||!tn(t.ifMatch)||!tn(t.ifNoneMatch)||!tn(t.ifRange))throw new a(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey,method:r,...t.versionId===void 0?{}:{versionId:t.versionId},...t.range===void 0?{}:{range:t.range},...t.ifMatch===void 0?{}:{ifMatch:t.ifMatch},...t.ifNoneMatch===void 0?{}:{ifNoneMatch:t.ifNoneMatch},...t.ifRange===void 0?{}:{ifRange:t.ifRange}}}function Tt(e){let t=B(e,[`workspaceId`,`query`],[`limit`,`cursor`,`signal`]),n=V(t.signal);if(typeof t.workspaceId!=`string`||!F.test(t.workspaceId)||!Zt(t.query)||t.limit!==void 0&&(!U(t.limit)||t.limit<1||t.limit>50)||t.cursor!==void 0&&(typeof t.cursor!=`string`||t.cursor.length>699||!ft.test(t.cursor)))throw new a(`invalid_input`);return{workspaceId:t.workspaceId,query:t.query,...t.limit===void 0?{}:{limit:t.limit},...t.cursor===void 0?{}:{cursor:t.cursor},...n===void 0?{}:{signal:n}}}function Et(e){let t=B(e,[`workspaceId`,`itemId`],[`signal`,`limit`,`cursor`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),r=t.limit,i=t.cursor;if(r!==void 0&&(!Number.isSafeInteger(r)||typeof r!=`number`||r<1||r>50)||i!==void 0&&(typeof i!=`string`||i.length>699||!ft.test(i)))throw new a(`invalid_input`);return{...n,...r===void 0?{}:{limit:r},...i===void 0?{}:{cursor:i}}}function Dt(e){let t=B(e,[`workspaceId`,`itemId`,`name`,`idempotencyKey`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(!$t(t.name)||!H(t.idempotencyKey))throw new a(`invalid_input`);return{...n,name:t.name,idempotencyKey:t.idempotencyKey}}function Ot(e){let t=B(e,[`workspaceId`,`itemId`,`name`,`parentItemId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=L({workspaceId:t.workspaceId,itemId:t.itemId,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch,...t.signal===void 0?{}:{signal:t.signal}});if(!$t(t.name)||typeof t.parentItemId!=`string`||!ct.test(t.parentItemId))throw new a(`invalid_input`);return{...n,name:t.name,parentItemId:t.parentItemId}}function L(e){let t=B(e,[`workspaceId`,`itemId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(!H(t.idempotencyKey)||typeof t.ifMatch!=`string`||h(t.ifMatch)===void 0)throw new a(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch}}function kt(e){let t=B(e,[`workspaceId`,`itemId`,`versionId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=L({workspaceId:t.workspaceId,itemId:t.itemId,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.versionId!=`string`||!dt.test(t.versionId))throw new a(`invalid_input`);return{...n,versionId:t.versionId}}function At(e){let t=B(e,[`workspaceId`,`itemId`,`grantee`,`actions`,`expiresAtEpochMilliseconds`,`ifMatch`,`idempotencyKey`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),r=Ut(t.grantee),i=Wt(t.actions),o=t.expiresAtEpochMilliseconds;if(!Qt(o)||typeof t.ifMatch!=`string`||p(t.ifMatch)===void 0||!H(t.idempotencyKey))throw new a(`invalid_input`);return{...n,grantee:r,actions:i,expiresAtEpochMilliseconds:o,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function jt(e){let t=B(e,[`workspaceId`,`itemId`,`email`,`role`,`ifMatch`,`idempotencyKey`],[`signal`,`expectedRecipientUserId`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.email!=`string`||t.email.length<3||t.email.length>320||t.role!==`viewer`&&t.role!==`editor`||typeof t.ifMatch!=`string`||p(t.ifMatch)===void 0||!H(t.idempotencyKey))throw new a(`invalid_input`);let r=t.email.trim().toLowerCase(),i=t.expectedRecipientUserId;if(i!==void 0&&(typeof i!=`string`||i.length<1||i.length>128||/[^A-Za-z0-9_-]/.test(i))||!r.includes(`@`)||/\s/.test(r)||new TextEncoder().encode(r).byteLength>320)throw new a(`invalid_input`);return{...n,email:r,expectedRecipientUserId:i,role:t.role,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function Mt(e){let t=B(e,[`workspaceId`,`itemId`,`grantId`,`ifMatch`,`idempotencyKey`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.grantId!=`string`||!lt.test(t.grantId)||typeof t.ifMatch!=`string`||m(t.ifMatch)===void 0||!H(t.idempotencyKey))throw new a(`invalid_input`);return{...n,grantId:t.grantId,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function Nt(e){let t=B(e,[`workspaceId`,`itemId`,`grantId`,`ifMatch`,`idempotencyKey`],[`signal`,`actions`,`expiresAtEpochMilliseconds`]),n=Mt({workspaceId:t.workspaceId,itemId:t.itemId,grantId:t.grantId,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey,...t.signal===void 0?{}:{signal:t.signal}}),r=t.actions===void 0?void 0:Wt(t.actions),i=t.expiresAtEpochMilliseconds;if(r===void 0&&i===void 0||i!==void 0&&!Qt(i))throw new a(`invalid_input`);return{...n,...r===void 0?{}:{actions:r},...i===void 0?{}:{expiresAtEpochMilliseconds:i}}}function Pt(e){let t=B(e,[`workspaceId`,`parentItemId`,`expectedByteLength`,`displayFilename`,`mediaType`,`callerDeclaredContentDigest`,`protectionClassification`,`idempotencyKey`],[`signal`,`contentMd5`]),n=V(t.signal);if(typeof t.workspaceId!=`string`||!F.test(t.workspaceId)||typeof t.parentItemId!=`string`||!ct.test(t.parentItemId)||typeof t.expectedByteLength!=`number`||!Number.isSafeInteger(t.expectedByteLength)||t.expectedByteLength<0||t.expectedByteLength>vt||t.contentMd5!==void 0&&(typeof t.contentMd5!=`string`||!/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(t.contentMd5)||t.expectedByteLength<1||t.expectedByteLength>8*1024*1024)||!$t(t.displayFilename)||!Xt(t.mediaType)||typeof t.callerDeclaredContentDigest!=`string`||!gt.test(t.callerDeclaredContentDigest)||t.protectionClassification!==`ordinary`&&t.protectionClassification!==`opaque-encrypted`||!H(t.idempotencyKey))throw new a(`invalid_input`);return{workspaceId:t.workspaceId,parentItemId:t.parentItemId,expectedByteLength:t.expectedByteLength,...t.contentMd5===void 0?{}:{contentMd5:t.contentMd5},displayFilename:t.displayFilename,mediaType:t.mediaType,callerDeclaredContentDigest:t.callerDeclaredContentDigest,protectionClassification:t.protectionClassification,idempotencyKey:t.idempotencyKey,...n===void 0?{}:{signal:n}}}function Ft(e){let t=B(e,[`workspaceId`,`uploadId`],[`afterPartNumber`,`limit`,`signal`]),n=Kt(t.workspaceId,t.uploadId,t.signal);if(t.afterPartNumber!==void 0&&(!U(t.afterPartNumber)||t.afterPartNumber>1e4)||t.limit!==void 0&&(!U(t.limit)||t.limit<1||t.limit>100))throw new a(`invalid_input`);return{...n,...t.afterPartNumber===void 0?{}:{afterPartNumber:t.afterPartNumber},...t.limit===void 0?{}:{limit:t.limit}}}function It(e){let t=B(e,[`workspaceId`,`uploadId`,`partNumber`,`checksumSha256`,`contentMd5`],[`signal`]),n=Kt(t.workspaceId,t.uploadId,t.signal);if(!qt(t.partNumber)||!Jt(t.checksumSha256)||typeof t.contentMd5!=`string`||!/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(t.contentMd5))throw new a(`invalid_input`);return{...n,partNumber:t.partNumber,checksumSha256:t.checksumSha256,contentMd5:t.contentMd5}}function Lt(e){let t=B(e,[`workspaceId`,`uploadId`,`partNumber`,`expectedUploadRevision`,`byteLength`,`etag`,`checksumSha256`],[`signal`]),n=Kt(t.workspaceId,t.uploadId,t.signal);if(!qt(t.partNumber)||!U(t.expectedUploadRevision)||t.expectedUploadRevision>=2**53-1||!U(t.byteLength)||t.byteLength<1||t.byteLength>33554432||!Yt(t.etag)||!Jt(t.checksumSha256))throw new a(`invalid_input`);return{...n,partNumber:t.partNumber,expectedUploadRevision:t.expectedUploadRevision,byteLength:t.byteLength,etag:t.etag,checksumSha256:t.checksumSha256}}function Rt(e){if(e===void 0)return`deferred`;if(e!==`deferred`&&e!==`inline`)throw new a(`invalid_input`);return e}function zt(e){let t=B(e,[`workspaceId`,`uploadId`,`idempotencyKey`],[`signal`,`verification`]),n=Kt(t.workspaceId,t.uploadId,t.signal);if(!H(t.idempotencyKey))throw new a(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey,verification:Rt(t.verification)}}function Bt(e){let t=B(e,[`workspaceId`,`uploadId`],[`signal`]);return Kt(t.workspaceId,t.uploadId,t.signal)}function Vt(e){let t=B(e,[`workspaceId`,`parentItemId`,`source`,`displayFilename`,`idempotencyKey`,`completionIdempotencyKey`],[`mediaType`,`protectionClassification`,`signal`,`onProgress`,`verification`]),n=V(t.signal),r=Rt(t.verification),i=t.mediaType??`application/octet-stream`,o=t.protectionClassification??`ordinary`,s,c;try{if(!(t.source instanceof Blob))throw new a(`invalid_input`);s=t.source,c=s.size}catch(e){throw e instanceof a?e:new a(`invalid_input`)}if(typeof t.workspaceId!=`string`||!F.test(t.workspaceId)||typeof t.parentItemId!=`string`||!ct.test(t.parentItemId)||!Number.isSafeInteger(c)||c<0||c>vt||!$t(t.displayFilename)||!Xt(i)||o!==`ordinary`&&o!==`opaque-encrypted`||!H(t.idempotencyKey)||!H(t.completionIdempotencyKey)||t.onProgress!==void 0&&typeof t.onProgress!=`function`)throw new a(`invalid_input`);return{workspaceId:t.workspaceId,parentItemId:t.parentItemId,source:s,byteLength:c,displayFilename:t.displayFilename,mediaType:i,protectionClassification:o,idempotencyKey:t.idempotencyKey,completionIdempotencyKey:t.completionIdempotencyKey,verification:r,...n===void 0?{}:{signal:n},...t.onProgress===void 0?{}:{onProgress:t.onProgress}}}function R(e){return{workspaceId:e.workspaceId,itemId:e.itemId}}function Ht(e){return{...e.limit===void 0?{}:{limit:e.limit},...e.cursor===void 0?{}:{cursor:e.cursor}}}function z(e,t){return t}function B(e,t,n){try{if(typeof e!=`object`&&typeof e!=`function`||e===null||Array.isArray(e))throw new a(`invalid_input`);let r=Object.getOwnPropertyDescriptors(e),i=Reflect.ownKeys(r),o=new Set([...t,...n]);if(i.some(e=>typeof e!=`string`||!o.has(e))||t.some(e=>!Object.hasOwn(r,e)))throw new a(`invalid_input`);let s={};for(let e of i){if(typeof e!=`string`)throw new a(`invalid_input`);let t=r[e];if(!t||!(`value`in t)||!t.enumerable)throw new a(`invalid_input`);s[e]=t.value}return s}catch(e){throw e instanceof a?e:new a(`invalid_input`)}}function V(e){if(e!==void 0){if(!(e instanceof AbortSignal))throw new a(`invalid_input`);return e}}function Ut(e){let t=B(e,[`type`],[`userId`,`teamId`]);if(t.type===`user`){let t=B(e,[`type`,`userId`],[]);if(typeof t.userId==`string`&&pt.test(t.userId))return{type:`user`,userId:t.userId}}if(t.type===`team`){let t=B(e,[`type`,`teamId`],[]);if(typeof t.teamId==`string`&&pt.test(t.teamId))return{type:`team`,teamId:t.teamId}}throw new a(`invalid_input`)}function Wt(e){let t=Gt(e);if(t.length<1||t.length>mt.length||new Set(t).size!==t.length||!t.every(e=>mt.includes(e)))throw new a(`invalid_input`);return t}function Gt(e){try{if(!Array.isArray(e))throw new a(`invalid_input`);let t=Object.getOwnPropertyDescriptors(e);if(Reflect.ownKeys(t).some(e=>typeof e!=`string`))throw new a(`invalid_input`);let n=[];for(let r=0;r<e.length;r+=1){let e=t[String(r)];if(!e||!(`value`in e)||!e.enumerable)throw new a(`invalid_input`);n.push(e.value)}if(Reflect.ownKeys(t).length!==e.length+1)throw new a(`invalid_input`);return n}catch(e){throw e instanceof a?e:new a(`invalid_input`)}}function H(e){return typeof e==`string`&&ht.test(e)}function Kt(e,t,n){let r=V(n);if(typeof e!=`string`||!F.test(e)||typeof t!=`string`||!ut.test(t))throw new a(`invalid_input`);return{workspaceId:e,uploadId:t,...r===void 0?{}:{signal:r}}}function qt(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=1&&e<=1e4}function Jt(e){return typeof e==`string`&&_t.test(e)}function Yt(e){return typeof e==`string`&&e.length>=1&&e.length<=1024&&/^[\x20-\x7e]+$/.test(e)}function Xt(e){return typeof e==`string`&&e.length<=255&&/^[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?\/[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?$/.test(e)}function Zt(e){if(typeof e!=`string`||e.length===0)return!1;try{if(e.normalize(`NFC`)!==e)return!1;let t=0,n=0;for(let r of e){let e=r.codePointAt(0);if(e===void 0||e<=31||e>=127&&e<=159||e===8232||e===8233||e>=55296&&e<=57343||(t+=1,n+=e<=127?1:e<=2047?2:e<=65535?3:4,t>64||n>255))return!1}return!0}catch{return!1}}function Qt(e){return e===null||U(e)}function $t(e){if(typeof e!=`string`||e.length===0||e.length>510||e.normalize(`NFC`)!==e||e.endsWith(`.`)||e.endsWith(` `)||en(e))return!1;let t=0,n=0;for(let r of e){let e=r.codePointAt(0);if(e===void 0||e===47||e===92||e<=31||e>=127&&e<=159||e===8232||e===8233||e>=55296&&e<=57343||(t+=1,n+=e<=127?1:e<=2047?2:e<=65535?3:4,t>255||n>255))return!1}return!0}function en(e){let t=e.split(`.`,1)[0].toUpperCase();return e===`.`||e===`..`||[`CON`,`PRN`,`AUX`,`NUL`,`CLOCK$`,`CONIN$`,`CONOUT$`].includes(t)||/^COM[1-9]$/.test(t)||/^LPT[1-9]$/.test(t)}function U(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function tn(e){return e===void 0||typeof e==`string`&&e.length<=8192&&!e.split(``).some(e=>{let t=e.charCodeAt(0);return t<=31||t===127})}const nn=/\{[^{}]+\}/g,rn=()=>typeof process==`object`&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function an(){return Math.random().toString(36).slice(2,11)}function on(e){let{baseUrl:t=``,Request:n=globalThis.Request,fetch:r=globalThis.fetch,querySerializer:i,bodySerializer:a,pathSerializer:o,headers:s,requestInitExt:c=void 0,...l}={...e};c=rn()?c:void 0,t=hn(t);let u=[];async function d(e,d){let{baseUrl:f,fetch:p=r,Request:m=n,headers:h,params:g={},parseAs:_=`json`,querySerializer:v,bodySerializer:ee=a??fn,pathSerializer:y,body:te,middleware:ne=[],...re}=d||{},b=t;f&&(b=hn(f)??t);let x=typeof i==`function`?i:un(i);v&&(x=typeof v==`function`?v:un({...typeof i==`object`?i:{},...v}));let S=y||o||dn,C=te===void 0?void 0:ee(te,mn(s,h,g.header)),ie=mn(C===void 0||C instanceof FormData?{}:{"Content-Type":`application/json`},s,h,g.header),w=[...u,...ne],T={redirect:`follow`,...l,...re,body:C,headers:ie},E,D,O=new m(pn(e,{baseUrl:b,params:g,querySerializer:x,pathSerializer:S}),T),k;for(let e in re)e in O||(O[e]=re[e]);if(w.length){E=an(),D=Object.freeze({baseUrl:b,fetch:p,parseAs:_,querySerializer:x,bodySerializer:ee,pathSerializer:S});for(let t of w)if(t&&typeof t==`object`&&typeof t.onRequest==`function`){let n=await t.onRequest({request:O,schemaPath:e,params:g,options:D,id:E});if(n)if(n instanceof m)O=n;else if(n instanceof Response){k=n;break}else throw Error(`onRequest: must return new Request() or Response() when modifying the request`)}}if(!k){try{k=await p(O,c)}catch(t){let n=t;if(w.length)for(let t=w.length-1;t>=0;t--){let r=w[t];if(r&&typeof r==`object`&&typeof r.onError==`function`){let t=await r.onError({request:O,error:n,schemaPath:e,params:g,options:D,id:E});if(t){if(t instanceof Response){n=void 0,k=t;break}if(t instanceof Error){n=t;continue}throw Error(`onError: must return new Response() or instance of Error`)}}}if(n)throw n}if(w.length)for(let t=w.length-1;t>=0;t--){let n=w[t];if(n&&typeof n==`object`&&typeof n.onResponse==`function`){let t=await n.onResponse({request:O,response:k,schemaPath:e,params:g,options:D,id:E});if(t){if(!(t instanceof Response))throw Error(`onResponse: must return new Response() when modifying the response`);k=t}}}}let ae=k.headers.get(`Content-Length`);if(k.status===204||O.method===`HEAD`||ae===`0`&&!k.headers.get(`Transfer-Encoding`)?.includes(`chunked`))return k.ok?{data:void 0,response:k}:{error:void 0,response:k};if(k.ok)return{data:await(async()=>{if(_===`stream`)return k.body;if(_===`json`&&!ae){let e=await k.text();return e?JSON.parse(e):void 0}return await k[_]()})(),response:k};let A=await k.text();try{A=JSON.parse(A)}catch{}return{error:A,response:k}}return{request(e,t,n){return d(t,{...n,method:e.toUpperCase()})},GET(e,t){return d(e,{...t,method:`GET`})},PUT(e,t){return d(e,{...t,method:`PUT`})},POST(e,t){return d(e,{...t,method:`POST`})},DELETE(e,t){return d(e,{...t,method:`DELETE`})},OPTIONS(e,t){return d(e,{...t,method:`OPTIONS`})},HEAD(e,t){return d(e,{...t,method:`HEAD`})},PATCH(e,t){return d(e,{...t,method:`PATCH`})},TRACE(e,t){return d(e,{...t,method:`TRACE`})},use(...e){for(let t of e)if(t){if(typeof t!=`object`||!(`onRequest`in t||`onResponse`in t||`onError`in t))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");u.push(t)}},eject(...e){for(let t of e){let e=u.indexOf(t);e!==-1&&u.splice(e,1)}}}}function sn(e,t,n){if(t==null)return``;if(typeof t==`object`)throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${n?.allowReserved===!0?t:encodeURIComponent(t)}`}function cn(e,t,n){if(!t||typeof t!=`object`)return``;let r=[],i={simple:`,`,label:`.`,matrix:`;`}[n.style]||`&`;if(n.style!==`deepObject`&&n.explode===!1){for(let e in t)r.push(e,n.allowReserved===!0?t[e]:encodeURIComponent(t[e]));let i=r.join(`,`);switch(n.style){case`form`:return`${e}=${i}`;case`label`:return`.${i}`;case`matrix`:return`;${e}=${i}`;default:return i}}for(let i in t){let a=n.style===`deepObject`?`${e}[${i}]`:i;r.push(sn(a,t[i],n))}let a=r.join(i);return n.style===`label`||n.style===`matrix`?`${i}${a}`:a}function ln(e,t,n){if(!Array.isArray(t))return``;if(n.explode===!1){let r={form:`,`,spaceDelimited:`%20`,pipeDelimited:`|`}[n.style]||`,`,i=(n.allowReserved===!0?t:t.map(e=>encodeURIComponent(e))).join(r);switch(n.style){case`simple`:return i;case`label`:return`.${i}`;case`matrix`:return`;${e}=${i}`;default:return`${e}=${i}`}}let r={simple:`,`,label:`.`,matrix:`;`}[n.style]||`&`,i=[];for(let r of t)n.style===`simple`||n.style===`label`?i.push(n.allowReserved===!0?r:encodeURIComponent(r)):i.push(sn(e,r,n));return n.style===`label`||n.style===`matrix`?`${r}${i.join(r)}`:i.join(r)}function un(e){return function(t){let n=[];if(t&&typeof t==`object`)for(let r in t){let i=t[r];if(i!=null){if(Array.isArray(i)){if(i.length===0)continue;n.push(ln(r,i,{style:`form`,explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==`object`){n.push(cn(r,i,{style:`deepObject`,explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}n.push(sn(r,i,e))}}return n.join(`&`)}}function dn(e,t){let n=e;for(let r of e.match(nn)??[]){let e=r.substring(1,r.length-1),i=!1,a=`simple`;if(e.endsWith(`*`)&&(i=!0,e=e.substring(0,e.length-1)),e.startsWith(`.`)?(a=`label`,e=e.substring(1)):e.startsWith(`;`)&&(a=`matrix`,e=e.substring(1)),!t||t[e]===void 0||t[e]===null)continue;let o=t[e];if(Array.isArray(o)){n=n.replace(r,ln(e,o,{style:a,explode:i}));continue}if(typeof o==`object`){n=n.replace(r,cn(e,o,{style:a,explode:i}));continue}if(a===`matrix`){n=n.replace(r,`;${sn(e,o)}`);continue}n=n.replace(r,a===`label`?`.${encodeURIComponent(o)}`:encodeURIComponent(o))}return n}function fn(e,t){return e instanceof FormData?e:t&&(t.get instanceof Function?t.get(`Content-Type`)??t.get(`content-type`):t[`Content-Type`]??t[`content-type`])===`application/x-www-form-urlencoded`?new URLSearchParams(e).toString():JSON.stringify(e)}function pn(e,t){let n=`${t.baseUrl}${e}`;t.params?.path&&(n=t.pathSerializer(n,t.params.path));let r=t.querySerializer(t.params.query??{});return r.startsWith(`?`)&&(r=r.substring(1)),r&&(n+=`?${r}`),n}function mn(...e){let t=new Headers;for(let n of e){if(!n||typeof n!=`object`)continue;let e=n instanceof Headers?n.entries():Object.entries(n);for(let[n,r]of e)if(r===null)t.delete(n);else if(Array.isArray(r))for(let e of r)t.append(n,e);else r!==void 0&&t.set(n,r)}return t}function hn(e){return e.endsWith(`/`)?e.substring(0,e.length-1):e}String.fromCharCode;const gn=/\/$|\/\?|\/#/,_n=/^\.?\//;function vn(e=``,t){return t?gn.test(e):e.endsWith(`/`)}function yn(e=``,t){if(!t)return e.endsWith(`/`)?e:e+`/`;if(vn(e,!0))return e||`/`;let n=e,r=``,i=e.indexOf(`#`);if(i!==-1&&(n=e.slice(0,i),r=e.slice(i),!n))return r;let[a,...o]=n.split(`?`);return a+`/`+(o.length>0?`?${o.join(`?`)}`:``)+r}function bn(e){return e&&e!==`/`}function xn(e,...t){let n=e||``;for(let e of t.filter(e=>bn(e)))if(n){let t=e.replace(_n,``);n=yn(n)+t}else n=e;return n}function Sn(e){let t;try{t=Object.freeze({baseUrl:Tn(e.baseUrl),fetchImplementation:e.fetch??globalThis.fetch.bind(globalThis),getCredential:e.getCredential,timeoutMilliseconds:Cn(e.timeoutMilliseconds)})}catch{throw new a(`invalid_input`)}if(typeof t.fetchImplementation!=`function`||typeof t.getCredential!=`function`)throw new a(`invalid_input`);return t}async function W(e,t,n,r,i,o,s=!1,c){let l=wn(t,e.timeoutMilliseconds);try{let t=l.signal;Dn(t);let u=await En(e.getCredential,t),p;if(await r(on({baseUrl:e.baseUrl,fetch:async n=>{try{let r=await On(e.fetchImplementation(n),t);if(!(r instanceof Response))throw new a(`invalid_response`);p=r}catch(e){throw e instanceof a?e:t.aborted?new a(`aborted`):new a(`network_error`)}return new Response(null,{status:204})}}),{referrerPolicy:`no-referrer`,redirect:`manual`,cache:`no-store`,credentials:`omit`,headers:new Headers({authorization:`${e.authorizationScheme??`Bearer`} ${u}`,...e.editingAudience?{"editing-audience":e.editingAudience}:{}}),signal:t}),!p)throw new a(`network_error`);return o===null?await f(p,t,n,i,c):await d(p,t,n,i,o,s,c)}catch(e){throw l.didTimeout()?new a(`timeout`):e instanceof a?e:l.signal.aborted?new a(`aborted`):new a(`network_error`)}finally{l.dispose()}}function Cn(e){if(e===void 0)return 3e4;if(!Number.isSafeInteger(e)||e<1||e>12e4)throw new a(`invalid_input`);return e}function wn(e,t){let n=new AbortController,r=!1,i=()=>n.abort();e?.aborted?n.abort():e?.addEventListener(`abort`,i,{once:!0});let a=setTimeout(()=>{r=!0,n.abort()},t);return{signal:n.signal,didTimeout:()=>r,dispose:()=>{clearTimeout(a),e?.removeEventListener(`abort`,i)}}}function Tn(e){if(typeof e!=`string`)throw TypeError(`Drive base URL is invalid`);let t;try{t=new URL(e)}catch{throw TypeError(`Drive base URL is invalid`)}let n=t.protocol===`http:`&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname);if(t.protocol!==`https:`&&!n||t.username||t.password||t.search||t.hash||!t.host)throw TypeError(`Drive base URL is invalid`);return xn(t.origin,t.pathname)}async function En(e,t){Dn(t);let n;try{n=await On(e({signal:t}),t)}catch(e){throw e instanceof a&&e.code===`aborted`?e:t.aborted?new a(`aborted`):new a(`credential_unavailable`)}if(typeof n!=`string`||n.length<1||n.length>16384||!/^[\x21-\x7e]+$/.test(n))throw new a(`credential_unavailable`);return n}function Dn(e){if(e.aborted)throw new a(`aborted`)}async function On(e,t){Dn(t);let n=()=>{},r=new Promise((e,r)=>{let i=()=>r(new a(`aborted`));t.addEventListener(`abort`,i,{once:!0}),n=()=>t.removeEventListener(`abort`,i)});try{return await Promise.race([e,r])}finally{n()}}function kn(e,t){let n=e[`x-amz-server-side-encryption-customer-algorithm`];return n===void 0||n===`AES256`&&t.headers.get(`x-amz-server-side-encryption-customer-algorithm`)===n&&t.headers.get(`x-amz-server-side-encryption-customer-key-md5`)===e[`x-amz-server-side-encryption-customer-key-md5`]}async function An(e,t,n){if(t.expiresAtEpochMilliseconds<=Date.now())throw new a(`invalid_response`);let r=wn(n,e.timeoutMilliseconds);try{let i=await On(e.fetchImplementation(Mn(t,r.signal)),r.signal);if(!Nn(i,t))throw await i.body?.cancel().catch(()=>void 0),new a(`invalid_response`);let o=jn(t);if(t.method===`HEAD`)return await i.body?.cancel().catch(()=>void 0),r.dispose(),new Response(null,{status:i.status,headers:o});if(!i.body){if(r.dispose(),t.response.contentLength!==0)throw new a(`invalid_response`);return new Response(null,{status:i.status,headers:o})}return r.dispose(),new Response(Pn(i.body,t.response.contentLength,n),{status:i.status,headers:o})}catch(e){throw r.dispose(),r.didTimeout()?new a(`timeout`):e instanceof a?e:r.signal.aborted?new a(r.didTimeout()?`timeout`:`aborted`):new a(`network_error`)}}function jn(e){let t=e.response,n=new Headers;return n.set(`cache-control`,`private, no-store, no-transform`),n.set(`accept-ranges`,t.acceptRanges),n.set(`content-disposition`,t.contentDisposition),n.set(`content-length`,String(t.contentLength)),n.set(`content-type`,t.contentType),n.set(`etag`,t.etag),t.contentRange===null?n.delete(`content-range`):n.set(`content-range`,t.contentRange),n}function Mn(e,t){let n={method:e.method,headers:e.headers,redirect:`manual`,signal:t};try{return new Request(e.url,{...n,cache:`no-store`,credentials:`omit`,referrerPolicy:`no-referrer`})}catch{try{return new Request(e.url,{...n,credentials:`omit`,referrerPolicy:`no-referrer`})}catch{return new Request(e.url,{...n,credentials:`omit`})}}}function Nn(e,t){let n=t.response,r=e.headers.get(`content-encoding`);return kn(t.headers,e)&&e.status===n.status&&e.headers.get(`etag`)===n.etag&&e.headers.get(`content-length`)===String(n.contentLength)&&(r===null||r===`identity`)&&(n.contentRange===null?e.headers.get(`content-range`)===null:e.headers.get(`content-range`)===n.contentRange)}function Pn(e,t,n){let r=e.getReader(),i=0,o=!1,s=()=>{};return new ReadableStream({start(e){if(!n)return;let t=()=>{o||(o=!0,s(),r.cancel().catch(()=>void 0),e.error(new a(`aborted`)))};n.aborted?t():(n.addEventListener(`abort`,t,{once:!0}),s=()=>n.removeEventListener(`abort`,t))},async pull(e){if(!o)try{let n=await r.read();if(o)return;if(n.done)o=!0,s(),r.releaseLock(),i===t?e.close():e.error(new a(`invalid_response`));else{if(i+=n.value.byteLength,!Number.isSafeInteger(i)||i>t){o=!0,s(),await r.cancel().catch(()=>void 0),e.error(new a(`invalid_response`));return}e.enqueue(n.value)}}catch(t){if(o)return;o=!0,s(),await r.cancel().catch(()=>void 0),e.error(t instanceof a?t:n?.aborted?new a(`aborted`):new a(`network_error`))}},async cancel(e){o||(o=!0,s(),await r.cancel(e).catch(()=>void 0))}})}const Fn=/^[A-Za-z0-9_-]{43}$/,G=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,K=/^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,In=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,Ln=/^[A-Za-z0-9._:-]{1,128}$/,Rn=/^drive_edit_[A-Za-z0-9_-]{43}$/,zn=`/api/v1/workspaces/{workspaceId}/items/{itemId}/visitor-grants`,Bn=e=>e===`viewer`||e===`editor`;function q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function J(e,t){return Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}function Y(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function Vn(e){return q(e)&&J(e,[`grantId`,`mode`,`role`,`email`,`status`,`createdAt`,`expiresAt`])&&typeof e.grantId==`string`&&G.test(e.grantId)&&Bn(e.role)&&(e.mode===`anyone`&&e.email===null&&e.status!==`pending`||e.mode===`email`&&typeof e.email==`string`&&e.email.length>=3&&e.email.length<=320)&&[`pending`,`active`,`expired`,`revoked`].includes(String(e.status))&&Y(e.createdAt)&&Y(e.expiresAt)&&e.expiresAt>e.createdAt&&e.expiresAt<=e.createdAt+2592e6}function Hn(e){return q(e)&&J(e,[`grant`,`token`,`tokenPurpose`])&&Vn(e.grant)&&(e.token===null||typeof e.token==`string`&&Fn.test(e.token))&&e.tokenPurpose===(e.grant.mode===`anyone`?`view`:`verify-email`)}function Un(e,t){if(!q(e))return!1;let{source:n,sourceItemId:r,...i}=e;return Vn(i)&&typeof r==`string`&&K.test(r)&&(n===`direct`&&r===t||n===`inherited`&&r!==t)}function Wn(e){return q(e)&&typeof e.itemId==`string`&&K.test(e.itemId)&&(e.kind===`file`||e.kind===`folder`)&&(e.name===null||typeof e.name==`string`&&e.name.length<=1024)}function Gn(e){return{async createVisitorGrant(t){let n=B(t,[`workspaceId`,`itemId`,`command`,`idempotencyKey`],[`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}}),i=B(n.command,[`mode`,`role`,`expiresAt`],[`email`]),o=i.role;if(!Bn(o)||!Y(i.expiresAt)||i.expiresAt>Date.now()+(o===`editor`?864e5:2592e6)||typeof n.idempotencyKey!=`string`||!/^[A-Za-z0-9_-]{16,128}$/.test(n.idempotencyKey)||!(i.mode===`anyone`&&!Object.hasOwn(i,`email`)||i.mode===`email`&&typeof i.email==`string`&&i.email.trim().length>=3&&new TextEncoder().encode(i.email).length<=320))throw new a(`invalid_input`);let s=i.mode===`anyone`?{mode:`anyone`,role:o,expiresAt:i.expiresAt}:{mode:`email`,role:o,email:String(i.email).trim().toLowerCase(),expiresAt:i.expiresAt};return W(e,r.signal,null,(e,t)=>e.POST(zn,{...t,params:{path:r,header:{"Idempotency-Key":n.idempotencyKey}},body:s}),[200],e=>Hn(e)&&e.grant.role===s.role&&e.grant.mode===s.mode&&e.grant.email===(s.mode===`email`?s.email:null)&&e.grant.expiresAt===s.expiresAt)},async getVisitorGrant(t){let n=B(t,[`workspaceId`,`itemId`,`grantId`],[`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}});if(typeof n.grantId!=`string`||!G.test(n.grantId))throw new a(`invalid_input`);let i=n.grantId;return W(e,r.signal,null,(e,t)=>e.GET(`${zn}/{grantId}`,{...t,params:{path:{...r,grantId:i}}}),[200],e=>Hn(e)&&e.grant.grantId===i)},async listVisitorGrants(t){let n=I(t);return W(e,n.signal,null,(e,t)=>e.GET(zn,{...t,params:{path:n}}),[200],e=>q(e)&&J(e,[`items`])&&Array.isArray(e.items)&&e.items.length<=64&&e.items.every(e=>Un(e,n.itemId)))},async revokeVisitorGrant(t){let n=B(t,[`workspaceId`,`itemId`,`grantId`],[`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}});if(typeof n.grantId!=`string`||!G.test(n.grantId))throw new a(`invalid_input`);return W(e,r.signal,null,(e,t)=>e.DELETE(`${zn}/{grantId}`,{...t,params:{path:{...r,grantId:n.grantId}}}),[200],e=>Vn(e)&&e.grantId===n.grantId&&e.status===`revoked`)}}}function Kn(e){if(!e||typeof e.token!=`string`||!Fn.test(e.token))throw new a(`invalid_input`);let t=e.token,n={...Sn({...e,getCredential:async()=>t}),authorizationScheme:`DriveVisitor`},r={Authorization:`DriveVisitor ${t}`},i={async readItem(e={}){let t=Jn(e);return W(n,t.signal,null,(e,n)=>e.GET(`/api/v1/visitor/item`,{...n,params:{header:r,query:t.query}}),[200],e=>Wn(e)&&q(e)&&J(e,[`itemId`,`kind`,`name`,`rootItemId`,`role`])&&Bn(e.role)&&typeof e.rootItemId==`string`&&K.test(e.rootItemId)&&(t.query.itemId===void 0||e.itemId===t.query.itemId))},async listChildren(e={}){let t=Jn(e,[`after`]);if(t.extra.after!==void 0&&(typeof t.extra.after!=`string`||!K.test(t.extra.after)))throw new a(`invalid_input`);let i=t.extra.after;return W(n,t.signal,null,(e,n)=>e.GET(`/api/v1/visitor/children`,{...n,params:{header:r,query:{...t.query,...i===void 0?{}:{after:i}}}}),[200],e=>q(e)&&J(e,[`items`,`nextAfter`])&&Array.isArray(e.items)&&e.items.length<=50&&e.items.every(e=>Wn(e)&&q(e)&&J(e,[`itemId`,`kind`,`name`]))&&(e.nextAfter===null||typeof e.nextAfter==`string`&&K.test(e.nextAfter)&&e.items.length===50&&q(e.items[49])&&e.items[49].itemId===e.nextAfter))},async createDownload(e={}){let t=Jn(e,[`method`,`range`]),i=t.extra.method??`GET`,o=t.extra.range;if(i!==`GET`&&i!==`HEAD`||o!==void 0&&(typeof o!=`string`||!/^bytes=(?:\d+-\d*|-\d+)$/.test(o)||o.length>128))throw new a(`invalid_input`);return W(n,t.signal,null,(e,n)=>(n.headers.set(`Download-Method`,i),typeof o==`string`&&n.headers.set(`Range`,o),e.POST(`/api/v1/visitor/downloads`,{...n,params:{header:r,query:t.query}})),[200],e=>be(e)&&e.method===i&&e.expiresAtEpochMilliseconds>Date.now())},async redeemInvitation(e){let i=B(e,[`sessionToken`],[`signal`]),o=V(i.signal);if(typeof i.sessionToken!=`string`||!Fn.test(i.sessionToken)||i.sessionToken===t)throw new a(`invalid_input`);let s=i.sessionToken;return W(n,o,null,(e,t)=>e.POST(`/api/v1/visitor/verify-email`,{...t,params:{header:r},body:{sessionToken:s}}),[200],e=>q(e)&&J(e,[`grantId`,`role`,`expiresAt`])&&typeof e.grantId==`string`&&G.test(e.grantId)&&Bn(e.role)&&Y(e.expiresAt)&&e.expiresAt>Date.now())},async downloadItem(e={}){let t=Jn(e,[`method`,`range`]),r=await i.createDownload(e);return An(n,r.data,t.signal)},async createEditingSession(e){let t=Jn(e,[`audience`,`writable`,`sourceVersionId`]),{audience:i,writable:o,sourceVersionId:s}=t.extra;if(typeof i!=`string`||!Ln.test(i)||typeof o!=`boolean`||s!==void 0&&(typeof s!=`string`||!In.test(s)))throw new a(`invalid_input`);let c={audience:i,writable:o,...s===void 0?{}:{sourceVersionId:s}};return W(n,t.signal,null,(e,n)=>e.POST(`/api/v1/visitor/editing-sessions`,{...n,params:{header:r,query:t.query},body:c}),[201],e=>qn(e,c))}};return Object.freeze(i)}function qn(e,t){return q(e)&&J(e,[`sessionId`,`workspaceId`,`itemId`,`sourceVersionId`,`expectedVersionId`,`contentGeneration`,`audience`,`grantId`,`writable`,`leaseUntil`,`expiresAt`,`revoked`,`token`])&&typeof e.sessionId==`string`&&G.test(e.sessionId)&&typeof e.workspaceId==`string`&&e.workspaceId.startsWith(`drive.workspace.`)&&G.test(e.workspaceId.slice(16))&&typeof e.itemId==`string`&&K.test(e.itemId)&&typeof e.sourceVersionId==`string`&&In.test(e.sourceVersionId)&&(t.sourceVersionId===void 0||e.sourceVersionId===t.sourceVersionId)&&typeof e.expectedVersionId==`string`&&In.test(e.expectedVersionId)&&typeof e.contentGeneration==`string`&&G.test(e.contentGeneration)&&e.audience===t.audience&&typeof e.grantId==`string`&&G.test(e.grantId)&&e.writable===t.writable&&e.revoked===!1&&Y(e.leaseUntil)&&Y(e.expiresAt)&&e.leaseUntil>Date.now()&&e.leaseUntil<=e.expiresAt&&typeof e.token==`string`&&Rn.test(e.token)}function Jn(e,t=[]){let n=B(e,[],[`itemId`,`signal`,...t]);if(n.itemId!==void 0&&(typeof n.itemId!=`string`||!K.test(n.itemId)))throw new a(`invalid_input`);return{signal:V(n.signal),query:n.itemId===void 0?{}:{itemId:n.itemId},extra:n}}function Yn(){let e=crypto.getRandomValues(new Uint8Array(32));return btoa(String.fromCharCode(...e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}const Xn=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;function Zn(e){if(typeof e.expectedVersionId!=`string`||!Xn.test(e.expectedVersionId)||typeof e.idempotencyKey!=`string`||!/^[A-Za-z0-9_-]{16,128}$/.test(e.idempotencyKey))throw new a(`invalid_input`);return{body:{expectedVersionId:e.expectedVersionId},headers:{"Idempotency-Key":e.idempotencyKey,"If-Match":`"${e.expectedVersionId}"`}}}function Qn(e){return{async getFileAccessContext(t){let n=I(t);return W(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/access-context`,{...t,params:{path:n}}),[200],e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return Object.keys(t).sort().join()===`canRead,canWrite,contentGeneration,itemId,subject,validUntil,versionId,workspaceId`&&t.workspaceId===n.workspaceId&&t.itemId===n.itemId&&typeof t.subject==`string`&&t.subject.length>0&&t.subject.length<=128&&typeof t.versionId==`string`&&Xn.test(t.versionId)&&(t.contentGeneration===null||typeof t.contentGeneration==`string`&&/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(t.contentGeneration))&&typeof t.canRead==`boolean`&&typeof t.canWrite==`boolean`&&typeof t.validUntil==`number`&&Number.isSafeInteger(t.validUntil)&&t.validUntil>Date.now()&&t.validUntil<=Date.now()+6e4})},async createFileVersionUpload(t){let n=B(t,[`workspaceId`,`itemId`,`expectedVersionId`,`byteLength`,`digest`,`idempotencyKey`],[`signal`,`contentMd5`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}}),i=Zn(n);if(typeof n.byteLength!=`number`||!Number.isSafeInteger(n.byteLength)||n.byteLength<0||n.contentMd5!==void 0&&(typeof n.contentMd5!=`string`||!/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(n.contentMd5)||n.byteLength<1||n.byteLength>8*1024*1024)||typeof n.digest!=`string`||!/^sha256:[0-9a-f]{64}$/.test(n.digest))throw new a(`invalid_input`);let o={...i.body,byteLength:n.byteLength,digest:n.digest,...n.contentMd5===void 0?{}:{contentMd5:n.contentMd5}};return W(e,r.signal,null,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/version-uploads`,{...t,params:{path:r,header:i.headers},body:o}),[200,201],t=>Re(t,o.byteLength,new URL(e.baseUrl).protocol===`http:`,o.contentMd5)&&t.itemId===r.itemId&&t.versionId!==o.expectedVersionId,!0)},async commitFileVersion(t){let n=B(t,[`workspaceId`,`itemId`,`uploadId`,`expectedVersionId`,`idempotencyKey`],[`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId}),i=Ft({workspaceId:n.workspaceId,uploadId:n.uploadId,...n.signal===void 0?{}:{signal:n.signal}}),a=Zn(n);return W(e,i.signal,null,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/version`,{...t,params:{path:{workspaceId:i.workspaceId,uploadId:i.uploadId},header:a.headers},body:a.body}),[200,202],(e,t)=>t===200?He(e,{uploadId:i.uploadId})&&e.itemId===r.itemId&&e.versionId!==a.body.expectedVersionId:Ue(e,i.uploadId)&&e.itemId===r.itemId&&e.versionId!==a.body.expectedVersionId)}}}const $n=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,er=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,tr=/^[A-Za-z0-9._:-]{1,128}$/;function nr(e,t){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let n=e;return Object.keys(n).sort().join()===`audience,contentGeneration,expectedVersionId,expiresAt,itemId,leaseUntil,revoked,sessionId,sourceVersionId,subject,workspaceId,writable`&&n.workspaceId===t&&typeof n.sessionId==`string`&&$n.test(n.sessionId)&&typeof n.itemId==`string`&&n.itemId.startsWith(`drive.item.`)&&$n.test(n.itemId.slice(11))&&typeof n.sourceVersionId==`string`&&er.test(n.sourceVersionId)&&typeof n.expectedVersionId==`string`&&er.test(n.expectedVersionId)&&typeof n.contentGeneration==`string`&&$n.test(n.contentGeneration)&&typeof n.audience==`string`&&tr.test(n.audience)&&typeof n.subject==`string`&&n.subject.length>0&&n.subject.length<=128&&typeof n.writable==`boolean`&&typeof n.revoked==`boolean`&&typeof n.leaseUntil==`number`&&Number.isSafeInteger(n.leaseUntil)&&typeof n.expiresAt==`number`&&Number.isSafeInteger(n.expiresAt)&&n.leaseUntil>0&&n.leaseUntil<=n.expiresAt}function rr(e){let t=t=>async n=>{let r=B(n,[`workspaceId`,`sessionId`],[`signal`]);if(typeof r.workspaceId!=`string`||!r.workspaceId.startsWith(`drive.workspace.`)||!$n.test(r.workspaceId.slice(16))||typeof r.sessionId!=`string`||!$n.test(r.sessionId))throw new a(`invalid_input`);let i=r.workspaceId,o=r.sessionId;return W(e,V(r.signal),null,(e,n)=>e.POST(`/api/v1/workspaces/{workspaceId}/editing-sessions/{sessionId}`,{...n,params:{path:{workspaceId:i,sessionId:o}},body:{operation:t}}),[200],e=>nr(e,i)&&e.sessionId===o)};return{async createEditingSession(t){let n=B(t,[`workspaceId`,`itemId`,`audience`,`writable`],[`sourceVersionId`,`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}});if(typeof n.audience!=`string`||!tr.test(n.audience)||typeof n.writable!=`boolean`||n.sourceVersionId!==void 0&&(typeof n.sourceVersionId!=`string`||!er.test(n.sourceVersionId)))throw new a(`invalid_input`);let i={audience:n.audience,writable:n.writable,...n.sourceVersionId===void 0?{}:{sourceVersionId:n.sourceVersionId}};return W(e,r.signal,null,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/editing-sessions`,{...t,params:{path:r},body:i}),[201],e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let{token:t,...n}=e;return typeof t==`string`&&/^drive_edit_[A-Za-z0-9_-]{43}$/.test(t)&&nr(n,r.workspaceId)&&n.itemId===r.itemId&&n.audience===i.audience&&n.writable===i.writable&&(i.sourceVersionId===void 0||n.sourceVersionId===i.sourceVersionId)})},renewEditingSession:t(`renew`),closeEditingSession:t(`close`),revokeEditingSession:t(`revoke`)}}function ir(e){if(!/^drive_edit_[A-Za-z0-9_-]{43}$/.test(e.token)||!tr.test(e.audience))throw new a(`invalid_input`);let t=e.token;return Object.freeze({...Sn({...e,getCredential:async()=>t}),authorizationScheme:`DriveEditing`,editingAudience:e.audience})}function ar(e){return Object.freeze({getFileAccessContext:e.getFileAccessContext,createDownload:e.createDownload,downloadItem:e.downloadItem,createFileVersionUpload:e.createFileVersionUpload,commitFileVersion:e.commitFileVersion,getUploadStatus:e.getUploadStatus,createUploadPartDescriptor:e.createUploadPartDescriptor,recordUploadPart:e.recordUploadPart,abortUpload:e.abortUpload})}const or=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,sr=/^[A-Za-z0-9_-]{1,128}$/,cr=/^[A-Za-z0-9_.-]+$/,lr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_pagination_cursor`,`precondition_failed`,`service_unavailable`]),ur=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_idempotency_key`,`idempotency_conflict`,`precondition_failed`,`rate_limited`,`service_unavailable`]);function dr(e){return{listOwnedItems:t=>mr(e,t),transferItemOwnership:t=>gr(e,t),archiveItem:t=>_r(e,t)}}async function fr(e,t){let n=B(t,[`workspaceId`,`ownerUserId`],[`lifecycle`,`rootsOnly`,`signal`,`maxItems`]),r=n.maxItems??500;if(typeof r!=`number`||!Number.isInteger(r)||r<1||r>500)throw new a(`invalid_input`);let{maxItems:i,...o}=n,s=[],c=null;do{let t=r-s.length,n=Math.min(50,t),i=await e.listOwnedItems({...o,limit:n,...c===null?{}:{cursor:c}});s.push(...i.data.items),c=i.data.nextCursor}while(c!==null&&s.length<r);return Object.freeze({items:Object.freeze(s),complete:c===null,nextCursor:c})}function pr(e){let t=B(e,[`workspaceId`,`ownerUserId`],[`lifecycle`,`rootsOnly`,`limit`,`cursor`,`signal`]),n=V(t.signal);if(typeof t.workspaceId!=`string`||!or.test(t.workspaceId)||typeof t.ownerUserId!=`string`||!sr.test(t.ownerUserId)||t.lifecycle!==void 0&&t.lifecycle!==`active`&&t.lifecycle!==`trashed`||t.rootsOnly!==void 0&&typeof t.rootsOnly!=`boolean`||t.limit!==void 0&&(typeof t.limit!=`number`||!Number.isInteger(t.limit)||t.limit<1||t.limit>50)||t.cursor!==void 0&&(typeof t.cursor!=`string`||t.cursor.length<1||t.cursor.length>2048||!cr.test(t.cursor)))throw new a(`invalid_input`);return{workspaceId:t.workspaceId,ownerUserId:t.ownerUserId,lifecycle:t.lifecycle??`active`,signal:n,query:{...t.lifecycle===void 0?{}:{lifecycle:t.lifecycle},...t.rootsOnly===void 0?{}:{rootsOnly:t.rootsOnly?`true`:`false`},...t.limit===void 0?{}:{limit:t.limit},...t.cursor===void 0?{}:{cursor:t.cursor}},limit:t.limit??25}}async function mr(e,t){let n=pr(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/owners/{ownerUserId}/items`,{...z(`listOwnedItems`,{params:{path:{workspaceId:n.workspaceId,ownerUserId:n.ownerUserId},query:n.query}}),...t}),[200],e=>he(e,n.ownerUserId,n.lifecycle)&&e.items.length<=n.limit&&e.items.every(e=>e.workspaceId===n.workspaceId),!1,lr)}function hr(e){let t=B(e,[`workspaceId`,`itemId`,`ownerUserId`,`includeDescendants`,`revokeVisitorGrants`,`idempotencyKey`,`ifMatch`],[`signal`]),n=L({workspaceId:t.workspaceId,itemId:t.itemId,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.ownerUserId!=`string`||!sr.test(t.ownerUserId)||typeof t.includeDescendants!=`boolean`||typeof t.revokeVisitorGrants!=`boolean`)throw new a(`invalid_input`);return{...n,body:{ownerUserId:t.ownerUserId,includeDescendants:t.includeDescendants,revokeVisitorGrants:t.revokeVisitorGrants}}}async function gr(e,t){let n=hr(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/ownership`,{...z(`transferItemOwnership`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:n.body}),...t}),[200],(e,t,r)=>ge(e,n.workspaceId,n.itemId,n.body.ownerUserId)&&j(r,e.revision),!1,ur)}async function _r(e,t){let n=L(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/archive`,{...z(`archiveItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>_e(e,n.workspaceId,n.itemId)&&j(r,e.revision),!1,ur)}const vr=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,yr=/^"drive\.sharing-policy\.v1\.(0|[1-9][0-9]{0,15})"$/,br=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`service_unavailable`]),xr=Object.freeze([...br,`precondition_failed`]);function Sr(e){return{getWorkspaceSharingPolicy:t=>Tr(e,t),updateWorkspaceSharingPolicy:t=>Er(e,t)}}function Cr(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function wr(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let n=e;return Object.keys(n).sort().join()===`canManage,externalSharing,revision,updatedAt,workspaceId`&&typeof n.workspaceId==`string`&&vr.test(n.workspaceId)&&(n.externalSharing===`allowed`||n.externalSharing===`disabled`)&&Cr(n.revision)&&(n.updatedAt===null||Cr(n.updatedAt))&&n.revision===0==(n.updatedAt===null)&&typeof n.canManage==`boolean`&&t.get(`etag`)===`"drive.sharing-policy.v1.${n.revision}"`}async function Tr(e,t){return W(e,V(B(t??{},[],[`signal`]).signal),null,(e,t)=>e.GET(`/api/v1/workspaces/current/sharing-policy`,{...z(`getWorkspaceSharingPolicy`,{params:{}}),...t}),[200],(e,t,n)=>wr(e,n),!1,br)}async function Er(e,t){let n=B(t,[`externalSharing`,`ifMatch`],[`signal`]),r=V(n.signal);if(n.externalSharing!==`allowed`&&n.externalSharing!==`disabled`||typeof n.ifMatch!=`string`||!yr.test(n.ifMatch))throw new a(`invalid_input`);let i=n.externalSharing,o=n.ifMatch;return W(e,r,412,(e,t)=>e.PUT(`/api/v1/workspaces/current/sharing-policy`,{...z(`updateWorkspaceSharingPolicy`,{params:{header:{"If-Match":o}},body:{externalSharing:i}}),...t}),[200],(e,t,n)=>wr(e,n)&&e.externalSharing===i,!1,xr)}const Dr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`service_unavailable`]),Or=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`service_unavailable`]),kr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_pagination_cursor`,`precondition_failed`,`service_unavailable`]),Ar=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`upload_recovery_required`,`service_unavailable`]),jr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`service_unavailable`]),Mr=Object.freeze([...Ar,`invalid_idempotency_key`,`idempotency_conflict`,`quota_exceeded`]),Nr=Object.freeze([...Ar,`invalid_idempotency_key`]),Pr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_idempotency_key`,`idempotency_conflict`,`precondition_failed`,`service_unavailable`]),Fr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`service_unavailable`]),Ir=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_idempotency_key`,`idempotency_conflict`,`precondition_failed`,`range_not_satisfiable`,`service_unavailable`]);function Lr(e){return Object.freeze({...Gn(e),...Qn(e),...rr(e),...dr(e),...Sr(e),registerItemRecipient:t=>oi(e,t),listItemSharingPeople:t=>si(e,t),listIncomingShares:t=>Rr(e,t),getCurrentWorkspace:t=>Wr(e,t),ensureOrganizationWorkspaceAccess:t=>Gr(e,t),listWorkspaceItems:t=>Hr(e,t),getWorkspaceUsage:t=>Ur(e,t),getCurrentWorkspaceSources:t=>Vr(e,t),getItem:t=>Kr(e,t),searchWorkspaceItems:t=>qr(e,t),listFolderChildren:t=>Jr(e,t),createFolder:t=>Yr(e,t),updateItem:t=>Xr(e,t),trashItem:t=>Zr(e,t),restoreItem:t=>Qr(e,t),deleteItem:t=>$r(e,t),listItemVersions:t=>ei(e,t),getItemVersion:t=>ti(e,t),restoreItemVersion:t=>ni(e,t),createDownload:t=>zr(e,t),downloadItem:t=>Br(e,t),listItemPermissions:t=>ri(e,t),readEffectiveItemPermissions:t=>ii(e,t),createItemPermission:t=>ai(e,t),updateItemPermission:t=>ci(e,t),revokeItemPermission:t=>li(e,t),createUpload:t=>ui(e,t),getUploadStatus:t=>di(e,t),createUploadPartDescriptor:t=>fi(e,t),recordUploadPart:t=>pi(e,t),completeUpload:t=>mi(e,t),abortUpload:t=>hi(e,t)})}async function Rr(e,t){let n=bt(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/shares/incoming`,{...z(`listIncomingShares`,{params:{query:n.query}}),...t}),[200],de,!1,kr)}async function zr(e,t){let n=wt(t);return W(e,n.signal,412,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/downloads`,{...z(`createDownload`,{params:{path:{workspaceId:n.workspaceId,itemId:n.itemId},query:n.versionId===void 0?{}:{versionId:n.versionId},header:{"Idempotency-Key":n.idempotencyKey,"Download-Method":n.method,...n.range===void 0?{}:{Range:n.range},...n.ifMatch===void 0?{}:{"If-Match":n.ifMatch},...n.ifNoneMatch===void 0?{}:{"If-None-Match":n.ifNoneMatch},...n.ifRange===void 0?{}:{"If-Range":n.ifRange}}}}),...t}),[200,202,304],(e,t)=>t===200?be(e):t===202?Se(e):e===void 0,!1,Ir)}async function Br(e,t){let n=wt(t),r=await zr(e,t);return r.status===202||r.status===304?r:An(e,r.data,n.signal)}async function Vr(e,t){return W(e,yt(t).signal,null,(e,t)=>e.GET(`/api/v1/workspaces/current/sources`,{...z(`getCurrentWorkspaceSources`,{params:{}}),...t}),[200],ve,!1,Dr)}async function Hr(e,t){let n=xt(t,!0);return W(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items`,{...z(`listWorkspaceItems`,{params:{path:{workspaceId:n.workspaceId},query:n.query}}),...t}),[200],e=>pe(e)&&e.items.length<=(n.query.limit??25)&&e.items.every((e,t,r)=>e.workspaceId===n.workspaceId&&e.lifecycleState===(n.query.view===`trash`?`trashed`:`active`)&&((n.query.view??`recent`)!==`recent`||e.modifiedAtEpochMilliseconds!==null)&&(n.query.kind===void 0||e.type===n.query.kind)&&(n.query.mediaTypes===void 0||e.type===`file`&&!!e.currentVersion&&n.query.mediaTypes.split(`,`).includes(e.currentVersion.mediaType))&&(n.query.creatorUserId===void 0||e.creatorUserId===n.query.creatorUserId)&&(t===0||((n.query.view??`recent`)===`recent`?r[t-1].modifiedAtEpochMilliseconds>e.modifiedAtEpochMilliseconds||r[t-1].modifiedAtEpochMilliseconds===e.modifiedAtEpochMilliseconds&&r[t-1].itemId<e.itemId:r[t-1].itemId<e.itemId))),!1,kr)}async function Ur(e,t){let n=xt(t,!1);return W(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/usage`,{...z(`getWorkspaceUsage`,{params:{path:{workspaceId:n.workspaceId}}}),...t}),[200],e=>fe(e)&&e.workspaceId===n.workspaceId,!1,kr)}async function Wr(e,t){return W(e,yt(t).signal,null,(e,t)=>e.GET(`/api/v1/workspaces/current`,{...z(`getCurrentWorkspace`,{params:{}}),...t}),[200],ye,!1,Dr)}async function Gr(e,t){return W(e,yt(t).signal,null,(e,t)=>e.POST(`/api/v1/workspaces/current/organization-access`,{...z(`ensureOrganizationWorkspaceAccess`,{params:{}}),...t}),[200],e=>ye(e)&&e.workspaceReference.type===`organization`,!1,Dr)}async function Kr(e,t){let n=I(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...z(`getItem`,{params:{path:R(n)}}),...t}),[200],(e,t,r)=>Ee(e,n.workspaceId,n.itemId)&&j(r,e.revision),!1,Or)}async function qr(e,t){let n=Tt(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/search`,{...z(`searchWorkspaceItems`,{params:{path:{workspaceId:n.workspaceId},query:{query:n.query,...n.limit===void 0?{}:{limit:n.limit},...n.cursor===void 0?{}:{cursor:n.cursor}}}}),...t}),[200],e=>De(e,n.workspaceId,n.query,n.limit??50),!1,kr)}async function Jr(e,t){let n=Et(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/children`,{...z(`listFolderChildren`,{params:{path:R(n),query:Ht(n)}}),...t}),[200],e=>Ce(e,n.workspaceId,n.itemId))}async function Yr(e,t){let n=Dt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/children`,{...z(`createFolder`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey}},body:{name:n.name}}),...t}),[200,201],e=>we(e)&&e.workspaceId===n.workspaceId&&e.parentItemId===n.itemId&&e.kind===`folder`&&e.name===n.name)}async function Xr(e,t){let n=Ot(t);return W(e,n.signal,409,(e,t)=>e.PATCH(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...z(`updateItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:{name:n.name,parentItemId:n.parentItemId}}),...t}),[200],(e,t,r)=>Te(e,n.workspaceId,n.itemId,`active`)&&e.name===n.name&&e.parentItemId===n.parentItemId&&j(r,e.revision),!1,Pr)}async function Zr(e,t){let n=L(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/trash`,{...z(`trashItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>Te(e,n.workspaceId,n.itemId,`trashed`)&&j(r,e.revision),!1,Pr)}async function Qr(e,t){let n=L(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/restore`,{...z(`restoreItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>Te(e,n.workspaceId,n.itemId,`active`)&&j(r,e.revision),!1,Pr)}async function $r(e,t){let n=L(t);return W(e,n.signal,409,(e,t)=>e.DELETE(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...z(`deleteItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200,202],(e,t,r)=>Te(e,n.workspaceId,n.itemId,`deleting`)&&j(r,e.revision),!1,Pr)}async function ei(e,t){let n=Et(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions`,{...z(`listItemVersions`,{params:{path:R(n),query:Ht(n)}}),...t}),[200],e=>Me(e,n.limit??50),!1,Fr)}async function ti(e,t){let n=Ct(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}`,{...z(`getItemVersion`,{params:{path:{...R(n),versionId:n.versionId}}}),...t}),[200],e=>Ke(e,n.workspaceId,n.itemId,n.versionId),!1,Fr)}async function ni(e,t){let n=kt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}/restore`,{...z(`restoreItemVersion`,{params:{path:{...R(n),versionId:n.versionId},header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>Ne(e,n.versionId)&&j(r,e.itemRevision),!1,Pr)}async function ri(e,t){let n=Et(t);return W(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions`,{...z(`listItemPermissions`,{params:{path:R(n),query:Ht(n)}}),...t}),[200],(e,t,r)=>Pe(e,r,n.itemId))}async function ii(e,t){let n=I(t);return W(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/effective`,{...z(`readEffectiveItemPermissions`,{params:{path:R(n)}}),...t}),[200],e=>Le(e,n.itemId))}async function ai(e,t){let n=At(t);return W(e,n.signal,412,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions`,{...z(`createItemPermission`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:{grantee:n.grantee,actions:n.actions,expiresAtEpochMilliseconds:n.expiresAtEpochMilliseconds}}),...t}),[200,201],(e,t,r)=>Ie(e,n.itemId)&&(t===201&&e.outcome===`committed`||t===200&&e.outcome===`replayed`)&&(t===200||e.grant.availability!==`revoked`)&&Ye(r))}async function oi(e,t){let n=jt(t);return W(e,n.signal,412,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/sharing`,{...z(`registerItemRecipient`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:{email:n.email,role:n.role,...n.expectedRecipientUserId===void 0?{}:{expectedRecipientUserId:n.expectedRecipientUserId}}}),...t}),[200,201],(e,t,r)=>Ie(e,n.itemId)&&(n.expectedRecipientUserId===void 0||e.grant.grantee.type===`user`&&e.grant.grantee.userId===n.expectedRecipientUserId)&&(t===201&&e.outcome===`committed`||t===200&&e.outcome===`replayed`)&&(t===200||e.grant.availability!==`revoked`)&&Ye(r),!1,[...kr,`recipient_unavailable`,`registration_conflict`,`rate_limited`,`idempotency_conflict`,`invalid_idempotency_key`])}async function si(e,t){let n=Et(t);return W(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/sharing/people`,{...z(`listItemSharingPeople`,{params:{path:R(n),query:Ht(n)}}),...t}),[200],(e,t,r)=>Fe(e,r,n.itemId))}async function ci(e,t){let n=Nt(t),r={};return n.actions!==void 0&&(r.actions=n.actions),n.expiresAtEpochMilliseconds!==void 0&&(r.expiresAtEpochMilliseconds=n.expiresAtEpochMilliseconds),W(e,n.signal,412,(e,t)=>e.PATCH(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/{grantId}`,{...z(`updateItemPermission`,{params:{path:{...R(n),grantId:n.grantId},header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:r}),...t}),[200],(e,t,r)=>Ie(e,n.itemId,n.grantId)&&e.grant.availability!==`revoked`&&Ye(r))}async function li(e,t){let n=Mt(t);return W(e,n.signal,412,(e,t)=>e.DELETE(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/{grantId}`,{...z(`revokeItemPermission`,{params:{path:{...R(n),grantId:n.grantId},header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>Ie(e,n.itemId,n.grantId)&&e.grant.availability===`revoked`&&p(r.get(`drive-permission-collection-etag`)??``)!==void 0&&r.get(`drive-permission-grant-etag`)===null)}async function ui(e,t){let n=Pt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads`,{...z(`createUpload`,{params:{path:{workspaceId:n.workspaceId},header:{"Idempotency-Key":n.idempotencyKey}},body:{parentItemId:n.parentItemId,expectedByteLength:n.expectedByteLength,...n.contentMd5===void 0?{}:{contentMd5:n.contentMd5},displayFilename:n.displayFilename,mediaType:n.mediaType,callerDeclaredContentDigest:n.callerDeclaredContentDigest,protectionClassification:n.protectionClassification}}),...t}),[200,201],t=>Re(t,n.expectedByteLength,new URL(e.baseUrl).protocol===`http:`,n.contentMd5),!0,Mr)}async function di(e,t){let n=Ft(t),r=n.afterPartNumber??0,i=n.limit??100;return W(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}`,{...z(`getUploadStatus`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId},query:{...n.afterPartNumber===void 0?{}:{afterPartNumber:String(n.afterPartNumber)},...n.limit===void 0?{}:{limit:String(n.limit)}}}}),...t}),[200],e=>ze(e,r,i)&&e.uploadId===n.uploadId,!1,jr)}async function fi(e,t){let n=It(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/parts`,{...z(`createUploadPartDescriptor`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId}},body:{partNumber:n.partNumber,checksumSha256:n.checksumSha256,contentMd5:n.contentMd5}}),...t}),[200],t=>Be(t,n.partNumber,new URL(e.baseUrl).protocol===`http:`,n.contentMd5),!1,Ar)}async function pi(e,t){let n=Lt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/parts/{partNumber}`,{...z(`recordUploadPart`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId,partNumber:String(n.partNumber)}},body:{expectedUploadRevision:n.expectedUploadRevision,byteLength:n.byteLength,etag:n.etag,checksumSha256:n.checksumSha256}}),...t}),[200],e=>Ve(e,n.partNumber,n.expectedUploadRevision),!1,Ar)}async function mi(e,t){let n=zt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/complete`,{...z(`completeUpload`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId},query:n.verification===`inline`?{verification:`inline`}:{},header:{"Idempotency-Key":n.idempotencyKey}}}),...t}),[200,202],(e,t)=>t===202?Ue(e,n.uploadId):He(e,{uploadId:n.uploadId}),!1,Nr)}async function hi(e,t){let n=Bt(t);return W(e,n.signal,409,(e,t)=>e.DELETE(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}`,{...z(`abortUpload`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId}}}),...t}),[204],null,!1,Ar)}const gi=e=>e/2**32|0,_i=e=>e>>>0;function vi(e,t,n,r){let i=gi(n),a=_i(n);e.setUint32(t,r?a:i,r),e.setUint32(t+4,r?i:a,r)}function yi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}const bi=e=>e?`"${e}" `:``;function xi(e,t=``){if(typeof e!=`number`)throw TypeError(bi(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(bi(t)+`expected integer >= 0, got `+e);return e}function Si(e,t,n=``){if(yi(e)&&(t===void 0||e.length===t))return e;t!==void 0&&xi(t,`length`);let r=yi(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=bi(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}const Ci=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`"${t}" `)+`expected object, got type=`+typeof e)};function wi(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function Ti(e,t){Si(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function Ei(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Di(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function X(e,t){return e<<32-t|e>>>t}function Oi(e,t){return e<<t|e>>>32-t>>>0}const ki=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,Ai=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function ji(e){if(Si(e),ki)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=Ai[e[n]];return t}function Mi(e,t,n=`opts`){return Ci(e,`defaults`),t!==void 0&&Ci(t,n),Object.assign(e,t)}function Ni(e,t={}){if(typeof e!=`function`)throw TypeError(`"hashCons" expected function, got type=`+typeof e);t=Mi({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}const Pi=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Fi(e,t,n){return e&t^~e&n}function Ii(e,t,n){return e&t^e&n^t&n}var Li=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Di(this.buffer)}update(e){wi(this),Si(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=Di(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){wi(this),Ti(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,t.fill(0,a),this.padOffset>r-a&&(this.process(n,0),t.fill(0)),vi(n,r-8,this.length*8,i),this.process(n,0),this.roundClean();let o=e===t?n:Di(e),s=this.outputLen,c=s/4,l=this.get();if(s%4||c>l.length)throw Error(`invalid outputLen`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}};const Ri=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),zi=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Z=new Uint32Array(64);var Bi=class extends Li{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)Z[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=Z[e-15],n=Z[e-2],r=X(t,7)^X(t,18)^t>>>3,i=X(n,17)^X(n,19)^n>>>10;Z[e]=i+Z[e-7]+r+Z[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=X(o,6)^X(o,11)^X(o,25),u=l+t+Fi(o,s,c)+zi[e]+Z[e]|0,d=(X(n,2)^X(n,13)^X(n,22))+Ii(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){Ei(Z)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ei(this.buffer)}},Vi=class extends Bi{constructor(){super(32,Ri)}};const Hi=Ni(()=>new Vi,Pi(1)),Ui=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),Wi=2**32,Gi=Array.from({length:64},(e,t)=>Math.floor(Wi*Math.abs(Math.sin(t+1)))),Ki=Ui.slice(0,4),qi=new Uint32Array(16),Ji=(()=>{let e=[[7,12,17,22],[5,9,14,20],[4,11,16,23],[6,10,15,21]];return Uint8Array.from({length:64},(t,n)=>e[Math.floor(n/16)][n%4])})();var Yi=class extends Li{A=Ki[0]|0;B=Ki[1]|0;C=Ki[2]|0;D=Ki[3]|0;constructor(){super(64,16,8,!0)}get(){let{A:e,B:t,C:n,D:r}=this;return[e,t,n,r]}set(e,t,n,r){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)qi[n]=e.getUint32(t,!0);let{A:n,B:r,C:i,D:a}=this;for(let e=0;e<64;e++){let t,o;e<16?(t=Fi(r,i,a),o=e):e<32?(t=Fi(a,r,i),o=(5*e+1)%16):e<48?(t=r^i^a,o=(3*e+5)%16):(t=i^(r|~a),o=7*e%16),t=t+n+Gi[e]+qi[o],n=a,a=i,i=r,r+=Oi(t,Ji[e])}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,this.set(n,r,i,a)}roundClean(){Ei(qi)}destroy(){this.destroyed=!0,this.set(0,0,0,0),Ei(this.buffer)}};const Xi=Ni(()=>new Yi),Q=32*1024*1024,Zi=8*1024*1024,Qi=256*1024;async function $i(e,t,n){let r=Vt(t),i=Math.ceil(r.byteLength/Q);$(r.onProgress,`preparing`,0,r.byteLength,0,i);let o;try{let t=await ia(r.source,r.byteLength,i,r.signal),s=await n.createUpload({workspaceId:r.workspaceId,parentItemId:r.parentItemId,expectedByteLength:r.byteLength,displayFilename:r.displayFilename,mediaType:r.mediaType,callerDeclaredContentDigest:t.callerDeclaredContentDigest,...r.byteLength>0&&r.byteLength<=Zi?{contentMd5:t.partMd5s[0]}:{},protectionClassification:r.protectionClassification,idempotencyKey:r.idempotencyKey,...r.signal===void 0?{}:{signal:r.signal}});if(o=s.data,oa(o,r.byteLength,i,s.status,s.requestId),o.mode===`presigned-single`){let i=o.singleUpload;if(!i)throw new a(`invalid_response`);let s=i.state===`uploading`?0:r.byteLength;if($(r.onProgress,`uploading`,0,r.byteLength,0,1),i.state===`uploading`&&i.descriptor&&i.descriptor.expiresAtEpochMilliseconds>Date.now()){if(i.descriptor.headers[`content-md5`]!==t.partMd5s[0]||i.descriptor.headers[`content-type`]!==r.mediaType)throw new a(`invalid_response`);try{await aa(e,i.descriptor,r.source,r.signal),s=r.byteLength}catch(e){if(!(e instanceof a)||r.signal?.aborted||![`network_error`,`timeout`].includes(e.code)&&e.status!==412)throw e}}$(r.onProgress,`completing`,s,r.byteLength,+!!s,1);let c=await ra(n,r,o,t);return c.data.state===`verifying`&&$(r.onProgress,`verifying`,r.byteLength,r.byteLength,1,1),c}let c=await ta(n,r,o,t);if($(r.onProgress,`uploading`,c.confirmedByteLength,r.byteLength,c.confirmedParts.size,i),c.readyResult)return $(r.onProgress,`completing`,c.confirmedByteLength,r.byteLength,c.confirmedParts.size,i),c.readyResult;let l=c.revision,u=c.confirmedByteLength,d=c.confirmedParts.size;if(c.lifecycle===`uploading`)for(let s of ea(o.partCount,c.confirmedParts)){let c=s-1;ga(r.signal);let f=c*o.partByteLength,p=Math.min(f+o.partByteLength,r.byteLength),m=p-f,h=t.partChecksums[c];if(!h)throw new a(`invalid_response`);let g=await n.createUploadPartDescriptor({workspaceId:r.workspaceId,uploadId:o.uploadId,partNumber:s,checksumSha256:h,contentMd5:t.partMd5s[c],...r.signal===void 0?{}:{signal:r.signal}}),_=g.data;if(_.expectedByteLength!==m||_.expiresAtEpochMilliseconds>o.expiresAtEpochMilliseconds)throw new a(`invalid_response`,{status:g.status,requestId:g.requestId});let v=await aa(e,_,pa(r.source,f,p,m),r.signal);l=await na(n,r,o,s,l,m,v,h),u+=m,d+=1,$(r.onProgress,`uploading`,u,r.byteLength,d,i)}$(r.onProgress,`completing`,u,r.byteLength,d,i);let f=await ra(n,r,o,t);return f.data.state===`verifying`&&$(r.onProgress,`verifying`,u,r.byteLength,d,i),f}catch(e){throw r.signal?.aborted&&o&&await ma(n,r.workspaceId,o.uploadId),e instanceof a?e:r.signal?.aborted?new a(`aborted`):new a(`invalid_input`)}}function*ea(e,t){for(let n=1;n<=e;n+=1)t.has(n)||(yield n)}async function ta(e,t,n,r){let i=new Set,o=0,s=0,c,l,u;for(let d=0;d<100;d+=1){let f=await e.getUploadStatus({workspaceId:t.workspaceId,uploadId:n.uploadId,afterPartNumber:s,limit:100,...t.signal===void 0?{}:{signal:t.signal}}),p=f.data;sa(p,n),c?ca(p,c):(c=p,l=f.requestId);for(let e of p.confirmedParts){let n=r.partChecksums[e.partNumber-1];if(!n||e.checksumSha256!==n||i.has(e.partNumber))throw new a(`invalid_response`,{status:f.status,requestId:f.requestId});i.add(e.partNumber),o+=fa(t.byteLength,e.partNumber)}if(p.lifecycle===`ready`&&p.ready&&(la(p.ready,n,t,r,f.requestId),u=da(f,p.ready)),p.nextAfterPartNumber===null)break;if(d===99)throw new a(`invalid_response`,{status:f.status,requestId:f.requestId});s=p.nextAfterPartNumber}if(!c||n.mode===`presigned-multipart`&&[`completing`,`provider-completed`,`verifying`,`ready`].includes(c.lifecycle)&&i.size!==n.partCount)throw new a(`invalid_response`);return ua(c.lifecycle,l),Object.freeze({revision:c.revision,confirmedParts:i,confirmedByteLength:o,lifecycle:c.lifecycle,...u===void 0?{}:{readyResult:u}})}async function na(e,t,n,r,i,o,s,c){let l=i=>e.recordUploadPart({workspaceId:t.workspaceId,uploadId:n.uploadId,partNumber:r,expectedUploadRevision:i,byteLength:o,etag:s,checksumSha256:c,...t.signal===void 0?{}:{signal:t.signal}});try{return(await l(i)).data.revision}catch(i){if(!ha(i)||t.signal?.aborted)throw i;let o=await e.getUploadStatus({workspaceId:t.workspaceId,uploadId:n.uploadId,afterPartNumber:r-1,limit:1,...t.signal===void 0?{}:{signal:t.signal}}),s=o.data;sa(s,n),ua(s.lifecycle,o.requestId);let u=s.confirmedParts.find(e=>e.partNumber===r);if(u){if(u.checksumSha256!==c)throw new a(`invalid_response`,{status:o.status,requestId:o.requestId});return s.revision}if(s.lifecycle!==`uploading`)throw new a(`precondition_failed`);return(await l(s.revision)).data.revision}}async function ra(e,t,n,r){try{let i=await e.completeUpload({workspaceId:t.workspaceId,uploadId:n.uploadId,idempotencyKey:t.completionIdempotencyKey,verification:t.verification,...t.signal===void 0?{}:{signal:t.signal}});if(i.data.state===`ready`)la(i.data,n,t,r,i.requestId);else if(i.data.itemId!==n.itemId||i.data.versionId!==n.versionId||i.data.uploadId!==n.uploadId||i.data.totalByteLength!==t.byteLength)throw new a(`invalid_response`);return i}catch(i){if(!ha(i)||t.signal?.aborted)throw i;let a=await e.getUploadStatus({workspaceId:t.workspaceId,uploadId:n.uploadId,afterPartNumber:0,limit:1,...t.signal===void 0?{}:{signal:t.signal}}),o=a.data;if(sa(o,n),o.lifecycle!==`ready`||!o.ready)throw i;return la(o.ready,n,t,r,a.requestId),da(a,o.ready)}}async function ia(e,t,n,r){let i=Hi.create(),o=[],s=[];for(let c=0;c<n;c+=1){ga(r);let n=c*Q,l=Math.min(n+Q,t),u=Hi.create(),d=Xi.create();for(let t=n;t<l;t+=Qi){ga(r);let n=Math.min(t+Qi,l),o=pa(e,t,n,n-t),s=r?await On(o.arrayBuffer(),r):await o.arrayBuffer();if(s.byteLength!==n-t)throw new a(`invalid_input`);let c=new Uint8Array(s);i.update(c),u.update(c),d.update(c)}o.push(_a(u.digest())),s.push(_a(d.digest()))}return Object.freeze({callerDeclaredContentDigest:`sha256:${ji(i.digest())}`,partChecksums:Object.freeze(o),partMd5s:Object.freeze(s)})}async function aa(e,t,n,r){let i=t.expiresAtEpochMilliseconds-Date.now();if(i<1)throw new a(`invalid_response`);let o=wn(r,Math.min(e.timeoutMilliseconds,i)),s;try{if(s=await On(e.fetchImplementation(t.url,{method:t.method,body:n,headers:t.headers,credentials:`omit`,cache:`no-store`,redirect:`manual`,referrerPolicy:`no-referrer`,signal:o.signal}),o.signal),!(s instanceof Response))throw new a(`invalid_response`);if(s.status>=300&&s.status<400)throw new a(`invalid_response`,{status:s.status});let r=s.headers.get(`etag`),i=s.headers.get(`content-md5`),c=i===null||i===t.headers[`content-md5`];if(s.status<200||s.status>299||!va(r)||!c||!kn(t.headers,s))throw new a(`invalid_response`,{status:s.status});return r}catch(e){throw o.didTimeout()?new a(`timeout`):r?.aborted?new a(`aborted`):e instanceof a?e:new a(`network_error`)}finally{o.dispose(),s?.body?.cancel().catch(()=>{})}}function oa(e,t,n,r,i){let o=t===0?`server-mediated-zero-byte`:t<=Zi?`presigned-single`:`presigned-multipart`;if(e.mode!==o&&!(r===200&&t>0&&e.mode===`presigned-multipart`)||e.partByteLength!==Q||e.partCount!==n||e.expiresAtEpochMilliseconds<=Date.now())throw new a(`invalid_response`,{status:r,requestId:i})}function sa(e,t){if(e.itemId!==t.itemId||e.versionId!==t.versionId||e.uploadId!==t.uploadId||e.mode!==t.mode||e.revision<t.revision||e.partPolicy.partByteLength!==t.partByteLength||e.partPolicy.partCount!==t.partCount||e.partPolicy.maxParts!==1e4||e.expiresAtEpochMilliseconds!==t.expiresAtEpochMilliseconds)throw new a(`invalid_response`)}function ca(e,t){if(e.itemId!==t.itemId||e.versionId!==t.versionId||e.uploadId!==t.uploadId||e.mode!==t.mode||e.lifecycle!==t.lifecycle||e.revision!==t.revision||e.partPolicy.partByteLength!==t.partPolicy.partByteLength||e.partPolicy.partCount!==t.partPolicy.partCount||e.partPolicy.maxParts!==t.partPolicy.maxParts||e.expiresAtEpochMilliseconds!==t.expiresAtEpochMilliseconds||JSON.stringify(e.ready)!==JSON.stringify(t.ready))throw new a(`invalid_response`)}function la(e,t,n,r,i){if(e.itemId!==t.itemId||e.versionId!==t.versionId||e.uploadId!==t.uploadId||e.byteLength!==n.byteLength||e.callerDeclaredContentDigest!==r.callerDeclaredContentDigest||e.displayFilename!==n.displayFilename||e.mediaType!==n.mediaType)throw new a(`invalid_response`,{status:200,requestId:i})}function ua(e,t){if(e===`initiating`||e===`recovery-required`)throw new a(`upload_recovery_required`,{status:409,...t===void 0?{}:{requestId:t}});if(e===`aborting`||e===`aborted`||e===`failed`)throw new a(`precondition_failed`,{status:409,...t===void 0?{}:{requestId:t}})}function da(e,t){return Object.freeze({data:t,status:e.status,requestId:e.requestId,validators:e.validators})}function fa(e,t){return Math.min(Q,e-(t-1)*Q)}function pa(e,t,n,r){try{let i=e.slice(t,n);if(!(i instanceof Blob)||i.size!==r)throw new a(`invalid_input`);return i}catch(e){throw e instanceof a?e:new a(`invalid_input`)}}function $(e,t,n,r,i,a){if(!e)return;let o=Object.freeze({phase:t,confirmedByteLength:n,totalByteLength:r,confirmedPartCount:i,totalPartCount:a});try{e(o)}catch{}}async function ma(e,t,n){let r=new AbortController,i=setTimeout(()=>r.abort(),5e3);try{await e.abortUpload({workspaceId:t,uploadId:n,signal:r.signal})}catch{}finally{clearTimeout(i)}}function ha(e){return e instanceof a&&(e.code===`network_error`||e.code===`timeout`||e.code===`invalid_response`)}function ga(e){if(e?.aborted)throw new a(`aborted`)}function _a(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t)}function va(e){return e!==null&&e.length>=1&&e.length<=1024&&/^[\x20-\x7e]+$/.test(e)}async function ya(e,t,n,r){let i=B(t,[`workspaceId`,`itemId`,`expectedVersionId`,`source`,`idempotencyKey`,`completionIdempotencyKey`],[`signal`,`onProgress`]),o=I({workspaceId:i.workspaceId,itemId:i.itemId,...i.signal===void 0?{}:{signal:i.signal}});if(!(i.source instanceof Blob)||typeof i.expectedVersionId!=`string`||!/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(i.expectedVersionId)||typeof i.idempotencyKey!=`string`||!/^[A-Za-z0-9_-]{16,128}$/.test(i.idempotencyKey)||typeof i.completionIdempotencyKey!=`string`||!/^[A-Za-z0-9_-]{16,128}$/.test(i.completionIdempotencyKey)||i.onProgress!==void 0&&typeof i.onProgress!=`function`)throw new a(`invalid_input`);let s=i.expectedVersionId,c=r;if(!c){let[e,t]=await Promise.all([n.getItem(o),n.getItemVersion({...o,versionId:s})]);if(e.data.type!==`file`||!e.data.parentId)throw new a(`invalid_input`);c={parentItemId:e.data.parentId,displayFilename:t.data.displayFilename,mediaType:t.data.mediaType,protectionClassification:t.data.protectionClassification}}let l=i.source.slice(0,i.source.size,c.mediaType),u;try{return await $i(e,{workspaceId:o.workspaceId,parentItemId:c.parentItemId,source:l,displayFilename:c.displayFilename,mediaType:c.mediaType,protectionClassification:c.protectionClassification,idempotencyKey:i.idempotencyKey,completionIdempotencyKey:i.completionIdempotencyKey,...o.signal===void 0?{}:{signal:o.signal},...i.onProgress===void 0?{}:{onProgress:i.onProgress}},{...n,async createUpload(e){let t=await n.createFileVersionUpload({...o,expectedVersionId:s,digest:e.callerDeclaredContentDigest,byteLength:l.size,...e.contentMd5===void 0?{}:{contentMd5:e.contentMd5},idempotencyKey:e.idempotencyKey});return u=t.data.uploadId,t},async completeUpload(e){return n.commitFileVersion({...o,expectedVersionId:s,uploadId:e.uploadId,idempotencyKey:e.idempotencyKey})}})}catch(t){if(e.authorizationScheme!==`DriveEditing`&&t instanceof a&&t.code===`precondition_failed`&&u)try{await n.abortUpload({workspaceId:o.workspaceId,uploadId:u,signal:AbortSignal.timeout(5e3)})}catch{}throw t}}function ba(e){let t=ir(e),n=Lr(t);return Object.freeze({...ar(n),uploadFileVersion:e=>{let{metadata:r,...i}=e;return ya(t,i,n,r)}})}function xa(e){let t=Sn(e),n=Lr(t);return Object.freeze({...n,uploadFile:e=>$i(t,e,n),uploadFileVersion:e=>ya(t,e,n)})}export{fr as collectOwnedItems,xa as createDriveClient,ba as createDriveEditingClient,Kn as createDriveVisitorClient,Yn as createVisitorSessionToken};
1
+ const e=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`recipient_unavailable`,`registration_conflict`,`rate_limited`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_pagination_cursor`,`invalid_idempotency_key`,`precondition_failed`,`range_not_satisfiable`,`idempotency_conflict`,`quota_exceeded`,`upload_recovery_required`,`service_unavailable`,`internal_error`]),t=Object.freeze([`upload_admission_saturated`,`upload_admission_stalled`,`ownership_unchanged`,`ownership_successor_not_member`,`ownership_restricted_items`,`ownership_subtree_too_large`,`external_sharing_disabled`,`unspecified`]);function n(e){return typeof e==`string`&&t.includes(e)}const r=Object.freeze({authentication_required:`Authentication is required.`,identity_authority_unavailable:`Authentication is temporarily unavailable.`,recipient_unavailable:`The recipient is unavailable.`,registration_conflict:`The recipient could not be confirmed.`,rate_limited:`Too many requests.`,permission_denied:`The requested action is not permitted.`,resource_not_found:`The requested resource was not found.`,invalid_request:`The request is invalid.`,invalid_pagination_cursor:`The pagination cursor is invalid.`,invalid_idempotency_key:`The idempotency key is invalid.`,precondition_failed:`The request precondition failed.`,range_not_satisfiable:`The requested byte range is not satisfiable.`,idempotency_conflict:`The idempotency key conflicts with an earlier request.`,quota_exceeded:`The workspace storage quota would be exceeded.`,upload_recovery_required:`The upload requires recovery before it can continue.`,service_unavailable:`The service is temporarily unavailable.`,internal_error:`The request could not be completed.`}),i=Object.freeze({invalid_input:`The Drive SDK input is invalid.`,credential_unavailable:`A Drive credential could not be obtained.`,network_error:`The Drive request could not reach the service.`,timeout:`The Drive request timed out.`,aborted:`The Drive request was aborted.`,invalid_response:`Drive returned an invalid response.`});var a=class extends Error{code;status;requestId;details;constructor(e,t={}){super(e in r?r[e]:i[e]),this.name=`DriveError`,this.code=e,this.status=t.status??null,this.requestId=t.requestId??null,this.details=Object.freeze(n(t.reason)?{reason:t.reason}:{})}};const o=/^[A-Za-z0-9_-]{16,128}$/,s=/^"drive\.permission-collection\.v1\.(0|[1-9][0-9]*)"$/,c=/^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/,l=/^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/,u=/^"drive\.item\.v1\.(0|[1-9][0-9]*)"$/;async function d(e,t,n,r,i,o,s){let c=te(e.headers.get(`x-request-id`));if(c===null)throw y(e),new a(`invalid_response`,{status:e.status});if(!r.includes(e.status))throw await g(e,c,t,n,o,s);if(e.status===304){let t=e.headers.get(`content-length`),n=e.headers.get(`etag`),r=e.status;if(e.body!==null||t!==null&&t!==`0`||e.headers.has(`content-type`)||n===null||!/^"[\x21\x23-\x7e]{1,1022}"$/.test(n)||!i(void 0,r,e.headers))throw y(e),new a(`invalid_response`,{status:r,requestId:c});return Object.freeze({data:void 0,status:r,requestId:c,validators:Object.freeze({etag:n})})}let{value:l}=await v(e,262144,e.status,c,t),u=e.status;if(!i(l,u,e.headers))throw new a(`invalid_response`,{status:u,requestId:c});return Object.freeze({data:l,status:u,requestId:c,validators:re(e.headers)})}async function f(e,t,n,r,i){let o=te(e.headers.get(`x-request-id`));if(o===null)throw y(e),new a(`invalid_response`,{status:e.status});if(!r.includes(e.status))throw await g(e,o,t,n,!1,i);let s=e.headers.get(`content-length`);if(e.body!==null||s!==null&&s!==`0`||e.headers.has(`content-type`))throw y(e),new a(`invalid_response`,{status:e.status,requestId:o});return Object.freeze({data:void 0,status:e.status,requestId:o,validators:Object.freeze({})})}function p(e){let t=s.exec(e);if(!t)return;let n=Number(t[1]);return Number.isSafeInteger(n)?n:void 0}function m(e){let t=c.exec(e);if(!t)return;let n=Number(t[1]),r=Number(t[2]);return Number.isSafeInteger(n)&&Number.isSafeInteger(r)?[n,r]:void 0}function h(e){let t=u.exec(e);if(!t)return;let n=Number(t[1]);return Number.isSafeInteger(n)?n:void 0}async function g(t,i,s,c,l,u){let d;try{d=await v(t,16384,t.status,i,s)}catch(e){return e instanceof a&&e.code===`aborted`?e:new a(`invalid_response`,{status:t.status,requestId:i})}let f=d.value;if(!b(f,[`error`])||!b(f.error,[`code`,`message`,`requestId`,`details`]))return new a(`invalid_response`,{status:t.status,requestId:i});let p=f.error,m=p.details,h=b(m,[`reason`])?m.reason:void 0;return typeof p.code!=`string`||!e.includes(p.code)||p.message!==r[p.code]||!o.test(String(p.requestId))||p.requestId!==i||!(b(m,[])||n(h))||!_(p.code,t.status,c,l,u)||d.text!==JSON.stringify(f)?new a(`invalid_response`,{status:t.status,requestId:i}):new a(p.code,{status:t.status,requestId:p.requestId,...n(h)?{reason:h}:{}})}function _(e,t,n,r,i){return i&&!i.includes(e)||e===`quota_exceeded`&&!r?!1:{authentication_required:[401],identity_authority_unavailable:[503],recipient_unavailable:[404],registration_conflict:[409],rate_limited:[429],permission_denied:[403],resource_not_found:[404],invalid_request:[422],invalid_pagination_cursor:[422],invalid_idempotency_key:[422],precondition_failed:n===null?[]:[n],range_not_satisfiable:[416],idempotency_conflict:[409],quota_exceeded:[409],upload_recovery_required:[409],service_unavailable:[503],internal_error:[500]}[e].includes(t)}async function v(e,t,n,r,i){if(!e.body)throw new a(`invalid_response`,{status:n,requestId:r});let o=e.body.getReader(),s=new TextDecoder(`utf-8`,{fatal:!0}),c=0,l=0,u=``,d=e.headers.get(`content-length`);if(d!==null&&(!/^(?:0|[1-9][0-9]*)$/.test(d)||Number(d)>t))throw o.cancel().catch(()=>{}),new a(`invalid_response`,{status:n,requestId:r});let f=new AbortController,p=setTimeout(()=>f.abort(),5e3);try{for(;;){if(i?.aborted)throw new a(`aborted`);let{done:e,value:d}=await ee(o,i,f.signal);if(e)break;if(l+=1,c+=d.byteLength,l>256||c>t)throw new a(`invalid_response`,{status:n,requestId:r});u+=s.decode(d,{stream:!0})}return u+=s.decode(),{value:JSON.parse(u),text:u}}catch(e){throw e instanceof a?e.code===`aborted`||i?.aborted?new a(`aborted`):e:new a(`invalid_response`,{status:n,requestId:r})}finally{clearTimeout(p),o.cancel().catch(()=>{})}}async function ee(e,t,n){if(t?.aborted)throw new a(`aborted`);if(n.aborted)throw new a(`invalid_response`);let r=()=>{},i=()=>{},o=new Promise((e,n)=>{if(!t)return;let i=()=>n(new a(`aborted`));t.addEventListener(`abort`,i,{once:!0}),r=()=>t.removeEventListener(`abort`,i)}),s=new Promise((e,t)=>{let r=()=>t(new a(`invalid_response`));n.addEventListener(`abort`,r,{once:!0}),i=()=>n.removeEventListener(`abort`,r)});try{return await Promise.race([e.read(),o,s])}finally{r(),i()}}function y(e){e.body?.cancel().catch(()=>{})}function te(e){return e!==null&&o.test(e)?e:null}const ne=/^"drive\.sharing-policy\.v1\.(0|[1-9][0-9]{0,15})"$/;function re(e){let t=e.get(`etag`),n=e.get(`drive-permission-collection-etag`),r=e.get(`drive-permission-grant-etag`);return Object.freeze({...t!==null&&(l.test(t)||ne.test(t)||h(t)!==void 0)?{etag:t}:{},...n!==null&&p(n)!==void 0?{permissionCollectionEtag:n}:{},...r!==null&&m(r)!==void 0?{permissionGrantEtag:r}:{}})}function b(e,t){return typeof e!=`object`||!e||Array.isArray(e)?!1:Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}const x=/^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,S=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,C=/^drive\.volume\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ie=/^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,w=/^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,T=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,E=/^drive\.retrieval\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,D=/^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/,O=/^[A-Za-z0-9_-]{1,128}$/,k=/^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/,ae=/^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/,A=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:read`,`items:update`]),oe=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:manage`,`items:permissions:read`,`items:update`]),se=33554432e4,ce=32*1024*1024,le=/^sha256:[0-9a-f]{64}$/,ue=new TextEncoder;function de(e){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>50||e.nextCursor!==null&&(typeof e.nextCursor!=`string`||e.nextCursor.length<1||e.nextCursor.length>2048||!/^[A-Za-z0-9_.-]+$/.test(e.nextCursor))||e.items.length===0&&e.nextCursor!==null)return!1;let t=``;for(let n of e.items){if(!P(n,[`workspaceId`,`itemId`])||typeof n.workspaceId!=`string`||!S.test(n.workspaceId)||typeof n.itemId!=`string`||!x.test(n.itemId))return!1;let e=`${n.workspaceId}/${n.itemId}`;if(t&&t>=e)return!1;t=e}return!0}function fe(e){if(!P(e,[`workspaceId`,`provider`,`usedBytes`,`reservedBytes`,`limitBytes`,`availableBytes`,`accounting`,`reservedBytesIncludeUnresolvedUploads`,`unresolvedReservedBytes`,`warnings`])||typeof e.workspaceId!=`string`||!S.test(e.workspaceId)||e.provider!==`managed`||e.accounting!==`current-versions-and-reservations`||e.reservedBytesIncludeUnresolvedUploads!==!0||!Array.isArray(e.warnings)||e.warnings.length>1||e.warnings.some(e=>e!==`unresolved-archive-ownership`)||![e.usedBytes,e.reservedBytes,e.limitBytes,e.availableBytes,e.unresolvedReservedBytes].every(e=>typeof e==`string`&&/^(0|[1-9][0-9]{0,18})$/.test(e)))return!1;let t=BigInt(e.limitBytes)-BigInt(e.usedBytes)-BigInt(e.reservedBytes),n=BigInt(e.availableBytes)===(t>0n?t:0n)&&BigInt(e.unresolvedReservedBytes)<=BigInt(e.reservedBytes)&&(e.unresolvedReservedBytes===`0`||e.warnings.length===1);return n&&Object.freeze(e.warnings),n}function pe(e){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>50||!(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length>0&&e.nextCursor.length<=2048&&/^[A-Za-z0-9_.-]+$/.test(e.nextCursor))||e.items.length===0&&e.nextCursor!==null)return!1;let t=new Set,n=e.items.every(e=>{if(!P(e,[`workspaceId`,`itemId`,`parentId`,`type`,`name`,`lifecycleState`,`revision`,`currentVersion`,`volumeId`,`provider`,`createdAtEpochMilliseconds`,`modifiedAtEpochMilliseconds`,`creatorUserId`,`etag`,`trashedAtEpochMilliseconds`,`purgeAfterEpochMilliseconds`])||e.lifecycleState!==`active`&&e.lifecycleState!==`trashed`||typeof e.volumeId!=`string`||!C.test(e.volumeId)||e.provider!==`managed`||e.creatorUserId!==null&&(typeof e.creatorUserId!=`string`||!O.test(e.creatorUserId))||![e.createdAtEpochMilliseconds,e.modifiedAtEpochMilliseconds,e.trashedAtEpochMilliseconds,e.purgeAfterEpochMilliseconds].every(e=>e===null||N(e)))return!1;let n={workspaceId:e.workspaceId,itemId:e.itemId,parentId:e.parentId,type:e.type,name:e.name,lifecycleState:`active`,revision:e.revision,currentVersion:e.currentVersion};return typeof n.workspaceId!=`string`||!S.test(n.workspaceId)||typeof n.itemId!=`string`||!x.test(n.itemId)||n.parentId===null||n.parentId===n.itemId||!Ee(n,n.workspaceId,n.itemId)||e.etag!==`"drive.item.v1.${n.revision}"`||t.has(n.itemId)||(e.lifecycleState===`active`?e.trashedAtEpochMilliseconds!==null||e.purgeAfterEpochMilliseconds!==null:!N(e.trashedAtEpochMilliseconds)||!N(e.purgeAfterEpochMilliseconds)||e.purgeAfterEpochMilliseconds<=e.trashedAtEpochMilliseconds)?!1:(t.add(n.itemId),!0)});if(n){for(let t of e.items)Object.freeze(t);Object.freeze(e.items),Object.freeze(e)}return n}const me=[`ownerUserId`,`ownership`,`visibility`,`archived`,`activeVisitorGrantCount`];function he(e,t,n){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items))return!1;let r=[],i=``;for(let a of e.items){if(!a||typeof a!=`object`||Array.isArray(a))return!1;let e=a,{ownerUserId:o,ownership:s,visibility:c,archived:l,activeVisitorGrantCount:u,...d}=e;if(!me.every(t=>Object.hasOwn(e,t))||o!==t||s!==`assigned`&&s!==`creator`||s===`creator`&&d.creatorUserId!==t||c!==`workspace`&&c!==`restricted`||typeof l!=`boolean`||n===`active`&&l||!N(u)||d.lifecycleState!==n||typeof d.itemId!=`string`||d.itemId<=i)return!1;i=d.itemId,r.push(d)}if(!pe({items:r,nextCursor:e.nextCursor}))return!1;for(let t of e.items)Object.freeze(t);return Object.freeze(e.items),Object.freeze(e),!0}function ge(e,t,n,r){return!P(e,[`workspaceId`,`volumeId`,`itemId`,`kind`,`revision`,`previousOwnerUserId`,`ownerUserId`,`transferredItemCount`,`revokedVisitorGrantCount`])||e.workspaceId!==t||e.itemId!==n||typeof e.volumeId!=`string`||!C.test(e.volumeId)||e.kind!==`file`&&e.kind!==`folder`||!N(e.revision)||e.revision<1||e.previousOwnerUserId!==null&&(typeof e.previousOwnerUserId!=`string`||!O.test(e.previousOwnerUserId))||e.previousOwnerUserId===r||e.ownerUserId!==r||!N(e.transferredItemCount)||e.transferredItemCount<1||!N(e.revokedVisitorGrantCount)?!1:(Object.freeze(e),!0)}function _e(e,t,n){return!P(e,[`workspaceId`,`volumeId`,`itemId`,`parentItemId`,`kind`,`name`,`state`,`revision`,`trashedAtEpochMilliseconds`,`purgeAfterEpochMilliseconds`,`retentionHold`])||e.workspaceId!==t||e.itemId!==n||typeof e.volumeId!=`string`||!C.test(e.volumeId)||typeof e.parentItemId!=`string`||!x.test(e.parentItemId)||e.parentItemId===n||e.kind!==`file`&&e.kind!==`folder`||!M(e.name)||e.state!==`trashed`||!N(e.revision)||e.revision<1||!N(e.trashedAtEpochMilliseconds)||!N(e.purgeAfterEpochMilliseconds)||e.purgeAfterEpochMilliseconds<=e.trashedAtEpochMilliseconds||e.retentionHold!==!0?!1:(Object.freeze(e),!0)}function ve(e){if(!P(e,[`workspace`,`volumes`,`knownProviders`,`externalConnectionsSupported`])||!ye(e.workspace)||!Array.isArray(e.volumes)||e.volumes.length!==1||!Array.isArray(e.knownProviders)||e.externalConnectionsSupported!==!1)return!1;let t=e.volumes[0],n=[`managed`,`google-drive`,`onedrive`,`dropbox`,`s3-compatible`];return P(t,[`volumeId`,`rootItemId`,`provider`,`name`])&&t.volumeId===e.workspace.rootVolumeId&&t.rootItemId===e.workspace.rootItemId&&t.provider===`managed`&&t.name===`Files`&&e.knownProviders.length===n.length&&e.knownProviders.every((e,t)=>e===n[t])}function ye(e){if(!P(e,[`workspaceId`,`rootVolumeId`,`rootItemId`,`workspaceReference`])||typeof e.workspaceId!=`string`||!S.test(e.workspaceId)||typeof e.rootVolumeId!=`string`||!C.test(e.rootVolumeId)||typeof e.rootItemId!=`string`||!x.test(e.rootItemId))return!1;let t=e.workspaceReference;return P(t,[`type`,`userId`])&&t.type===`personal`&&typeof t.userId==`string`&&O.test(t.userId)||P(t,[`type`,`organizationId`])&&t.type===`organization`&&typeof t.organizationId==`string`&&O.test(t.organizationId)}function be(e){return!P(e,[`mode`,`method`,`url`,`headers`,`expiresAtEpochMilliseconds`,`response`])||e.mode!==`presigned-single`||e.method!==`GET`&&e.method!==`HEAD`||typeof e.url!=`string`||!ot(e.url)||!N(e.expiresAtEpochMilliseconds)||!st(e.headers,[`if-match`],e.url)&&!st(e.headers,[`if-match`,`range`],e.url)||typeof e.headers[`if-match`]!=`string`||!at(e.headers[`if-match`])||e.headers.range!==void 0&&(typeof e.headers.range!=`string`||!/^bytes=(?:0|[1-9][0-9]*)-(?:0|[1-9][0-9]*)$/.test(e.headers.range))||!P(e.response,[`status`,`versionId`,`byteLength`,`contentLength`,`contentType`,`contentDisposition`,`etag`,`acceptRanges`,`contentRange`])||e.response.status!==200&&e.response.status!==206||typeof e.response.versionId!=`string`||!T.test(e.response.versionId)||!N(e.response.byteLength)||!N(e.response.contentLength)||typeof e.response.contentType!=`string`||!/^[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?\/[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?$/.test(e.response.contentType)||typeof e.response.contentDisposition!=`string`||e.response.contentDisposition.length>2048||!/^[\x20-\x7e]+$/.test(e.response.contentDisposition)||e.response.etag!==e.headers[`if-match`]||e.response.acceptRanges!==`bytes`||e.response.contentRange!==null&&typeof e.response.contentRange!=`string`||!xe(e)?!1:(Object.freeze(e.headers),Object.freeze(e.response),Object.freeze(e),!0)}function xe(e){let t=e.response;if(t.contentLength>t.byteLength||e.method===`HEAD`&&t.status!==200||!t.contentDisposition.startsWith(`attachment; filename="`))return!1;if(t.status===200)return e.headers.range===void 0&&t.contentRange===null&&t.contentLength===t.byteLength;if(e.method!==`GET`||e.headers.range===void 0||t.contentRange===null)return!1;let n=/^bytes=(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$/.exec(e.headers.range),r=/^bytes (0|[1-9][0-9]*)-(0|[1-9][0-9]*)\/(0|[1-9][0-9]*)$/.exec(t.contentRange);if(!n||!r)return!1;let i=Number(n[1]),a=Number(n[2]),o=Number(r[1]),s=Number(r[2]),c=Number(r[3]);return[i,a,o,s,c].every(N)&&i===o&&a===s&&c===t.byteLength&&i<=a&&a<c&&t.contentLength===a-i+1}function Se(e){return P(e,[`mode`,`operationId`,`versionId`,`state`,`pollAfterSeconds`])&&e.mode===`restore-pending`&&typeof e.operationId==`string`&&E.test(e.operationId)&&typeof e.versionId==`string`&&T.test(e.versionId)&&(e.state===`pending`||e.state===`restoring`)&&N(e.pollAfterSeconds)&&e.pollAfterSeconds>=1&&e.pollAfterSeconds<=60}function Ce(e,t,n){return P(e,[`items`,`nextCursor`])&&Array.isArray(e.items)&&e.items.length<=50&&e.items.every(we)&&(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&D.test(e.nextCursor))?e.items.every(e=>e.workspaceId===t&&e.parentItemId===n)&&it(e.items,e=>e.itemId):!1}function we(e){return P(e,[`workspaceId`,`volumeId`,`itemId`,`parentItemId`,`kind`,`name`,`visibility`,`revision`])&&typeof e.workspaceId==`string`&&S.test(e.workspaceId)&&typeof e.volumeId==`string`&&C.test(e.volumeId)&&typeof e.itemId==`string`&&x.test(e.itemId)&&typeof e.parentItemId==`string`&&x.test(e.parentItemId)&&(e.kind===`file`||e.kind===`folder`)&&M(e.name)&&(e.visibility===`workspace`||e.visibility===`restricted`)&&N(e.revision)}function Te(e,t,n,r){return!P(e,[`workspaceId`,`volumeId`,`itemId`,`parentItemId`,`kind`,`name`,`state`,`revision`,`purgeAfterEpochMilliseconds`])||e.workspaceId!==t||e.itemId!==n||typeof e.volumeId!=`string`||!C.test(e.volumeId)||typeof e.parentItemId!=`string`||!x.test(e.parentItemId)||e.kind!==`file`&&e.kind!==`folder`||!M(e.name)||e.state!==r||!N(e.revision)||(e.state===`active`?e.purgeAfterEpochMilliseconds!==null:!N(e.purgeAfterEpochMilliseconds))?!1:(Object.freeze(e),!0)}function Ee(e,t,n){return!P(e,[`workspaceId`,`itemId`,`parentId`,`type`,`name`,`lifecycleState`,`revision`,`currentVersion`])||e.workspaceId!==t||e.itemId!==n||!(e.parentId===null||typeof e.parentId==`string`&&x.test(e.parentId))||e.type!==`file`&&e.type!==`folder`||!M(e.name)||e.lifecycleState!==`active`||!N(e.revision)||(e.type===`folder`?e.currentVersion!==null:!Oe(e.currentVersion))?!1:(e.currentVersion!==null&&Object.freeze(e.currentVersion),Object.freeze(e),!0)}function De(e,t,n,r){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>r||!e.items.every(e=>ke(e,t,n))||!(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&D.test(e.nextCursor))||e.items.length===0&&e.nextCursor!==null||new Set(e.items.map(e=>e.itemId)).size!==e.items.length||!Ae(e.items))return!1;for(let t of e.items)t.currentVersion!==null&&Object.freeze(t.currentVersion),Object.freeze(t);return Object.freeze(e.items),Object.freeze(e),!0}function j(e,t){let n=e.get(`etag`);return n!==null&&h(n)===t}function Oe(e){return P(e,[`versionId`,`state`,`byteLength`,`mediaType`,`protectionClassification`])&&typeof e.versionId==`string`&&T.test(e.versionId)&&e.state===`current`&&N(e.byteLength)&&tt(e.mediaType)&&(e.protectionClassification===`ordinary`||e.protectionClassification===`opaque-encrypted`)}function ke(e,t,n){return P(e,[`workspaceId`,`volumeId`,`provider`,`itemId`,`parentId`,`type`,`name`,`lifecycleState`,`revision`,`currentVersion`])&&e.workspaceId===t&&typeof e.volumeId==`string`&&C.test(e.volumeId)&&e.provider===`managed`&&typeof e.itemId==`string`&&x.test(e.itemId)&&(e.parentId===null||typeof e.parentId==`string`&&x.test(e.parentId))&&(e.type===`file`||e.type===`folder`)&&M(e.name)&&e.name.startsWith(n)&&e.lifecycleState===`active`&&N(e.revision)&&(e.type===`folder`?e.currentVersion===null:Oe(e.currentVersion))}function Ae(e){for(let t=1;t<e.length;t+=1){let n=e[t-1],r=e[t],i=je(n.name,r.name);if(i>0||i===0&&n.itemId>=r.itemId)return!1}return!0}function je(e,t){let n=ue.encode(e),r=ue.encode(t),i=Math.min(n.length,r.length);for(let e=0;e<i;e+=1)if(n[e]!==r[e])return n[e]-r[e];return n.length-r.length}function Me(e,t){if(!P(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>t||!e.items.every(Ge)||!(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&D.test(e.nextCursor))||e.nextCursor!==null&&e.items.length===0||!it(e.items,e=>e.versionId))return!1;for(let t of e.items)Object.freeze(t);return Object.freeze(e.items),Object.freeze(e),!0}function Ne(e,t){return!P(e,[`itemRevision`,`currentVersionId`])||!N(e.itemRevision)||e.currentVersionId!==t?!1:(Object.freeze(e),!0)}function Pe(e,t,n,r=ae){if(!(P(e,[`items`,`nextCursor`,`collectionRevision`,`collectionEtag`])&&Array.isArray(e.items)&&e.items.length<=50&&e.items.every(Xe)&&(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&D.test(e.nextCursor))&&N(e.collectionRevision)&&typeof e.collectionEtag==`string`&&p(e.collectionEtag)===e.collectionRevision))return!1;let i=t.get(`drive-permission-collection-etag`),a=t.get(`etag`),o=e.collectionRevision;return N(o)?i===e.collectionEtag&&a!==null&&r.test(a)&&e.items.every(e=>{let t=m(e.etag);return t===void 0||e.etag!==et(t[0],e.revision)?!1:e.source===`direct`?e.sourceItemId===n&&t[0]===o:e.sourceItemId!==n})&&it(e.items,e=>`${e.sourceItemId}\0${e.grantId}`):!1}function Fe(e,t,n){if(!P(e,[`items`,`nextCursor`,`collectionRevision`,`collectionEtag`])||!Array.isArray(e.items)||e.items.length>50)return!1;let r=[];for(let t of e.items){if(!P(t,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`,`etag`,`recipient`]))return!1;let{recipient:e,...n}=t;if(!Xe(n)||e!==null&&(!P(e,[`userId`,`name`,`email`,`resolvedAt`,`expiresAt`])||n.grantee.type!==`user`||e.userId!==n.grantee.userId||typeof e.name!=`string`||e.name.length<1||ue.encode(e.name).byteLength>1024||typeof e.email!=`string`||e.email.length<3||ue.encode(e.email).byteLength>320||!e.email.includes(`@`)||!N(e.resolvedAt)||!N(e.expiresAt)||e.expiresAt!==e.resolvedAt+864e5))return!1;r.push(n)}return Pe({...e,items:r},t,n,/^"drive\.sharing-people\.v1\.[0-9a-f]{64}"$/)}function Ie(e,t,n){if(!P(e,[`outcome`,`grant`,`collectionRevision`])||e.outcome!==`committed`&&e.outcome!==`replayed`||!N(e.collectionRevision))return!1;let r=e.grant;return P(r,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`])&&r.source===`direct`&&typeof r.sourceItemId==`string`&&r.sourceItemId===t&&typeof r.grantId==`string`&&ie.test(r.grantId)&&(n===void 0||r.grantId===n)&&Ze(r.grantee)&&Qe(r.actions)&&[`active`,`expired`,`revoked`].includes(String(r.availability))&&(r.expiresAtEpochMilliseconds===null||N(r.expiresAtEpochMilliseconds))&&N(r.revision)}function Le(e,t){if(!P(e,[`actions`])||!Array.isArray(e.actions)||e.actions.length!==7)return!1;for(let n=0;n<e.actions.length;n+=1){let r=e.actions[n];if(r===void 0||!P(r,[`action`,`allowed`,`basis`,`sourceItemId`,`grantId`])||r.action!==oe[n]||typeof r.allowed!=`boolean`||!(r.basis===null||[`workspace_visibility`,`restricted_administrator_bypass`,`item_owner`,`direct_grant`,`inherited_grant`].includes(String(r.basis)))||!(r.sourceItemId===null||typeof r.sourceItemId==`string`&&x.test(r.sourceItemId))||!(r.grantId===null||typeof r.grantId==`string`&&ie.test(r.grantId))||!$e(r,t))return!1}return!0}function Re(e,t,n=!1,r){if(!P(e,[`itemId`,`versionId`,`uploadId`,`mode`,`partByteLength`,`partCount`,`revision`,`expiresAtEpochMilliseconds`],[`singleUpload`])||typeof e.itemId!=`string`||!x.test(e.itemId)||typeof e.versionId!=`string`||!T.test(e.versionId)||typeof e.uploadId!=`string`||!w.test(e.uploadId)||e.mode!==`presigned-multipart`&&e.mode!==`server-mediated-zero-byte`&&e.mode!==`presigned-single`||e.partByteLength!==ce||!N(e.partCount)||e.partCount>1e4||e.partCount!==Math.ceil(t/ce)||(t===0?e.mode!==`server-mediated-zero-byte`:e.mode!==`presigned-multipart`&&e.mode!==`presigned-single`)||!N(e.revision)||!N(e.expiresAtEpochMilliseconds)||e.expiresAtEpochMilliseconds<=Date.now())return!1;if(e.mode===`presigned-single`){if(t<1||t>8*1024*1024||!r||!P(e.singleUpload,[`state`,`descriptor`])||![`uploading`,`completing`,`ready`].includes(String(e.singleUpload.state)))return!1;let i=e.singleUpload.descriptor;if(i!==null){if(e.singleUpload.state!==`uploading`||!P(i,[`url`,`method`,`headers`,`expectedByteLength`,`expiresAtEpochMilliseconds`])||!nt(i.url,n)||i.method!==`PUT`||!st(i.headers,[`content-md5`,`content-type`,`if-none-match`],i.url)||i.headers[`content-md5`]!==r||i.headers[`if-none-match`]!==`*`||typeof i.headers[`content-type`]!=`string`||i.expectedByteLength!==t||!N(i.expiresAtEpochMilliseconds)||i.expiresAtEpochMilliseconds>e.expiresAtEpochMilliseconds)return!1;Object.freeze(i.headers),Object.freeze(i)}Object.freeze(e.singleUpload)}else if(e.singleUpload!==void 0)return!1;return Object.freeze(e),!0}function ze(e,t,n){if(!P(e,[`itemId`,`versionId`,`uploadId`,`mode`,`lifecycle`,`revision`,`partPolicy`,`confirmedParts`,`nextAfterPartNumber`,`expiresAtEpochMilliseconds`,`ready`],[`verification`])||typeof e.itemId!=`string`||!x.test(e.itemId)||typeof e.versionId!=`string`||!T.test(e.versionId)||typeof e.uploadId!=`string`||!w.test(e.uploadId)||e.mode!==`presigned-multipart`&&e.mode!==`server-mediated-zero-byte`&&e.mode!==`presigned-single`||![`initiating`,`recovery-required`,`uploading`,`completing`,`provider-completed`,`verifying`,`failed`,`ready`,`aborting`,`aborted`].includes(String(e.lifecycle))||!N(e.revision)||!P(e.partPolicy,[`partByteLength`,`partCount`,`maxParts`])||e.partPolicy.partByteLength!==ce||!N(e.partPolicy.partCount)||e.partPolicy.partCount>1e4||e.partPolicy.maxParts!==1e4||e.mode===`presigned-single`&&e.partPolicy.partCount!==1||(e.mode===`server-mediated-zero-byte`?e.partPolicy.partCount!==0:e.partPolicy.partCount<1)||!Array.isArray(e.confirmedParts)||e.confirmedParts.length>n||!N(e.expiresAtEpochMilliseconds))return!1;let r=t;if(e.verification!==void 0){let t=e.verification;if(!P(t,[`state`,`verifiedByteLength`,`totalByteLength`,`revision`])||![`pending`,`verified`,`failed`].includes(String(t.state))||!N(t.verifiedByteLength)||!N(t.totalByteLength)||t.totalByteLength>se||t.verifiedByteLength>t.totalByteLength||!N(t.revision)||t.state===`verified`&&t.verifiedByteLength!==t.totalByteLength)return!1;Object.freeze(t)}if([`verifying`,`failed`].includes(String(e.lifecycle))&&e.verification===void 0)return!1;for(let t of e.confirmedParts){if(!P(t,[`partNumber`,`checksumSha256`])||!N(t.partNumber)||t.partNumber<=r||t.partNumber>e.partPolicy.partCount||!We(t.checksumSha256))return!1;r=t.partNumber}if(!(e.nextAfterPartNumber===null||N(e.nextAfterPartNumber)&&e.confirmedParts.length===n&&e.nextAfterPartNumber===r)||e.mode===`server-mediated-zero-byte`&&(e.confirmedParts.length!==0||e.nextAfterPartNumber!==null)||e.lifecycle===`ready`!=(e.ready!==null)||e.ready!==null&&(!He(e.ready,{uploadId:e.uploadId})||e.ready.itemId!==e.itemId||e.ready.versionId!==e.versionId||!P(e.verification,[`state`,`verifiedByteLength`,`totalByteLength`,`revision`])||e.verification.state!==`verified`||e.verification.totalByteLength!==e.ready.byteLength))return!1;Object.freeze(e.partPolicy);for(let t of e.confirmedParts)Object.freeze(t);return Object.freeze(e.confirmedParts),Object.freeze(e),!0}function Be(e,t,n,r){return!P(e,[`url`,`method`,`headers`,`partNumber`,`expectedByteLength`,`expiresAtEpochMilliseconds`])||!nt(e.url,n)||e.method!==`PUT`||!r||!st(e.headers,[`content-md5`],e.url)||e.headers[`content-md5`]!==r||e.partNumber!==t||!N(e.expectedByteLength)||e.expectedByteLength<1||e.expectedByteLength>ce||!N(e.expiresAtEpochMilliseconds)||e.expiresAtEpochMilliseconds<=Date.now()?!1:(Object.freeze(e.headers),Object.freeze(e),!0)}function Ve(e,t,n){return!P(e,[`partNumber`,`revision`])||e.partNumber!==t||e.revision!==n+1||!N(e.revision)?!1:(Object.freeze(e),!0)}function He(e,t){return!P(e,[`itemId`,`versionId`,`uploadId`,`byteLength`,`callerDeclaredContentDigest`,`displayFilename`,`mediaType`,`state`])||typeof e.itemId!=`string`||!x.test(e.itemId)||typeof e.versionId!=`string`||!T.test(e.versionId)||e.uploadId!==t.uploadId||!N(e.byteLength)||e.byteLength<0||e.byteLength>se||typeof e.callerDeclaredContentDigest!=`string`||!le.test(e.callerDeclaredContentDigest)||!M(e.displayFilename)||!tt(e.mediaType)||e.state!==`ready`||t.byteLength!==void 0&&e.byteLength!==t.byteLength||t.callerDeclaredContentDigest!==void 0&&e.callerDeclaredContentDigest!==t.callerDeclaredContentDigest||t.displayFilename!==void 0&&e.displayFilename!==t.displayFilename||t.mediaType!==void 0&&e.mediaType!==t.mediaType?!1:(Object.freeze(e),!0)}function Ue(e,t){return!P(e,[`itemId`,`versionId`,`uploadId`,`state`,`verifiedByteLength`,`totalByteLength`,`verificationRevision`])||typeof e.itemId!=`string`||!x.test(e.itemId)||typeof e.versionId!=`string`||!T.test(e.versionId)||e.uploadId!==t||e.state!==`verifying`||!N(e.verifiedByteLength)||!N(e.totalByteLength)||e.totalByteLength>se||e.verifiedByteLength>e.totalByteLength||!N(e.verificationRevision)?!1:(Object.freeze(e),!0)}function We(e){return typeof e==`string`&&/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/.test(e)}function Ge(e){let t=P(e,qe)&&Je(e);return t&&Object.freeze(e),t}function Ke(e,t,n,r){let i=P(e,[...qe,`workspaceId`,`itemId`])&&e.workspaceId===t&&e.itemId===n&&e.versionId===r&&Je(e);return i&&Object.freeze(e),i}const qe=Object.freeze([`versionId`,`state`,`revision`,`byteLength`,`contentDigest`,`mediaType`,`displayFilename`,`protectionClassification`,`archiveState`]);function Je(e){return typeof e.versionId==`string`&&T.test(e.versionId)&&(e.state===`current`||e.state===`superseded`)&&N(e.revision)&&N(e.byteLength)&&typeof e.contentDigest==`string`&&le.test(e.contentDigest)&&tt(e.mediaType)&&M(e.displayFilename)&&(e.protectionClassification===`ordinary`||e.protectionClassification===`opaque-encrypted`)&&[`available`,`cold`,`restoring`,`unavailable`,`corrupt`].includes(String(e.archiveState))}function Ye(e){let t=e.get(`drive-permission-collection-etag`),n=e.get(`drive-permission-grant-etag`),r=t===null?void 0:p(t);if(r===void 0)return!1;if(n===null)return!0;let i=m(n);return i!==void 0&&i[0]===r}function Xe(e){return P(e,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`,`etag`])&&(e.source===`direct`||e.source===`inherited`)&&typeof e.sourceItemId==`string`&&x.test(e.sourceItemId)&&typeof e.grantId==`string`&&ie.test(e.grantId)&&Ze(e.grantee)&&Qe(e.actions)&&[`active`,`expired`,`revoked`].includes(String(e.availability))&&(e.expiresAtEpochMilliseconds===null||N(e.expiresAtEpochMilliseconds))&&N(e.revision)&&typeof e.etag==`string`&&k.test(e.etag)}function Ze(e){return P(e,[`type`,`userId`])&&e.type===`user`&&typeof e.userId==`string`&&O.test(e.userId)||P(e,[`type`,`teamId`])&&e.type===`team`&&typeof e.teamId==`string`&&O.test(e.teamId)}function Qe(e){return Array.isArray(e)&&e.length>=1&&e.length<=6&&new Set(e).size===e.length&&e.every(e=>A.includes(e))&&e.every((t,n)=>n===0||A.indexOf(t)>A.indexOf(e[n-1]))}function $e(e,t){return e.allowed?e.basis===`workspace_visibility`||e.basis===`restricted_administrator_bypass`||e.basis===`item_owner`?e.sourceItemId===null&&e.grantId===null:e.basis===`direct_grant`?e.sourceItemId===t&&typeof e.grantId==`string`:e.basis===`inherited_grant`&&typeof e.sourceItemId==`string`&&e.sourceItemId!==t&&typeof e.grantId==`string`:e.basis===null&&e.sourceItemId===null&&e.grantId===null}function et(e,t){return`"drive.permission-grant.v1.${e}.${t}"`}function M(e){if(typeof e!=`string`||e.length===0||e.length>510||e.normalize(`NFC`)!==e||e.endsWith(`.`)||e.endsWith(` `)||rt(e))return!1;let t=0,n=0;for(let r of e){let e=r.codePointAt(0);if(e===void 0||e===47||e===92||e<=31||e>=127&&e<=159||e===8232||e===8233||e>=55296&&e<=57343||(t+=1,n+=e<=127?1:e<=2047?2:e<=65535?3:4,t>255||n>255))return!1}return!0}function tt(e){return typeof e==`string`&&e.length<=255&&/^[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?\/[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?$/.test(e)}function nt(e,t){if(typeof e!=`string`||e.length<1||e.length>8192||e!==e.trim())return!1;try{let n=new URL(e),r=n.hostname===`localhost`||n.hostname===`127.0.0.1`||n.hostname===`[::1]`;return(n.protocol===`https:`||n.protocol===`http:`&&t&&r)&&n.username===``&&n.password===``&&n.hash===``&&n.host!==``}catch{return!1}}function rt(e){let t=e.split(`.`,1)[0].toUpperCase();return e===`.`||e===`..`||[`CON`,`PRN`,`AUX`,`NUL`,`CLOCK$`,`CONIN$`,`CONOUT$`].includes(t)||/^COM[1-9]$/.test(t)||/^LPT[1-9]$/.test(t)}function it(e,t){return e.every((n,r)=>r===0||t(e[r-1])<t(n))}function N(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function at(e){return/^"[\x21\x23-\x7e]{1,1022}"$/.test(e)}function ot(e){try{let t=new URL(e),n=t.protocol===`http:`&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname);return(t.protocol===`https:`||n)&&!t.username&&!t.password&&!t.hash}catch{return!1}}function P(e,t,n=[]){return typeof e!=`object`||!e||Array.isArray(e)?!1:Object.keys(e).every(e=>t.includes(e)||n.includes(e))&&t.every(t=>Object.hasOwn(e,t))}function st(e,t,n){if(P(e,t))return!0;let r=[`x-amz-server-side-encryption-customer-algorithm`,`x-amz-server-side-encryption-customer-key`,`x-amz-server-side-encryption-customer-key-md5`];if(!P(e,[...t,...r])||typeof n!=`string`)return!1;try{let t=new URL(n),i=t.searchParams.get(`X-Amz-SignedHeaders`)?.split(`;`)??[];return t.protocol===`https:`&&r.every(e=>i.includes(e))&&e[r[0]]===`AES256`&&typeof e[r[1]]==`string`&&/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/.test(e[r[1]])&&typeof e[r[2]]==`string`&&/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(e[r[2]])}catch{return!1}}const ct=/^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,F=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,lt=/^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ut=/^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,dt=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ft=/^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/,pt=/^[A-Za-z0-9_-]{1,128}$/,mt=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:read`,`items:update`]),ht=/^[A-Za-z0-9_-]{16,128}$/,gt=/^sha256:[0-9a-f]{64}$/,_t=/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/,vt=33554432e4;function yt(e){let t=V(B(e===void 0?{}:e,[],[`signal`]).signal);return t===void 0?{}:{signal:t}}function bt(e){let t=B(e===void 0?{}:e,[],[`signal`,`limit`,`cursor`,`mediaTypes`]),n=V(t.signal),r=St(t.mediaTypes);if(t.limit!==void 0&&(typeof t.limit!=`number`||!Number.isInteger(t.limit)||t.limit<1||t.limit>50)||t.cursor!==void 0&&(typeof t.cursor!=`string`||t.cursor.length<1||t.cursor.length>2048||!/^[A-Za-z0-9_.-]+$/.test(t.cursor)))throw new a(`invalid_input`);return{signal:n,query:{...t.limit===void 0?{}:{limit:t.limit},...t.cursor===void 0?{}:{cursor:t.cursor},...r===void 0?{}:{mediaTypes:r}}}}function xt(e,t){let n=B(e,[`workspaceId`],t?[`signal`,`view`,`kind`,`creatorUserId`,`mediaTypes`,`limit`,`cursor`]:[`signal`]),r=V(n.signal),i=St(n.mediaTypes);if(i!==void 0&&n.kind===`folder`||typeof n.workspaceId!=`string`||!F.test(n.workspaceId)||n.view!==void 0&&n.view!==`recent`&&n.view!==`shared`&&n.view!==`trash`||n.kind!==void 0&&n.kind!==`file`&&n.kind!==`folder`||n.creatorUserId!==void 0&&(typeof n.creatorUserId!=`string`||!pt.test(n.creatorUserId))||n.limit!==void 0&&(typeof n.limit!=`number`||!Number.isInteger(n.limit)||n.limit<1||n.limit>50)||n.cursor!==void 0&&(typeof n.cursor!=`string`||n.cursor.length<1||n.cursor.length>2048||!/^[A-Za-z0-9_.-]+$/.test(n.cursor)))throw new a(`invalid_input`);return{workspaceId:n.workspaceId,signal:r,query:{...n.view===void 0?{}:{view:n.view},...n.kind===void 0?{}:{kind:n.kind},...n.creatorUserId===void 0?{}:{creatorUserId:n.creatorUserId},...i===void 0?{}:{mediaTypes:i},...n.limit===void 0?{}:{limit:n.limit},...n.cursor===void 0?{}:{cursor:n.cursor}}}}function St(e){if(e!==void 0&&(!Array.isArray(e)||e.length<1||e.length>32||new Set(e).size!==e.length||e.some(e=>typeof e!=`string`||!/^[a-z0-9][a-z0-9!#$&^_.+-]{0,63}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,127}$/.test(e))||e.join(`,`).length>2048))throw new a(`invalid_input`);return e===void 0?void 0:[...e].sort().join(`,`)}function I(e){let t=B(e,[`workspaceId`,`itemId`],[`signal`]),n=t.workspaceId,r=t.itemId,i=V(t.signal);if(typeof n!=`string`||!F.test(n)||typeof r!=`string`||!ct.test(r))throw new a(`invalid_input`);return{workspaceId:n,itemId:r,...i===void 0?{}:{signal:i}}}function Ct(e){let t=B(e,[`workspaceId`,`itemId`,`versionId`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.versionId!=`string`||!dt.test(t.versionId))throw new a(`invalid_input`);return{...n,versionId:t.versionId}}function wt(e){let t=B(e,[`workspaceId`,`itemId`,`idempotencyKey`],[`versionId`,`method`,`range`,`ifMatch`,`ifNoneMatch`,`ifRange`,`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),r=t.method??`GET`;if(!H(t.idempotencyKey)||t.versionId!==void 0&&(typeof t.versionId!=`string`||!dt.test(t.versionId))||r!==`GET`&&r!==`HEAD`||t.range!==void 0&&(typeof t.range!=`string`||t.range.length>128||!/^bytes=(?:[0-9]+-[0-9]*|-[0-9]+)$/.test(t.range))||!tn(t.ifMatch)||!tn(t.ifNoneMatch)||!tn(t.ifRange))throw new a(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey,method:r,...t.versionId===void 0?{}:{versionId:t.versionId},...t.range===void 0?{}:{range:t.range},...t.ifMatch===void 0?{}:{ifMatch:t.ifMatch},...t.ifNoneMatch===void 0?{}:{ifNoneMatch:t.ifNoneMatch},...t.ifRange===void 0?{}:{ifRange:t.ifRange}}}function Tt(e){let t=B(e,[`workspaceId`,`query`],[`limit`,`cursor`,`signal`]),n=V(t.signal);if(typeof t.workspaceId!=`string`||!F.test(t.workspaceId)||!Zt(t.query)||t.limit!==void 0&&(!U(t.limit)||t.limit<1||t.limit>50)||t.cursor!==void 0&&(typeof t.cursor!=`string`||t.cursor.length>699||!ft.test(t.cursor)))throw new a(`invalid_input`);return{workspaceId:t.workspaceId,query:t.query,...t.limit===void 0?{}:{limit:t.limit},...t.cursor===void 0?{}:{cursor:t.cursor},...n===void 0?{}:{signal:n}}}function Et(e){let t=B(e,[`workspaceId`,`itemId`],[`signal`,`limit`,`cursor`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),r=t.limit,i=t.cursor;if(r!==void 0&&(!Number.isSafeInteger(r)||typeof r!=`number`||r<1||r>50)||i!==void 0&&(typeof i!=`string`||i.length>699||!ft.test(i)))throw new a(`invalid_input`);return{...n,...r===void 0?{}:{limit:r},...i===void 0?{}:{cursor:i}}}function Dt(e){let t=B(e,[`workspaceId`,`itemId`,`name`,`idempotencyKey`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(!$t(t.name)||!H(t.idempotencyKey))throw new a(`invalid_input`);return{...n,name:t.name,idempotencyKey:t.idempotencyKey}}function Ot(e){let t=B(e,[`workspaceId`,`itemId`,`name`,`parentItemId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=L({workspaceId:t.workspaceId,itemId:t.itemId,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch,...t.signal===void 0?{}:{signal:t.signal}});if(!$t(t.name)||typeof t.parentItemId!=`string`||!ct.test(t.parentItemId))throw new a(`invalid_input`);return{...n,name:t.name,parentItemId:t.parentItemId}}function L(e){let t=B(e,[`workspaceId`,`itemId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(!H(t.idempotencyKey)||typeof t.ifMatch!=`string`||h(t.ifMatch)===void 0)throw new a(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch}}function kt(e){let t=B(e,[`workspaceId`,`itemId`,`versionId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=L({workspaceId:t.workspaceId,itemId:t.itemId,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.versionId!=`string`||!dt.test(t.versionId))throw new a(`invalid_input`);return{...n,versionId:t.versionId}}function At(e){let t=B(e,[`workspaceId`,`itemId`,`grantee`,`actions`,`expiresAtEpochMilliseconds`,`ifMatch`,`idempotencyKey`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),r=Ut(t.grantee),i=Wt(t.actions),o=t.expiresAtEpochMilliseconds;if(!Qt(o)||typeof t.ifMatch!=`string`||p(t.ifMatch)===void 0||!H(t.idempotencyKey))throw new a(`invalid_input`);return{...n,grantee:r,actions:i,expiresAtEpochMilliseconds:o,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function jt(e){let t=B(e,[`workspaceId`,`itemId`,`email`,`role`,`ifMatch`,`idempotencyKey`],[`signal`,`expectedRecipientUserId`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.email!=`string`||t.email.length<3||t.email.length>320||t.role!==`viewer`&&t.role!==`editor`||typeof t.ifMatch!=`string`||p(t.ifMatch)===void 0||!H(t.idempotencyKey))throw new a(`invalid_input`);let r=t.email.trim().toLowerCase(),i=t.expectedRecipientUserId;if(i!==void 0&&(typeof i!=`string`||i.length<1||i.length>128||/[^A-Za-z0-9_-]/.test(i))||!r.includes(`@`)||/\s/.test(r)||new TextEncoder().encode(r).byteLength>320)throw new a(`invalid_input`);return{...n,email:r,expectedRecipientUserId:i,role:t.role,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function Mt(e){let t=B(e,[`workspaceId`,`itemId`,`grantId`,`ifMatch`,`idempotencyKey`],[`signal`]),n=I({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.grantId!=`string`||!lt.test(t.grantId)||typeof t.ifMatch!=`string`||m(t.ifMatch)===void 0||!H(t.idempotencyKey))throw new a(`invalid_input`);return{...n,grantId:t.grantId,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function Nt(e){let t=B(e,[`workspaceId`,`itemId`,`grantId`,`ifMatch`,`idempotencyKey`],[`signal`,`actions`,`expiresAtEpochMilliseconds`]),n=Mt({workspaceId:t.workspaceId,itemId:t.itemId,grantId:t.grantId,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey,...t.signal===void 0?{}:{signal:t.signal}}),r=t.actions===void 0?void 0:Wt(t.actions),i=t.expiresAtEpochMilliseconds;if(r===void 0&&i===void 0||i!==void 0&&!Qt(i))throw new a(`invalid_input`);return{...n,...r===void 0?{}:{actions:r},...i===void 0?{}:{expiresAtEpochMilliseconds:i}}}function Pt(e){let t=B(e,[`workspaceId`,`parentItemId`,`expectedByteLength`,`displayFilename`,`mediaType`,`callerDeclaredContentDigest`,`protectionClassification`,`idempotencyKey`],[`signal`,`contentMd5`]),n=V(t.signal);if(typeof t.workspaceId!=`string`||!F.test(t.workspaceId)||typeof t.parentItemId!=`string`||!ct.test(t.parentItemId)||typeof t.expectedByteLength!=`number`||!Number.isSafeInteger(t.expectedByteLength)||t.expectedByteLength<0||t.expectedByteLength>vt||t.contentMd5!==void 0&&(typeof t.contentMd5!=`string`||!/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(t.contentMd5)||t.expectedByteLength<1||t.expectedByteLength>8*1024*1024)||!$t(t.displayFilename)||!Xt(t.mediaType)||typeof t.callerDeclaredContentDigest!=`string`||!gt.test(t.callerDeclaredContentDigest)||t.protectionClassification!==`ordinary`&&t.protectionClassification!==`opaque-encrypted`||!H(t.idempotencyKey))throw new a(`invalid_input`);return{workspaceId:t.workspaceId,parentItemId:t.parentItemId,expectedByteLength:t.expectedByteLength,...t.contentMd5===void 0?{}:{contentMd5:t.contentMd5},displayFilename:t.displayFilename,mediaType:t.mediaType,callerDeclaredContentDigest:t.callerDeclaredContentDigest,protectionClassification:t.protectionClassification,idempotencyKey:t.idempotencyKey,...n===void 0?{}:{signal:n}}}function Ft(e){let t=B(e,[`workspaceId`,`uploadId`],[`afterPartNumber`,`limit`,`signal`]),n=Kt(t.workspaceId,t.uploadId,t.signal);if(t.afterPartNumber!==void 0&&(!U(t.afterPartNumber)||t.afterPartNumber>1e4)||t.limit!==void 0&&(!U(t.limit)||t.limit<1||t.limit>100))throw new a(`invalid_input`);return{...n,...t.afterPartNumber===void 0?{}:{afterPartNumber:t.afterPartNumber},...t.limit===void 0?{}:{limit:t.limit}}}function It(e){let t=B(e,[`workspaceId`,`uploadId`,`partNumber`,`checksumSha256`,`contentMd5`],[`signal`]),n=Kt(t.workspaceId,t.uploadId,t.signal);if(!qt(t.partNumber)||!Jt(t.checksumSha256)||typeof t.contentMd5!=`string`||!/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(t.contentMd5))throw new a(`invalid_input`);return{...n,partNumber:t.partNumber,checksumSha256:t.checksumSha256,contentMd5:t.contentMd5}}function Lt(e){let t=B(e,[`workspaceId`,`uploadId`,`partNumber`,`expectedUploadRevision`,`byteLength`,`etag`,`checksumSha256`],[`signal`]),n=Kt(t.workspaceId,t.uploadId,t.signal);if(!qt(t.partNumber)||!U(t.expectedUploadRevision)||t.expectedUploadRevision>=2**53-1||!U(t.byteLength)||t.byteLength<1||t.byteLength>33554432||!Yt(t.etag)||!Jt(t.checksumSha256))throw new a(`invalid_input`);return{...n,partNumber:t.partNumber,expectedUploadRevision:t.expectedUploadRevision,byteLength:t.byteLength,etag:t.etag,checksumSha256:t.checksumSha256}}function Rt(e){if(e===void 0)return`deferred`;if(e!==`deferred`&&e!==`inline`)throw new a(`invalid_input`);return e}function zt(e){let t=B(e,[`workspaceId`,`uploadId`,`idempotencyKey`],[`signal`,`verification`]),n=Kt(t.workspaceId,t.uploadId,t.signal);if(!H(t.idempotencyKey))throw new a(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey,verification:Rt(t.verification)}}function Bt(e){let t=B(e,[`workspaceId`,`uploadId`],[`signal`]);return Kt(t.workspaceId,t.uploadId,t.signal)}function Vt(e){let t=B(e,[`workspaceId`,`parentItemId`,`source`,`displayFilename`,`idempotencyKey`,`completionIdempotencyKey`],[`mediaType`,`protectionClassification`,`signal`,`onProgress`,`verification`]),n=V(t.signal),r=Rt(t.verification),i=t.mediaType??`application/octet-stream`,o=t.protectionClassification??`ordinary`,s,c;try{if(!(t.source instanceof Blob))throw new a(`invalid_input`);s=t.source,c=s.size}catch(e){throw e instanceof a?e:new a(`invalid_input`)}if(typeof t.workspaceId!=`string`||!F.test(t.workspaceId)||typeof t.parentItemId!=`string`||!ct.test(t.parentItemId)||!Number.isSafeInteger(c)||c<0||c>vt||!$t(t.displayFilename)||!Xt(i)||o!==`ordinary`&&o!==`opaque-encrypted`||!H(t.idempotencyKey)||!H(t.completionIdempotencyKey)||t.onProgress!==void 0&&typeof t.onProgress!=`function`)throw new a(`invalid_input`);return{workspaceId:t.workspaceId,parentItemId:t.parentItemId,source:s,byteLength:c,displayFilename:t.displayFilename,mediaType:i,protectionClassification:o,idempotencyKey:t.idempotencyKey,completionIdempotencyKey:t.completionIdempotencyKey,verification:r,...n===void 0?{}:{signal:n},...t.onProgress===void 0?{}:{onProgress:t.onProgress}}}function R(e){return{workspaceId:e.workspaceId,itemId:e.itemId}}function Ht(e){return{...e.limit===void 0?{}:{limit:e.limit},...e.cursor===void 0?{}:{cursor:e.cursor}}}function z(e,t){return t}function B(e,t,n){try{if(typeof e!=`object`&&typeof e!=`function`||e===null||Array.isArray(e))throw new a(`invalid_input`);let r=Object.getOwnPropertyDescriptors(e),i=Reflect.ownKeys(r),o=new Set([...t,...n]);if(i.some(e=>typeof e!=`string`||!o.has(e))||t.some(e=>!Object.hasOwn(r,e)))throw new a(`invalid_input`);let s={};for(let e of i){if(typeof e!=`string`)throw new a(`invalid_input`);let t=r[e];if(!t||!(`value`in t)||!t.enumerable)throw new a(`invalid_input`);s[e]=t.value}return s}catch(e){throw e instanceof a?e:new a(`invalid_input`)}}function V(e){if(e!==void 0){if(!(e instanceof AbortSignal))throw new a(`invalid_input`);return e}}function Ut(e){let t=B(e,[`type`],[`userId`,`teamId`]);if(t.type===`user`){let t=B(e,[`type`,`userId`],[]);if(typeof t.userId==`string`&&pt.test(t.userId))return{type:`user`,userId:t.userId}}if(t.type===`team`){let t=B(e,[`type`,`teamId`],[]);if(typeof t.teamId==`string`&&pt.test(t.teamId))return{type:`team`,teamId:t.teamId}}throw new a(`invalid_input`)}function Wt(e){let t=Gt(e);if(t.length<1||t.length>mt.length||new Set(t).size!==t.length||!t.every(e=>mt.includes(e)))throw new a(`invalid_input`);return t}function Gt(e){try{if(!Array.isArray(e))throw new a(`invalid_input`);let t=Object.getOwnPropertyDescriptors(e);if(Reflect.ownKeys(t).some(e=>typeof e!=`string`))throw new a(`invalid_input`);let n=[];for(let r=0;r<e.length;r+=1){let e=t[String(r)];if(!e||!(`value`in e)||!e.enumerable)throw new a(`invalid_input`);n.push(e.value)}if(Reflect.ownKeys(t).length!==e.length+1)throw new a(`invalid_input`);return n}catch(e){throw e instanceof a?e:new a(`invalid_input`)}}function H(e){return typeof e==`string`&&ht.test(e)}function Kt(e,t,n){let r=V(n);if(typeof e!=`string`||!F.test(e)||typeof t!=`string`||!ut.test(t))throw new a(`invalid_input`);return{workspaceId:e,uploadId:t,...r===void 0?{}:{signal:r}}}function qt(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=1&&e<=1e4}function Jt(e){return typeof e==`string`&&_t.test(e)}function Yt(e){return typeof e==`string`&&e.length>=1&&e.length<=1024&&/^[\x20-\x7e]+$/.test(e)}function Xt(e){return typeof e==`string`&&e.length<=255&&/^[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?\/[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?$/.test(e)}function Zt(e){if(typeof e!=`string`||e.length===0)return!1;try{if(e.normalize(`NFC`)!==e)return!1;let t=0,n=0;for(let r of e){let e=r.codePointAt(0);if(e===void 0||e<=31||e>=127&&e<=159||e===8232||e===8233||e>=55296&&e<=57343||(t+=1,n+=e<=127?1:e<=2047?2:e<=65535?3:4,t>64||n>255))return!1}return!0}catch{return!1}}function Qt(e){return e===null||U(e)}function $t(e){if(typeof e!=`string`||e.length===0||e.length>510||e.normalize(`NFC`)!==e||e.endsWith(`.`)||e.endsWith(` `)||en(e))return!1;let t=0,n=0;for(let r of e){let e=r.codePointAt(0);if(e===void 0||e===47||e===92||e<=31||e>=127&&e<=159||e===8232||e===8233||e>=55296&&e<=57343||(t+=1,n+=e<=127?1:e<=2047?2:e<=65535?3:4,t>255||n>255))return!1}return!0}function en(e){let t=e.split(`.`,1)[0].toUpperCase();return e===`.`||e===`..`||[`CON`,`PRN`,`AUX`,`NUL`,`CLOCK$`,`CONIN$`,`CONOUT$`].includes(t)||/^COM[1-9]$/.test(t)||/^LPT[1-9]$/.test(t)}function U(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function tn(e){return e===void 0||typeof e==`string`&&e.length<=8192&&!e.split(``).some(e=>{let t=e.charCodeAt(0);return t<=31||t===127})}const nn=/\{[^{}]+\}/g,rn=()=>typeof process==`object`&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function an(){return Math.random().toString(36).slice(2,11)}function on(e){let{baseUrl:t=``,Request:n=globalThis.Request,fetch:r=globalThis.fetch,querySerializer:i,bodySerializer:a,pathSerializer:o,headers:s,requestInitExt:c=void 0,...l}={...e};c=rn()?c:void 0,t=hn(t);let u=[];async function d(e,d){let{baseUrl:f,fetch:p=r,Request:m=n,headers:h,params:g={},parseAs:_=`json`,querySerializer:v,bodySerializer:ee=a??fn,pathSerializer:y,body:te,middleware:ne=[],...re}=d||{},b=t;f&&(b=hn(f)??t);let x=typeof i==`function`?i:un(i);v&&(x=typeof v==`function`?v:un({...typeof i==`object`?i:{},...v}));let S=y||o||dn,C=te===void 0?void 0:ee(te,mn(s,h,g.header)),ie=mn(C===void 0||C instanceof FormData?{}:{"Content-Type":`application/json`},s,h,g.header),w=[...u,...ne],T={redirect:`follow`,...l,...re,body:C,headers:ie},E,D,O=new m(pn(e,{baseUrl:b,params:g,querySerializer:x,pathSerializer:S}),T),k;for(let e in re)e in O||(O[e]=re[e]);if(w.length){E=an(),D=Object.freeze({baseUrl:b,fetch:p,parseAs:_,querySerializer:x,bodySerializer:ee,pathSerializer:S});for(let t of w)if(t&&typeof t==`object`&&typeof t.onRequest==`function`){let n=await t.onRequest({request:O,schemaPath:e,params:g,options:D,id:E});if(n)if(n instanceof m)O=n;else if(n instanceof Response){k=n;break}else throw Error(`onRequest: must return new Request() or Response() when modifying the request`)}}if(!k){try{k=await p(O,c)}catch(t){let n=t;if(w.length)for(let t=w.length-1;t>=0;t--){let r=w[t];if(r&&typeof r==`object`&&typeof r.onError==`function`){let t=await r.onError({request:O,error:n,schemaPath:e,params:g,options:D,id:E});if(t){if(t instanceof Response){n=void 0,k=t;break}if(t instanceof Error){n=t;continue}throw Error(`onError: must return new Response() or instance of Error`)}}}if(n)throw n}if(w.length)for(let t=w.length-1;t>=0;t--){let n=w[t];if(n&&typeof n==`object`&&typeof n.onResponse==`function`){let t=await n.onResponse({request:O,response:k,schemaPath:e,params:g,options:D,id:E});if(t){if(!(t instanceof Response))throw Error(`onResponse: must return new Response() when modifying the response`);k=t}}}}let ae=k.headers.get(`Content-Length`);if(k.status===204||O.method===`HEAD`||ae===`0`&&!k.headers.get(`Transfer-Encoding`)?.includes(`chunked`))return k.ok?{data:void 0,response:k}:{error:void 0,response:k};if(k.ok)return{data:await(async()=>{if(_===`stream`)return k.body;if(_===`json`&&!ae){let e=await k.text();return e?JSON.parse(e):void 0}return await k[_]()})(),response:k};let A=await k.text();try{A=JSON.parse(A)}catch{}return{error:A,response:k}}return{request(e,t,n){return d(t,{...n,method:e.toUpperCase()})},GET(e,t){return d(e,{...t,method:`GET`})},PUT(e,t){return d(e,{...t,method:`PUT`})},POST(e,t){return d(e,{...t,method:`POST`})},DELETE(e,t){return d(e,{...t,method:`DELETE`})},OPTIONS(e,t){return d(e,{...t,method:`OPTIONS`})},HEAD(e,t){return d(e,{...t,method:`HEAD`})},PATCH(e,t){return d(e,{...t,method:`PATCH`})},TRACE(e,t){return d(e,{...t,method:`TRACE`})},use(...e){for(let t of e)if(t){if(typeof t!=`object`||!(`onRequest`in t||`onResponse`in t||`onError`in t))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");u.push(t)}},eject(...e){for(let t of e){let e=u.indexOf(t);e!==-1&&u.splice(e,1)}}}}function sn(e,t,n){if(t==null)return``;if(typeof t==`object`)throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${n?.allowReserved===!0?t:encodeURIComponent(t)}`}function cn(e,t,n){if(!t||typeof t!=`object`)return``;let r=[],i={simple:`,`,label:`.`,matrix:`;`}[n.style]||`&`;if(n.style!==`deepObject`&&n.explode===!1){for(let e in t)r.push(e,n.allowReserved===!0?t[e]:encodeURIComponent(t[e]));let i=r.join(`,`);switch(n.style){case`form`:return`${e}=${i}`;case`label`:return`.${i}`;case`matrix`:return`;${e}=${i}`;default:return i}}for(let i in t){let a=n.style===`deepObject`?`${e}[${i}]`:i;r.push(sn(a,t[i],n))}let a=r.join(i);return n.style===`label`||n.style===`matrix`?`${i}${a}`:a}function ln(e,t,n){if(!Array.isArray(t))return``;if(n.explode===!1){let r={form:`,`,spaceDelimited:`%20`,pipeDelimited:`|`}[n.style]||`,`,i=(n.allowReserved===!0?t:t.map(e=>encodeURIComponent(e))).join(r);switch(n.style){case`simple`:return i;case`label`:return`.${i}`;case`matrix`:return`;${e}=${i}`;default:return`${e}=${i}`}}let r={simple:`,`,label:`.`,matrix:`;`}[n.style]||`&`,i=[];for(let r of t)n.style===`simple`||n.style===`label`?i.push(n.allowReserved===!0?r:encodeURIComponent(r)):i.push(sn(e,r,n));return n.style===`label`||n.style===`matrix`?`${r}${i.join(r)}`:i.join(r)}function un(e){return function(t){let n=[];if(t&&typeof t==`object`)for(let r in t){let i=t[r];if(i!=null){if(Array.isArray(i)){if(i.length===0)continue;n.push(ln(r,i,{style:`form`,explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==`object`){n.push(cn(r,i,{style:`deepObject`,explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}n.push(sn(r,i,e))}}return n.join(`&`)}}function dn(e,t){let n=e;for(let r of e.match(nn)??[]){let e=r.substring(1,r.length-1),i=!1,a=`simple`;if(e.endsWith(`*`)&&(i=!0,e=e.substring(0,e.length-1)),e.startsWith(`.`)?(a=`label`,e=e.substring(1)):e.startsWith(`;`)&&(a=`matrix`,e=e.substring(1)),!t||t[e]===void 0||t[e]===null)continue;let o=t[e];if(Array.isArray(o)){n=n.replace(r,ln(e,o,{style:a,explode:i}));continue}if(typeof o==`object`){n=n.replace(r,cn(e,o,{style:a,explode:i}));continue}if(a===`matrix`){n=n.replace(r,`;${sn(e,o)}`);continue}n=n.replace(r,a===`label`?`.${encodeURIComponent(o)}`:encodeURIComponent(o))}return n}function fn(e,t){return e instanceof FormData?e:t&&(t.get instanceof Function?t.get(`Content-Type`)??t.get(`content-type`):t[`Content-Type`]??t[`content-type`])===`application/x-www-form-urlencoded`?new URLSearchParams(e).toString():JSON.stringify(e)}function pn(e,t){let n=`${t.baseUrl}${e}`;t.params?.path&&(n=t.pathSerializer(n,t.params.path));let r=t.querySerializer(t.params.query??{});return r.startsWith(`?`)&&(r=r.substring(1)),r&&(n+=`?${r}`),n}function mn(...e){let t=new Headers;for(let n of e){if(!n||typeof n!=`object`)continue;let e=n instanceof Headers?n.entries():Object.entries(n);for(let[n,r]of e)if(r===null)t.delete(n);else if(Array.isArray(r))for(let e of r)t.append(n,e);else r!==void 0&&t.set(n,r)}return t}function hn(e){return e.endsWith(`/`)?e.substring(0,e.length-1):e}String.fromCharCode;const gn=/\/$|\/\?|\/#/,_n=/^\.?\//;function vn(e=``,t){return t?gn.test(e):e.endsWith(`/`)}function yn(e=``,t){if(!t)return e.endsWith(`/`)?e:e+`/`;if(vn(e,!0))return e||`/`;let n=e,r=``,i=e.indexOf(`#`);if(i!==-1&&(n=e.slice(0,i),r=e.slice(i),!n))return r;let[a,...o]=n.split(`?`);return a+`/`+(o.length>0?`?${o.join(`?`)}`:``)+r}function bn(e){return e&&e!==`/`}function xn(e,...t){let n=e||``;for(let e of t.filter(e=>bn(e)))if(n){let t=e.replace(_n,``);n=yn(n)+t}else n=e;return n}function Sn(e){let t;try{t=Object.freeze({baseUrl:Tn(e.baseUrl),fetchImplementation:e.fetch??globalThis.fetch.bind(globalThis),getCredential:e.getCredential,timeoutMilliseconds:Cn(e.timeoutMilliseconds)})}catch{throw new a(`invalid_input`)}if(typeof t.fetchImplementation!=`function`||typeof t.getCredential!=`function`)throw new a(`invalid_input`);return t}async function W(e,t,n,r,i,o,s=!1,c){let l=wn(t,e.timeoutMilliseconds);try{let t=l.signal;Dn(t);let u=await En(e.getCredential,t),p;if(await r(on({baseUrl:e.baseUrl,fetch:async n=>{try{let r=await On(e.fetchImplementation(n),t);if(!(r instanceof Response))throw new a(`invalid_response`);p=r}catch(e){throw e instanceof a?e:t.aborted?new a(`aborted`):new a(`network_error`)}return new Response(null,{status:204})}}),{referrerPolicy:`no-referrer`,redirect:`manual`,cache:`no-store`,credentials:`omit`,headers:new Headers({authorization:`${e.authorizationScheme??`Bearer`} ${u}`,...e.editingAudience?{"editing-audience":e.editingAudience}:{}}),signal:t}),!p)throw new a(`network_error`);return o===null?await f(p,t,n,i,c):await d(p,t,n,i,o,s,c)}catch(e){throw l.didTimeout()?new a(`timeout`):e instanceof a?e:l.signal.aborted?new a(`aborted`):new a(`network_error`)}finally{l.dispose()}}function Cn(e){if(e===void 0)return 3e4;if(!Number.isSafeInteger(e)||e<1||e>12e4)throw new a(`invalid_input`);return e}function wn(e,t){let n=new AbortController,r=!1,i=()=>n.abort();e?.aborted?n.abort():e?.addEventListener(`abort`,i,{once:!0});let a=setTimeout(()=>{r=!0,n.abort()},t);return{signal:n.signal,didTimeout:()=>r,dispose:()=>{clearTimeout(a),e?.removeEventListener(`abort`,i)}}}function Tn(e){if(typeof e!=`string`)throw TypeError(`Drive base URL is invalid`);let t;try{t=new URL(e)}catch{throw TypeError(`Drive base URL is invalid`)}let n=t.protocol===`http:`&&[`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname);if(t.protocol!==`https:`&&!n||t.username||t.password||t.search||t.hash||!t.host)throw TypeError(`Drive base URL is invalid`);return xn(t.origin,t.pathname)}async function En(e,t){Dn(t);let n;try{n=await On(e({signal:t}),t)}catch(e){throw e instanceof a&&e.code===`aborted`?e:t.aborted?new a(`aborted`):new a(`credential_unavailable`)}if(typeof n!=`string`||n.length<1||n.length>16384||!/^[\x21-\x7e]+$/.test(n))throw new a(`credential_unavailable`);return n}function Dn(e){if(e.aborted)throw new a(`aborted`)}async function On(e,t){Dn(t);let n=()=>{},r=new Promise((e,r)=>{let i=()=>r(new a(`aborted`));t.addEventListener(`abort`,i,{once:!0}),n=()=>t.removeEventListener(`abort`,i)});try{return await Promise.race([e,r])}finally{n()}}function kn(e,t){let n=e[`x-amz-server-side-encryption-customer-algorithm`];return n===void 0||n===`AES256`&&t.headers.get(`x-amz-server-side-encryption-customer-algorithm`)===n&&t.headers.get(`x-amz-server-side-encryption-customer-key-md5`)===e[`x-amz-server-side-encryption-customer-key-md5`]}async function An(e,t,n){if(t.expiresAtEpochMilliseconds<=Date.now())throw new a(`invalid_response`);let r=wn(n,e.timeoutMilliseconds);try{let i=await On(e.fetchImplementation(Mn(t,r.signal)),r.signal);if(!Nn(i,t))throw await i.body?.cancel().catch(()=>void 0),new a(`invalid_response`);let o=jn(t);if(t.method===`HEAD`)return await i.body?.cancel().catch(()=>void 0),r.dispose(),new Response(null,{status:i.status,headers:o});if(!i.body){if(r.dispose(),t.response.contentLength!==0)throw new a(`invalid_response`);return new Response(null,{status:i.status,headers:o})}return r.dispose(),new Response(Pn(i.body,t.response.contentLength,n),{status:i.status,headers:o})}catch(e){throw r.dispose(),r.didTimeout()?new a(`timeout`):e instanceof a?e:r.signal.aborted?new a(r.didTimeout()?`timeout`:`aborted`):new a(`network_error`)}}function jn(e){let t=e.response,n=new Headers;return n.set(`cache-control`,`private, no-store, no-transform`),n.set(`accept-ranges`,t.acceptRanges),n.set(`content-disposition`,t.contentDisposition),n.set(`content-length`,String(t.contentLength)),n.set(`content-type`,t.contentType),n.set(`etag`,t.etag),t.contentRange===null?n.delete(`content-range`):n.set(`content-range`,t.contentRange),n}function Mn(e,t){let n={method:e.method,headers:e.headers,redirect:`manual`,signal:t};try{return new Request(e.url,{...n,cache:`no-store`,credentials:`omit`,referrerPolicy:`no-referrer`})}catch{try{return new Request(e.url,{...n,credentials:`omit`,referrerPolicy:`no-referrer`})}catch{return new Request(e.url,{...n,credentials:`omit`})}}}function Nn(e,t){let n=t.response,r=e.headers.get(`content-encoding`);return kn(t.headers,e)&&e.status===n.status&&e.headers.get(`etag`)===n.etag&&e.headers.get(`content-length`)===String(n.contentLength)&&(r===null||r===`identity`)&&(n.contentRange===null?e.headers.get(`content-range`)===null:e.headers.get(`content-range`)===n.contentRange)}function Pn(e,t,n){let r=e.getReader(),i=0,o=!1,s=()=>{};return new ReadableStream({start(e){if(!n)return;let t=()=>{o||(o=!0,s(),r.cancel().catch(()=>void 0),e.error(new a(`aborted`)))};n.aborted?t():(n.addEventListener(`abort`,t,{once:!0}),s=()=>n.removeEventListener(`abort`,t))},async pull(e){if(!o)try{let n=await r.read();if(o)return;if(n.done)o=!0,s(),r.releaseLock(),i===t?e.close():e.error(new a(`invalid_response`));else{if(i+=n.value.byteLength,!Number.isSafeInteger(i)||i>t){o=!0,s(),await r.cancel().catch(()=>void 0),e.error(new a(`invalid_response`));return}e.enqueue(n.value)}}catch(t){if(o)return;o=!0,s(),await r.cancel().catch(()=>void 0),e.error(t instanceof a?t:n?.aborted?new a(`aborted`):new a(`network_error`))}},async cancel(e){o||(o=!0,s(),await r.cancel(e).catch(()=>void 0))}})}const Fn=/^[A-Za-z0-9_-]{43}$/,G=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,K=/^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,In=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,Ln=/^[A-Za-z0-9._:-]{1,128}$/,Rn=/^drive_edit_[A-Za-z0-9_-]{43}$/,zn=`/api/v1/workspaces/{workspaceId}/items/{itemId}/visitor-grants`,Bn=e=>e===`viewer`||e===`editor`;function q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function J(e,t){return Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))}function Y(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function Vn(e){return q(e)&&J(e,[`grantId`,`mode`,`role`,`email`,`status`,`createdAt`,`expiresAt`])&&typeof e.grantId==`string`&&G.test(e.grantId)&&Bn(e.role)&&(e.mode===`anyone`&&e.email===null&&e.status!==`pending`||e.mode===`email`&&typeof e.email==`string`&&e.email.length>=3&&e.email.length<=320)&&[`pending`,`active`,`expired`,`revoked`].includes(String(e.status))&&Y(e.createdAt)&&Y(e.expiresAt)&&e.expiresAt>e.createdAt&&e.expiresAt<=e.createdAt+2592e6}function Hn(e){return q(e)&&J(e,[`grant`,`token`,`tokenPurpose`])&&Vn(e.grant)&&(e.token===null||typeof e.token==`string`&&Fn.test(e.token))&&e.tokenPurpose===(e.grant.mode===`anyone`?`view`:`verify-email`)}function Un(e,t){if(!q(e))return!1;let{source:n,sourceItemId:r,...i}=e;return Vn(i)&&typeof r==`string`&&K.test(r)&&(n===`direct`&&r===t||n===`inherited`&&r!==t)}function Wn(e){return q(e)&&typeof e.itemId==`string`&&K.test(e.itemId)&&(e.kind===`file`||e.kind===`folder`)&&(e.name===null||typeof e.name==`string`&&e.name.length<=1024)}function Gn(e){return{async createVisitorGrant(t){let n=B(t,[`workspaceId`,`itemId`,`command`,`idempotencyKey`],[`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}}),i=B(n.command,[`mode`,`role`,`expiresAt`],[`email`]),o=i.role;if(!Bn(o)||!Y(i.expiresAt)||i.expiresAt>Date.now()+(o===`editor`?864e5:2592e6)||typeof n.idempotencyKey!=`string`||!/^[A-Za-z0-9_-]{16,128}$/.test(n.idempotencyKey)||!(i.mode===`anyone`&&!Object.hasOwn(i,`email`)||i.mode===`email`&&typeof i.email==`string`&&i.email.trim().length>=3&&new TextEncoder().encode(i.email).length<=320))throw new a(`invalid_input`);let s=i.mode===`anyone`?{mode:`anyone`,role:o,expiresAt:i.expiresAt}:{mode:`email`,role:o,email:String(i.email).trim().toLowerCase(),expiresAt:i.expiresAt};return W(e,r.signal,null,(e,t)=>e.POST(zn,{...t,params:{path:r,header:{"Idempotency-Key":n.idempotencyKey}},body:s}),[200],e=>Hn(e)&&e.grant.role===s.role&&e.grant.mode===s.mode&&e.grant.email===(s.mode===`email`?s.email:null)&&e.grant.expiresAt===s.expiresAt)},async getVisitorGrant(t){let n=B(t,[`workspaceId`,`itemId`,`grantId`],[`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}});if(typeof n.grantId!=`string`||!G.test(n.grantId))throw new a(`invalid_input`);let i=n.grantId;return W(e,r.signal,null,(e,t)=>e.GET(`${zn}/{grantId}`,{...t,params:{path:{...r,grantId:i}}}),[200],e=>Hn(e)&&e.grant.grantId===i)},async listVisitorGrants(t){let n=I(t);return W(e,n.signal,null,(e,t)=>e.GET(zn,{...t,params:{path:n}}),[200],e=>q(e)&&J(e,[`items`])&&Array.isArray(e.items)&&e.items.length<=64&&e.items.every(e=>Un(e,n.itemId)))},async revokeVisitorGrant(t){let n=B(t,[`workspaceId`,`itemId`,`grantId`],[`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}});if(typeof n.grantId!=`string`||!G.test(n.grantId))throw new a(`invalid_input`);return W(e,r.signal,null,(e,t)=>e.DELETE(`${zn}/{grantId}`,{...t,params:{path:{...r,grantId:n.grantId}}}),[200],e=>Vn(e)&&e.grantId===n.grantId&&e.status===`revoked`)}}}function Kn(e){if(!e||typeof e.token!=`string`||!Fn.test(e.token))throw new a(`invalid_input`);let t=e.token,n={...Sn({...e,getCredential:async()=>t}),authorizationScheme:`DriveVisitor`},r={Authorization:`DriveVisitor ${t}`},i={async readItem(e={}){let t=Jn(e);return W(n,t.signal,null,(e,n)=>e.GET(`/api/v1/visitor/item`,{...n,params:{header:r,query:t.query}}),[200],e=>Wn(e)&&q(e)&&J(e,[`itemId`,`kind`,`name`,`rootItemId`,`role`])&&Bn(e.role)&&typeof e.rootItemId==`string`&&K.test(e.rootItemId)&&(t.query.itemId===void 0||e.itemId===t.query.itemId))},async listChildren(e={}){let t=Jn(e,[`after`]);if(t.extra.after!==void 0&&(typeof t.extra.after!=`string`||!K.test(t.extra.after)))throw new a(`invalid_input`);let i=t.extra.after;return W(n,t.signal,null,(e,n)=>e.GET(`/api/v1/visitor/children`,{...n,params:{header:r,query:{...t.query,...i===void 0?{}:{after:i}}}}),[200],e=>q(e)&&J(e,[`items`,`nextAfter`])&&Array.isArray(e.items)&&e.items.length<=50&&e.items.every(e=>Wn(e)&&q(e)&&J(e,[`itemId`,`kind`,`name`]))&&(e.nextAfter===null||typeof e.nextAfter==`string`&&K.test(e.nextAfter)&&e.items.length===50&&q(e.items[49])&&e.items[49].itemId===e.nextAfter))},async createDownload(e={}){let t=Jn(e,[`method`,`range`]),i=t.extra.method??`GET`,o=t.extra.range;if(i!==`GET`&&i!==`HEAD`||o!==void 0&&(typeof o!=`string`||!/^bytes=(?:\d+-\d*|-\d+)$/.test(o)||o.length>128))throw new a(`invalid_input`);return W(n,t.signal,null,(e,n)=>(n.headers.set(`Download-Method`,i),typeof o==`string`&&n.headers.set(`Range`,o),e.POST(`/api/v1/visitor/downloads`,{...n,params:{header:r,query:t.query}})),[200],e=>be(e)&&e.method===i&&e.expiresAtEpochMilliseconds>Date.now())},async redeemInvitation(e){let i=B(e,[`sessionToken`],[`signal`]),o=V(i.signal);if(typeof i.sessionToken!=`string`||!Fn.test(i.sessionToken)||i.sessionToken===t)throw new a(`invalid_input`);let s=i.sessionToken;return W(n,o,null,(e,t)=>e.POST(`/api/v1/visitor/verify-email`,{...t,params:{header:r},body:{sessionToken:s}}),[200],e=>q(e)&&J(e,[`grantId`,`role`,`expiresAt`])&&typeof e.grantId==`string`&&G.test(e.grantId)&&Bn(e.role)&&Y(e.expiresAt)&&e.expiresAt>Date.now())},async downloadItem(e={}){let t=Jn(e,[`method`,`range`]),r=await i.createDownload(e);return An(n,r.data,t.signal)},async createEditingSession(e){let t=Jn(e,[`audience`,`writable`,`sourceVersionId`]),{audience:i,writable:o,sourceVersionId:s}=t.extra;if(typeof i!=`string`||!Ln.test(i)||typeof o!=`boolean`||s!==void 0&&(typeof s!=`string`||!In.test(s)))throw new a(`invalid_input`);let c={audience:i,writable:o,...s===void 0?{}:{sourceVersionId:s}};return W(n,t.signal,null,(e,n)=>e.POST(`/api/v1/visitor/editing-sessions`,{...n,params:{header:r,query:t.query},body:c}),[201],e=>qn(e,c))}};return Object.freeze(i)}function qn(e,t){return q(e)&&J(e,[`sessionId`,`workspaceId`,`itemId`,`sourceVersionId`,`expectedVersionId`,`contentGeneration`,`audience`,`grantId`,`writable`,`leaseUntil`,`expiresAt`,`revoked`,`token`])&&typeof e.sessionId==`string`&&G.test(e.sessionId)&&typeof e.workspaceId==`string`&&e.workspaceId.startsWith(`drive.workspace.`)&&G.test(e.workspaceId.slice(16))&&typeof e.itemId==`string`&&K.test(e.itemId)&&typeof e.sourceVersionId==`string`&&In.test(e.sourceVersionId)&&(t.sourceVersionId===void 0||e.sourceVersionId===t.sourceVersionId)&&typeof e.expectedVersionId==`string`&&In.test(e.expectedVersionId)&&typeof e.contentGeneration==`string`&&G.test(e.contentGeneration)&&e.audience===t.audience&&typeof e.grantId==`string`&&G.test(e.grantId)&&e.writable===t.writable&&e.revoked===!1&&Y(e.leaseUntil)&&Y(e.expiresAt)&&e.leaseUntil>Date.now()&&e.leaseUntil<=e.expiresAt&&typeof e.token==`string`&&Rn.test(e.token)}function Jn(e,t=[]){let n=B(e,[],[`itemId`,`signal`,...t]);if(n.itemId!==void 0&&(typeof n.itemId!=`string`||!K.test(n.itemId)))throw new a(`invalid_input`);return{signal:V(n.signal),query:n.itemId===void 0?{}:{itemId:n.itemId},extra:n}}function Yn(){let e=crypto.getRandomValues(new Uint8Array(32));return btoa(String.fromCharCode(...e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}const Xn=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;function Zn(e){if(typeof e.expectedVersionId!=`string`||!Xn.test(e.expectedVersionId)||typeof e.idempotencyKey!=`string`||!/^[A-Za-z0-9_-]{16,128}$/.test(e.idempotencyKey))throw new a(`invalid_input`);return{body:{expectedVersionId:e.expectedVersionId},headers:{"Idempotency-Key":e.idempotencyKey,"If-Match":`"${e.expectedVersionId}"`}}}function Qn(e){return{async getFileAccessContext(t){let n=I(t);return W(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/access-context`,{...t,params:{path:n}}),[200],e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return Object.keys(t).sort().join()===`canRead,canWrite,contentGeneration,itemId,subject,validUntil,versionId,workspaceId`&&t.workspaceId===n.workspaceId&&t.itemId===n.itemId&&typeof t.subject==`string`&&t.subject.length>0&&t.subject.length<=128&&typeof t.versionId==`string`&&Xn.test(t.versionId)&&(t.contentGeneration===null||typeof t.contentGeneration==`string`&&/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(t.contentGeneration))&&typeof t.canRead==`boolean`&&typeof t.canWrite==`boolean`&&typeof t.validUntil==`number`&&Number.isSafeInteger(t.validUntil)&&t.validUntil>Date.now()&&t.validUntil<=Date.now()+6e4})},async createFileVersionUpload(t){let n=B(t,[`workspaceId`,`itemId`,`expectedVersionId`,`byteLength`,`digest`,`idempotencyKey`],[`signal`,`contentMd5`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}}),i=Zn(n);if(typeof n.byteLength!=`number`||!Number.isSafeInteger(n.byteLength)||n.byteLength<0||n.contentMd5!==void 0&&(typeof n.contentMd5!=`string`||!/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(n.contentMd5)||n.byteLength<1||n.byteLength>8*1024*1024)||typeof n.digest!=`string`||!/^sha256:[0-9a-f]{64}$/.test(n.digest))throw new a(`invalid_input`);let o={...i.body,byteLength:n.byteLength,digest:n.digest,...n.contentMd5===void 0?{}:{contentMd5:n.contentMd5}};return W(e,r.signal,null,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/version-uploads`,{...t,params:{path:r,header:i.headers},body:o}),[200,201],t=>Re(t,o.byteLength,new URL(e.baseUrl).protocol===`http:`,o.contentMd5)&&t.itemId===r.itemId&&t.versionId!==o.expectedVersionId,!0)},async commitFileVersion(t){let n=B(t,[`workspaceId`,`itemId`,`uploadId`,`expectedVersionId`,`idempotencyKey`],[`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId}),i=Ft({workspaceId:n.workspaceId,uploadId:n.uploadId,...n.signal===void 0?{}:{signal:n.signal}}),a=Zn(n);return W(e,i.signal,null,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/version`,{...t,params:{path:{workspaceId:i.workspaceId,uploadId:i.uploadId},header:a.headers},body:a.body}),[200,202],(e,t)=>t===200?He(e,{uploadId:i.uploadId})&&e.itemId===r.itemId&&e.versionId!==a.body.expectedVersionId:Ue(e,i.uploadId)&&e.itemId===r.itemId&&e.versionId!==a.body.expectedVersionId)}}}const $n=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,er=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,tr=/^[A-Za-z0-9._:-]{1,128}$/;function nr(e,t){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let n=e;return Object.keys(n).sort().join()===`audience,contentGeneration,expectedVersionId,expiresAt,itemId,leaseUntil,revoked,sessionId,sourceVersionId,subject,workspaceId,writable`&&n.workspaceId===t&&typeof n.sessionId==`string`&&$n.test(n.sessionId)&&typeof n.itemId==`string`&&n.itemId.startsWith(`drive.item.`)&&$n.test(n.itemId.slice(11))&&typeof n.sourceVersionId==`string`&&er.test(n.sourceVersionId)&&typeof n.expectedVersionId==`string`&&er.test(n.expectedVersionId)&&typeof n.contentGeneration==`string`&&$n.test(n.contentGeneration)&&typeof n.audience==`string`&&tr.test(n.audience)&&typeof n.subject==`string`&&n.subject.length>0&&n.subject.length<=128&&typeof n.writable==`boolean`&&typeof n.revoked==`boolean`&&typeof n.leaseUntil==`number`&&Number.isSafeInteger(n.leaseUntil)&&typeof n.expiresAt==`number`&&Number.isSafeInteger(n.expiresAt)&&n.leaseUntil>0&&n.leaseUntil<=n.expiresAt}function rr(e){let t=t=>async n=>{let r=B(n,[`workspaceId`,`sessionId`],[`signal`]);if(typeof r.workspaceId!=`string`||!r.workspaceId.startsWith(`drive.workspace.`)||!$n.test(r.workspaceId.slice(16))||typeof r.sessionId!=`string`||!$n.test(r.sessionId))throw new a(`invalid_input`);let i=r.workspaceId,o=r.sessionId;return W(e,V(r.signal),null,(e,n)=>e.POST(`/api/v1/workspaces/{workspaceId}/editing-sessions/{sessionId}`,{...n,params:{path:{workspaceId:i,sessionId:o}},body:{operation:t}}),[200],e=>nr(e,i)&&e.sessionId===o)};return{async createEditingSession(t){let n=B(t,[`workspaceId`,`itemId`,`audience`,`writable`],[`sourceVersionId`,`signal`]),r=I({workspaceId:n.workspaceId,itemId:n.itemId,...n.signal===void 0?{}:{signal:n.signal}});if(typeof n.audience!=`string`||!tr.test(n.audience)||typeof n.writable!=`boolean`||n.sourceVersionId!==void 0&&(typeof n.sourceVersionId!=`string`||!er.test(n.sourceVersionId)))throw new a(`invalid_input`);let i={audience:n.audience,writable:n.writable,...n.sourceVersionId===void 0?{}:{sourceVersionId:n.sourceVersionId}};return W(e,r.signal,null,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/editing-sessions`,{...t,params:{path:r},body:i}),[201],e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let{token:t,...n}=e;return typeof t==`string`&&/^drive_edit_[A-Za-z0-9_-]{43}$/.test(t)&&nr(n,r.workspaceId)&&n.itemId===r.itemId&&n.audience===i.audience&&n.writable===i.writable&&(i.sourceVersionId===void 0||n.sourceVersionId===i.sourceVersionId)})},renewEditingSession:t(`renew`),closeEditingSession:t(`close`),revokeEditingSession:t(`revoke`)}}function ir(e){if(!/^drive_edit_[A-Za-z0-9_-]{43}$/.test(e.token)||!tr.test(e.audience))throw new a(`invalid_input`);let t=e.token;return Object.freeze({...Sn({...e,getCredential:async()=>t}),authorizationScheme:`DriveEditing`,editingAudience:e.audience})}function ar(e){return Object.freeze({getFileAccessContext:e.getFileAccessContext,createDownload:e.createDownload,downloadItem:e.downloadItem,createFileVersionUpload:e.createFileVersionUpload,commitFileVersion:e.commitFileVersion,getUploadStatus:e.getUploadStatus,createUploadPartDescriptor:e.createUploadPartDescriptor,recordUploadPart:e.recordUploadPart,abortUpload:e.abortUpload})}const or=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,sr=/^[A-Za-z0-9_-]{1,128}$/,cr=/^[A-Za-z0-9_.-]+$/,lr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_pagination_cursor`,`precondition_failed`,`service_unavailable`]),ur=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_idempotency_key`,`idempotency_conflict`,`precondition_failed`,`rate_limited`,`service_unavailable`]);function dr(e){return{listOwnedItems:t=>mr(e,t),transferItemOwnership:t=>gr(e,t),archiveItem:t=>_r(e,t)}}async function fr(e,t){let n=B(t,[`workspaceId`,`ownerUserId`],[`lifecycle`,`rootsOnly`,`signal`,`maxItems`]),r=n.maxItems??500;if(typeof r!=`number`||!Number.isInteger(r)||r<1||r>500)throw new a(`invalid_input`);let{maxItems:i,...o}=n,s=[],c=null;do{let t=r-s.length,n=Math.min(50,t),i=await e.listOwnedItems({...o,limit:n,...c===null?{}:{cursor:c}});s.push(...i.data.items),c=i.data.nextCursor}while(c!==null&&s.length<r);return Object.freeze({items:Object.freeze(s),complete:c===null,nextCursor:c})}function pr(e){let t=B(e,[`workspaceId`,`ownerUserId`],[`lifecycle`,`rootsOnly`,`limit`,`cursor`,`signal`]),n=V(t.signal);if(typeof t.workspaceId!=`string`||!or.test(t.workspaceId)||typeof t.ownerUserId!=`string`||!sr.test(t.ownerUserId)||t.lifecycle!==void 0&&t.lifecycle!==`active`&&t.lifecycle!==`trashed`||t.rootsOnly!==void 0&&typeof t.rootsOnly!=`boolean`||t.limit!==void 0&&(typeof t.limit!=`number`||!Number.isInteger(t.limit)||t.limit<1||t.limit>50)||t.cursor!==void 0&&(typeof t.cursor!=`string`||t.cursor.length<1||t.cursor.length>2048||!cr.test(t.cursor)))throw new a(`invalid_input`);return{workspaceId:t.workspaceId,ownerUserId:t.ownerUserId,lifecycle:t.lifecycle??`active`,signal:n,query:{...t.lifecycle===void 0?{}:{lifecycle:t.lifecycle},...t.rootsOnly===void 0?{}:{rootsOnly:t.rootsOnly?`true`:`false`},...t.limit===void 0?{}:{limit:t.limit},...t.cursor===void 0?{}:{cursor:t.cursor}},limit:t.limit??25}}async function mr(e,t){let n=pr(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/owners/{ownerUserId}/items`,{...z(`listOwnedItems`,{params:{path:{workspaceId:n.workspaceId,ownerUserId:n.ownerUserId},query:n.query}}),...t}),[200],e=>he(e,n.ownerUserId,n.lifecycle)&&e.items.length<=n.limit&&e.items.every(e=>e.workspaceId===n.workspaceId),!1,lr)}function hr(e){let t=B(e,[`workspaceId`,`itemId`,`ownerUserId`,`includeDescendants`,`revokeVisitorGrants`,`idempotencyKey`,`ifMatch`],[`signal`]),n=L({workspaceId:t.workspaceId,itemId:t.itemId,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.ownerUserId!=`string`||!sr.test(t.ownerUserId)||typeof t.includeDescendants!=`boolean`||typeof t.revokeVisitorGrants!=`boolean`)throw new a(`invalid_input`);return{...n,body:{ownerUserId:t.ownerUserId,includeDescendants:t.includeDescendants,revokeVisitorGrants:t.revokeVisitorGrants}}}async function gr(e,t){let n=hr(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/ownership`,{...z(`transferItemOwnership`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:n.body}),...t}),[200],(e,t,r)=>ge(e,n.workspaceId,n.itemId,n.body.ownerUserId)&&j(r,e.revision),!1,ur)}async function _r(e,t){let n=L(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/archive`,{...z(`archiveItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>_e(e,n.workspaceId,n.itemId)&&j(r,e.revision),!1,ur)}const vr=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,yr=/^"drive\.sharing-policy\.v1\.(0|[1-9][0-9]{0,15})"$/,br=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`service_unavailable`]),xr=Object.freeze([...br,`precondition_failed`]);function Sr(e){return{getWorkspaceSharingPolicy:t=>Tr(e,t),updateWorkspaceSharingPolicy:t=>Er(e,t)}}function Cr(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function wr(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let n=e;return Object.keys(n).sort().join()===`canManage,externalSharing,revision,updatedAt,workspaceId`&&typeof n.workspaceId==`string`&&vr.test(n.workspaceId)&&(n.externalSharing===`allowed`||n.externalSharing===`disabled`)&&Cr(n.revision)&&(n.updatedAt===null||Cr(n.updatedAt))&&n.revision===0==(n.updatedAt===null)&&typeof n.canManage==`boolean`&&t.get(`etag`)===`"drive.sharing-policy.v1.${n.revision}"`}async function Tr(e,t){return W(e,V(B(t??{},[],[`signal`]).signal),null,(e,t)=>e.GET(`/api/v1/workspaces/current/sharing-policy`,{...z(`getWorkspaceSharingPolicy`,{params:{}}),...t}),[200],(e,t,n)=>wr(e,n),!1,br)}async function Er(e,t){let n=B(t,[`externalSharing`,`ifMatch`],[`signal`]),r=V(n.signal);if(n.externalSharing!==`allowed`&&n.externalSharing!==`disabled`||typeof n.ifMatch!=`string`||!yr.test(n.ifMatch))throw new a(`invalid_input`);let i=n.externalSharing,o=n.ifMatch;return W(e,r,412,(e,t)=>e.PUT(`/api/v1/workspaces/current/sharing-policy`,{...z(`updateWorkspaceSharingPolicy`,{params:{header:{"If-Match":o}},body:{externalSharing:i}}),...t}),[200],(e,t,n)=>wr(e,n)&&e.externalSharing===i,!1,xr)}const Dr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`service_unavailable`]),Or=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`service_unavailable`]),kr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_pagination_cursor`,`precondition_failed`,`service_unavailable`]),Ar=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`upload_recovery_required`,`service_unavailable`]),jr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`service_unavailable`]),Mr=Object.freeze([...Ar,`invalid_idempotency_key`,`idempotency_conflict`,`quota_exceeded`]),Nr=Object.freeze([...Ar,`invalid_idempotency_key`]),Pr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_idempotency_key`,`idempotency_conflict`,`precondition_failed`,`service_unavailable`]),Fr=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`service_unavailable`]),Ir=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_idempotency_key`,`idempotency_conflict`,`precondition_failed`,`range_not_satisfiable`,`service_unavailable`]);function Lr(e){return Object.freeze({...Gn(e),...Qn(e),...rr(e),...dr(e),...Sr(e),registerItemRecipient:t=>oi(e,t),listItemSharingPeople:t=>si(e,t),listIncomingShares:t=>Rr(e,t),getCurrentWorkspace:t=>Wr(e,t),ensureOrganizationWorkspaceAccess:t=>Gr(e,t),listWorkspaceItems:t=>Hr(e,t),getWorkspaceUsage:t=>Ur(e,t),getCurrentWorkspaceSources:t=>Vr(e,t),getItem:t=>Kr(e,t),searchWorkspaceItems:t=>qr(e,t),listFolderChildren:t=>Jr(e,t),createFolder:t=>Yr(e,t),updateItem:t=>Xr(e,t),trashItem:t=>Zr(e,t),restoreItem:t=>Qr(e,t),deleteItem:t=>$r(e,t),listItemVersions:t=>ei(e,t),getItemVersion:t=>ti(e,t),restoreItemVersion:t=>ni(e,t),createDownload:t=>zr(e,t),downloadItem:t=>Br(e,t),listItemPermissions:t=>ri(e,t),readEffectiveItemPermissions:t=>ii(e,t),createItemPermission:t=>ai(e,t),createInternalItemPermission:t=>ai(e,t,!0),updateItemPermission:t=>ci(e,t),revokeItemPermission:t=>li(e,t),revokeInternalItemPermission:t=>li(e,t,!0),createUpload:t=>ui(e,t),getUploadStatus:t=>di(e,t),createUploadPartDescriptor:t=>fi(e,t),recordUploadPart:t=>pi(e,t),completeUpload:t=>mi(e,t),abortUpload:t=>hi(e,t)})}async function Rr(e,t){let n=bt(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/shares/incoming`,{...z(`listIncomingShares`,{params:{query:n.query}}),...t}),[200],de,!1,kr)}async function zr(e,t){let n=wt(t);return W(e,n.signal,412,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/downloads`,{...z(`createDownload`,{params:{path:{workspaceId:n.workspaceId,itemId:n.itemId},query:n.versionId===void 0?{}:{versionId:n.versionId},header:{"Idempotency-Key":n.idempotencyKey,"Download-Method":n.method,...n.range===void 0?{}:{Range:n.range},...n.ifMatch===void 0?{}:{"If-Match":n.ifMatch},...n.ifNoneMatch===void 0?{}:{"If-None-Match":n.ifNoneMatch},...n.ifRange===void 0?{}:{"If-Range":n.ifRange}}}}),...t}),[200,202,304],(e,t)=>t===200?be(e):t===202?Se(e):e===void 0,!1,Ir)}async function Br(e,t){let n=wt(t),r=await zr(e,t);return r.status===202||r.status===304?r:An(e,r.data,n.signal)}async function Vr(e,t){return W(e,yt(t).signal,null,(e,t)=>e.GET(`/api/v1/workspaces/current/sources`,{...z(`getCurrentWorkspaceSources`,{params:{}}),...t}),[200],ve,!1,Dr)}async function Hr(e,t){let n=xt(t,!0);return W(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items`,{...z(`listWorkspaceItems`,{params:{path:{workspaceId:n.workspaceId},query:n.query}}),...t}),[200],e=>pe(e)&&e.items.length<=(n.query.limit??25)&&e.items.every((e,t,r)=>e.workspaceId===n.workspaceId&&e.lifecycleState===(n.query.view===`trash`?`trashed`:`active`)&&((n.query.view??`recent`)!==`recent`||e.modifiedAtEpochMilliseconds!==null)&&(n.query.kind===void 0||e.type===n.query.kind)&&(n.query.mediaTypes===void 0||e.type===`file`&&!!e.currentVersion&&n.query.mediaTypes.split(`,`).includes(e.currentVersion.mediaType))&&(n.query.creatorUserId===void 0||e.creatorUserId===n.query.creatorUserId)&&(t===0||((n.query.view??`recent`)===`recent`?r[t-1].modifiedAtEpochMilliseconds>e.modifiedAtEpochMilliseconds||r[t-1].modifiedAtEpochMilliseconds===e.modifiedAtEpochMilliseconds&&r[t-1].itemId<e.itemId:r[t-1].itemId<e.itemId))),!1,kr)}async function Ur(e,t){let n=xt(t,!1);return W(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/usage`,{...z(`getWorkspaceUsage`,{params:{path:{workspaceId:n.workspaceId}}}),...t}),[200],e=>fe(e)&&e.workspaceId===n.workspaceId,!1,kr)}async function Wr(e,t){return W(e,yt(t).signal,null,(e,t)=>e.GET(`/api/v1/workspaces/current`,{...z(`getCurrentWorkspace`,{params:{}}),...t}),[200],ye,!1,Dr)}async function Gr(e,t){return W(e,yt(t).signal,null,(e,t)=>e.POST(`/api/v1/workspaces/current/organization-access`,{...z(`ensureOrganizationWorkspaceAccess`,{params:{}}),...t}),[200],e=>ye(e)&&e.workspaceReference.type===`organization`,!1,Dr)}async function Kr(e,t){let n=I(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...z(`getItem`,{params:{path:R(n)}}),...t}),[200],(e,t,r)=>Ee(e,n.workspaceId,n.itemId)&&j(r,e.revision),!1,Or)}async function qr(e,t){let n=Tt(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/search`,{...z(`searchWorkspaceItems`,{params:{path:{workspaceId:n.workspaceId},query:{query:n.query,...n.limit===void 0?{}:{limit:n.limit},...n.cursor===void 0?{}:{cursor:n.cursor}}}}),...t}),[200],e=>De(e,n.workspaceId,n.query,n.limit??50),!1,kr)}async function Jr(e,t){let n=Et(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/children`,{...z(`listFolderChildren`,{params:{path:R(n),query:Ht(n)}}),...t}),[200],e=>Ce(e,n.workspaceId,n.itemId))}async function Yr(e,t){let n=Dt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/children`,{...z(`createFolder`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey}},body:{name:n.name}}),...t}),[200,201],e=>we(e)&&e.workspaceId===n.workspaceId&&e.parentItemId===n.itemId&&e.kind===`folder`&&e.name===n.name)}async function Xr(e,t){let n=Ot(t);return W(e,n.signal,409,(e,t)=>e.PATCH(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...z(`updateItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:{name:n.name,parentItemId:n.parentItemId}}),...t}),[200],(e,t,r)=>Te(e,n.workspaceId,n.itemId,`active`)&&e.name===n.name&&e.parentItemId===n.parentItemId&&j(r,e.revision),!1,Pr)}async function Zr(e,t){let n=L(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/trash`,{...z(`trashItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>Te(e,n.workspaceId,n.itemId,`trashed`)&&j(r,e.revision),!1,Pr)}async function Qr(e,t){let n=L(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/restore`,{...z(`restoreItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>Te(e,n.workspaceId,n.itemId,`active`)&&j(r,e.revision),!1,Pr)}async function $r(e,t){let n=L(t);return W(e,n.signal,409,(e,t)=>e.DELETE(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...z(`deleteItem`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200,202],(e,t,r)=>Te(e,n.workspaceId,n.itemId,`deleting`)&&j(r,e.revision),!1,Pr)}async function ei(e,t){let n=Et(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions`,{...z(`listItemVersions`,{params:{path:R(n),query:Ht(n)}}),...t}),[200],e=>Me(e,n.limit??50),!1,Fr)}async function ti(e,t){let n=Ct(t);return W(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}`,{...z(`getItemVersion`,{params:{path:{...R(n),versionId:n.versionId}}}),...t}),[200],e=>Ke(e,n.workspaceId,n.itemId,n.versionId),!1,Fr)}async function ni(e,t){let n=kt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}/restore`,{...z(`restoreItemVersion`,{params:{path:{...R(n),versionId:n.versionId},header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>Ne(e,n.versionId)&&j(r,e.itemRevision),!1,Pr)}async function ri(e,t){let n=Et(t);return W(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions`,{...z(`listItemPermissions`,{params:{path:R(n),query:Ht(n)}}),...t}),[200],(e,t,r)=>Pe(e,r,n.itemId))}async function ii(e,t){let n=I(t);return W(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/effective`,{...z(`readEffectiveItemPermissions`,{params:{path:R(n)}}),...t}),[200],e=>Le(e,n.itemId))}async function ai(e,t,n=!1){let r=At(t);return W(e,r.signal,412,(e,t)=>e.POST(n?`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/internal`:`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions`,{...z(n?`createInternalItemPermission`:`createItemPermission`,{params:{path:R(r),header:{"Idempotency-Key":r.idempotencyKey,"If-Match":r.ifMatch}},body:{grantee:r.grantee,actions:r.actions,expiresAtEpochMilliseconds:r.expiresAtEpochMilliseconds}}),...t}),[200,201],(e,t,n)=>Ie(e,r.itemId)&&(t===201&&e.outcome===`committed`||t===200&&e.outcome===`replayed`)&&(t===200||e.grant.availability!==`revoked`)&&Ye(n))}async function oi(e,t){let n=jt(t);return W(e,n.signal,412,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/sharing`,{...z(`registerItemRecipient`,{params:{path:R(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:{email:n.email,role:n.role,...n.expectedRecipientUserId===void 0?{}:{expectedRecipientUserId:n.expectedRecipientUserId}}}),...t}),[200,201],(e,t,r)=>Ie(e,n.itemId)&&(n.expectedRecipientUserId===void 0||e.grant.grantee.type===`user`&&e.grant.grantee.userId===n.expectedRecipientUserId)&&(t===201&&e.outcome===`committed`||t===200&&e.outcome===`replayed`)&&(t===200||e.grant.availability!==`revoked`)&&Ye(r),!1,[...kr,`recipient_unavailable`,`registration_conflict`,`rate_limited`,`idempotency_conflict`,`invalid_idempotency_key`])}async function si(e,t){let n=Et(t);return W(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/sharing/people`,{...z(`listItemSharingPeople`,{params:{path:R(n),query:Ht(n)}}),...t}),[200],(e,t,r)=>Fe(e,r,n.itemId))}async function ci(e,t){let n=Nt(t),r={};return n.actions!==void 0&&(r.actions=n.actions),n.expiresAtEpochMilliseconds!==void 0&&(r.expiresAtEpochMilliseconds=n.expiresAtEpochMilliseconds),W(e,n.signal,412,(e,t)=>e.PATCH(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/{grantId}`,{...z(`updateItemPermission`,{params:{path:{...R(n),grantId:n.grantId},header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:r}),...t}),[200],(e,t,r)=>Ie(e,n.itemId,n.grantId)&&e.grant.availability!==`revoked`&&Ye(r))}async function li(e,t,n=!1){let r=Mt(t);return W(e,r.signal,412,(e,t)=>e.DELETE(n?`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/internal/{grantId}`:`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/{grantId}`,{...z(n?`revokeInternalItemPermission`:`revokeItemPermission`,{params:{path:{...R(r),grantId:r.grantId},header:{"Idempotency-Key":r.idempotencyKey,"If-Match":r.ifMatch}}}),...t}),[200],(e,t,n)=>Ie(e,r.itemId,r.grantId)&&e.grant.availability===`revoked`&&p(n.get(`drive-permission-collection-etag`)??``)!==void 0&&n.get(`drive-permission-grant-etag`)===null)}async function ui(e,t){let n=Pt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads`,{...z(`createUpload`,{params:{path:{workspaceId:n.workspaceId},header:{"Idempotency-Key":n.idempotencyKey}},body:{parentItemId:n.parentItemId,expectedByteLength:n.expectedByteLength,...n.contentMd5===void 0?{}:{contentMd5:n.contentMd5},displayFilename:n.displayFilename,mediaType:n.mediaType,callerDeclaredContentDigest:n.callerDeclaredContentDigest,protectionClassification:n.protectionClassification}}),...t}),[200,201],t=>Re(t,n.expectedByteLength,new URL(e.baseUrl).protocol===`http:`,n.contentMd5),!0,Mr)}async function di(e,t){let n=Ft(t),r=n.afterPartNumber??0,i=n.limit??100;return W(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}`,{...z(`getUploadStatus`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId},query:{...n.afterPartNumber===void 0?{}:{afterPartNumber:String(n.afterPartNumber)},...n.limit===void 0?{}:{limit:String(n.limit)}}}}),...t}),[200],e=>ze(e,r,i)&&e.uploadId===n.uploadId,!1,jr)}async function fi(e,t){let n=It(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/parts`,{...z(`createUploadPartDescriptor`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId}},body:{partNumber:n.partNumber,checksumSha256:n.checksumSha256,contentMd5:n.contentMd5}}),...t}),[200],t=>Be(t,n.partNumber,new URL(e.baseUrl).protocol===`http:`,n.contentMd5),!1,Ar)}async function pi(e,t){let n=Lt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/parts/{partNumber}`,{...z(`recordUploadPart`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId,partNumber:String(n.partNumber)}},body:{expectedUploadRevision:n.expectedUploadRevision,byteLength:n.byteLength,etag:n.etag,checksumSha256:n.checksumSha256}}),...t}),[200],e=>Ve(e,n.partNumber,n.expectedUploadRevision),!1,Ar)}async function mi(e,t){let n=zt(t);return W(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/complete`,{...z(`completeUpload`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId},query:n.verification===`inline`?{verification:`inline`}:{},header:{"Idempotency-Key":n.idempotencyKey}}}),...t}),[200,202],(e,t)=>t===202?Ue(e,n.uploadId):He(e,{uploadId:n.uploadId}),!1,Nr)}async function hi(e,t){let n=Bt(t);return W(e,n.signal,409,(e,t)=>e.DELETE(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}`,{...z(`abortUpload`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId}}}),...t}),[204],null,!1,Ar)}const gi=e=>e/2**32|0,_i=e=>e>>>0;function vi(e,t,n,r){let i=gi(n),a=_i(n);e.setUint32(t,r?a:i,r),e.setUint32(t+4,r?i:a,r)}function yi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}const bi=e=>e?`"${e}" `:``;function xi(e,t=``){if(typeof e!=`number`)throw TypeError(bi(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(bi(t)+`expected integer >= 0, got `+e);return e}function Si(e,t,n=``){if(yi(e)&&(t===void 0||e.length===t))return e;t!==void 0&&xi(t,`length`);let r=yi(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=bi(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}const Ci=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`"${t}" `)+`expected object, got type=`+typeof e)};function wi(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function Ti(e,t){Si(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function Ei(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Di(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function X(e,t){return e<<32-t|e>>>t}function Oi(e,t){return e<<t|e>>>32-t>>>0}const ki=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,Ai=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function ji(e){if(Si(e),ki)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=Ai[e[n]];return t}function Mi(e,t,n=`opts`){return Ci(e,`defaults`),t!==void 0&&Ci(t,n),Object.assign(e,t)}function Ni(e,t={}){if(typeof e!=`function`)throw TypeError(`"hashCons" expected function, got type=`+typeof e);t=Mi({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}const Pi=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Fi(e,t,n){return e&t^~e&n}function Ii(e,t,n){return e&t^e&n^t&n}var Li=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Di(this.buffer)}update(e){wi(this),Si(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=Di(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){wi(this),Ti(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,t.fill(0,a),this.padOffset>r-a&&(this.process(n,0),t.fill(0)),vi(n,r-8,this.length*8,i),this.process(n,0),this.roundClean();let o=e===t?n:Di(e),s=this.outputLen,c=s/4,l=this.get();if(s%4||c>l.length)throw Error(`invalid outputLen`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}};const Ri=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),zi=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Z=new Uint32Array(64);var Bi=class extends Li{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)Z[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=Z[e-15],n=Z[e-2],r=X(t,7)^X(t,18)^t>>>3,i=X(n,17)^X(n,19)^n>>>10;Z[e]=i+Z[e-7]+r+Z[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=X(o,6)^X(o,11)^X(o,25),u=l+t+Fi(o,s,c)+zi[e]+Z[e]|0,d=(X(n,2)^X(n,13)^X(n,22))+Ii(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){Ei(Z)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Ei(this.buffer)}},Vi=class extends Bi{constructor(){super(32,Ri)}};const Hi=Ni(()=>new Vi,Pi(1)),Ui=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),Wi=2**32,Gi=Array.from({length:64},(e,t)=>Math.floor(Wi*Math.abs(Math.sin(t+1)))),Ki=Ui.slice(0,4),qi=new Uint32Array(16),Ji=(()=>{let e=[[7,12,17,22],[5,9,14,20],[4,11,16,23],[6,10,15,21]];return Uint8Array.from({length:64},(t,n)=>e[Math.floor(n/16)][n%4])})();var Yi=class extends Li{A=Ki[0]|0;B=Ki[1]|0;C=Ki[2]|0;D=Ki[3]|0;constructor(){super(64,16,8,!0)}get(){let{A:e,B:t,C:n,D:r}=this;return[e,t,n,r]}set(e,t,n,r){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)qi[n]=e.getUint32(t,!0);let{A:n,B:r,C:i,D:a}=this;for(let e=0;e<64;e++){let t,o;e<16?(t=Fi(r,i,a),o=e):e<32?(t=Fi(a,r,i),o=(5*e+1)%16):e<48?(t=r^i^a,o=(3*e+5)%16):(t=i^(r|~a),o=7*e%16),t=t+n+Gi[e]+qi[o],n=a,a=i,i=r,r+=Oi(t,Ji[e])}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,this.set(n,r,i,a)}roundClean(){Ei(qi)}destroy(){this.destroyed=!0,this.set(0,0,0,0),Ei(this.buffer)}};const Xi=Ni(()=>new Yi),Q=32*1024*1024,Zi=8*1024*1024,Qi=256*1024;async function $i(e,t,n){let r=Vt(t),i=Math.ceil(r.byteLength/Q);$(r.onProgress,`preparing`,0,r.byteLength,0,i);let o;try{let t=await ia(r.source,r.byteLength,i,r.signal),s=await n.createUpload({workspaceId:r.workspaceId,parentItemId:r.parentItemId,expectedByteLength:r.byteLength,displayFilename:r.displayFilename,mediaType:r.mediaType,callerDeclaredContentDigest:t.callerDeclaredContentDigest,...r.byteLength>0&&r.byteLength<=Zi?{contentMd5:t.partMd5s[0]}:{},protectionClassification:r.protectionClassification,idempotencyKey:r.idempotencyKey,...r.signal===void 0?{}:{signal:r.signal}});if(o=s.data,oa(o,r.byteLength,i,s.status,s.requestId),o.mode===`presigned-single`){let i=o.singleUpload;if(!i)throw new a(`invalid_response`);let s=i.state===`uploading`?0:r.byteLength;if($(r.onProgress,`uploading`,0,r.byteLength,0,1),i.state===`uploading`&&i.descriptor&&i.descriptor.expiresAtEpochMilliseconds>Date.now()){if(i.descriptor.headers[`content-md5`]!==t.partMd5s[0]||i.descriptor.headers[`content-type`]!==r.mediaType)throw new a(`invalid_response`);try{await aa(e,i.descriptor,r.source,r.signal),s=r.byteLength}catch(e){if(!(e instanceof a)||r.signal?.aborted||![`network_error`,`timeout`].includes(e.code)&&e.status!==412)throw e}}$(r.onProgress,`completing`,s,r.byteLength,+!!s,1);let c=await ra(n,r,o,t);return c.data.state===`verifying`&&$(r.onProgress,`verifying`,r.byteLength,r.byteLength,1,1),c}let c=await ta(n,r,o,t);if($(r.onProgress,`uploading`,c.confirmedByteLength,r.byteLength,c.confirmedParts.size,i),c.readyResult)return $(r.onProgress,`completing`,c.confirmedByteLength,r.byteLength,c.confirmedParts.size,i),c.readyResult;let l=c.revision,u=c.confirmedByteLength,d=c.confirmedParts.size;if(c.lifecycle===`uploading`)for(let s of ea(o.partCount,c.confirmedParts)){let c=s-1;ga(r.signal);let f=c*o.partByteLength,p=Math.min(f+o.partByteLength,r.byteLength),m=p-f,h=t.partChecksums[c];if(!h)throw new a(`invalid_response`);let g=await n.createUploadPartDescriptor({workspaceId:r.workspaceId,uploadId:o.uploadId,partNumber:s,checksumSha256:h,contentMd5:t.partMd5s[c],...r.signal===void 0?{}:{signal:r.signal}}),_=g.data;if(_.expectedByteLength!==m||_.expiresAtEpochMilliseconds>o.expiresAtEpochMilliseconds)throw new a(`invalid_response`,{status:g.status,requestId:g.requestId});let v=await aa(e,_,pa(r.source,f,p,m),r.signal);l=await na(n,r,o,s,l,m,v,h),u+=m,d+=1,$(r.onProgress,`uploading`,u,r.byteLength,d,i)}$(r.onProgress,`completing`,u,r.byteLength,d,i);let f=await ra(n,r,o,t);return f.data.state===`verifying`&&$(r.onProgress,`verifying`,u,r.byteLength,d,i),f}catch(e){throw r.signal?.aborted&&o&&await ma(n,r.workspaceId,o.uploadId),e instanceof a?e:r.signal?.aborted?new a(`aborted`):new a(`invalid_input`)}}function*ea(e,t){for(let n=1;n<=e;n+=1)t.has(n)||(yield n)}async function ta(e,t,n,r){let i=new Set,o=0,s=0,c,l,u;for(let d=0;d<100;d+=1){let f=await e.getUploadStatus({workspaceId:t.workspaceId,uploadId:n.uploadId,afterPartNumber:s,limit:100,...t.signal===void 0?{}:{signal:t.signal}}),p=f.data;sa(p,n),c?ca(p,c):(c=p,l=f.requestId);for(let e of p.confirmedParts){let n=r.partChecksums[e.partNumber-1];if(!n||e.checksumSha256!==n||i.has(e.partNumber))throw new a(`invalid_response`,{status:f.status,requestId:f.requestId});i.add(e.partNumber),o+=fa(t.byteLength,e.partNumber)}if(p.lifecycle===`ready`&&p.ready&&(la(p.ready,n,t,r,f.requestId),u=da(f,p.ready)),p.nextAfterPartNumber===null)break;if(d===99)throw new a(`invalid_response`,{status:f.status,requestId:f.requestId});s=p.nextAfterPartNumber}if(!c||n.mode===`presigned-multipart`&&[`completing`,`provider-completed`,`verifying`,`ready`].includes(c.lifecycle)&&i.size!==n.partCount)throw new a(`invalid_response`);return ua(c.lifecycle,l),Object.freeze({revision:c.revision,confirmedParts:i,confirmedByteLength:o,lifecycle:c.lifecycle,...u===void 0?{}:{readyResult:u}})}async function na(e,t,n,r,i,o,s,c){let l=i=>e.recordUploadPart({workspaceId:t.workspaceId,uploadId:n.uploadId,partNumber:r,expectedUploadRevision:i,byteLength:o,etag:s,checksumSha256:c,...t.signal===void 0?{}:{signal:t.signal}});try{return(await l(i)).data.revision}catch(i){if(!ha(i)||t.signal?.aborted)throw i;let o=await e.getUploadStatus({workspaceId:t.workspaceId,uploadId:n.uploadId,afterPartNumber:r-1,limit:1,...t.signal===void 0?{}:{signal:t.signal}}),s=o.data;sa(s,n),ua(s.lifecycle,o.requestId);let u=s.confirmedParts.find(e=>e.partNumber===r);if(u){if(u.checksumSha256!==c)throw new a(`invalid_response`,{status:o.status,requestId:o.requestId});return s.revision}if(s.lifecycle!==`uploading`)throw new a(`precondition_failed`);return(await l(s.revision)).data.revision}}async function ra(e,t,n,r){try{let i=await e.completeUpload({workspaceId:t.workspaceId,uploadId:n.uploadId,idempotencyKey:t.completionIdempotencyKey,verification:t.verification,...t.signal===void 0?{}:{signal:t.signal}});if(i.data.state===`ready`)la(i.data,n,t,r,i.requestId);else if(i.data.itemId!==n.itemId||i.data.versionId!==n.versionId||i.data.uploadId!==n.uploadId||i.data.totalByteLength!==t.byteLength)throw new a(`invalid_response`);return i}catch(i){if(!ha(i)||t.signal?.aborted)throw i;let a=await e.getUploadStatus({workspaceId:t.workspaceId,uploadId:n.uploadId,afterPartNumber:0,limit:1,...t.signal===void 0?{}:{signal:t.signal}}),o=a.data;if(sa(o,n),o.lifecycle!==`ready`||!o.ready)throw i;return la(o.ready,n,t,r,a.requestId),da(a,o.ready)}}async function ia(e,t,n,r){let i=Hi.create(),o=[],s=[];for(let c=0;c<n;c+=1){ga(r);let n=c*Q,l=Math.min(n+Q,t),u=Hi.create(),d=Xi.create();for(let t=n;t<l;t+=Qi){ga(r);let n=Math.min(t+Qi,l),o=pa(e,t,n,n-t),s=r?await On(o.arrayBuffer(),r):await o.arrayBuffer();if(s.byteLength!==n-t)throw new a(`invalid_input`);let c=new Uint8Array(s);i.update(c),u.update(c),d.update(c)}o.push(_a(u.digest())),s.push(_a(d.digest()))}return Object.freeze({callerDeclaredContentDigest:`sha256:${ji(i.digest())}`,partChecksums:Object.freeze(o),partMd5s:Object.freeze(s)})}async function aa(e,t,n,r){let i=t.expiresAtEpochMilliseconds-Date.now();if(i<1)throw new a(`invalid_response`);let o=wn(r,Math.min(e.timeoutMilliseconds,i)),s;try{if(s=await On(e.fetchImplementation(t.url,{method:t.method,body:n,headers:t.headers,credentials:`omit`,cache:`no-store`,redirect:`manual`,referrerPolicy:`no-referrer`,signal:o.signal}),o.signal),!(s instanceof Response))throw new a(`invalid_response`);if(s.status>=300&&s.status<400)throw new a(`invalid_response`,{status:s.status});let r=s.headers.get(`etag`),i=s.headers.get(`content-md5`),c=i===null||i===t.headers[`content-md5`];if(s.status<200||s.status>299||!va(r)||!c||!kn(t.headers,s))throw new a(`invalid_response`,{status:s.status});return r}catch(e){throw o.didTimeout()?new a(`timeout`):r?.aborted?new a(`aborted`):e instanceof a?e:new a(`network_error`)}finally{o.dispose(),s?.body?.cancel().catch(()=>{})}}function oa(e,t,n,r,i){let o=t===0?`server-mediated-zero-byte`:t<=Zi?`presigned-single`:`presigned-multipart`;if(e.mode!==o&&!(r===200&&t>0&&e.mode===`presigned-multipart`)||e.partByteLength!==Q||e.partCount!==n||e.expiresAtEpochMilliseconds<=Date.now())throw new a(`invalid_response`,{status:r,requestId:i})}function sa(e,t){if(e.itemId!==t.itemId||e.versionId!==t.versionId||e.uploadId!==t.uploadId||e.mode!==t.mode||e.revision<t.revision||e.partPolicy.partByteLength!==t.partByteLength||e.partPolicy.partCount!==t.partCount||e.partPolicy.maxParts!==1e4||e.expiresAtEpochMilliseconds!==t.expiresAtEpochMilliseconds)throw new a(`invalid_response`)}function ca(e,t){if(e.itemId!==t.itemId||e.versionId!==t.versionId||e.uploadId!==t.uploadId||e.mode!==t.mode||e.lifecycle!==t.lifecycle||e.revision!==t.revision||e.partPolicy.partByteLength!==t.partPolicy.partByteLength||e.partPolicy.partCount!==t.partPolicy.partCount||e.partPolicy.maxParts!==t.partPolicy.maxParts||e.expiresAtEpochMilliseconds!==t.expiresAtEpochMilliseconds||JSON.stringify(e.ready)!==JSON.stringify(t.ready))throw new a(`invalid_response`)}function la(e,t,n,r,i){if(e.itemId!==t.itemId||e.versionId!==t.versionId||e.uploadId!==t.uploadId||e.byteLength!==n.byteLength||e.callerDeclaredContentDigest!==r.callerDeclaredContentDigest||e.displayFilename!==n.displayFilename||e.mediaType!==n.mediaType)throw new a(`invalid_response`,{status:200,requestId:i})}function ua(e,t){if(e===`initiating`||e===`recovery-required`)throw new a(`upload_recovery_required`,{status:409,...t===void 0?{}:{requestId:t}});if(e===`aborting`||e===`aborted`||e===`failed`)throw new a(`precondition_failed`,{status:409,...t===void 0?{}:{requestId:t}})}function da(e,t){return Object.freeze({data:t,status:e.status,requestId:e.requestId,validators:e.validators})}function fa(e,t){return Math.min(Q,e-(t-1)*Q)}function pa(e,t,n,r){try{let i=e.slice(t,n);if(!(i instanceof Blob)||i.size!==r)throw new a(`invalid_input`);return i}catch(e){throw e instanceof a?e:new a(`invalid_input`)}}function $(e,t,n,r,i,a){if(!e)return;let o=Object.freeze({phase:t,confirmedByteLength:n,totalByteLength:r,confirmedPartCount:i,totalPartCount:a});try{e(o)}catch{}}async function ma(e,t,n){let r=new AbortController,i=setTimeout(()=>r.abort(),5e3);try{await e.abortUpload({workspaceId:t,uploadId:n,signal:r.signal})}catch{}finally{clearTimeout(i)}}function ha(e){return e instanceof a&&(e.code===`network_error`||e.code===`timeout`||e.code===`invalid_response`)}function ga(e){if(e?.aborted)throw new a(`aborted`)}function _a(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t)}function va(e){return e!==null&&e.length>=1&&e.length<=1024&&/^[\x20-\x7e]+$/.test(e)}async function ya(e,t,n,r){let i=B(t,[`workspaceId`,`itemId`,`expectedVersionId`,`source`,`idempotencyKey`,`completionIdempotencyKey`],[`signal`,`onProgress`]),o=I({workspaceId:i.workspaceId,itemId:i.itemId,...i.signal===void 0?{}:{signal:i.signal}});if(!(i.source instanceof Blob)||typeof i.expectedVersionId!=`string`||!/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(i.expectedVersionId)||typeof i.idempotencyKey!=`string`||!/^[A-Za-z0-9_-]{16,128}$/.test(i.idempotencyKey)||typeof i.completionIdempotencyKey!=`string`||!/^[A-Za-z0-9_-]{16,128}$/.test(i.completionIdempotencyKey)||i.onProgress!==void 0&&typeof i.onProgress!=`function`)throw new a(`invalid_input`);let s=i.expectedVersionId,c=r;if(!c){let[e,t]=await Promise.all([n.getItem(o),n.getItemVersion({...o,versionId:s})]);if(e.data.type!==`file`||!e.data.parentId)throw new a(`invalid_input`);c={parentItemId:e.data.parentId,displayFilename:t.data.displayFilename,mediaType:t.data.mediaType,protectionClassification:t.data.protectionClassification}}let l=i.source.slice(0,i.source.size,c.mediaType),u;try{return await $i(e,{workspaceId:o.workspaceId,parentItemId:c.parentItemId,source:l,displayFilename:c.displayFilename,mediaType:c.mediaType,protectionClassification:c.protectionClassification,idempotencyKey:i.idempotencyKey,completionIdempotencyKey:i.completionIdempotencyKey,...o.signal===void 0?{}:{signal:o.signal},...i.onProgress===void 0?{}:{onProgress:i.onProgress}},{...n,async createUpload(e){let t=await n.createFileVersionUpload({...o,expectedVersionId:s,digest:e.callerDeclaredContentDigest,byteLength:l.size,...e.contentMd5===void 0?{}:{contentMd5:e.contentMd5},idempotencyKey:e.idempotencyKey});return u=t.data.uploadId,t},async completeUpload(e){return n.commitFileVersion({...o,expectedVersionId:s,uploadId:e.uploadId,idempotencyKey:e.idempotencyKey})}})}catch(t){if(e.authorizationScheme!==`DriveEditing`&&t instanceof a&&t.code===`precondition_failed`&&u)try{await n.abortUpload({workspaceId:o.workspaceId,uploadId:u,signal:AbortSignal.timeout(5e3)})}catch{}throw t}}function ba(e){let t=ir(e),n=Lr(t);return Object.freeze({...ar(n),uploadFileVersion:e=>{let{metadata:r,...i}=e;return ya(t,i,n,r)}})}function xa(e){let t=Sn(e),n=Lr(t);return Object.freeze({...n,uploadFile:e=>$i(t,e,n),uploadFileVersion:e=>ya(t,e,n)})}export{fr as collectOwnedItems,xa as createDriveClient,ba as createDriveEditingClient,Kn as createDriveVisitorClient,Yn as createVisitorSessionToken};