@finueva/drive 0.7.0 → 0.10.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 +28 -0
- package/README.md +27 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -3371
- package/dist/contract.d.ts +1549 -546
- package/dist/core.d.ts +3 -1
- package/dist/core.js +1 -57
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -3371
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -2588
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3371 +1 @@
|
|
|
1
|
-
//#region src/core.ts
|
|
2
|
-
const DRIVE_API_ERROR_CODES = Object.freeze([
|
|
3
|
-
"authentication_required",
|
|
4
|
-
"identity_authority_unavailable",
|
|
5
|
-
"permission_denied",
|
|
6
|
-
"resource_not_found",
|
|
7
|
-
"invalid_request",
|
|
8
|
-
"invalid_pagination_cursor",
|
|
9
|
-
"invalid_idempotency_key",
|
|
10
|
-
"precondition_failed",
|
|
11
|
-
"range_not_satisfiable",
|
|
12
|
-
"idempotency_conflict",
|
|
13
|
-
"quota_exceeded",
|
|
14
|
-
"upload_recovery_required",
|
|
15
|
-
"service_unavailable",
|
|
16
|
-
"internal_error"
|
|
17
|
-
]);
|
|
18
|
-
const DRIVE_API_ERROR_MESSAGES = Object.freeze({
|
|
19
|
-
authentication_required: "Authentication is required.",
|
|
20
|
-
identity_authority_unavailable: "Authentication is temporarily unavailable.",
|
|
21
|
-
permission_denied: "The requested action is not permitted.",
|
|
22
|
-
resource_not_found: "The requested resource was not found.",
|
|
23
|
-
invalid_request: "The request is invalid.",
|
|
24
|
-
invalid_pagination_cursor: "The pagination cursor is invalid.",
|
|
25
|
-
invalid_idempotency_key: "The idempotency key is invalid.",
|
|
26
|
-
precondition_failed: "The request precondition failed.",
|
|
27
|
-
range_not_satisfiable: "The requested byte range is not satisfiable.",
|
|
28
|
-
idempotency_conflict: "The idempotency key conflicts with an earlier request.",
|
|
29
|
-
quota_exceeded: "The workspace storage quota would be exceeded.",
|
|
30
|
-
upload_recovery_required: "The upload requires recovery before it can continue.",
|
|
31
|
-
service_unavailable: "The service is temporarily unavailable.",
|
|
32
|
-
internal_error: "The request could not be completed."
|
|
33
|
-
});
|
|
34
|
-
const SDK_MESSAGES = Object.freeze({
|
|
35
|
-
invalid_input: "The Drive SDK input is invalid.",
|
|
36
|
-
credential_unavailable: "A Drive credential could not be obtained.",
|
|
37
|
-
network_error: "The Drive request could not reach the service.",
|
|
38
|
-
timeout: "The Drive request timed out.",
|
|
39
|
-
aborted: "The Drive request was aborted.",
|
|
40
|
-
invalid_response: "Drive returned an invalid response."
|
|
41
|
-
});
|
|
42
|
-
var DriveError = class extends Error {
|
|
43
|
-
code;
|
|
44
|
-
status;
|
|
45
|
-
requestId;
|
|
46
|
-
details;
|
|
47
|
-
constructor(code, options = {}) {
|
|
48
|
-
super(code in DRIVE_API_ERROR_MESSAGES ? DRIVE_API_ERROR_MESSAGES[code] : SDK_MESSAGES[code]);
|
|
49
|
-
this.name = "DriveError";
|
|
50
|
-
this.code = code;
|
|
51
|
-
this.status = options.status ?? null;
|
|
52
|
-
this.requestId = options.requestId ?? null;
|
|
53
|
-
this.details = Object.freeze({});
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/internal/client/response.ts
|
|
58
|
-
const ERROR_BODY_LIMIT = 16 * 1024;
|
|
59
|
-
const SUCCESS_BODY_LIMIT = 256 * 1024;
|
|
60
|
-
const RESPONSE_CHUNK_LIMIT = 256;
|
|
61
|
-
const RESPONSE_DEADLINE_MILLISECONDS = 5e3;
|
|
62
|
-
const REQUEST_ID = /^[A-Za-z0-9_-]{16,128}$/;
|
|
63
|
-
const COLLECTION_ETAG = /^"drive\.permission-collection\.v1\.(0|[1-9][0-9]*)"$/;
|
|
64
|
-
const GRANT_ETAG$1 = /^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/;
|
|
65
|
-
const LIST_ETAG$1 = /^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/;
|
|
66
|
-
const ITEM_ETAG = /^"drive\.item\.v1\.(0|[1-9][0-9]*)"$/;
|
|
67
|
-
async function parseResponse(response, operationSignal, preconditionStatus, successStatuses, guard, allowsQuotaExceeded, allowedErrorCodes) {
|
|
68
|
-
const requestId = safeRequestId(response.headers.get("x-request-id"));
|
|
69
|
-
if (requestId === null) {
|
|
70
|
-
cancelResponse(response);
|
|
71
|
-
throw new DriveError("invalid_response", { status: response.status });
|
|
72
|
-
}
|
|
73
|
-
if (!successStatuses.includes(response.status)) throw await normalizeError(response, requestId, operationSignal, preconditionStatus, allowsQuotaExceeded, allowedErrorCodes);
|
|
74
|
-
if (response.status === 304) {
|
|
75
|
-
const contentLength = response.headers.get("content-length");
|
|
76
|
-
const etag = response.headers.get("etag");
|
|
77
|
-
const status = response.status;
|
|
78
|
-
if (response.body !== null || contentLength !== null && contentLength !== "0" || response.headers.has("content-type") || etag === null || !/^"[\x21\x23-\x7e]{1,1022}"$/.test(etag) || !guard(void 0, status, response.headers)) {
|
|
79
|
-
cancelResponse(response);
|
|
80
|
-
throw new DriveError("invalid_response", {
|
|
81
|
-
status,
|
|
82
|
-
requestId
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return Object.freeze({
|
|
86
|
-
data: void 0,
|
|
87
|
-
status,
|
|
88
|
-
requestId,
|
|
89
|
-
validators: Object.freeze({ etag })
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
const { value } = await parseBoundedJson(response, SUCCESS_BODY_LIMIT, response.status, requestId, operationSignal);
|
|
93
|
-
const status = response.status;
|
|
94
|
-
if (!guard(value, status, response.headers)) throw new DriveError("invalid_response", {
|
|
95
|
-
status,
|
|
96
|
-
requestId
|
|
97
|
-
});
|
|
98
|
-
return Object.freeze({
|
|
99
|
-
data: value,
|
|
100
|
-
status,
|
|
101
|
-
requestId,
|
|
102
|
-
validators: readValidators(response.headers)
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
async function parseNoContentResponse(response, operationSignal, preconditionStatus, successStatuses, allowedErrorCodes) {
|
|
106
|
-
const requestId = safeRequestId(response.headers.get("x-request-id"));
|
|
107
|
-
if (requestId === null) {
|
|
108
|
-
cancelResponse(response);
|
|
109
|
-
throw new DriveError("invalid_response", { status: response.status });
|
|
110
|
-
}
|
|
111
|
-
if (!successStatuses.includes(response.status)) throw await normalizeError(response, requestId, operationSignal, preconditionStatus, false, allowedErrorCodes);
|
|
112
|
-
const contentLength = response.headers.get("content-length");
|
|
113
|
-
if (response.body !== null || contentLength !== null && contentLength !== "0" || response.headers.has("content-type")) {
|
|
114
|
-
cancelResponse(response);
|
|
115
|
-
throw new DriveError("invalid_response", {
|
|
116
|
-
status: response.status,
|
|
117
|
-
requestId
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return Object.freeze({
|
|
121
|
-
data: void 0,
|
|
122
|
-
status: response.status,
|
|
123
|
-
requestId,
|
|
124
|
-
validators: Object.freeze({})
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
function parseCollectionEtag(value) {
|
|
128
|
-
const match = COLLECTION_ETAG.exec(value);
|
|
129
|
-
if (!match) return void 0;
|
|
130
|
-
const revision = Number(match[1]);
|
|
131
|
-
return Number.isSafeInteger(revision) ? revision : void 0;
|
|
132
|
-
}
|
|
133
|
-
function parseGrantEtag(value) {
|
|
134
|
-
const match = GRANT_ETAG$1.exec(value);
|
|
135
|
-
if (!match) return void 0;
|
|
136
|
-
const collectionRevision = Number(match[1]);
|
|
137
|
-
const grantRevision = Number(match[2]);
|
|
138
|
-
return Number.isSafeInteger(collectionRevision) && Number.isSafeInteger(grantRevision) ? [collectionRevision, grantRevision] : void 0;
|
|
139
|
-
}
|
|
140
|
-
function parseItemEtag(value) {
|
|
141
|
-
const match = ITEM_ETAG.exec(value);
|
|
142
|
-
if (!match) return void 0;
|
|
143
|
-
const revision = Number(match[1]);
|
|
144
|
-
return Number.isSafeInteger(revision) ? revision : void 0;
|
|
145
|
-
}
|
|
146
|
-
async function normalizeError(response, headerRequestId, signal, preconditionStatus, allowsQuotaExceeded, allowedErrorCodes) {
|
|
147
|
-
let parsed;
|
|
148
|
-
try {
|
|
149
|
-
parsed = await parseBoundedJson(response, ERROR_BODY_LIMIT, response.status, headerRequestId, signal);
|
|
150
|
-
} catch (error) {
|
|
151
|
-
if (error instanceof DriveError && error.code === "aborted") return error;
|
|
152
|
-
return new DriveError("invalid_response", {
|
|
153
|
-
status: response.status,
|
|
154
|
-
requestId: headerRequestId
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
const value = parsed.value;
|
|
158
|
-
if (!isExactRecord$1(value, ["error"]) || !isExactRecord$1(value.error, [
|
|
159
|
-
"code",
|
|
160
|
-
"message",
|
|
161
|
-
"requestId",
|
|
162
|
-
"details"
|
|
163
|
-
])) return new DriveError("invalid_response", {
|
|
164
|
-
status: response.status,
|
|
165
|
-
requestId: headerRequestId
|
|
166
|
-
});
|
|
167
|
-
const envelope = value.error;
|
|
168
|
-
if (typeof envelope.code !== "string" || !DRIVE_API_ERROR_CODES.includes(envelope.code) || envelope.message !== DRIVE_API_ERROR_MESSAGES[envelope.code] || !REQUEST_ID.test(String(envelope.requestId)) || envelope.requestId !== headerRequestId || !isExactRecord$1(envelope.details, []) || !errorStatusMatches(envelope.code, response.status, preconditionStatus, allowsQuotaExceeded, allowedErrorCodes) || parsed.text !== JSON.stringify(value)) return new DriveError("invalid_response", {
|
|
169
|
-
status: response.status,
|
|
170
|
-
requestId: headerRequestId
|
|
171
|
-
});
|
|
172
|
-
return new DriveError(envelope.code, {
|
|
173
|
-
status: response.status,
|
|
174
|
-
requestId: envelope.requestId
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
function errorStatusMatches(code, status, preconditionStatus, allowsQuotaExceeded, allowedErrorCodes) {
|
|
178
|
-
if (allowedErrorCodes && !allowedErrorCodes.includes(code)) return false;
|
|
179
|
-
if (code === "quota_exceeded" && !allowsQuotaExceeded) return false;
|
|
180
|
-
return {
|
|
181
|
-
authentication_required: [401],
|
|
182
|
-
identity_authority_unavailable: [503],
|
|
183
|
-
permission_denied: [403],
|
|
184
|
-
resource_not_found: [404],
|
|
185
|
-
invalid_request: [422],
|
|
186
|
-
invalid_pagination_cursor: [422],
|
|
187
|
-
invalid_idempotency_key: [422],
|
|
188
|
-
precondition_failed: preconditionStatus === null ? [] : [preconditionStatus],
|
|
189
|
-
range_not_satisfiable: [416],
|
|
190
|
-
idempotency_conflict: [409],
|
|
191
|
-
quota_exceeded: [409],
|
|
192
|
-
upload_recovery_required: [409],
|
|
193
|
-
service_unavailable: [503],
|
|
194
|
-
internal_error: [500]
|
|
195
|
-
}[code].includes(status);
|
|
196
|
-
}
|
|
197
|
-
async function parseBoundedJson(response, maximumBytes, status, requestId, signal) {
|
|
198
|
-
if (!response.body) throw new DriveError("invalid_response", {
|
|
199
|
-
status,
|
|
200
|
-
requestId
|
|
201
|
-
});
|
|
202
|
-
const reader = response.body.getReader();
|
|
203
|
-
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
204
|
-
let size = 0;
|
|
205
|
-
let chunks = 0;
|
|
206
|
-
let text = "";
|
|
207
|
-
const contentLength = response.headers.get("content-length");
|
|
208
|
-
if (contentLength !== null && (!/^(?:0|[1-9][0-9]*)$/.test(contentLength) || Number(contentLength) > maximumBytes)) {
|
|
209
|
-
reader.cancel().catch(() => {});
|
|
210
|
-
throw new DriveError("invalid_response", {
|
|
211
|
-
status,
|
|
212
|
-
requestId
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
const deadline = new AbortController();
|
|
216
|
-
const timeout = setTimeout(() => deadline.abort(), RESPONSE_DEADLINE_MILLISECONDS);
|
|
217
|
-
try {
|
|
218
|
-
while (true) {
|
|
219
|
-
if (signal?.aborted) throw new DriveError("aborted");
|
|
220
|
-
const { done, value } = await readResponseChunk(reader, signal, deadline.signal);
|
|
221
|
-
if (done) break;
|
|
222
|
-
chunks += 1;
|
|
223
|
-
size += value.byteLength;
|
|
224
|
-
if (chunks > RESPONSE_CHUNK_LIMIT || size > maximumBytes) throw new DriveError("invalid_response", {
|
|
225
|
-
status,
|
|
226
|
-
requestId
|
|
227
|
-
});
|
|
228
|
-
text += decoder.decode(value, { stream: true });
|
|
229
|
-
}
|
|
230
|
-
text += decoder.decode();
|
|
231
|
-
return {
|
|
232
|
-
value: JSON.parse(text),
|
|
233
|
-
text
|
|
234
|
-
};
|
|
235
|
-
} catch (error) {
|
|
236
|
-
if (error instanceof DriveError) {
|
|
237
|
-
if (error.code === "aborted" || signal?.aborted) throw new DriveError("aborted");
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
throw new DriveError("invalid_response", {
|
|
241
|
-
status,
|
|
242
|
-
requestId
|
|
243
|
-
});
|
|
244
|
-
} finally {
|
|
245
|
-
clearTimeout(timeout);
|
|
246
|
-
reader.cancel().catch(() => {});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
async function readResponseChunk(reader, operationSignal, deadlineSignal) {
|
|
250
|
-
if (operationSignal?.aborted) throw new DriveError("aborted");
|
|
251
|
-
if (deadlineSignal.aborted) throw new DriveError("invalid_response");
|
|
252
|
-
let removeOperationAbort = () => {};
|
|
253
|
-
let removeDeadlineAbort = () => {};
|
|
254
|
-
const operationAbort = new Promise((_, reject) => {
|
|
255
|
-
if (!operationSignal) return;
|
|
256
|
-
const onAbort = () => reject(new DriveError("aborted"));
|
|
257
|
-
operationSignal.addEventListener("abort", onAbort, { once: true });
|
|
258
|
-
removeOperationAbort = () => operationSignal.removeEventListener("abort", onAbort);
|
|
259
|
-
});
|
|
260
|
-
const deadlineAbort = new Promise((_, reject) => {
|
|
261
|
-
const onAbort = () => reject(new DriveError("invalid_response"));
|
|
262
|
-
deadlineSignal.addEventListener("abort", onAbort, { once: true });
|
|
263
|
-
removeDeadlineAbort = () => deadlineSignal.removeEventListener("abort", onAbort);
|
|
264
|
-
});
|
|
265
|
-
try {
|
|
266
|
-
return await Promise.race([
|
|
267
|
-
reader.read(),
|
|
268
|
-
operationAbort,
|
|
269
|
-
deadlineAbort
|
|
270
|
-
]);
|
|
271
|
-
} finally {
|
|
272
|
-
removeOperationAbort();
|
|
273
|
-
removeDeadlineAbort();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function cancelResponse(response) {
|
|
277
|
-
response.body?.cancel().catch(() => {});
|
|
278
|
-
}
|
|
279
|
-
function safeRequestId(value) {
|
|
280
|
-
return value !== null && REQUEST_ID.test(value) ? value : null;
|
|
281
|
-
}
|
|
282
|
-
function readValidators(headers) {
|
|
283
|
-
const etag = headers.get("etag");
|
|
284
|
-
const permissionCollectionEtag = headers.get("drive-permission-collection-etag");
|
|
285
|
-
const permissionGrantEtag = headers.get("drive-permission-grant-etag");
|
|
286
|
-
return Object.freeze({
|
|
287
|
-
...etag !== null && (LIST_ETAG$1.test(etag) || parseItemEtag(etag) !== void 0) ? { etag } : {},
|
|
288
|
-
...permissionCollectionEtag !== null && parseCollectionEtag(permissionCollectionEtag) !== void 0 ? { permissionCollectionEtag } : {},
|
|
289
|
-
...permissionGrantEtag !== null && parseGrantEtag(permissionGrantEtag) !== void 0 ? { permissionGrantEtag } : {}
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
function isExactRecord$1(value, keys) {
|
|
293
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
294
|
-
return Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
|
|
295
|
-
}
|
|
296
|
-
//#endregion
|
|
297
|
-
//#region src/internal/client/guards.ts
|
|
298
|
-
const ITEM_ID$1 = /^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
299
|
-
const WORKSPACE_ID$1 = /^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
300
|
-
const VOLUME_ID = /^drive\.volume\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
301
|
-
const GRANT_ID$1 = /^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
302
|
-
const UPLOAD_ID$1 = /^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
303
|
-
const VERSION_ID$1 = /^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
304
|
-
const RETRIEVAL_ID = /^drive\.retrieval\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
305
|
-
const CURSOR$1 = /^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/;
|
|
306
|
-
const AUTH_ID$1 = /^[A-Za-z0-9_-]{1,128}$/;
|
|
307
|
-
const GRANT_ETAG = /^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/;
|
|
308
|
-
const LIST_ETAG = /^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/;
|
|
309
|
-
const PERMISSION_ACTIONS$1 = Object.freeze([
|
|
310
|
-
"items:content:read",
|
|
311
|
-
"items:create",
|
|
312
|
-
"items:delete",
|
|
313
|
-
"items:metadata:read",
|
|
314
|
-
"items:permissions:read",
|
|
315
|
-
"items:update"
|
|
316
|
-
]);
|
|
317
|
-
const EFFECTIVE_ACTIONS = Object.freeze([
|
|
318
|
-
"items:content:read",
|
|
319
|
-
"items:create",
|
|
320
|
-
"items:delete",
|
|
321
|
-
"items:metadata:read",
|
|
322
|
-
"items:permissions:manage",
|
|
323
|
-
"items:permissions:read",
|
|
324
|
-
"items:update"
|
|
325
|
-
]);
|
|
326
|
-
const MAX_UPLOAD_BYTE_LENGTH$1 = 33554432e4;
|
|
327
|
-
const UPLOAD_PART_BYTE_LENGTH$2 = 32 * 1024 * 1024;
|
|
328
|
-
const CONTENT_DIGEST$1 = /^sha256:[0-9a-f]{64}$/;
|
|
329
|
-
const UTF8 = new TextEncoder();
|
|
330
|
-
function isCurrentWorkspace(value) {
|
|
331
|
-
if (!isExactRecord(value, [
|
|
332
|
-
"workspaceId",
|
|
333
|
-
"rootVolumeId",
|
|
334
|
-
"rootItemId",
|
|
335
|
-
"workspaceReference"
|
|
336
|
-
]) || typeof value.workspaceId !== "string" || !WORKSPACE_ID$1.test(value.workspaceId) || typeof value.rootVolumeId !== "string" || !VOLUME_ID.test(value.rootVolumeId) || typeof value.rootItemId !== "string" || !ITEM_ID$1.test(value.rootItemId)) return false;
|
|
337
|
-
const reference = value.workspaceReference;
|
|
338
|
-
return isExactRecord(reference, ["type", "userId"]) && reference.type === "personal" && typeof reference.userId === "string" && AUTH_ID$1.test(reference.userId) || isExactRecord(reference, ["type", "organizationId"]) && reference.type === "organization" && typeof reference.organizationId === "string" && AUTH_ID$1.test(reference.organizationId);
|
|
339
|
-
}
|
|
340
|
-
function isManagedDownloadDescriptor(value) {
|
|
341
|
-
if (!isExactRecord(value, [
|
|
342
|
-
"mode",
|
|
343
|
-
"method",
|
|
344
|
-
"url",
|
|
345
|
-
"headers",
|
|
346
|
-
"expiresAtEpochMilliseconds",
|
|
347
|
-
"response"
|
|
348
|
-
]) || value.mode !== "presigned-single" || value.method !== "GET" && value.method !== "HEAD" || typeof value.url !== "string" || !isSafeCapabilityUrl(value.url) || !isSafeInteger$1(value.expiresAtEpochMilliseconds) || !isExactRecord(value.headers, ["if-match"]) && !isExactRecord(value.headers, ["if-match", "range"]) || typeof value.headers["if-match"] !== "string" || !isStrongEtag(value.headers["if-match"]) || value.headers.range !== void 0 && (typeof value.headers.range !== "string" || !/^bytes=(?:0|[1-9][0-9]*)-(?:0|[1-9][0-9]*)$/.test(value.headers.range)) || !isExactRecord(value.response, [
|
|
349
|
-
"status",
|
|
350
|
-
"versionId",
|
|
351
|
-
"byteLength",
|
|
352
|
-
"contentLength",
|
|
353
|
-
"contentType",
|
|
354
|
-
"contentDisposition",
|
|
355
|
-
"etag",
|
|
356
|
-
"acceptRanges",
|
|
357
|
-
"contentRange"
|
|
358
|
-
]) || value.response.status !== 200 && value.response.status !== 206 || typeof value.response.versionId !== "string" || !VERSION_ID$1.test(value.response.versionId) || !isSafeInteger$1(value.response.byteLength) || !isSafeInteger$1(value.response.contentLength) || typeof value.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(value.response.contentType) || typeof value.response.contentDisposition !== "string" || value.response.contentDisposition.length > 2048 || !/^[\x20-\x7e]+$/.test(value.response.contentDisposition) || value.response.etag !== value.headers["if-match"] || value.response.acceptRanges !== "bytes" || value.response.contentRange !== null && typeof value.response.contentRange !== "string") return false;
|
|
359
|
-
if (!downloadDescriptorIsCoherent(value)) return false;
|
|
360
|
-
Object.freeze(value.headers);
|
|
361
|
-
Object.freeze(value.response);
|
|
362
|
-
Object.freeze(value);
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
function downloadDescriptorIsCoherent(value) {
|
|
366
|
-
const response = value.response;
|
|
367
|
-
if (response.contentLength > response.byteLength || value.method === "HEAD" && response.status !== 200 || !response.contentDisposition.startsWith("attachment; filename=\"")) return false;
|
|
368
|
-
if (response.status === 200) return value.headers.range === void 0 && response.contentRange === null && response.contentLength === response.byteLength;
|
|
369
|
-
if (value.method !== "GET" || value.headers.range === void 0 || response.contentRange === null) return false;
|
|
370
|
-
const range = /^bytes=(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$/.exec(value.headers.range);
|
|
371
|
-
const contentRange = /^bytes (0|[1-9][0-9]*)-(0|[1-9][0-9]*)\/(0|[1-9][0-9]*)$/.exec(response.contentRange);
|
|
372
|
-
if (!range || !contentRange) return false;
|
|
373
|
-
const start = Number(range[1]);
|
|
374
|
-
const end = Number(range[2]);
|
|
375
|
-
const contentStart = Number(contentRange[1]);
|
|
376
|
-
const contentEnd = Number(contentRange[2]);
|
|
377
|
-
const byteLength = Number(contentRange[3]);
|
|
378
|
-
return [
|
|
379
|
-
start,
|
|
380
|
-
end,
|
|
381
|
-
contentStart,
|
|
382
|
-
contentEnd,
|
|
383
|
-
byteLength
|
|
384
|
-
].every(isSafeInteger$1) && start === contentStart && end === contentEnd && byteLength === response.byteLength && start <= end && end < byteLength && response.contentLength === end - start + 1;
|
|
385
|
-
}
|
|
386
|
-
function isManagedDownloadRestorePending(value) {
|
|
387
|
-
return isExactRecord(value, [
|
|
388
|
-
"mode",
|
|
389
|
-
"operationId",
|
|
390
|
-
"versionId",
|
|
391
|
-
"state",
|
|
392
|
-
"pollAfterSeconds"
|
|
393
|
-
]) && value.mode === "restore-pending" && typeof value.operationId === "string" && RETRIEVAL_ID.test(value.operationId) && typeof value.versionId === "string" && VERSION_ID$1.test(value.versionId) && (value.state === "pending" || value.state === "restoring") && isSafeInteger$1(value.pollAfterSeconds) && value.pollAfterSeconds >= 1 && value.pollAfterSeconds <= 60;
|
|
394
|
-
}
|
|
395
|
-
function isFolderPage(value, workspaceId, parentItemId) {
|
|
396
|
-
if (!(isExactRecord(value, ["items", "nextCursor"]) && Array.isArray(value.items) && value.items.length <= 50 && value.items.every(isFolderItem) && (value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length <= 699 && CURSOR$1.test(value.nextCursor)))) return false;
|
|
397
|
-
return value.items.every((item) => item.workspaceId === workspaceId && item.parentItemId === parentItemId) && isStrictlyOrdered(value.items, (item) => item.itemId);
|
|
398
|
-
}
|
|
399
|
-
function isFolderItem(value) {
|
|
400
|
-
return isExactRecord(value, [
|
|
401
|
-
"workspaceId",
|
|
402
|
-
"volumeId",
|
|
403
|
-
"itemId",
|
|
404
|
-
"parentItemId",
|
|
405
|
-
"kind",
|
|
406
|
-
"name",
|
|
407
|
-
"visibility",
|
|
408
|
-
"revision"
|
|
409
|
-
]) && typeof value.workspaceId === "string" && WORKSPACE_ID$1.test(value.workspaceId) && typeof value.volumeId === "string" && VOLUME_ID.test(value.volumeId) && typeof value.itemId === "string" && ITEM_ID$1.test(value.itemId) && typeof value.parentItemId === "string" && ITEM_ID$1.test(value.parentItemId) && (value.kind === "file" || value.kind === "folder") && isSafeFilename$1(value.name) && (value.visibility === "workspace" || value.visibility === "restricted") && isSafeInteger$1(value.revision);
|
|
410
|
-
}
|
|
411
|
-
function isManagedLifecycleItem(value, workspaceId, itemId, expectedState) {
|
|
412
|
-
if (!isExactRecord(value, [
|
|
413
|
-
"workspaceId",
|
|
414
|
-
"volumeId",
|
|
415
|
-
"itemId",
|
|
416
|
-
"parentItemId",
|
|
417
|
-
"kind",
|
|
418
|
-
"name",
|
|
419
|
-
"state",
|
|
420
|
-
"revision",
|
|
421
|
-
"purgeAfterEpochMilliseconds"
|
|
422
|
-
]) || value.workspaceId !== workspaceId || value.itemId !== itemId || typeof value.volumeId !== "string" || !VOLUME_ID.test(value.volumeId) || typeof value.parentItemId !== "string" || !ITEM_ID$1.test(value.parentItemId) || value.kind !== "file" && value.kind !== "folder" || !isSafeFilename$1(value.name) || value.state !== expectedState || !isSafeInteger$1(value.revision) || (value.state === "active" ? value.purgeAfterEpochMilliseconds !== null : !isSafeInteger$1(value.purgeAfterEpochMilliseconds))) return false;
|
|
423
|
-
Object.freeze(value);
|
|
424
|
-
return true;
|
|
425
|
-
}
|
|
426
|
-
function isManagedItemMetadata(value, workspaceId, itemId) {
|
|
427
|
-
if (!isExactRecord(value, [
|
|
428
|
-
"workspaceId",
|
|
429
|
-
"itemId",
|
|
430
|
-
"parentId",
|
|
431
|
-
"type",
|
|
432
|
-
"name",
|
|
433
|
-
"lifecycleState",
|
|
434
|
-
"revision",
|
|
435
|
-
"currentVersion"
|
|
436
|
-
]) || value.workspaceId !== workspaceId || value.itemId !== itemId || !(value.parentId === null || typeof value.parentId === "string" && ITEM_ID$1.test(value.parentId)) || value.type !== "file" && value.type !== "folder" || !isSafeFilename$1(value.name) || value.lifecycleState !== "active" || !isSafeInteger$1(value.revision) || (value.type === "folder" ? value.currentVersion !== null : !isCurrentVersionMetadata(value.currentVersion))) return false;
|
|
437
|
-
if (value.currentVersion !== null) Object.freeze(value.currentVersion);
|
|
438
|
-
Object.freeze(value);
|
|
439
|
-
return true;
|
|
440
|
-
}
|
|
441
|
-
function isWorkspaceItemSearchPage(value, workspaceId, query, limit) {
|
|
442
|
-
if (!isExactRecord(value, ["items", "nextCursor"]) || !Array.isArray(value.items) || value.items.length > limit || !value.items.every((item) => isWorkspaceItemSearchItem(item, workspaceId, query)) || !(value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length <= 699 && CURSOR$1.test(value.nextCursor)) || value.items.length === 0 && value.nextCursor !== null || new Set(value.items.map((item) => item.itemId)).size !== value.items.length || !isWorkspaceItemSearchOrder(value.items)) return false;
|
|
443
|
-
for (const item of value.items) {
|
|
444
|
-
if (item.currentVersion !== null) Object.freeze(item.currentVersion);
|
|
445
|
-
Object.freeze(item);
|
|
446
|
-
}
|
|
447
|
-
Object.freeze(value.items);
|
|
448
|
-
Object.freeze(value);
|
|
449
|
-
return true;
|
|
450
|
-
}
|
|
451
|
-
function itemEtagMatchesRevision(headers, revision) {
|
|
452
|
-
const etag = headers.get("etag");
|
|
453
|
-
return etag !== null && parseItemEtag(etag) === revision;
|
|
454
|
-
}
|
|
455
|
-
function isCurrentVersionMetadata(value) {
|
|
456
|
-
return isExactRecord(value, [
|
|
457
|
-
"versionId",
|
|
458
|
-
"state",
|
|
459
|
-
"byteLength",
|
|
460
|
-
"mediaType",
|
|
461
|
-
"protectionClassification"
|
|
462
|
-
]) && typeof value.versionId === "string" && VERSION_ID$1.test(value.versionId) && value.state === "current" && isSafeInteger$1(value.byteLength) && isMediaType$1(value.mediaType) && (value.protectionClassification === "ordinary" || value.protectionClassification === "opaque-encrypted");
|
|
463
|
-
}
|
|
464
|
-
function isWorkspaceItemSearchItem(value, workspaceId, query) {
|
|
465
|
-
return isExactRecord(value, [
|
|
466
|
-
"workspaceId",
|
|
467
|
-
"volumeId",
|
|
468
|
-
"provider",
|
|
469
|
-
"itemId",
|
|
470
|
-
"parentId",
|
|
471
|
-
"type",
|
|
472
|
-
"name",
|
|
473
|
-
"lifecycleState",
|
|
474
|
-
"revision",
|
|
475
|
-
"currentVersion"
|
|
476
|
-
]) && value.workspaceId === workspaceId && typeof value.volumeId === "string" && VOLUME_ID.test(value.volumeId) && value.provider === "managed" && typeof value.itemId === "string" && ITEM_ID$1.test(value.itemId) && (value.parentId === null || typeof value.parentId === "string" && ITEM_ID$1.test(value.parentId)) && (value.type === "file" || value.type === "folder") && isSafeFilename$1(value.name) && value.name.startsWith(query) && value.lifecycleState === "active" && isSafeInteger$1(value.revision) && (value.type === "folder" ? value.currentVersion === null : isCurrentVersionMetadata(value.currentVersion));
|
|
477
|
-
}
|
|
478
|
-
function isWorkspaceItemSearchOrder(items) {
|
|
479
|
-
for (let index = 1; index < items.length; index += 1) {
|
|
480
|
-
const previous = items[index - 1];
|
|
481
|
-
const current = items[index];
|
|
482
|
-
const nameOrder = compareBinary(previous.name, current.name);
|
|
483
|
-
if (nameOrder > 0 || nameOrder === 0 && previous.itemId >= current.itemId) return false;
|
|
484
|
-
}
|
|
485
|
-
return true;
|
|
486
|
-
}
|
|
487
|
-
function compareBinary(left, right) {
|
|
488
|
-
const leftBytes = UTF8.encode(left);
|
|
489
|
-
const rightBytes = UTF8.encode(right);
|
|
490
|
-
const length = Math.min(leftBytes.length, rightBytes.length);
|
|
491
|
-
for (let index = 0; index < length; index += 1) if (leftBytes[index] !== rightBytes[index]) return leftBytes[index] - rightBytes[index];
|
|
492
|
-
return leftBytes.length - rightBytes.length;
|
|
493
|
-
}
|
|
494
|
-
function isManagedItemVersionPage(value, limit) {
|
|
495
|
-
if (!isExactRecord(value, ["items", "nextCursor"]) || !Array.isArray(value.items) || value.items.length > limit || !value.items.every(isManagedItemVersion) || !(value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length <= 699 && CURSOR$1.test(value.nextCursor)) || value.nextCursor !== null && value.items.length === 0 || !isStrictlyOrdered(value.items, (version) => version.versionId)) return false;
|
|
496
|
-
for (const version of value.items) Object.freeze(version);
|
|
497
|
-
Object.freeze(value.items);
|
|
498
|
-
Object.freeze(value);
|
|
499
|
-
return true;
|
|
500
|
-
}
|
|
501
|
-
function isManagedItemVersionRestoreResult(value, versionId) {
|
|
502
|
-
if (!isExactRecord(value, ["itemRevision", "currentVersionId"]) || !isSafeInteger$1(value.itemRevision) || value.currentVersionId !== versionId) return false;
|
|
503
|
-
Object.freeze(value);
|
|
504
|
-
return true;
|
|
505
|
-
}
|
|
506
|
-
function isPermissionPage(value, headers, targetItemId) {
|
|
507
|
-
if (!(isExactRecord(value, [
|
|
508
|
-
"items",
|
|
509
|
-
"nextCursor",
|
|
510
|
-
"collectionRevision",
|
|
511
|
-
"collectionEtag"
|
|
512
|
-
]) && Array.isArray(value.items) && value.items.length <= 50 && value.items.every(isPermissionGrant) && (value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length <= 699 && CURSOR$1.test(value.nextCursor)) && isSafeInteger$1(value.collectionRevision) && typeof value.collectionEtag === "string" && parseCollectionEtag(value.collectionEtag) === value.collectionRevision)) return false;
|
|
513
|
-
const collectionHeader = headers.get("drive-permission-collection-etag");
|
|
514
|
-
const representationEtag = headers.get("etag");
|
|
515
|
-
const collectionRevision = value.collectionRevision;
|
|
516
|
-
if (!isSafeInteger$1(collectionRevision)) return false;
|
|
517
|
-
return collectionHeader === value.collectionEtag && representationEtag !== null && LIST_ETAG.test(representationEtag) && value.items.every((grant) => (grant.source === "direct" ? grant.sourceItemId === targetItemId : grant.sourceItemId !== targetItemId) && grant.etag === permissionGrantEtag(collectionRevision, grant.revision)) && isStrictlyOrdered(value.items, (grant) => `${grant.sourceItemId}\0${grant.grantId}`);
|
|
518
|
-
}
|
|
519
|
-
function isPermissionMutation(value, targetItemId, expectedGrantId) {
|
|
520
|
-
if (!isExactRecord(value, [
|
|
521
|
-
"outcome",
|
|
522
|
-
"grant",
|
|
523
|
-
"collectionRevision"
|
|
524
|
-
]) || value.outcome !== "committed" && value.outcome !== "replayed" || !isSafeInteger$1(value.collectionRevision)) return false;
|
|
525
|
-
const grant = value.grant;
|
|
526
|
-
return isExactRecord(grant, [
|
|
527
|
-
"source",
|
|
528
|
-
"sourceItemId",
|
|
529
|
-
"grantId",
|
|
530
|
-
"grantee",
|
|
531
|
-
"actions",
|
|
532
|
-
"availability",
|
|
533
|
-
"expiresAtEpochMilliseconds",
|
|
534
|
-
"revision"
|
|
535
|
-
]) && grant.source === "direct" && typeof grant.sourceItemId === "string" && grant.sourceItemId === targetItemId && typeof grant.grantId === "string" && GRANT_ID$1.test(grant.grantId) && (expectedGrantId === void 0 || grant.grantId === expectedGrantId) && isGrantee(grant.grantee) && isPermissionActions(grant.actions) && [
|
|
536
|
-
"active",
|
|
537
|
-
"expired",
|
|
538
|
-
"revoked"
|
|
539
|
-
].includes(String(grant.availability)) && (grant.expiresAtEpochMilliseconds === null || isSafeInteger$1(grant.expiresAtEpochMilliseconds)) && isSafeInteger$1(grant.revision);
|
|
540
|
-
}
|
|
541
|
-
function isEffectivePermissionResponse(value, targetItemId) {
|
|
542
|
-
if (!isExactRecord(value, ["actions"]) || !Array.isArray(value.actions) || value.actions.length !== 7) return false;
|
|
543
|
-
for (let index = 0; index < value.actions.length; index += 1) {
|
|
544
|
-
const action = value.actions[index];
|
|
545
|
-
if (action === void 0 || !isExactRecord(action, [
|
|
546
|
-
"action",
|
|
547
|
-
"allowed",
|
|
548
|
-
"basis",
|
|
549
|
-
"sourceItemId",
|
|
550
|
-
"grantId"
|
|
551
|
-
]) || action.action !== EFFECTIVE_ACTIONS[index] || typeof action.allowed !== "boolean" || !(action.basis === null || [
|
|
552
|
-
"workspace_visibility",
|
|
553
|
-
"restricted_administrator_bypass",
|
|
554
|
-
"direct_grant",
|
|
555
|
-
"inherited_grant"
|
|
556
|
-
].includes(String(action.basis))) || !(action.sourceItemId === null || typeof action.sourceItemId === "string" && ITEM_ID$1.test(action.sourceItemId)) || !(action.grantId === null || typeof action.grantId === "string" && GRANT_ID$1.test(action.grantId)) || !effectiveSourceIsCoherent(action, targetItemId)) return false;
|
|
557
|
-
}
|
|
558
|
-
return true;
|
|
559
|
-
}
|
|
560
|
-
function isUploadSession(value, expectedByteLength) {
|
|
561
|
-
if (!isExactRecord(value, [
|
|
562
|
-
"itemId",
|
|
563
|
-
"versionId",
|
|
564
|
-
"uploadId",
|
|
565
|
-
"mode",
|
|
566
|
-
"partByteLength",
|
|
567
|
-
"partCount",
|
|
568
|
-
"revision",
|
|
569
|
-
"expiresAtEpochMilliseconds"
|
|
570
|
-
]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID$1.test(value.versionId) || typeof value.uploadId !== "string" || !UPLOAD_ID$1.test(value.uploadId) || value.mode !== "presigned-multipart" && value.mode !== "server-mediated-zero-byte" || value.partByteLength !== UPLOAD_PART_BYTE_LENGTH$2 || !isSafeInteger$1(value.partCount) || value.partCount > 1e4 || value.partCount !== Math.ceil(expectedByteLength / UPLOAD_PART_BYTE_LENGTH$2) || (expectedByteLength === 0 ? value.mode !== "server-mediated-zero-byte" : value.mode !== "presigned-multipart") || !isSafeInteger$1(value.revision) || !isSafeInteger$1(value.expiresAtEpochMilliseconds) || value.expiresAtEpochMilliseconds <= Date.now()) return false;
|
|
571
|
-
Object.freeze(value);
|
|
572
|
-
return true;
|
|
573
|
-
}
|
|
574
|
-
function isUploadStatus(value, afterPartNumber, limit) {
|
|
575
|
-
if (!isExactRecord(value, [
|
|
576
|
-
"itemId",
|
|
577
|
-
"versionId",
|
|
578
|
-
"uploadId",
|
|
579
|
-
"mode",
|
|
580
|
-
"lifecycle",
|
|
581
|
-
"revision",
|
|
582
|
-
"partPolicy",
|
|
583
|
-
"confirmedParts",
|
|
584
|
-
"nextAfterPartNumber",
|
|
585
|
-
"expiresAtEpochMilliseconds",
|
|
586
|
-
"ready"
|
|
587
|
-
], ["verification"]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID$1.test(value.versionId) || typeof value.uploadId !== "string" || !UPLOAD_ID$1.test(value.uploadId) || value.mode !== "presigned-multipart" && value.mode !== "server-mediated-zero-byte" || ![
|
|
588
|
-
"initiating",
|
|
589
|
-
"recovery-required",
|
|
590
|
-
"uploading",
|
|
591
|
-
"completing",
|
|
592
|
-
"provider-completed",
|
|
593
|
-
"verifying",
|
|
594
|
-
"failed",
|
|
595
|
-
"ready",
|
|
596
|
-
"aborting",
|
|
597
|
-
"aborted"
|
|
598
|
-
].includes(String(value.lifecycle)) || !isSafeInteger$1(value.revision) || !isExactRecord(value.partPolicy, [
|
|
599
|
-
"partByteLength",
|
|
600
|
-
"partCount",
|
|
601
|
-
"maxParts"
|
|
602
|
-
]) || value.partPolicy.partByteLength !== UPLOAD_PART_BYTE_LENGTH$2 || !isSafeInteger$1(value.partPolicy.partCount) || value.partPolicy.partCount > 1e4 || value.partPolicy.maxParts !== 1e4 || (value.mode === "server-mediated-zero-byte" ? value.partPolicy.partCount !== 0 : value.partPolicy.partCount < 1) || !Array.isArray(value.confirmedParts) || value.confirmedParts.length > limit || !isSafeInteger$1(value.expiresAtEpochMilliseconds)) return false;
|
|
603
|
-
let previousPartNumber = afterPartNumber;
|
|
604
|
-
if (value.verification !== void 0) {
|
|
605
|
-
const progress = value.verification;
|
|
606
|
-
if (!isExactRecord(progress, [
|
|
607
|
-
"state",
|
|
608
|
-
"verifiedByteLength",
|
|
609
|
-
"totalByteLength",
|
|
610
|
-
"revision"
|
|
611
|
-
]) || ![
|
|
612
|
-
"pending",
|
|
613
|
-
"verified",
|
|
614
|
-
"failed"
|
|
615
|
-
].includes(String(progress.state)) || !isSafeInteger$1(progress.verifiedByteLength) || !isSafeInteger$1(progress.totalByteLength) || progress.totalByteLength > MAX_UPLOAD_BYTE_LENGTH$1 || progress.verifiedByteLength > progress.totalByteLength || !isSafeInteger$1(progress.revision) || progress.state === "verified" && progress.verifiedByteLength !== progress.totalByteLength) return false;
|
|
616
|
-
Object.freeze(progress);
|
|
617
|
-
}
|
|
618
|
-
if (["verifying", "failed"].includes(String(value.lifecycle)) && value.verification === void 0) return false;
|
|
619
|
-
for (const part of value.confirmedParts) {
|
|
620
|
-
if (!isExactRecord(part, ["partNumber", "checksumSha256"]) || !isSafeInteger$1(part.partNumber) || part.partNumber <= previousPartNumber || part.partNumber > value.partPolicy.partCount || !isPartChecksum$1(part.checksumSha256)) return false;
|
|
621
|
-
previousPartNumber = part.partNumber;
|
|
622
|
-
}
|
|
623
|
-
if (!(value.nextAfterPartNumber === null || isSafeInteger$1(value.nextAfterPartNumber) && value.confirmedParts.length === limit && value.nextAfterPartNumber === previousPartNumber) || value.mode === "server-mediated-zero-byte" && (value.confirmedParts.length !== 0 || value.nextAfterPartNumber !== null) || value.lifecycle === "ready" !== (value.ready !== null) || value.ready !== null && (!isReadyUpload(value.ready, { uploadId: value.uploadId }) || value.ready.itemId !== value.itemId || value.ready.versionId !== value.versionId || !isExactRecord(value.verification, [
|
|
624
|
-
"state",
|
|
625
|
-
"verifiedByteLength",
|
|
626
|
-
"totalByteLength",
|
|
627
|
-
"revision"
|
|
628
|
-
]) || value.verification.state !== "verified" || value.verification.totalByteLength !== value.ready.byteLength)) return false;
|
|
629
|
-
Object.freeze(value.partPolicy);
|
|
630
|
-
for (const part of value.confirmedParts) Object.freeze(part);
|
|
631
|
-
Object.freeze(value.confirmedParts);
|
|
632
|
-
Object.freeze(value);
|
|
633
|
-
return true;
|
|
634
|
-
}
|
|
635
|
-
function isUploadPartDescriptor(value, expectedPartNumber, allowInsecureHttp, contentMd5) {
|
|
636
|
-
if (!isExactRecord(value, [
|
|
637
|
-
"url",
|
|
638
|
-
"method",
|
|
639
|
-
"headers",
|
|
640
|
-
"partNumber",
|
|
641
|
-
"expectedByteLength",
|
|
642
|
-
"expiresAtEpochMilliseconds"
|
|
643
|
-
]) || !isSignedTransferUrl(value.url, allowInsecureHttp) || value.method !== "PUT" || !contentMd5 || !isExactRecord(value.headers, ["content-md5"]) || value.headers["content-md5"] !== contentMd5 || value.partNumber !== expectedPartNumber || !isSafeInteger$1(value.expectedByteLength) || value.expectedByteLength < 1 || value.expectedByteLength > UPLOAD_PART_BYTE_LENGTH$2 || !isSafeInteger$1(value.expiresAtEpochMilliseconds) || value.expiresAtEpochMilliseconds <= Date.now()) return false;
|
|
644
|
-
Object.freeze(value.headers);
|
|
645
|
-
Object.freeze(value);
|
|
646
|
-
return true;
|
|
647
|
-
}
|
|
648
|
-
function isUploadPartResult(value, expectedPartNumber, expectedUploadRevision) {
|
|
649
|
-
if (!isExactRecord(value, ["partNumber", "revision"]) || value.partNumber !== expectedPartNumber || value.revision !== expectedUploadRevision + 1 || !isSafeInteger$1(value.revision)) return false;
|
|
650
|
-
Object.freeze(value);
|
|
651
|
-
return true;
|
|
652
|
-
}
|
|
653
|
-
function isReadyUpload(value, expected) {
|
|
654
|
-
if (!isExactRecord(value, [
|
|
655
|
-
"itemId",
|
|
656
|
-
"versionId",
|
|
657
|
-
"uploadId",
|
|
658
|
-
"byteLength",
|
|
659
|
-
"callerDeclaredContentDigest",
|
|
660
|
-
"displayFilename",
|
|
661
|
-
"mediaType",
|
|
662
|
-
"state"
|
|
663
|
-
]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID$1.test(value.versionId) || value.uploadId !== expected.uploadId || !isSafeInteger$1(value.byteLength) || value.byteLength < 0 || value.byteLength > MAX_UPLOAD_BYTE_LENGTH$1 || typeof value.callerDeclaredContentDigest !== "string" || !CONTENT_DIGEST$1.test(value.callerDeclaredContentDigest) || !isSafeFilename$1(value.displayFilename) || !isMediaType$1(value.mediaType) || value.state !== "ready" || expected.byteLength !== void 0 && value.byteLength !== expected.byteLength || expected.callerDeclaredContentDigest !== void 0 && value.callerDeclaredContentDigest !== expected.callerDeclaredContentDigest || expected.displayFilename !== void 0 && value.displayFilename !== expected.displayFilename || expected.mediaType !== void 0 && value.mediaType !== expected.mediaType) return false;
|
|
664
|
-
Object.freeze(value);
|
|
665
|
-
return true;
|
|
666
|
-
}
|
|
667
|
-
function isPendingUpload(value, uploadId) {
|
|
668
|
-
if (!isExactRecord(value, [
|
|
669
|
-
"itemId",
|
|
670
|
-
"versionId",
|
|
671
|
-
"uploadId",
|
|
672
|
-
"state",
|
|
673
|
-
"verifiedByteLength",
|
|
674
|
-
"totalByteLength",
|
|
675
|
-
"verificationRevision"
|
|
676
|
-
]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID$1.test(value.versionId) || value.uploadId !== uploadId || value.state !== "verifying" || !isSafeInteger$1(value.verifiedByteLength) || !isSafeInteger$1(value.totalByteLength) || value.totalByteLength > MAX_UPLOAD_BYTE_LENGTH$1 || value.verifiedByteLength > value.totalByteLength || !isSafeInteger$1(value.verificationRevision)) return false;
|
|
677
|
-
Object.freeze(value);
|
|
678
|
-
return true;
|
|
679
|
-
}
|
|
680
|
-
function isPartChecksum$1(value) {
|
|
681
|
-
return typeof value === "string" && /^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/.test(value);
|
|
682
|
-
}
|
|
683
|
-
function isManagedItemVersion(value) {
|
|
684
|
-
const valid = isExactRecord(value, managedItemVersionKeys) && managedItemVersionFieldsAreValid(value);
|
|
685
|
-
if (valid) Object.freeze(value);
|
|
686
|
-
return valid;
|
|
687
|
-
}
|
|
688
|
-
function isManagedItemVersionResource(value, workspaceId, itemId, versionId) {
|
|
689
|
-
const valid = isExactRecord(value, [
|
|
690
|
-
...managedItemVersionKeys,
|
|
691
|
-
"workspaceId",
|
|
692
|
-
"itemId"
|
|
693
|
-
]) && value.workspaceId === workspaceId && value.itemId === itemId && value.versionId === versionId && managedItemVersionFieldsAreValid(value);
|
|
694
|
-
if (valid) Object.freeze(value);
|
|
695
|
-
return valid;
|
|
696
|
-
}
|
|
697
|
-
const managedItemVersionKeys = Object.freeze([
|
|
698
|
-
"versionId",
|
|
699
|
-
"state",
|
|
700
|
-
"revision",
|
|
701
|
-
"byteLength",
|
|
702
|
-
"contentDigest",
|
|
703
|
-
"mediaType",
|
|
704
|
-
"displayFilename",
|
|
705
|
-
"protectionClassification",
|
|
706
|
-
"archiveState"
|
|
707
|
-
]);
|
|
708
|
-
function managedItemVersionFieldsAreValid(value) {
|
|
709
|
-
return typeof value.versionId === "string" && VERSION_ID$1.test(value.versionId) && (value.state === "current" || value.state === "superseded") && isSafeInteger$1(value.revision) && isSafeInteger$1(value.byteLength) && typeof value.contentDigest === "string" && CONTENT_DIGEST$1.test(value.contentDigest) && isMediaType$1(value.mediaType) && isSafeFilename$1(value.displayFilename) && (value.protectionClassification === "ordinary" || value.protectionClassification === "opaque-encrypted") && [
|
|
710
|
-
"available",
|
|
711
|
-
"cold",
|
|
712
|
-
"restoring",
|
|
713
|
-
"unavailable",
|
|
714
|
-
"corrupt"
|
|
715
|
-
].includes(String(value.archiveState));
|
|
716
|
-
}
|
|
717
|
-
function mutationValidatorsAreCoherent(headers) {
|
|
718
|
-
const collection = headers.get("drive-permission-collection-etag");
|
|
719
|
-
const grant = headers.get("drive-permission-grant-etag");
|
|
720
|
-
const collectionRevision = collection === null ? void 0 : parseCollectionEtag(collection);
|
|
721
|
-
if (collectionRevision === void 0) return false;
|
|
722
|
-
if (grant === null) return true;
|
|
723
|
-
const currentGrant = parseGrantEtag(grant);
|
|
724
|
-
return currentGrant !== void 0 && currentGrant[0] === collectionRevision;
|
|
725
|
-
}
|
|
726
|
-
function isPermissionGrant(value) {
|
|
727
|
-
return isExactRecord(value, [
|
|
728
|
-
"source",
|
|
729
|
-
"sourceItemId",
|
|
730
|
-
"grantId",
|
|
731
|
-
"grantee",
|
|
732
|
-
"actions",
|
|
733
|
-
"availability",
|
|
734
|
-
"expiresAtEpochMilliseconds",
|
|
735
|
-
"revision",
|
|
736
|
-
"etag"
|
|
737
|
-
]) && (value.source === "direct" || value.source === "inherited") && typeof value.sourceItemId === "string" && ITEM_ID$1.test(value.sourceItemId) && typeof value.grantId === "string" && GRANT_ID$1.test(value.grantId) && isGrantee(value.grantee) && isPermissionActions(value.actions) && [
|
|
738
|
-
"active",
|
|
739
|
-
"expired",
|
|
740
|
-
"revoked"
|
|
741
|
-
].includes(String(value.availability)) && (value.expiresAtEpochMilliseconds === null || isSafeInteger$1(value.expiresAtEpochMilliseconds)) && isSafeInteger$1(value.revision) && typeof value.etag === "string" && GRANT_ETAG.test(value.etag);
|
|
742
|
-
}
|
|
743
|
-
function isGrantee(value) {
|
|
744
|
-
return isExactRecord(value, ["type", "userId"]) && value.type === "user" && typeof value.userId === "string" && AUTH_ID$1.test(value.userId) || isExactRecord(value, ["type", "teamId"]) && value.type === "team" && typeof value.teamId === "string" && AUTH_ID$1.test(value.teamId);
|
|
745
|
-
}
|
|
746
|
-
function isPermissionActions(value) {
|
|
747
|
-
return Array.isArray(value) && value.length >= 1 && value.length <= 6 && new Set(value).size === value.length && value.every((action) => PERMISSION_ACTIONS$1.includes(action)) && value.every((action, index) => index === 0 || PERMISSION_ACTIONS$1.indexOf(action) > PERMISSION_ACTIONS$1.indexOf(value[index - 1]));
|
|
748
|
-
}
|
|
749
|
-
function effectiveSourceIsCoherent(action, targetItemId) {
|
|
750
|
-
if (!action.allowed) return action.basis === null && action.sourceItemId === null && action.grantId === null;
|
|
751
|
-
if (action.basis === "workspace_visibility" || action.basis === "restricted_administrator_bypass") return action.sourceItemId === null && action.grantId === null;
|
|
752
|
-
if (action.basis === "direct_grant") return action.sourceItemId === targetItemId && typeof action.grantId === "string";
|
|
753
|
-
if (action.basis === "inherited_grant") return typeof action.sourceItemId === "string" && action.sourceItemId !== targetItemId && typeof action.grantId === "string";
|
|
754
|
-
return false;
|
|
755
|
-
}
|
|
756
|
-
function permissionGrantEtag(collectionRevision, grantRevision) {
|
|
757
|
-
return `"drive.permission-grant.v1.${collectionRevision}.${grantRevision}"`;
|
|
758
|
-
}
|
|
759
|
-
function isSafeFilename$1(value) {
|
|
760
|
-
if (typeof value !== "string" || value.length === 0 || value.length > 510 || value.normalize("NFC") !== value || value.endsWith(".") || value.endsWith(" ") || filenameIsReserved$1(value)) return false;
|
|
761
|
-
let codePoints = 0;
|
|
762
|
-
let bytes = 0;
|
|
763
|
-
for (const character of value) {
|
|
764
|
-
const point = character.codePointAt(0);
|
|
765
|
-
if (point === void 0 || point === 47 || point === 92 || point <= 31 || point >= 127 && point <= 159 || point === 8232 || point === 8233 || point >= 55296 && point <= 57343) return false;
|
|
766
|
-
codePoints += 1;
|
|
767
|
-
bytes += point <= 127 ? 1 : point <= 2047 ? 2 : point <= 65535 ? 3 : 4;
|
|
768
|
-
if (codePoints > 255 || bytes > 255) return false;
|
|
769
|
-
}
|
|
770
|
-
return true;
|
|
771
|
-
}
|
|
772
|
-
function isMediaType$1(value) {
|
|
773
|
-
return typeof value === "string" && value.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(value);
|
|
774
|
-
}
|
|
775
|
-
function isSignedTransferUrl(value, allowInsecureHttp) {
|
|
776
|
-
if (typeof value !== "string" || value.length < 1 || value.length > 8192 || value !== value.trim()) return false;
|
|
777
|
-
try {
|
|
778
|
-
const url = new URL(value);
|
|
779
|
-
const loopbackHost = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
780
|
-
return (url.protocol === "https:" || url.protocol === "http:" && allowInsecureHttp && loopbackHost) && url.username === "" && url.password === "" && url.hash === "" && url.host !== "";
|
|
781
|
-
} catch {
|
|
782
|
-
return false;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
function filenameIsReserved$1(value) {
|
|
786
|
-
const base = value.split(".", 1)[0].toUpperCase();
|
|
787
|
-
return value === "." || value === ".." || [
|
|
788
|
-
"CON",
|
|
789
|
-
"PRN",
|
|
790
|
-
"AUX",
|
|
791
|
-
"NUL",
|
|
792
|
-
"CLOCK$",
|
|
793
|
-
"CONIN$",
|
|
794
|
-
"CONOUT$"
|
|
795
|
-
].includes(base) || /^COM[1-9]$/.test(base) || /^LPT[1-9]$/.test(base);
|
|
796
|
-
}
|
|
797
|
-
function isStrictlyOrdered(values, key) {
|
|
798
|
-
return values.every((value, index) => index === 0 || key(values[index - 1]) < key(value));
|
|
799
|
-
}
|
|
800
|
-
function isSafeInteger$1(value) {
|
|
801
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
802
|
-
}
|
|
803
|
-
function isStrongEtag(value) {
|
|
804
|
-
return /^"[\x21\x23-\x7e]{1,1022}"$/.test(value);
|
|
805
|
-
}
|
|
806
|
-
function isSafeCapabilityUrl(value) {
|
|
807
|
-
try {
|
|
808
|
-
const url = new URL(value);
|
|
809
|
-
const localHttp = url.protocol === "http:" && [
|
|
810
|
-
"localhost",
|
|
811
|
-
"127.0.0.1",
|
|
812
|
-
"[::1]"
|
|
813
|
-
].includes(url.hostname);
|
|
814
|
-
return (url.protocol === "https:" || localHttp) && !url.username && !url.password && !url.hash;
|
|
815
|
-
} catch {
|
|
816
|
-
return false;
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
function isExactRecord(value, keys, optional = []) {
|
|
820
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
821
|
-
return Object.keys(value).every((key) => keys.includes(key) || optional.includes(key)) && keys.every((key) => Object.hasOwn(value, key));
|
|
822
|
-
}
|
|
823
|
-
//#endregion
|
|
824
|
-
//#region src/internal/client/request.ts
|
|
825
|
-
const ITEM_ID = /^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
826
|
-
const WORKSPACE_ID = /^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
827
|
-
const GRANT_ID = /^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
828
|
-
const UPLOAD_ID = /^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
829
|
-
const VERSION_ID = /^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
830
|
-
const CURSOR = /^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/;
|
|
831
|
-
const AUTH_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
832
|
-
const PERMISSION_ACTIONS = Object.freeze([
|
|
833
|
-
"items:content:read",
|
|
834
|
-
"items:create",
|
|
835
|
-
"items:delete",
|
|
836
|
-
"items:metadata:read",
|
|
837
|
-
"items:permissions:read",
|
|
838
|
-
"items:update"
|
|
839
|
-
]);
|
|
840
|
-
const IDEMPOTENCY_KEY = /^[A-Za-z0-9_-]{16,128}$/;
|
|
841
|
-
const CONTENT_DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
842
|
-
const PART_CHECKSUM = /^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/;
|
|
843
|
-
const MAX_UPLOAD_BYTE_LENGTH = 33554432e4;
|
|
844
|
-
const UPLOAD_PART_BYTE_LENGTH$1 = 32 * 1024 * 1024;
|
|
845
|
-
function validateCurrentWorkspaceInput(value) {
|
|
846
|
-
const signal = validateSignal(captureRecord(value === void 0 ? {} : value, [], ["signal"]).signal);
|
|
847
|
-
return signal === void 0 ? {} : { signal };
|
|
848
|
-
}
|
|
849
|
-
function validateResourceInput(value) {
|
|
850
|
-
const input = captureRecord(value, ["workspaceId", "itemId"], ["signal"]);
|
|
851
|
-
const workspaceId = input.workspaceId;
|
|
852
|
-
const itemId = input.itemId;
|
|
853
|
-
const signal = validateSignal(input.signal);
|
|
854
|
-
if (typeof workspaceId !== "string" || !WORKSPACE_ID.test(workspaceId) || typeof itemId !== "string" || !ITEM_ID.test(itemId)) throw new DriveError("invalid_input");
|
|
855
|
-
return {
|
|
856
|
-
workspaceId,
|
|
857
|
-
itemId,
|
|
858
|
-
...signal === void 0 ? {} : { signal }
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
function validateItemVersionInput(value) {
|
|
862
|
-
const input = captureRecord(value, [
|
|
863
|
-
"workspaceId",
|
|
864
|
-
"itemId",
|
|
865
|
-
"versionId"
|
|
866
|
-
], ["signal"]);
|
|
867
|
-
const resource = validateResourceInput({
|
|
868
|
-
workspaceId: input.workspaceId,
|
|
869
|
-
itemId: input.itemId,
|
|
870
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
871
|
-
});
|
|
872
|
-
if (typeof input.versionId !== "string" || !VERSION_ID.test(input.versionId)) throw new DriveError("invalid_input");
|
|
873
|
-
return {
|
|
874
|
-
...resource,
|
|
875
|
-
versionId: input.versionId
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
function validateCreateDownloadInput(value) {
|
|
879
|
-
const input = captureRecord(value, [
|
|
880
|
-
"workspaceId",
|
|
881
|
-
"itemId",
|
|
882
|
-
"idempotencyKey"
|
|
883
|
-
], [
|
|
884
|
-
"versionId",
|
|
885
|
-
"method",
|
|
886
|
-
"range",
|
|
887
|
-
"ifMatch",
|
|
888
|
-
"ifNoneMatch",
|
|
889
|
-
"ifRange",
|
|
890
|
-
"signal"
|
|
891
|
-
]);
|
|
892
|
-
const resource = validateResourceInput({
|
|
893
|
-
workspaceId: input.workspaceId,
|
|
894
|
-
itemId: input.itemId,
|
|
895
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
896
|
-
});
|
|
897
|
-
const method = input.method ?? "GET";
|
|
898
|
-
if (!isIdempotencyKey(input.idempotencyKey) || input.versionId !== void 0 && (typeof input.versionId !== "string" || !VERSION_ID.test(input.versionId)) || method !== "GET" && method !== "HEAD" || input.range !== void 0 && (typeof input.range !== "string" || input.range.length > 128 || !/^bytes=(?:[0-9]+-[0-9]*|-[0-9]+)$/.test(input.range)) || !isOptionalHeaderValue(input.ifMatch) || !isOptionalHeaderValue(input.ifNoneMatch) || !isOptionalHeaderValue(input.ifRange)) throw new DriveError("invalid_input");
|
|
899
|
-
return {
|
|
900
|
-
...resource,
|
|
901
|
-
idempotencyKey: input.idempotencyKey,
|
|
902
|
-
method,
|
|
903
|
-
...input.versionId === void 0 ? {} : { versionId: input.versionId },
|
|
904
|
-
...input.range === void 0 ? {} : { range: input.range },
|
|
905
|
-
...input.ifMatch === void 0 ? {} : { ifMatch: input.ifMatch },
|
|
906
|
-
...input.ifNoneMatch === void 0 ? {} : { ifNoneMatch: input.ifNoneMatch },
|
|
907
|
-
...input.ifRange === void 0 ? {} : { ifRange: input.ifRange }
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
function validateSearchWorkspaceItemsInput(value) {
|
|
911
|
-
const input = captureRecord(value, ["workspaceId", "query"], [
|
|
912
|
-
"limit",
|
|
913
|
-
"cursor",
|
|
914
|
-
"signal"
|
|
915
|
-
]);
|
|
916
|
-
const signal = validateSignal(input.signal);
|
|
917
|
-
if (typeof input.workspaceId !== "string" || !WORKSPACE_ID.test(input.workspaceId) || !isSearchQuery(input.query) || input.limit !== void 0 && (!isSafeInteger(input.limit) || input.limit < 1 || input.limit > 50) || input.cursor !== void 0 && (typeof input.cursor !== "string" || input.cursor.length > 699 || !CURSOR.test(input.cursor))) throw new DriveError("invalid_input");
|
|
918
|
-
return {
|
|
919
|
-
workspaceId: input.workspaceId,
|
|
920
|
-
query: input.query,
|
|
921
|
-
...input.limit === void 0 ? {} : { limit: input.limit },
|
|
922
|
-
...input.cursor === void 0 ? {} : { cursor: input.cursor },
|
|
923
|
-
...signal === void 0 ? {} : { signal }
|
|
924
|
-
};
|
|
925
|
-
}
|
|
926
|
-
function validatePageInput(value) {
|
|
927
|
-
const input = captureRecord(value, ["workspaceId", "itemId"], [
|
|
928
|
-
"signal",
|
|
929
|
-
"limit",
|
|
930
|
-
"cursor"
|
|
931
|
-
]);
|
|
932
|
-
const resource = validateResourceInput({
|
|
933
|
-
workspaceId: input.workspaceId,
|
|
934
|
-
itemId: input.itemId,
|
|
935
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
936
|
-
});
|
|
937
|
-
const limit = input.limit;
|
|
938
|
-
const cursor = input.cursor;
|
|
939
|
-
if (limit !== void 0 && (!Number.isSafeInteger(limit) || typeof limit !== "number" || limit < 1 || limit > 50) || cursor !== void 0 && (typeof cursor !== "string" || cursor.length > 699 || !CURSOR.test(cursor))) throw new DriveError("invalid_input");
|
|
940
|
-
return {
|
|
941
|
-
...resource,
|
|
942
|
-
...limit === void 0 ? {} : { limit },
|
|
943
|
-
...cursor === void 0 ? {} : { cursor }
|
|
944
|
-
};
|
|
945
|
-
}
|
|
946
|
-
function validateCreateFolderInput(value) {
|
|
947
|
-
const input = captureRecord(value, [
|
|
948
|
-
"workspaceId",
|
|
949
|
-
"itemId",
|
|
950
|
-
"name",
|
|
951
|
-
"idempotencyKey"
|
|
952
|
-
], ["signal"]);
|
|
953
|
-
const resource = validateResourceInput({
|
|
954
|
-
workspaceId: input.workspaceId,
|
|
955
|
-
itemId: input.itemId,
|
|
956
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
957
|
-
});
|
|
958
|
-
if (!isSafeFilename(input.name) || !isIdempotencyKey(input.idempotencyKey)) throw new DriveError("invalid_input");
|
|
959
|
-
return {
|
|
960
|
-
...resource,
|
|
961
|
-
name: input.name,
|
|
962
|
-
idempotencyKey: input.idempotencyKey
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
function validateUpdateItemInput(value) {
|
|
966
|
-
const input = captureRecord(value, [
|
|
967
|
-
"workspaceId",
|
|
968
|
-
"itemId",
|
|
969
|
-
"name",
|
|
970
|
-
"parentItemId",
|
|
971
|
-
"idempotencyKey",
|
|
972
|
-
"ifMatch"
|
|
973
|
-
], ["signal"]);
|
|
974
|
-
const mutation = validateLifecycleMutationInput({
|
|
975
|
-
workspaceId: input.workspaceId,
|
|
976
|
-
itemId: input.itemId,
|
|
977
|
-
idempotencyKey: input.idempotencyKey,
|
|
978
|
-
ifMatch: input.ifMatch,
|
|
979
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
980
|
-
});
|
|
981
|
-
if (!isSafeFilename(input.name) || typeof input.parentItemId !== "string" || !ITEM_ID.test(input.parentItemId)) throw new DriveError("invalid_input");
|
|
982
|
-
return {
|
|
983
|
-
...mutation,
|
|
984
|
-
name: input.name,
|
|
985
|
-
parentItemId: input.parentItemId
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
function validateLifecycleMutationInput(value) {
|
|
989
|
-
const input = captureRecord(value, [
|
|
990
|
-
"workspaceId",
|
|
991
|
-
"itemId",
|
|
992
|
-
"idempotencyKey",
|
|
993
|
-
"ifMatch"
|
|
994
|
-
], ["signal"]);
|
|
995
|
-
const resource = validateResourceInput({
|
|
996
|
-
workspaceId: input.workspaceId,
|
|
997
|
-
itemId: input.itemId,
|
|
998
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
999
|
-
});
|
|
1000
|
-
if (!isIdempotencyKey(input.idempotencyKey) || typeof input.ifMatch !== "string" || parseItemEtag(input.ifMatch) === void 0) throw new DriveError("invalid_input");
|
|
1001
|
-
return {
|
|
1002
|
-
...resource,
|
|
1003
|
-
idempotencyKey: input.idempotencyKey,
|
|
1004
|
-
ifMatch: input.ifMatch
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
function validateRestoreItemVersionInput(value) {
|
|
1008
|
-
const input = captureRecord(value, [
|
|
1009
|
-
"workspaceId",
|
|
1010
|
-
"itemId",
|
|
1011
|
-
"versionId",
|
|
1012
|
-
"idempotencyKey",
|
|
1013
|
-
"ifMatch"
|
|
1014
|
-
], ["signal"]);
|
|
1015
|
-
const mutation = validateLifecycleMutationInput({
|
|
1016
|
-
workspaceId: input.workspaceId,
|
|
1017
|
-
itemId: input.itemId,
|
|
1018
|
-
idempotencyKey: input.idempotencyKey,
|
|
1019
|
-
ifMatch: input.ifMatch,
|
|
1020
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
1021
|
-
});
|
|
1022
|
-
if (typeof input.versionId !== "string" || !VERSION_ID.test(input.versionId)) throw new DriveError("invalid_input");
|
|
1023
|
-
return {
|
|
1024
|
-
...mutation,
|
|
1025
|
-
versionId: input.versionId
|
|
1026
|
-
};
|
|
1027
|
-
}
|
|
1028
|
-
function validateCreatePermissionInput(value) {
|
|
1029
|
-
const input = captureRecord(value, [
|
|
1030
|
-
"workspaceId",
|
|
1031
|
-
"itemId",
|
|
1032
|
-
"grantee",
|
|
1033
|
-
"actions",
|
|
1034
|
-
"expiresAtEpochMilliseconds",
|
|
1035
|
-
"ifMatch",
|
|
1036
|
-
"idempotencyKey"
|
|
1037
|
-
], ["signal"]);
|
|
1038
|
-
const resource = validateResourceInput({
|
|
1039
|
-
workspaceId: input.workspaceId,
|
|
1040
|
-
itemId: input.itemId,
|
|
1041
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
1042
|
-
});
|
|
1043
|
-
const grantee = validateGrantee(input.grantee);
|
|
1044
|
-
const actions = validateInputActions(input.actions);
|
|
1045
|
-
const expiry = input.expiresAtEpochMilliseconds;
|
|
1046
|
-
if (!isExpiry(expiry) || typeof input.ifMatch !== "string" || parseCollectionEtag(input.ifMatch) === void 0 || !isIdempotencyKey(input.idempotencyKey)) throw new DriveError("invalid_input");
|
|
1047
|
-
return {
|
|
1048
|
-
...resource,
|
|
1049
|
-
grantee,
|
|
1050
|
-
actions,
|
|
1051
|
-
expiresAtEpochMilliseconds: expiry,
|
|
1052
|
-
ifMatch: input.ifMatch,
|
|
1053
|
-
idempotencyKey: input.idempotencyKey
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
function validateGrantMutationInput(value) {
|
|
1057
|
-
const input = captureRecord(value, [
|
|
1058
|
-
"workspaceId",
|
|
1059
|
-
"itemId",
|
|
1060
|
-
"grantId",
|
|
1061
|
-
"ifMatch",
|
|
1062
|
-
"idempotencyKey"
|
|
1063
|
-
], ["signal"]);
|
|
1064
|
-
const resource = validateResourceInput({
|
|
1065
|
-
workspaceId: input.workspaceId,
|
|
1066
|
-
itemId: input.itemId,
|
|
1067
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
1068
|
-
});
|
|
1069
|
-
if (typeof input.grantId !== "string" || !GRANT_ID.test(input.grantId) || typeof input.ifMatch !== "string" || parseGrantEtag(input.ifMatch) === void 0 || !isIdempotencyKey(input.idempotencyKey)) throw new DriveError("invalid_input");
|
|
1070
|
-
return {
|
|
1071
|
-
...resource,
|
|
1072
|
-
grantId: input.grantId,
|
|
1073
|
-
ifMatch: input.ifMatch,
|
|
1074
|
-
idempotencyKey: input.idempotencyKey
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
|
-
function validateUpdatePermissionInput(value) {
|
|
1078
|
-
const input = captureRecord(value, [
|
|
1079
|
-
"workspaceId",
|
|
1080
|
-
"itemId",
|
|
1081
|
-
"grantId",
|
|
1082
|
-
"ifMatch",
|
|
1083
|
-
"idempotencyKey"
|
|
1084
|
-
], [
|
|
1085
|
-
"signal",
|
|
1086
|
-
"actions",
|
|
1087
|
-
"expiresAtEpochMilliseconds"
|
|
1088
|
-
]);
|
|
1089
|
-
const mutation = validateGrantMutationInput({
|
|
1090
|
-
workspaceId: input.workspaceId,
|
|
1091
|
-
itemId: input.itemId,
|
|
1092
|
-
grantId: input.grantId,
|
|
1093
|
-
ifMatch: input.ifMatch,
|
|
1094
|
-
idempotencyKey: input.idempotencyKey,
|
|
1095
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
1096
|
-
});
|
|
1097
|
-
const actions = input.actions === void 0 ? void 0 : validateInputActions(input.actions);
|
|
1098
|
-
const expiry = input.expiresAtEpochMilliseconds;
|
|
1099
|
-
if (actions === void 0 && expiry === void 0 || expiry !== void 0 && !isExpiry(expiry)) throw new DriveError("invalid_input");
|
|
1100
|
-
return {
|
|
1101
|
-
...mutation,
|
|
1102
|
-
...actions === void 0 ? {} : { actions },
|
|
1103
|
-
...expiry === void 0 ? {} : { expiresAtEpochMilliseconds: expiry }
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
function validateCreateUploadInput(value) {
|
|
1107
|
-
const input = captureRecord(value, [
|
|
1108
|
-
"workspaceId",
|
|
1109
|
-
"parentItemId",
|
|
1110
|
-
"expectedByteLength",
|
|
1111
|
-
"displayFilename",
|
|
1112
|
-
"mediaType",
|
|
1113
|
-
"callerDeclaredContentDigest",
|
|
1114
|
-
"protectionClassification",
|
|
1115
|
-
"idempotencyKey"
|
|
1116
|
-
], ["signal"]);
|
|
1117
|
-
const signal = validateSignal(input.signal);
|
|
1118
|
-
if (typeof input.workspaceId !== "string" || !WORKSPACE_ID.test(input.workspaceId) || typeof input.parentItemId !== "string" || !ITEM_ID.test(input.parentItemId) || typeof input.expectedByteLength !== "number" || !Number.isSafeInteger(input.expectedByteLength) || input.expectedByteLength < 0 || input.expectedByteLength > MAX_UPLOAD_BYTE_LENGTH || !isSafeFilename(input.displayFilename) || !isMediaType(input.mediaType) || typeof input.callerDeclaredContentDigest !== "string" || !CONTENT_DIGEST.test(input.callerDeclaredContentDigest) || input.protectionClassification !== "ordinary" && input.protectionClassification !== "opaque-encrypted" || !isIdempotencyKey(input.idempotencyKey)) throw new DriveError("invalid_input");
|
|
1119
|
-
return {
|
|
1120
|
-
workspaceId: input.workspaceId,
|
|
1121
|
-
parentItemId: input.parentItemId,
|
|
1122
|
-
expectedByteLength: input.expectedByteLength,
|
|
1123
|
-
displayFilename: input.displayFilename,
|
|
1124
|
-
mediaType: input.mediaType,
|
|
1125
|
-
callerDeclaredContentDigest: input.callerDeclaredContentDigest,
|
|
1126
|
-
protectionClassification: input.protectionClassification,
|
|
1127
|
-
idempotencyKey: input.idempotencyKey,
|
|
1128
|
-
...signal === void 0 ? {} : { signal }
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
function validateGetUploadStatusInput(value) {
|
|
1132
|
-
const input = captureRecord(value, ["workspaceId", "uploadId"], [
|
|
1133
|
-
"afterPartNumber",
|
|
1134
|
-
"limit",
|
|
1135
|
-
"signal"
|
|
1136
|
-
]);
|
|
1137
|
-
const upload = validateUploadPath(input.workspaceId, input.uploadId, input.signal);
|
|
1138
|
-
if (input.afterPartNumber !== void 0 && (!isSafeInteger(input.afterPartNumber) || input.afterPartNumber > 1e4) || input.limit !== void 0 && (!isSafeInteger(input.limit) || input.limit < 1 || input.limit > 100)) throw new DriveError("invalid_input");
|
|
1139
|
-
return {
|
|
1140
|
-
...upload,
|
|
1141
|
-
...input.afterPartNumber === void 0 ? {} : { afterPartNumber: input.afterPartNumber },
|
|
1142
|
-
...input.limit === void 0 ? {} : { limit: input.limit }
|
|
1143
|
-
};
|
|
1144
|
-
}
|
|
1145
|
-
function validateCreateUploadPartDescriptorInput(value) {
|
|
1146
|
-
const input = captureRecord(value, [
|
|
1147
|
-
"workspaceId",
|
|
1148
|
-
"uploadId",
|
|
1149
|
-
"partNumber",
|
|
1150
|
-
"checksumSha256",
|
|
1151
|
-
"contentMd5"
|
|
1152
|
-
], ["signal"]);
|
|
1153
|
-
const upload = validateUploadPath(input.workspaceId, input.uploadId, input.signal);
|
|
1154
|
-
if (!isPartNumber(input.partNumber) || !isPartChecksum(input.checksumSha256)) throw new DriveError("invalid_input");
|
|
1155
|
-
if (typeof input.contentMd5 !== "string" || !/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(input.contentMd5)) throw new DriveError("invalid_input");
|
|
1156
|
-
return {
|
|
1157
|
-
...upload,
|
|
1158
|
-
partNumber: input.partNumber,
|
|
1159
|
-
checksumSha256: input.checksumSha256,
|
|
1160
|
-
contentMd5: input.contentMd5
|
|
1161
|
-
};
|
|
1162
|
-
}
|
|
1163
|
-
function validateRecordUploadPartInput(value) {
|
|
1164
|
-
const input = captureRecord(value, [
|
|
1165
|
-
"workspaceId",
|
|
1166
|
-
"uploadId",
|
|
1167
|
-
"partNumber",
|
|
1168
|
-
"expectedUploadRevision",
|
|
1169
|
-
"byteLength",
|
|
1170
|
-
"etag",
|
|
1171
|
-
"checksumSha256"
|
|
1172
|
-
], ["signal"]);
|
|
1173
|
-
const upload = validateUploadPath(input.workspaceId, input.uploadId, input.signal);
|
|
1174
|
-
if (!isPartNumber(input.partNumber) || !isSafeInteger(input.expectedUploadRevision) || input.expectedUploadRevision >= Number.MAX_SAFE_INTEGER || !isSafeInteger(input.byteLength) || input.byteLength < 1 || input.byteLength > UPLOAD_PART_BYTE_LENGTH$1 || !isEtag$1(input.etag) || !isPartChecksum(input.checksumSha256)) throw new DriveError("invalid_input");
|
|
1175
|
-
return {
|
|
1176
|
-
...upload,
|
|
1177
|
-
partNumber: input.partNumber,
|
|
1178
|
-
expectedUploadRevision: input.expectedUploadRevision,
|
|
1179
|
-
byteLength: input.byteLength,
|
|
1180
|
-
etag: input.etag,
|
|
1181
|
-
checksumSha256: input.checksumSha256
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
function validateCompleteUploadInput(value) {
|
|
1185
|
-
const input = captureRecord(value, [
|
|
1186
|
-
"workspaceId",
|
|
1187
|
-
"uploadId",
|
|
1188
|
-
"idempotencyKey"
|
|
1189
|
-
], ["signal"]);
|
|
1190
|
-
const upload = validateUploadPath(input.workspaceId, input.uploadId, input.signal);
|
|
1191
|
-
if (!isIdempotencyKey(input.idempotencyKey)) throw new DriveError("invalid_input");
|
|
1192
|
-
return {
|
|
1193
|
-
...upload,
|
|
1194
|
-
idempotencyKey: input.idempotencyKey
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
function validateAbortUploadInput(value) {
|
|
1198
|
-
const input = captureRecord(value, ["workspaceId", "uploadId"], ["signal"]);
|
|
1199
|
-
return validateUploadPath(input.workspaceId, input.uploadId, input.signal);
|
|
1200
|
-
}
|
|
1201
|
-
function validateUploadFileInput(value) {
|
|
1202
|
-
const input = captureRecord(value, [
|
|
1203
|
-
"workspaceId",
|
|
1204
|
-
"parentItemId",
|
|
1205
|
-
"source",
|
|
1206
|
-
"displayFilename",
|
|
1207
|
-
"idempotencyKey",
|
|
1208
|
-
"completionIdempotencyKey"
|
|
1209
|
-
], [
|
|
1210
|
-
"mediaType",
|
|
1211
|
-
"protectionClassification",
|
|
1212
|
-
"signal",
|
|
1213
|
-
"onProgress"
|
|
1214
|
-
]);
|
|
1215
|
-
const signal = validateSignal(input.signal);
|
|
1216
|
-
const mediaType = input.mediaType ?? "application/octet-stream";
|
|
1217
|
-
const protectionClassification = input.protectionClassification ?? "ordinary";
|
|
1218
|
-
let source;
|
|
1219
|
-
let byteLength;
|
|
1220
|
-
try {
|
|
1221
|
-
if (!(input.source instanceof Blob)) throw new DriveError("invalid_input");
|
|
1222
|
-
source = input.source;
|
|
1223
|
-
byteLength = source.size;
|
|
1224
|
-
} catch (error) {
|
|
1225
|
-
if (error instanceof DriveError) throw error;
|
|
1226
|
-
throw new DriveError("invalid_input");
|
|
1227
|
-
}
|
|
1228
|
-
if (typeof input.workspaceId !== "string" || !WORKSPACE_ID.test(input.workspaceId) || typeof input.parentItemId !== "string" || !ITEM_ID.test(input.parentItemId) || !Number.isSafeInteger(byteLength) || byteLength < 0 || byteLength > MAX_UPLOAD_BYTE_LENGTH || !isSafeFilename(input.displayFilename) || !isMediaType(mediaType) || protectionClassification !== "ordinary" && protectionClassification !== "opaque-encrypted" || !isIdempotencyKey(input.idempotencyKey) || !isIdempotencyKey(input.completionIdempotencyKey) || input.onProgress !== void 0 && typeof input.onProgress !== "function") throw new DriveError("invalid_input");
|
|
1229
|
-
return {
|
|
1230
|
-
workspaceId: input.workspaceId,
|
|
1231
|
-
parentItemId: input.parentItemId,
|
|
1232
|
-
source,
|
|
1233
|
-
byteLength,
|
|
1234
|
-
displayFilename: input.displayFilename,
|
|
1235
|
-
mediaType,
|
|
1236
|
-
protectionClassification,
|
|
1237
|
-
idempotencyKey: input.idempotencyKey,
|
|
1238
|
-
completionIdempotencyKey: input.completionIdempotencyKey,
|
|
1239
|
-
...signal === void 0 ? {} : { signal },
|
|
1240
|
-
...input.onProgress === void 0 ? {} : { onProgress: input.onProgress }
|
|
1241
|
-
};
|
|
1242
|
-
}
|
|
1243
|
-
function resourcePath(input) {
|
|
1244
|
-
return {
|
|
1245
|
-
workspaceId: input.workspaceId,
|
|
1246
|
-
itemId: input.itemId
|
|
1247
|
-
};
|
|
1248
|
-
}
|
|
1249
|
-
function pageQuery(input) {
|
|
1250
|
-
return {
|
|
1251
|
-
...input.limit === void 0 ? {} : { limit: input.limit },
|
|
1252
|
-
...input.cursor === void 0 ? {} : { cursor: input.cursor }
|
|
1253
|
-
};
|
|
1254
|
-
}
|
|
1255
|
-
function operationOptions(_operationId, options) {
|
|
1256
|
-
return options;
|
|
1257
|
-
}
|
|
1258
|
-
function captureRecord(value, required, optional) {
|
|
1259
|
-
try {
|
|
1260
|
-
if (typeof value !== "object" && typeof value !== "function" || value === null || Array.isArray(value)) throw new DriveError("invalid_input");
|
|
1261
|
-
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
1262
|
-
const keys = Reflect.ownKeys(descriptors);
|
|
1263
|
-
const allowed = new Set([...required, ...optional]);
|
|
1264
|
-
if (keys.some((key) => typeof key !== "string" || !allowed.has(key)) || required.some((key) => !Object.hasOwn(descriptors, key))) throw new DriveError("invalid_input");
|
|
1265
|
-
const result = {};
|
|
1266
|
-
for (const key of keys) {
|
|
1267
|
-
if (typeof key !== "string") throw new DriveError("invalid_input");
|
|
1268
|
-
const descriptor = descriptors[key];
|
|
1269
|
-
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) throw new DriveError("invalid_input");
|
|
1270
|
-
result[key] = descriptor.value;
|
|
1271
|
-
}
|
|
1272
|
-
return result;
|
|
1273
|
-
} catch (error) {
|
|
1274
|
-
if (error instanceof DriveError) throw error;
|
|
1275
|
-
throw new DriveError("invalid_input");
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
function validateSignal(value) {
|
|
1279
|
-
if (value === void 0) return void 0;
|
|
1280
|
-
if (!(value instanceof AbortSignal)) throw new DriveError("invalid_input");
|
|
1281
|
-
return value;
|
|
1282
|
-
}
|
|
1283
|
-
function validateGrantee(value) {
|
|
1284
|
-
const type = captureRecord(value, ["type"], ["userId", "teamId"]);
|
|
1285
|
-
if (type.type === "user") {
|
|
1286
|
-
const user = captureRecord(value, ["type", "userId"], []);
|
|
1287
|
-
if (typeof user.userId === "string" && AUTH_ID.test(user.userId)) return {
|
|
1288
|
-
type: "user",
|
|
1289
|
-
userId: user.userId
|
|
1290
|
-
};
|
|
1291
|
-
}
|
|
1292
|
-
if (type.type === "team") {
|
|
1293
|
-
const team = captureRecord(value, ["type", "teamId"], []);
|
|
1294
|
-
if (typeof team.teamId === "string" && AUTH_ID.test(team.teamId)) return {
|
|
1295
|
-
type: "team",
|
|
1296
|
-
teamId: team.teamId
|
|
1297
|
-
};
|
|
1298
|
-
}
|
|
1299
|
-
throw new DriveError("invalid_input");
|
|
1300
|
-
}
|
|
1301
|
-
function validateInputActions(value) {
|
|
1302
|
-
const actions = captureArray(value);
|
|
1303
|
-
if (actions.length < 1 || actions.length > PERMISSION_ACTIONS.length || new Set(actions).size !== actions.length || !actions.every((action) => PERMISSION_ACTIONS.includes(action))) throw new DriveError("invalid_input");
|
|
1304
|
-
return actions;
|
|
1305
|
-
}
|
|
1306
|
-
function captureArray(value) {
|
|
1307
|
-
try {
|
|
1308
|
-
if (!Array.isArray(value)) throw new DriveError("invalid_input");
|
|
1309
|
-
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
1310
|
-
if (Reflect.ownKeys(descriptors).some((key) => typeof key !== "string")) throw new DriveError("invalid_input");
|
|
1311
|
-
const result = [];
|
|
1312
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
1313
|
-
const descriptor = descriptors[String(index)];
|
|
1314
|
-
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) throw new DriveError("invalid_input");
|
|
1315
|
-
result.push(descriptor.value);
|
|
1316
|
-
}
|
|
1317
|
-
if (Reflect.ownKeys(descriptors).length !== value.length + 1) throw new DriveError("invalid_input");
|
|
1318
|
-
return result;
|
|
1319
|
-
} catch (error) {
|
|
1320
|
-
if (error instanceof DriveError) throw error;
|
|
1321
|
-
throw new DriveError("invalid_input");
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
function isIdempotencyKey(value) {
|
|
1325
|
-
return typeof value === "string" && IDEMPOTENCY_KEY.test(value);
|
|
1326
|
-
}
|
|
1327
|
-
function validateUploadPath(workspaceId, uploadId, signalValue) {
|
|
1328
|
-
const signal = validateSignal(signalValue);
|
|
1329
|
-
if (typeof workspaceId !== "string" || !WORKSPACE_ID.test(workspaceId) || typeof uploadId !== "string" || !UPLOAD_ID.test(uploadId)) throw new DriveError("invalid_input");
|
|
1330
|
-
return {
|
|
1331
|
-
workspaceId,
|
|
1332
|
-
uploadId,
|
|
1333
|
-
...signal === void 0 ? {} : { signal }
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
function isPartNumber(value) {
|
|
1337
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1 && value <= 1e4;
|
|
1338
|
-
}
|
|
1339
|
-
function isPartChecksum(value) {
|
|
1340
|
-
return typeof value === "string" && PART_CHECKSUM.test(value);
|
|
1341
|
-
}
|
|
1342
|
-
function isEtag$1(value) {
|
|
1343
|
-
return typeof value === "string" && value.length >= 1 && value.length <= 1024 && /^[\x20-\x7e]+$/.test(value);
|
|
1344
|
-
}
|
|
1345
|
-
function isMediaType(value) {
|
|
1346
|
-
return typeof value === "string" && value.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(value);
|
|
1347
|
-
}
|
|
1348
|
-
function isSearchQuery(value) {
|
|
1349
|
-
if (typeof value !== "string" || value.length === 0) return false;
|
|
1350
|
-
try {
|
|
1351
|
-
if (value.normalize("NFC") !== value) return false;
|
|
1352
|
-
let codePoints = 0;
|
|
1353
|
-
let bytes = 0;
|
|
1354
|
-
for (const character of value) {
|
|
1355
|
-
const point = character.codePointAt(0);
|
|
1356
|
-
if (point === void 0 || point <= 31 || point >= 127 && point <= 159 || point === 8232 || point === 8233 || point >= 55296 && point <= 57343) return false;
|
|
1357
|
-
codePoints += 1;
|
|
1358
|
-
bytes += point <= 127 ? 1 : point <= 2047 ? 2 : point <= 65535 ? 3 : 4;
|
|
1359
|
-
if (codePoints > 64 || bytes > 255) return false;
|
|
1360
|
-
}
|
|
1361
|
-
return true;
|
|
1362
|
-
} catch {
|
|
1363
|
-
return false;
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
function isExpiry(value) {
|
|
1367
|
-
return value === null || isSafeInteger(value);
|
|
1368
|
-
}
|
|
1369
|
-
function isSafeFilename(value) {
|
|
1370
|
-
if (typeof value !== "string" || value.length === 0 || value.length > 510 || value.normalize("NFC") !== value || value.endsWith(".") || value.endsWith(" ") || filenameIsReserved(value)) return false;
|
|
1371
|
-
let codePoints = 0;
|
|
1372
|
-
let bytes = 0;
|
|
1373
|
-
for (const character of value) {
|
|
1374
|
-
const point = character.codePointAt(0);
|
|
1375
|
-
if (point === void 0 || point === 47 || point === 92 || point <= 31 || point >= 127 && point <= 159 || point === 8232 || point === 8233 || point >= 55296 && point <= 57343) return false;
|
|
1376
|
-
codePoints += 1;
|
|
1377
|
-
bytes += point <= 127 ? 1 : point <= 2047 ? 2 : point <= 65535 ? 3 : 4;
|
|
1378
|
-
if (codePoints > 255 || bytes > 255) return false;
|
|
1379
|
-
}
|
|
1380
|
-
return true;
|
|
1381
|
-
}
|
|
1382
|
-
function filenameIsReserved(value) {
|
|
1383
|
-
const base = value.split(".", 1)[0].toUpperCase();
|
|
1384
|
-
return value === "." || value === ".." || [
|
|
1385
|
-
"CON",
|
|
1386
|
-
"PRN",
|
|
1387
|
-
"AUX",
|
|
1388
|
-
"NUL",
|
|
1389
|
-
"CLOCK$",
|
|
1390
|
-
"CONIN$",
|
|
1391
|
-
"CONOUT$"
|
|
1392
|
-
].includes(base) || /^COM[1-9]$/.test(base) || /^LPT[1-9]$/.test(base);
|
|
1393
|
-
}
|
|
1394
|
-
function isSafeInteger(value) {
|
|
1395
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
1396
|
-
}
|
|
1397
|
-
function isOptionalHeaderValue(value) {
|
|
1398
|
-
return value === void 0 || typeof value === "string" && value.length <= 8192 && !value.split("").some((character) => {
|
|
1399
|
-
const code = character.charCodeAt(0);
|
|
1400
|
-
return code <= 31 || code === 127;
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
//#endregion
|
|
1404
|
-
//#region ../../node_modules/.pnpm/openapi-fetch@0.17.0/node_modules/openapi-fetch/dist/index.mjs
|
|
1405
|
-
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
1406
|
-
const supportsRequestInitExt = () => {
|
|
1407
|
-
return typeof process === "object" && Number.parseInt(process?.versions?.node?.substring(0, 2)) >= 18 && process.versions.undici;
|
|
1408
|
-
};
|
|
1409
|
-
function randomID() {
|
|
1410
|
-
return Math.random().toString(36).slice(2, 11);
|
|
1411
|
-
}
|
|
1412
|
-
function createClient(clientOptions) {
|
|
1413
|
-
let { baseUrl = "", Request: CustomRequest = globalThis.Request, fetch: baseFetch = globalThis.fetch, querySerializer: globalQuerySerializer, bodySerializer: globalBodySerializer, pathSerializer: globalPathSerializer, headers: baseHeaders, requestInitExt = void 0, ...baseOptions } = { ...clientOptions };
|
|
1414
|
-
requestInitExt = supportsRequestInitExt() ? requestInitExt : void 0;
|
|
1415
|
-
baseUrl = removeTrailingSlash(baseUrl);
|
|
1416
|
-
const globalMiddlewares = [];
|
|
1417
|
-
async function coreFetch(schemaPath, fetchOptions) {
|
|
1418
|
-
const { baseUrl: localBaseUrl, fetch = baseFetch, Request = CustomRequest, headers, params = {}, parseAs = "json", querySerializer: requestQuerySerializer, bodySerializer = globalBodySerializer ?? defaultBodySerializer, pathSerializer: requestPathSerializer, body, middleware: requestMiddlewares = [], ...init } = fetchOptions || {};
|
|
1419
|
-
let finalBaseUrl = baseUrl;
|
|
1420
|
-
if (localBaseUrl) finalBaseUrl = removeTrailingSlash(localBaseUrl) ?? baseUrl;
|
|
1421
|
-
let querySerializer = typeof globalQuerySerializer === "function" ? globalQuerySerializer : createQuerySerializer(globalQuerySerializer);
|
|
1422
|
-
if (requestQuerySerializer) querySerializer = typeof requestQuerySerializer === "function" ? requestQuerySerializer : createQuerySerializer({
|
|
1423
|
-
...typeof globalQuerySerializer === "object" ? globalQuerySerializer : {},
|
|
1424
|
-
...requestQuerySerializer
|
|
1425
|
-
});
|
|
1426
|
-
const pathSerializer = requestPathSerializer || globalPathSerializer || defaultPathSerializer;
|
|
1427
|
-
const serializedBody = body === void 0 ? void 0 : bodySerializer(body, mergeHeaders(baseHeaders, headers, params.header));
|
|
1428
|
-
const finalHeaders = mergeHeaders(serializedBody === void 0 || serializedBody instanceof FormData ? {} : { "Content-Type": "application/json" }, baseHeaders, headers, params.header);
|
|
1429
|
-
const finalMiddlewares = [...globalMiddlewares, ...requestMiddlewares];
|
|
1430
|
-
const requestInit = {
|
|
1431
|
-
redirect: "follow",
|
|
1432
|
-
...baseOptions,
|
|
1433
|
-
...init,
|
|
1434
|
-
body: serializedBody,
|
|
1435
|
-
headers: finalHeaders
|
|
1436
|
-
};
|
|
1437
|
-
let id;
|
|
1438
|
-
let options;
|
|
1439
|
-
let request = new Request(createFinalURL(schemaPath, {
|
|
1440
|
-
baseUrl: finalBaseUrl,
|
|
1441
|
-
params,
|
|
1442
|
-
querySerializer,
|
|
1443
|
-
pathSerializer
|
|
1444
|
-
}), requestInit);
|
|
1445
|
-
let response;
|
|
1446
|
-
for (const key in init) if (!(key in request)) request[key] = init[key];
|
|
1447
|
-
if (finalMiddlewares.length) {
|
|
1448
|
-
id = randomID();
|
|
1449
|
-
options = Object.freeze({
|
|
1450
|
-
baseUrl: finalBaseUrl,
|
|
1451
|
-
fetch,
|
|
1452
|
-
parseAs,
|
|
1453
|
-
querySerializer,
|
|
1454
|
-
bodySerializer,
|
|
1455
|
-
pathSerializer
|
|
1456
|
-
});
|
|
1457
|
-
for (const m of finalMiddlewares) if (m && typeof m === "object" && typeof m.onRequest === "function") {
|
|
1458
|
-
const result = await m.onRequest({
|
|
1459
|
-
request,
|
|
1460
|
-
schemaPath,
|
|
1461
|
-
params,
|
|
1462
|
-
options,
|
|
1463
|
-
id
|
|
1464
|
-
});
|
|
1465
|
-
if (result) if (result instanceof Request) request = result;
|
|
1466
|
-
else if (result instanceof Response) {
|
|
1467
|
-
response = result;
|
|
1468
|
-
break;
|
|
1469
|
-
} else throw new Error("onRequest: must return new Request() or Response() when modifying the request");
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
if (!response) {
|
|
1473
|
-
try {
|
|
1474
|
-
response = await fetch(request, requestInitExt);
|
|
1475
|
-
} catch (error2) {
|
|
1476
|
-
let errorAfterMiddleware = error2;
|
|
1477
|
-
if (finalMiddlewares.length) for (let i = finalMiddlewares.length - 1; i >= 0; i--) {
|
|
1478
|
-
const m = finalMiddlewares[i];
|
|
1479
|
-
if (m && typeof m === "object" && typeof m.onError === "function") {
|
|
1480
|
-
const result = await m.onError({
|
|
1481
|
-
request,
|
|
1482
|
-
error: errorAfterMiddleware,
|
|
1483
|
-
schemaPath,
|
|
1484
|
-
params,
|
|
1485
|
-
options,
|
|
1486
|
-
id
|
|
1487
|
-
});
|
|
1488
|
-
if (result) {
|
|
1489
|
-
if (result instanceof Response) {
|
|
1490
|
-
errorAfterMiddleware = void 0;
|
|
1491
|
-
response = result;
|
|
1492
|
-
break;
|
|
1493
|
-
}
|
|
1494
|
-
if (result instanceof Error) {
|
|
1495
|
-
errorAfterMiddleware = result;
|
|
1496
|
-
continue;
|
|
1497
|
-
}
|
|
1498
|
-
throw new Error("onError: must return new Response() or instance of Error");
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
if (errorAfterMiddleware) throw errorAfterMiddleware;
|
|
1503
|
-
}
|
|
1504
|
-
if (finalMiddlewares.length) for (let i = finalMiddlewares.length - 1; i >= 0; i--) {
|
|
1505
|
-
const m = finalMiddlewares[i];
|
|
1506
|
-
if (m && typeof m === "object" && typeof m.onResponse === "function") {
|
|
1507
|
-
const result = await m.onResponse({
|
|
1508
|
-
request,
|
|
1509
|
-
response,
|
|
1510
|
-
schemaPath,
|
|
1511
|
-
params,
|
|
1512
|
-
options,
|
|
1513
|
-
id
|
|
1514
|
-
});
|
|
1515
|
-
if (result) {
|
|
1516
|
-
if (!(result instanceof Response)) throw new Error("onResponse: must return new Response() when modifying the response");
|
|
1517
|
-
response = result;
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
const contentLength = response.headers.get("Content-Length");
|
|
1523
|
-
if (response.status === 204 || request.method === "HEAD" || contentLength === "0" && !response.headers.get("Transfer-Encoding")?.includes("chunked")) return response.ok ? {
|
|
1524
|
-
data: void 0,
|
|
1525
|
-
response
|
|
1526
|
-
} : {
|
|
1527
|
-
error: void 0,
|
|
1528
|
-
response
|
|
1529
|
-
};
|
|
1530
|
-
if (response.ok) {
|
|
1531
|
-
const getResponseData = async () => {
|
|
1532
|
-
if (parseAs === "stream") return response.body;
|
|
1533
|
-
if (parseAs === "json" && !contentLength) {
|
|
1534
|
-
const raw = await response.text();
|
|
1535
|
-
return raw ? JSON.parse(raw) : void 0;
|
|
1536
|
-
}
|
|
1537
|
-
return await response[parseAs]();
|
|
1538
|
-
};
|
|
1539
|
-
return {
|
|
1540
|
-
data: await getResponseData(),
|
|
1541
|
-
response
|
|
1542
|
-
};
|
|
1543
|
-
}
|
|
1544
|
-
let error = await response.text();
|
|
1545
|
-
try {
|
|
1546
|
-
error = JSON.parse(error);
|
|
1547
|
-
} catch {}
|
|
1548
|
-
return {
|
|
1549
|
-
error,
|
|
1550
|
-
response
|
|
1551
|
-
};
|
|
1552
|
-
}
|
|
1553
|
-
return {
|
|
1554
|
-
request(method, url, init) {
|
|
1555
|
-
return coreFetch(url, {
|
|
1556
|
-
...init,
|
|
1557
|
-
method: method.toUpperCase()
|
|
1558
|
-
});
|
|
1559
|
-
},
|
|
1560
|
-
GET(url, init) {
|
|
1561
|
-
return coreFetch(url, {
|
|
1562
|
-
...init,
|
|
1563
|
-
method: "GET"
|
|
1564
|
-
});
|
|
1565
|
-
},
|
|
1566
|
-
PUT(url, init) {
|
|
1567
|
-
return coreFetch(url, {
|
|
1568
|
-
...init,
|
|
1569
|
-
method: "PUT"
|
|
1570
|
-
});
|
|
1571
|
-
},
|
|
1572
|
-
POST(url, init) {
|
|
1573
|
-
return coreFetch(url, {
|
|
1574
|
-
...init,
|
|
1575
|
-
method: "POST"
|
|
1576
|
-
});
|
|
1577
|
-
},
|
|
1578
|
-
DELETE(url, init) {
|
|
1579
|
-
return coreFetch(url, {
|
|
1580
|
-
...init,
|
|
1581
|
-
method: "DELETE"
|
|
1582
|
-
});
|
|
1583
|
-
},
|
|
1584
|
-
OPTIONS(url, init) {
|
|
1585
|
-
return coreFetch(url, {
|
|
1586
|
-
...init,
|
|
1587
|
-
method: "OPTIONS"
|
|
1588
|
-
});
|
|
1589
|
-
},
|
|
1590
|
-
HEAD(url, init) {
|
|
1591
|
-
return coreFetch(url, {
|
|
1592
|
-
...init,
|
|
1593
|
-
method: "HEAD"
|
|
1594
|
-
});
|
|
1595
|
-
},
|
|
1596
|
-
PATCH(url, init) {
|
|
1597
|
-
return coreFetch(url, {
|
|
1598
|
-
...init,
|
|
1599
|
-
method: "PATCH"
|
|
1600
|
-
});
|
|
1601
|
-
},
|
|
1602
|
-
TRACE(url, init) {
|
|
1603
|
-
return coreFetch(url, {
|
|
1604
|
-
...init,
|
|
1605
|
-
method: "TRACE"
|
|
1606
|
-
});
|
|
1607
|
-
},
|
|
1608
|
-
use(...middleware) {
|
|
1609
|
-
for (const m of middleware) {
|
|
1610
|
-
if (!m) continue;
|
|
1611
|
-
if (typeof m !== "object" || !("onRequest" in m || "onResponse" in m || "onError" in m)) throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
|
|
1612
|
-
globalMiddlewares.push(m);
|
|
1613
|
-
}
|
|
1614
|
-
},
|
|
1615
|
-
eject(...middleware) {
|
|
1616
|
-
for (const m of middleware) {
|
|
1617
|
-
const i = globalMiddlewares.indexOf(m);
|
|
1618
|
-
if (i !== -1) globalMiddlewares.splice(i, 1);
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
}
|
|
1623
|
-
function serializePrimitiveParam(name, value, options) {
|
|
1624
|
-
if (value === void 0 || value === null) return "";
|
|
1625
|
-
if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
1626
|
-
return `${name}=${options?.allowReserved === true ? value : encodeURIComponent(value)}`;
|
|
1627
|
-
}
|
|
1628
|
-
function serializeObjectParam(name, value, options) {
|
|
1629
|
-
if (!value || typeof value !== "object") return "";
|
|
1630
|
-
const values = [];
|
|
1631
|
-
const joiner = {
|
|
1632
|
-
simple: ",",
|
|
1633
|
-
label: ".",
|
|
1634
|
-
matrix: ";"
|
|
1635
|
-
}[options.style] || "&";
|
|
1636
|
-
if (options.style !== "deepObject" && options.explode === false) {
|
|
1637
|
-
for (const k in value) values.push(k, options.allowReserved === true ? value[k] : encodeURIComponent(value[k]));
|
|
1638
|
-
const final2 = values.join(",");
|
|
1639
|
-
switch (options.style) {
|
|
1640
|
-
case "form": return `${name}=${final2}`;
|
|
1641
|
-
case "label": return `.${final2}`;
|
|
1642
|
-
case "matrix": return `;${name}=${final2}`;
|
|
1643
|
-
default: return final2;
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
for (const k in value) {
|
|
1647
|
-
const finalName = options.style === "deepObject" ? `${name}[${k}]` : k;
|
|
1648
|
-
values.push(serializePrimitiveParam(finalName, value[k], options));
|
|
1649
|
-
}
|
|
1650
|
-
const final = values.join(joiner);
|
|
1651
|
-
return options.style === "label" || options.style === "matrix" ? `${joiner}${final}` : final;
|
|
1652
|
-
}
|
|
1653
|
-
function serializeArrayParam(name, value, options) {
|
|
1654
|
-
if (!Array.isArray(value)) return "";
|
|
1655
|
-
if (options.explode === false) {
|
|
1656
|
-
const joiner2 = {
|
|
1657
|
-
form: ",",
|
|
1658
|
-
spaceDelimited: "%20",
|
|
1659
|
-
pipeDelimited: "|"
|
|
1660
|
-
}[options.style] || ",";
|
|
1661
|
-
const final = (options.allowReserved === true ? value : value.map((v) => encodeURIComponent(v))).join(joiner2);
|
|
1662
|
-
switch (options.style) {
|
|
1663
|
-
case "simple": return final;
|
|
1664
|
-
case "label": return `.${final}`;
|
|
1665
|
-
case "matrix": return `;${name}=${final}`;
|
|
1666
|
-
default: return `${name}=${final}`;
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
const joiner = {
|
|
1670
|
-
simple: ",",
|
|
1671
|
-
label: ".",
|
|
1672
|
-
matrix: ";"
|
|
1673
|
-
}[options.style] || "&";
|
|
1674
|
-
const values = [];
|
|
1675
|
-
for (const v of value) if (options.style === "simple" || options.style === "label") values.push(options.allowReserved === true ? v : encodeURIComponent(v));
|
|
1676
|
-
else values.push(serializePrimitiveParam(name, v, options));
|
|
1677
|
-
return options.style === "label" || options.style === "matrix" ? `${joiner}${values.join(joiner)}` : values.join(joiner);
|
|
1678
|
-
}
|
|
1679
|
-
function createQuerySerializer(options) {
|
|
1680
|
-
return function querySerializer(queryParams) {
|
|
1681
|
-
const search = [];
|
|
1682
|
-
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
1683
|
-
const value = queryParams[name];
|
|
1684
|
-
if (value === void 0 || value === null) continue;
|
|
1685
|
-
if (Array.isArray(value)) {
|
|
1686
|
-
if (value.length === 0) continue;
|
|
1687
|
-
search.push(serializeArrayParam(name, value, {
|
|
1688
|
-
style: "form",
|
|
1689
|
-
explode: true,
|
|
1690
|
-
...options?.array,
|
|
1691
|
-
allowReserved: options?.allowReserved || false
|
|
1692
|
-
}));
|
|
1693
|
-
continue;
|
|
1694
|
-
}
|
|
1695
|
-
if (typeof value === "object") {
|
|
1696
|
-
search.push(serializeObjectParam(name, value, {
|
|
1697
|
-
style: "deepObject",
|
|
1698
|
-
explode: true,
|
|
1699
|
-
...options?.object,
|
|
1700
|
-
allowReserved: options?.allowReserved || false
|
|
1701
|
-
}));
|
|
1702
|
-
continue;
|
|
1703
|
-
}
|
|
1704
|
-
search.push(serializePrimitiveParam(name, value, options));
|
|
1705
|
-
}
|
|
1706
|
-
return search.join("&");
|
|
1707
|
-
};
|
|
1708
|
-
}
|
|
1709
|
-
function defaultPathSerializer(pathname, pathParams) {
|
|
1710
|
-
let nextURL = pathname;
|
|
1711
|
-
for (const match of pathname.match(PATH_PARAM_RE) ?? []) {
|
|
1712
|
-
let name = match.substring(1, match.length - 1);
|
|
1713
|
-
let explode = false;
|
|
1714
|
-
let style = "simple";
|
|
1715
|
-
if (name.endsWith("*")) {
|
|
1716
|
-
explode = true;
|
|
1717
|
-
name = name.substring(0, name.length - 1);
|
|
1718
|
-
}
|
|
1719
|
-
if (name.startsWith(".")) {
|
|
1720
|
-
style = "label";
|
|
1721
|
-
name = name.substring(1);
|
|
1722
|
-
} else if (name.startsWith(";")) {
|
|
1723
|
-
style = "matrix";
|
|
1724
|
-
name = name.substring(1);
|
|
1725
|
-
}
|
|
1726
|
-
if (!pathParams || pathParams[name] === void 0 || pathParams[name] === null) continue;
|
|
1727
|
-
const value = pathParams[name];
|
|
1728
|
-
if (Array.isArray(value)) {
|
|
1729
|
-
nextURL = nextURL.replace(match, serializeArrayParam(name, value, {
|
|
1730
|
-
style,
|
|
1731
|
-
explode
|
|
1732
|
-
}));
|
|
1733
|
-
continue;
|
|
1734
|
-
}
|
|
1735
|
-
if (typeof value === "object") {
|
|
1736
|
-
nextURL = nextURL.replace(match, serializeObjectParam(name, value, {
|
|
1737
|
-
style,
|
|
1738
|
-
explode
|
|
1739
|
-
}));
|
|
1740
|
-
continue;
|
|
1741
|
-
}
|
|
1742
|
-
if (style === "matrix") {
|
|
1743
|
-
nextURL = nextURL.replace(match, `;${serializePrimitiveParam(name, value)}`);
|
|
1744
|
-
continue;
|
|
1745
|
-
}
|
|
1746
|
-
nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
|
|
1747
|
-
}
|
|
1748
|
-
return nextURL;
|
|
1749
|
-
}
|
|
1750
|
-
function defaultBodySerializer(body, headers) {
|
|
1751
|
-
if (body instanceof FormData) return body;
|
|
1752
|
-
if (headers) {
|
|
1753
|
-
if ((headers.get instanceof Function ? headers.get("Content-Type") ?? headers.get("content-type") : headers["Content-Type"] ?? headers["content-type"]) === "application/x-www-form-urlencoded") return new URLSearchParams(body).toString();
|
|
1754
|
-
}
|
|
1755
|
-
return JSON.stringify(body);
|
|
1756
|
-
}
|
|
1757
|
-
function createFinalURL(pathname, options) {
|
|
1758
|
-
let finalURL = `${options.baseUrl}${pathname}`;
|
|
1759
|
-
if (options.params?.path) finalURL = options.pathSerializer(finalURL, options.params.path);
|
|
1760
|
-
let search = options.querySerializer(options.params.query ?? {});
|
|
1761
|
-
if (search.startsWith("?")) search = search.substring(1);
|
|
1762
|
-
if (search) finalURL += `?${search}`;
|
|
1763
|
-
return finalURL;
|
|
1764
|
-
}
|
|
1765
|
-
function mergeHeaders(...allHeaders) {
|
|
1766
|
-
const finalHeaders = new Headers();
|
|
1767
|
-
for (const h of allHeaders) {
|
|
1768
|
-
if (!h || typeof h !== "object") continue;
|
|
1769
|
-
const iterator = h instanceof Headers ? h.entries() : Object.entries(h);
|
|
1770
|
-
for (const [k, v] of iterator) if (v === null) finalHeaders.delete(k);
|
|
1771
|
-
else if (Array.isArray(v)) for (const v2 of v) finalHeaders.append(k, v2);
|
|
1772
|
-
else if (v !== void 0) finalHeaders.set(k, v);
|
|
1773
|
-
}
|
|
1774
|
-
return finalHeaders;
|
|
1775
|
-
}
|
|
1776
|
-
function removeTrailingSlash(url) {
|
|
1777
|
-
if (url.endsWith("/")) return url.substring(0, url.length - 1);
|
|
1778
|
-
return url;
|
|
1779
|
-
}
|
|
1780
|
-
String.fromCharCode;
|
|
1781
|
-
const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
|
|
1782
|
-
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
1783
|
-
function hasTrailingSlash(input = "", respectQueryAndFragment) {
|
|
1784
|
-
if (!respectQueryAndFragment) return input.endsWith("/");
|
|
1785
|
-
return TRAILING_SLASH_RE.test(input);
|
|
1786
|
-
}
|
|
1787
|
-
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
1788
|
-
if (!respectQueryAndFragment) return input.endsWith("/") ? input : input + "/";
|
|
1789
|
-
if (hasTrailingSlash(input, true)) return input || "/";
|
|
1790
|
-
let path = input;
|
|
1791
|
-
let fragment = "";
|
|
1792
|
-
const fragmentIndex = input.indexOf("#");
|
|
1793
|
-
if (fragmentIndex !== -1) {
|
|
1794
|
-
path = input.slice(0, fragmentIndex);
|
|
1795
|
-
fragment = input.slice(fragmentIndex);
|
|
1796
|
-
if (!path) return fragment;
|
|
1797
|
-
}
|
|
1798
|
-
const [s0, ...s] = path.split("?");
|
|
1799
|
-
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
1800
|
-
}
|
|
1801
|
-
function isNonEmptyURL(url) {
|
|
1802
|
-
return url && url !== "/";
|
|
1803
|
-
}
|
|
1804
|
-
function joinURL(base, ...input) {
|
|
1805
|
-
let url = base || "";
|
|
1806
|
-
for (const segment of input.filter((url2) => isNonEmptyURL(url2))) if (url) {
|
|
1807
|
-
const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
|
|
1808
|
-
url = withTrailingSlash(url) + _segment;
|
|
1809
|
-
} else url = segment;
|
|
1810
|
-
return url;
|
|
1811
|
-
}
|
|
1812
|
-
//#endregion
|
|
1813
|
-
//#region src/internal/client/transport.ts
|
|
1814
|
-
const DEFAULT_REQUEST_TIMEOUT_MILLISECONDS = 3e4;
|
|
1815
|
-
const MAX_REQUEST_TIMEOUT_MILLISECONDS = 12e4;
|
|
1816
|
-
function createClientRuntime(config) {
|
|
1817
|
-
let runtime;
|
|
1818
|
-
try {
|
|
1819
|
-
runtime = Object.freeze({
|
|
1820
|
-
baseUrl: parseBaseUrl(config.baseUrl),
|
|
1821
|
-
fetchImplementation: config.fetch ?? globalThis.fetch.bind(globalThis),
|
|
1822
|
-
getCredential: config.getCredential,
|
|
1823
|
-
timeoutMilliseconds: parseTimeoutMilliseconds(config.timeoutMilliseconds)
|
|
1824
|
-
});
|
|
1825
|
-
} catch {
|
|
1826
|
-
throw new DriveError("invalid_input");
|
|
1827
|
-
}
|
|
1828
|
-
if (typeof runtime.fetchImplementation !== "function" || typeof runtime.getCredential !== "function") throw new DriveError("invalid_input");
|
|
1829
|
-
return runtime;
|
|
1830
|
-
}
|
|
1831
|
-
async function execute(runtime, signal, preconditionStatus, send, successStatuses, guard, allowsQuotaExceeded = false, allowedErrorCodes) {
|
|
1832
|
-
const operation = createOperationSignal(signal, runtime.timeoutMilliseconds);
|
|
1833
|
-
try {
|
|
1834
|
-
const operationSignal = operation.signal;
|
|
1835
|
-
throwIfAborted(operationSignal);
|
|
1836
|
-
const credential = await obtainCredential(runtime.getCredential, operationSignal);
|
|
1837
|
-
let capturedResponse;
|
|
1838
|
-
await send(createClient({
|
|
1839
|
-
baseUrl: runtime.baseUrl,
|
|
1840
|
-
fetch: async (request) => {
|
|
1841
|
-
try {
|
|
1842
|
-
const response = await raceWithAbort(runtime.fetchImplementation(request), operationSignal);
|
|
1843
|
-
if (!(response instanceof Response)) throw new DriveError("invalid_response");
|
|
1844
|
-
capturedResponse = response;
|
|
1845
|
-
} catch (error) {
|
|
1846
|
-
if (error instanceof DriveError) throw error;
|
|
1847
|
-
throw operationSignal.aborted ? new DriveError("aborted") : new DriveError("network_error");
|
|
1848
|
-
}
|
|
1849
|
-
return new Response(null, { status: 204 });
|
|
1850
|
-
}
|
|
1851
|
-
}), {
|
|
1852
|
-
cache: "no-store",
|
|
1853
|
-
credentials: "omit",
|
|
1854
|
-
headers: new Headers({ authorization: `Bearer ${credential}` }),
|
|
1855
|
-
signal: operationSignal
|
|
1856
|
-
});
|
|
1857
|
-
if (!capturedResponse) throw new DriveError("network_error");
|
|
1858
|
-
return guard === null ? await parseNoContentResponse(capturedResponse, operationSignal, preconditionStatus, successStatuses, allowedErrorCodes) : await parseResponse(capturedResponse, operationSignal, preconditionStatus, successStatuses, guard, allowsQuotaExceeded, allowedErrorCodes);
|
|
1859
|
-
} catch (error) {
|
|
1860
|
-
if (operation.didTimeout()) throw new DriveError("timeout");
|
|
1861
|
-
if (error instanceof DriveError) throw error;
|
|
1862
|
-
throw operation.signal.aborted ? new DriveError("aborted") : new DriveError("network_error");
|
|
1863
|
-
} finally {
|
|
1864
|
-
operation.dispose();
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
function parseTimeoutMilliseconds(value) {
|
|
1868
|
-
if (value === void 0) return DEFAULT_REQUEST_TIMEOUT_MILLISECONDS;
|
|
1869
|
-
if (!Number.isSafeInteger(value) || value < 1 || value > MAX_REQUEST_TIMEOUT_MILLISECONDS) throw new DriveError("invalid_input");
|
|
1870
|
-
return value;
|
|
1871
|
-
}
|
|
1872
|
-
function createOperationSignal(callerSignal, timeoutMilliseconds) {
|
|
1873
|
-
const controller = new AbortController();
|
|
1874
|
-
let timedOut = false;
|
|
1875
|
-
const onAbort = () => controller.abort();
|
|
1876
|
-
if (callerSignal?.aborted) controller.abort();
|
|
1877
|
-
else callerSignal?.addEventListener("abort", onAbort, { once: true });
|
|
1878
|
-
const timeout = setTimeout(() => {
|
|
1879
|
-
timedOut = true;
|
|
1880
|
-
controller.abort();
|
|
1881
|
-
}, timeoutMilliseconds);
|
|
1882
|
-
return {
|
|
1883
|
-
signal: controller.signal,
|
|
1884
|
-
didTimeout: () => timedOut,
|
|
1885
|
-
dispose: () => {
|
|
1886
|
-
clearTimeout(timeout);
|
|
1887
|
-
callerSignal?.removeEventListener("abort", onAbort);
|
|
1888
|
-
}
|
|
1889
|
-
};
|
|
1890
|
-
}
|
|
1891
|
-
function parseBaseUrl(value) {
|
|
1892
|
-
if (typeof value !== "string") throw new TypeError("Drive base URL is invalid");
|
|
1893
|
-
let url;
|
|
1894
|
-
try {
|
|
1895
|
-
url = new URL(value);
|
|
1896
|
-
} catch {
|
|
1897
|
-
throw new TypeError("Drive base URL is invalid");
|
|
1898
|
-
}
|
|
1899
|
-
const localHttp = url.protocol === "http:" && [
|
|
1900
|
-
"localhost",
|
|
1901
|
-
"127.0.0.1",
|
|
1902
|
-
"[::1]"
|
|
1903
|
-
].includes(url.hostname);
|
|
1904
|
-
if (url.protocol !== "https:" && !localHttp || url.username || url.password || url.search || url.hash || !url.host) throw new TypeError("Drive base URL is invalid");
|
|
1905
|
-
return joinURL(url.origin, url.pathname);
|
|
1906
|
-
}
|
|
1907
|
-
async function obtainCredential(provider, signal) {
|
|
1908
|
-
throwIfAborted(signal);
|
|
1909
|
-
let credential;
|
|
1910
|
-
try {
|
|
1911
|
-
credential = await raceWithAbort(provider({ signal }), signal);
|
|
1912
|
-
} catch (error) {
|
|
1913
|
-
if (error instanceof DriveError && error.code === "aborted") throw error;
|
|
1914
|
-
throw signal.aborted ? new DriveError("aborted") : new DriveError("credential_unavailable");
|
|
1915
|
-
}
|
|
1916
|
-
if (typeof credential !== "string" || credential.length < 1 || credential.length > 16384 || !/^[\x21-\x7e]+$/.test(credential)) throw new DriveError("credential_unavailable");
|
|
1917
|
-
return credential;
|
|
1918
|
-
}
|
|
1919
|
-
function throwIfAborted(signal) {
|
|
1920
|
-
if (signal.aborted) throw new DriveError("aborted");
|
|
1921
|
-
}
|
|
1922
|
-
async function raceWithAbort(promise, signal) {
|
|
1923
|
-
throwIfAborted(signal);
|
|
1924
|
-
let removeAbort = () => {};
|
|
1925
|
-
const aborted = new Promise((_, reject) => {
|
|
1926
|
-
const onAbort = () => reject(new DriveError("aborted"));
|
|
1927
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1928
|
-
removeAbort = () => signal.removeEventListener("abort", onAbort);
|
|
1929
|
-
});
|
|
1930
|
-
try {
|
|
1931
|
-
return await Promise.race([promise, aborted]);
|
|
1932
|
-
} finally {
|
|
1933
|
-
removeAbort();
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
//#endregion
|
|
1937
|
-
//#region src/internal/client/operations.ts
|
|
1938
|
-
const CURRENT_WORKSPACE_ERROR_CODES = Object.freeze([
|
|
1939
|
-
"authentication_required",
|
|
1940
|
-
"identity_authority_unavailable",
|
|
1941
|
-
"permission_denied",
|
|
1942
|
-
"resource_not_found",
|
|
1943
|
-
"invalid_request",
|
|
1944
|
-
"service_unavailable"
|
|
1945
|
-
]);
|
|
1946
|
-
const GET_ITEM_ERROR_CODES = Object.freeze([
|
|
1947
|
-
"authentication_required",
|
|
1948
|
-
"identity_authority_unavailable",
|
|
1949
|
-
"permission_denied",
|
|
1950
|
-
"resource_not_found",
|
|
1951
|
-
"invalid_request",
|
|
1952
|
-
"precondition_failed",
|
|
1953
|
-
"service_unavailable"
|
|
1954
|
-
]);
|
|
1955
|
-
const SEARCH_WORKSPACE_ITEMS_ERROR_CODES = Object.freeze([
|
|
1956
|
-
"authentication_required",
|
|
1957
|
-
"identity_authority_unavailable",
|
|
1958
|
-
"permission_denied",
|
|
1959
|
-
"resource_not_found",
|
|
1960
|
-
"invalid_request",
|
|
1961
|
-
"invalid_pagination_cursor",
|
|
1962
|
-
"precondition_failed",
|
|
1963
|
-
"service_unavailable"
|
|
1964
|
-
]);
|
|
1965
|
-
const TRANSFER_ERROR_CODES = Object.freeze([
|
|
1966
|
-
"authentication_required",
|
|
1967
|
-
"identity_authority_unavailable",
|
|
1968
|
-
"permission_denied",
|
|
1969
|
-
"resource_not_found",
|
|
1970
|
-
"invalid_request",
|
|
1971
|
-
"precondition_failed",
|
|
1972
|
-
"upload_recovery_required",
|
|
1973
|
-
"service_unavailable"
|
|
1974
|
-
]);
|
|
1975
|
-
const STATUS_ERROR_CODES = Object.freeze([
|
|
1976
|
-
"authentication_required",
|
|
1977
|
-
"identity_authority_unavailable",
|
|
1978
|
-
"permission_denied",
|
|
1979
|
-
"resource_not_found",
|
|
1980
|
-
"invalid_request",
|
|
1981
|
-
"service_unavailable"
|
|
1982
|
-
]);
|
|
1983
|
-
const CREATE_UPLOAD_ERROR_CODES = Object.freeze([
|
|
1984
|
-
...TRANSFER_ERROR_CODES,
|
|
1985
|
-
"invalid_idempotency_key",
|
|
1986
|
-
"idempotency_conflict",
|
|
1987
|
-
"quota_exceeded"
|
|
1988
|
-
]);
|
|
1989
|
-
const COMPLETE_UPLOAD_ERROR_CODES = Object.freeze([...TRANSFER_ERROR_CODES, "invalid_idempotency_key"]);
|
|
1990
|
-
const LIFECYCLE_MUTATION_ERROR_CODES = Object.freeze([
|
|
1991
|
-
"authentication_required",
|
|
1992
|
-
"identity_authority_unavailable",
|
|
1993
|
-
"permission_denied",
|
|
1994
|
-
"resource_not_found",
|
|
1995
|
-
"invalid_request",
|
|
1996
|
-
"invalid_idempotency_key",
|
|
1997
|
-
"idempotency_conflict",
|
|
1998
|
-
"precondition_failed",
|
|
1999
|
-
"service_unavailable"
|
|
2000
|
-
]);
|
|
2001
|
-
const LIST_ITEM_VERSIONS_ERROR_CODES = Object.freeze([
|
|
2002
|
-
"authentication_required",
|
|
2003
|
-
"identity_authority_unavailable",
|
|
2004
|
-
"permission_denied",
|
|
2005
|
-
"resource_not_found",
|
|
2006
|
-
"invalid_request",
|
|
2007
|
-
"precondition_failed",
|
|
2008
|
-
"service_unavailable"
|
|
2009
|
-
]);
|
|
2010
|
-
const DOWNLOAD_ERROR_CODES = Object.freeze([
|
|
2011
|
-
"authentication_required",
|
|
2012
|
-
"identity_authority_unavailable",
|
|
2013
|
-
"permission_denied",
|
|
2014
|
-
"resource_not_found",
|
|
2015
|
-
"invalid_request",
|
|
2016
|
-
"invalid_idempotency_key",
|
|
2017
|
-
"idempotency_conflict",
|
|
2018
|
-
"precondition_failed",
|
|
2019
|
-
"range_not_satisfiable",
|
|
2020
|
-
"service_unavailable"
|
|
2021
|
-
]);
|
|
2022
|
-
function createDriveOperations(runtime) {
|
|
2023
|
-
return Object.freeze({
|
|
2024
|
-
getCurrentWorkspace: (input) => getCurrentWorkspace(runtime, input),
|
|
2025
|
-
getItem: (input) => getItem(runtime, input),
|
|
2026
|
-
searchWorkspaceItems: (input) => searchWorkspaceItems(runtime, input),
|
|
2027
|
-
listFolderChildren: (input) => listFolderChildren(runtime, input),
|
|
2028
|
-
createFolder: (input) => createFolder(runtime, input),
|
|
2029
|
-
updateItem: (input) => updateItem(runtime, input),
|
|
2030
|
-
trashItem: (input) => trashItem(runtime, input),
|
|
2031
|
-
restoreItem: (input) => restoreItem(runtime, input),
|
|
2032
|
-
deleteItem: (input) => deleteItem(runtime, input),
|
|
2033
|
-
listItemVersions: (input) => listItemVersions(runtime, input),
|
|
2034
|
-
getItemVersion: (input) => getItemVersion(runtime, input),
|
|
2035
|
-
restoreItemVersion: (input) => restoreItemVersion(runtime, input),
|
|
2036
|
-
createDownload: (input) => createDownload(runtime, input),
|
|
2037
|
-
downloadItem: (input) => downloadItem(runtime, input),
|
|
2038
|
-
listItemPermissions: (input) => listItemPermissions(runtime, input),
|
|
2039
|
-
readEffectiveItemPermissions: (input) => readEffectiveItemPermissions(runtime, input),
|
|
2040
|
-
createItemPermission: (input) => createItemPermission(runtime, input),
|
|
2041
|
-
updateItemPermission: (input) => updateItemPermission(runtime, input),
|
|
2042
|
-
revokeItemPermission: (input) => revokeItemPermission(runtime, input),
|
|
2043
|
-
createUpload: (input) => createUpload(runtime, input),
|
|
2044
|
-
getUploadStatus: (input) => getUploadStatus(runtime, input),
|
|
2045
|
-
createUploadPartDescriptor: (input) => createUploadPartDescriptor(runtime, input),
|
|
2046
|
-
recordUploadPart: (input) => recordUploadPart(runtime, input),
|
|
2047
|
-
completeUpload: (input) => completeUpload(runtime, input),
|
|
2048
|
-
abortUpload: (input) => abortUpload(runtime, input)
|
|
2049
|
-
});
|
|
2050
|
-
}
|
|
2051
|
-
async function createDownload(runtime, input) {
|
|
2052
|
-
const validated = validateCreateDownloadInput(input);
|
|
2053
|
-
return execute(runtime, validated.signal, 412, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/downloads", {
|
|
2054
|
-
...operationOptions("createDownload", { params: {
|
|
2055
|
-
path: {
|
|
2056
|
-
workspaceId: validated.workspaceId,
|
|
2057
|
-
itemId: validated.itemId
|
|
2058
|
-
},
|
|
2059
|
-
query: validated.versionId === void 0 ? {} : { versionId: validated.versionId },
|
|
2060
|
-
header: {
|
|
2061
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2062
|
-
"Download-Method": validated.method,
|
|
2063
|
-
...validated.range === void 0 ? {} : { Range: validated.range },
|
|
2064
|
-
...validated.ifMatch === void 0 ? {} : { "If-Match": validated.ifMatch },
|
|
2065
|
-
...validated.ifNoneMatch === void 0 ? {} : { "If-None-Match": validated.ifNoneMatch },
|
|
2066
|
-
...validated.ifRange === void 0 ? {} : { "If-Range": validated.ifRange }
|
|
2067
|
-
}
|
|
2068
|
-
} }),
|
|
2069
|
-
...requestOptions
|
|
2070
|
-
}), [
|
|
2071
|
-
200,
|
|
2072
|
-
202,
|
|
2073
|
-
304
|
|
2074
|
-
], (value, status) => status === 200 ? isManagedDownloadDescriptor(value) : status === 202 ? isManagedDownloadRestorePending(value) : value === void 0, false, DOWNLOAD_ERROR_CODES);
|
|
2075
|
-
}
|
|
2076
|
-
async function downloadItem(runtime, input) {
|
|
2077
|
-
const validated = validateCreateDownloadInput(input);
|
|
2078
|
-
const created = await createDownload(runtime, input);
|
|
2079
|
-
if (created.status === 202 || created.status === 304) return created;
|
|
2080
|
-
const descriptor = created.data;
|
|
2081
|
-
if (descriptor.expiresAtEpochMilliseconds <= Date.now()) throw new DriveError("invalid_response");
|
|
2082
|
-
const operation = createOperationSignal(validated.signal, runtime.timeoutMilliseconds);
|
|
2083
|
-
try {
|
|
2084
|
-
const response = await raceWithAbort(runtime.fetchImplementation(directDownloadRequest(descriptor, operation.signal)), operation.signal);
|
|
2085
|
-
if (!responseMatchesDownloadDescriptor(response, descriptor)) {
|
|
2086
|
-
await response.body?.cancel().catch(() => void 0);
|
|
2087
|
-
throw new DriveError("invalid_response");
|
|
2088
|
-
}
|
|
2089
|
-
const responseHeaders = downloadResponseHeaders(descriptor);
|
|
2090
|
-
if (descriptor.method === "HEAD") {
|
|
2091
|
-
await response.body?.cancel().catch(() => void 0);
|
|
2092
|
-
operation.dispose();
|
|
2093
|
-
return new Response(null, {
|
|
2094
|
-
status: response.status,
|
|
2095
|
-
headers: responseHeaders
|
|
2096
|
-
});
|
|
2097
|
-
}
|
|
2098
|
-
if (!response.body) {
|
|
2099
|
-
operation.dispose();
|
|
2100
|
-
if (descriptor.response.contentLength !== 0) throw new DriveError("invalid_response");
|
|
2101
|
-
return new Response(null, {
|
|
2102
|
-
status: response.status,
|
|
2103
|
-
headers: responseHeaders
|
|
2104
|
-
});
|
|
2105
|
-
}
|
|
2106
|
-
operation.dispose();
|
|
2107
|
-
return new Response(streamWithOperationLifetime(response.body, descriptor.response.contentLength, validated.signal), {
|
|
2108
|
-
status: response.status,
|
|
2109
|
-
headers: responseHeaders
|
|
2110
|
-
});
|
|
2111
|
-
} catch (error) {
|
|
2112
|
-
operation.dispose();
|
|
2113
|
-
if (operation.didTimeout()) throw new DriveError("timeout");
|
|
2114
|
-
if (error instanceof DriveError) throw error;
|
|
2115
|
-
throw operation.signal.aborted ? new DriveError(operation.didTimeout() ? "timeout" : "aborted") : new DriveError("network_error");
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
function downloadResponseHeaders(descriptor) {
|
|
2119
|
-
const expected = descriptor.response;
|
|
2120
|
-
const headers = new Headers();
|
|
2121
|
-
headers.set("accept-ranges", expected.acceptRanges);
|
|
2122
|
-
headers.set("content-disposition", expected.contentDisposition);
|
|
2123
|
-
headers.set("content-length", String(expected.contentLength));
|
|
2124
|
-
headers.set("content-type", expected.contentType);
|
|
2125
|
-
headers.set("etag", expected.etag);
|
|
2126
|
-
if (expected.contentRange === null) headers.delete("content-range");
|
|
2127
|
-
else headers.set("content-range", expected.contentRange);
|
|
2128
|
-
return headers;
|
|
2129
|
-
}
|
|
2130
|
-
function directDownloadRequest(descriptor, signal) {
|
|
2131
|
-
const base = {
|
|
2132
|
-
method: descriptor.method,
|
|
2133
|
-
headers: descriptor.headers,
|
|
2134
|
-
redirect: "manual",
|
|
2135
|
-
signal
|
|
2136
|
-
};
|
|
2137
|
-
try {
|
|
2138
|
-
return new Request(descriptor.url, {
|
|
2139
|
-
...base,
|
|
2140
|
-
cache: "no-store",
|
|
2141
|
-
credentials: "omit",
|
|
2142
|
-
referrerPolicy: "no-referrer"
|
|
2143
|
-
});
|
|
2144
|
-
} catch {
|
|
2145
|
-
try {
|
|
2146
|
-
return new Request(descriptor.url, {
|
|
2147
|
-
...base,
|
|
2148
|
-
credentials: "omit",
|
|
2149
|
-
referrerPolicy: "no-referrer"
|
|
2150
|
-
});
|
|
2151
|
-
} catch {
|
|
2152
|
-
return new Request(descriptor.url, {
|
|
2153
|
-
...base,
|
|
2154
|
-
credentials: "omit"
|
|
2155
|
-
});
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
function responseMatchesDownloadDescriptor(response, descriptor) {
|
|
2160
|
-
const expected = descriptor.response;
|
|
2161
|
-
const encoding = response.headers.get("content-encoding");
|
|
2162
|
-
return response.status === expected.status && response.headers.get("etag") === expected.etag && response.headers.get("content-length") === String(expected.contentLength) && (encoding === null || encoding === "identity") && (expected.contentRange === null ? response.headers.get("content-range") === null : response.headers.get("content-range") === expected.contentRange);
|
|
2163
|
-
}
|
|
2164
|
-
function streamWithOperationLifetime(source, expectedLength, signal) {
|
|
2165
|
-
const reader = source.getReader();
|
|
2166
|
-
let receivedLength = 0;
|
|
2167
|
-
let finished = false;
|
|
2168
|
-
let removeAbort = () => {};
|
|
2169
|
-
return new ReadableStream({
|
|
2170
|
-
start(controller) {
|
|
2171
|
-
if (!signal) return;
|
|
2172
|
-
const onAbort = () => {
|
|
2173
|
-
if (finished) return;
|
|
2174
|
-
finished = true;
|
|
2175
|
-
removeAbort();
|
|
2176
|
-
reader.cancel().catch(() => void 0);
|
|
2177
|
-
controller.error(new DriveError("aborted"));
|
|
2178
|
-
};
|
|
2179
|
-
if (signal.aborted) onAbort();
|
|
2180
|
-
else {
|
|
2181
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
2182
|
-
removeAbort = () => signal.removeEventListener("abort", onAbort);
|
|
2183
|
-
}
|
|
2184
|
-
},
|
|
2185
|
-
async pull(controller) {
|
|
2186
|
-
if (finished) return;
|
|
2187
|
-
try {
|
|
2188
|
-
const chunk = await reader.read();
|
|
2189
|
-
if (finished) return;
|
|
2190
|
-
if (chunk.done) {
|
|
2191
|
-
finished = true;
|
|
2192
|
-
removeAbort();
|
|
2193
|
-
reader.releaseLock();
|
|
2194
|
-
if (receivedLength === expectedLength) controller.close();
|
|
2195
|
-
else controller.error(new DriveError("invalid_response"));
|
|
2196
|
-
} else {
|
|
2197
|
-
receivedLength += chunk.value.byteLength;
|
|
2198
|
-
if (!Number.isSafeInteger(receivedLength) || receivedLength > expectedLength) {
|
|
2199
|
-
finished = true;
|
|
2200
|
-
removeAbort();
|
|
2201
|
-
await reader.cancel().catch(() => void 0);
|
|
2202
|
-
controller.error(new DriveError("invalid_response"));
|
|
2203
|
-
return;
|
|
2204
|
-
}
|
|
2205
|
-
controller.enqueue(chunk.value);
|
|
2206
|
-
}
|
|
2207
|
-
} catch (error) {
|
|
2208
|
-
if (finished) return;
|
|
2209
|
-
finished = true;
|
|
2210
|
-
removeAbort();
|
|
2211
|
-
await reader.cancel().catch(() => void 0);
|
|
2212
|
-
controller.error(error instanceof DriveError ? error : signal?.aborted ? new DriveError("aborted") : new DriveError("network_error"));
|
|
2213
|
-
}
|
|
2214
|
-
},
|
|
2215
|
-
async cancel(reason) {
|
|
2216
|
-
if (finished) return;
|
|
2217
|
-
finished = true;
|
|
2218
|
-
removeAbort();
|
|
2219
|
-
await reader.cancel(reason).catch(() => void 0);
|
|
2220
|
-
}
|
|
2221
|
-
});
|
|
2222
|
-
}
|
|
2223
|
-
async function getCurrentWorkspace(runtime, input) {
|
|
2224
|
-
return execute(runtime, validateCurrentWorkspaceInput(input).signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/current", {
|
|
2225
|
-
...operationOptions("getCurrentWorkspace", { params: {} }),
|
|
2226
|
-
...requestOptions
|
|
2227
|
-
}), [200], isCurrentWorkspace, false, CURRENT_WORKSPACE_ERROR_CODES);
|
|
2228
|
-
}
|
|
2229
|
-
async function getItem(runtime, input) {
|
|
2230
|
-
const validated = validateResourceInput(input);
|
|
2231
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}", {
|
|
2232
|
-
...operationOptions("getItem", { params: { path: resourcePath(validated) } }),
|
|
2233
|
-
...requestOptions
|
|
2234
|
-
}), [200], (value, _status, headers) => isManagedItemMetadata(value, validated.workspaceId, validated.itemId) && itemEtagMatchesRevision(headers, value.revision), false, GET_ITEM_ERROR_CODES);
|
|
2235
|
-
}
|
|
2236
|
-
async function searchWorkspaceItems(runtime, input) {
|
|
2237
|
-
const validated = validateSearchWorkspaceItemsInput(input);
|
|
2238
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/search", {
|
|
2239
|
-
...operationOptions("searchWorkspaceItems", { params: {
|
|
2240
|
-
path: { workspaceId: validated.workspaceId },
|
|
2241
|
-
query: {
|
|
2242
|
-
query: validated.query,
|
|
2243
|
-
...validated.limit === void 0 ? {} : { limit: validated.limit },
|
|
2244
|
-
...validated.cursor === void 0 ? {} : { cursor: validated.cursor }
|
|
2245
|
-
}
|
|
2246
|
-
} }),
|
|
2247
|
-
...requestOptions
|
|
2248
|
-
}), [200], (value) => isWorkspaceItemSearchPage(value, validated.workspaceId, validated.query, validated.limit ?? 50), false, SEARCH_WORKSPACE_ITEMS_ERROR_CODES);
|
|
2249
|
-
}
|
|
2250
|
-
async function listFolderChildren(runtime, input) {
|
|
2251
|
-
const validated = validatePageInput(input);
|
|
2252
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/children", {
|
|
2253
|
-
...operationOptions("listFolderChildren", { params: {
|
|
2254
|
-
path: resourcePath(validated),
|
|
2255
|
-
query: pageQuery(validated)
|
|
2256
|
-
} }),
|
|
2257
|
-
...requestOptions
|
|
2258
|
-
}), [200], (value) => isFolderPage(value, validated.workspaceId, validated.itemId));
|
|
2259
|
-
}
|
|
2260
|
-
async function createFolder(runtime, input) {
|
|
2261
|
-
const validated = validateCreateFolderInput(input);
|
|
2262
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/children", {
|
|
2263
|
-
...operationOptions("createFolder", {
|
|
2264
|
-
params: {
|
|
2265
|
-
path: resourcePath(validated),
|
|
2266
|
-
header: { "Idempotency-Key": validated.idempotencyKey }
|
|
2267
|
-
},
|
|
2268
|
-
body: { name: validated.name }
|
|
2269
|
-
}),
|
|
2270
|
-
...requestOptions
|
|
2271
|
-
}), [200, 201], (value) => isFolderItem(value) && value.workspaceId === validated.workspaceId && value.parentItemId === validated.itemId && value.kind === "folder" && value.name === validated.name);
|
|
2272
|
-
}
|
|
2273
|
-
async function updateItem(runtime, input) {
|
|
2274
|
-
const validated = validateUpdateItemInput(input);
|
|
2275
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.PATCH("/api/v1/workspaces/{workspaceId}/items/{itemId}", {
|
|
2276
|
-
...operationOptions("updateItem", {
|
|
2277
|
-
params: {
|
|
2278
|
-
path: resourcePath(validated),
|
|
2279
|
-
header: {
|
|
2280
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2281
|
-
"If-Match": validated.ifMatch
|
|
2282
|
-
}
|
|
2283
|
-
},
|
|
2284
|
-
body: {
|
|
2285
|
-
name: validated.name,
|
|
2286
|
-
parentItemId: validated.parentItemId
|
|
2287
|
-
}
|
|
2288
|
-
}),
|
|
2289
|
-
...requestOptions
|
|
2290
|
-
}), [200], (value, _status, headers) => isManagedLifecycleItem(value, validated.workspaceId, validated.itemId, "active") && value.name === validated.name && value.parentItemId === validated.parentItemId && itemEtagMatchesRevision(headers, value.revision), false, LIFECYCLE_MUTATION_ERROR_CODES);
|
|
2291
|
-
}
|
|
2292
|
-
async function trashItem(runtime, input) {
|
|
2293
|
-
const validated = validateLifecycleMutationInput(input);
|
|
2294
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/trash", {
|
|
2295
|
-
...operationOptions("trashItem", { params: {
|
|
2296
|
-
path: resourcePath(validated),
|
|
2297
|
-
header: {
|
|
2298
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2299
|
-
"If-Match": validated.ifMatch
|
|
2300
|
-
}
|
|
2301
|
-
} }),
|
|
2302
|
-
...requestOptions
|
|
2303
|
-
}), [200], (value, _status, headers) => isManagedLifecycleItem(value, validated.workspaceId, validated.itemId, "trashed") && itemEtagMatchesRevision(headers, value.revision), false, LIFECYCLE_MUTATION_ERROR_CODES);
|
|
2304
|
-
}
|
|
2305
|
-
async function restoreItem(runtime, input) {
|
|
2306
|
-
const validated = validateLifecycleMutationInput(input);
|
|
2307
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/restore", {
|
|
2308
|
-
...operationOptions("restoreItem", { params: {
|
|
2309
|
-
path: resourcePath(validated),
|
|
2310
|
-
header: {
|
|
2311
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2312
|
-
"If-Match": validated.ifMatch
|
|
2313
|
-
}
|
|
2314
|
-
} }),
|
|
2315
|
-
...requestOptions
|
|
2316
|
-
}), [200], (value, _status, headers) => isManagedLifecycleItem(value, validated.workspaceId, validated.itemId, "active") && itemEtagMatchesRevision(headers, value.revision), false, LIFECYCLE_MUTATION_ERROR_CODES);
|
|
2317
|
-
}
|
|
2318
|
-
async function deleteItem(runtime, input) {
|
|
2319
|
-
const validated = validateLifecycleMutationInput(input);
|
|
2320
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.DELETE("/api/v1/workspaces/{workspaceId}/items/{itemId}", {
|
|
2321
|
-
...operationOptions("deleteItem", { params: {
|
|
2322
|
-
path: resourcePath(validated),
|
|
2323
|
-
header: {
|
|
2324
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2325
|
-
"If-Match": validated.ifMatch
|
|
2326
|
-
}
|
|
2327
|
-
} }),
|
|
2328
|
-
...requestOptions
|
|
2329
|
-
}), [200, 202], (value, _status, headers) => isManagedLifecycleItem(value, validated.workspaceId, validated.itemId, "deleting") && itemEtagMatchesRevision(headers, value.revision), false, LIFECYCLE_MUTATION_ERROR_CODES);
|
|
2330
|
-
}
|
|
2331
|
-
async function listItemVersions(runtime, input) {
|
|
2332
|
-
const validated = validatePageInput(input);
|
|
2333
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/versions", {
|
|
2334
|
-
...operationOptions("listItemVersions", { params: {
|
|
2335
|
-
path: resourcePath(validated),
|
|
2336
|
-
query: pageQuery(validated)
|
|
2337
|
-
} }),
|
|
2338
|
-
...requestOptions
|
|
2339
|
-
}), [200], (value) => isManagedItemVersionPage(value, validated.limit ?? 50), false, LIST_ITEM_VERSIONS_ERROR_CODES);
|
|
2340
|
-
}
|
|
2341
|
-
async function getItemVersion(runtime, input) {
|
|
2342
|
-
const validated = validateItemVersionInput(input);
|
|
2343
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}", {
|
|
2344
|
-
...operationOptions("getItemVersion", { params: { path: {
|
|
2345
|
-
...resourcePath(validated),
|
|
2346
|
-
versionId: validated.versionId
|
|
2347
|
-
} } }),
|
|
2348
|
-
...requestOptions
|
|
2349
|
-
}), [200], (value) => isManagedItemVersionResource(value, validated.workspaceId, validated.itemId, validated.versionId), false, LIST_ITEM_VERSIONS_ERROR_CODES);
|
|
2350
|
-
}
|
|
2351
|
-
async function restoreItemVersion(runtime, input) {
|
|
2352
|
-
const validated = validateRestoreItemVersionInput(input);
|
|
2353
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}/restore", {
|
|
2354
|
-
...operationOptions("restoreItemVersion", { params: {
|
|
2355
|
-
path: {
|
|
2356
|
-
...resourcePath(validated),
|
|
2357
|
-
versionId: validated.versionId
|
|
2358
|
-
},
|
|
2359
|
-
header: {
|
|
2360
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2361
|
-
"If-Match": validated.ifMatch
|
|
2362
|
-
}
|
|
2363
|
-
} }),
|
|
2364
|
-
...requestOptions
|
|
2365
|
-
}), [200], (value, _status, headers) => isManagedItemVersionRestoreResult(value, validated.versionId) && itemEtagMatchesRevision(headers, value.itemRevision), false, LIFECYCLE_MUTATION_ERROR_CODES);
|
|
2366
|
-
}
|
|
2367
|
-
async function listItemPermissions(runtime, input) {
|
|
2368
|
-
const validated = validatePageInput(input);
|
|
2369
|
-
return execute(runtime, validated.signal, 412, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions", {
|
|
2370
|
-
...operationOptions("listItemPermissions", { params: {
|
|
2371
|
-
path: resourcePath(validated),
|
|
2372
|
-
query: pageQuery(validated)
|
|
2373
|
-
} }),
|
|
2374
|
-
...requestOptions
|
|
2375
|
-
}), [200], (value, _status, headers) => isPermissionPage(value, headers, validated.itemId));
|
|
2376
|
-
}
|
|
2377
|
-
async function readEffectiveItemPermissions(runtime, input) {
|
|
2378
|
-
const validated = validateResourceInput(input);
|
|
2379
|
-
return execute(runtime, validated.signal, 412, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/effective", {
|
|
2380
|
-
...operationOptions("readEffectiveItemPermissions", { params: { path: resourcePath(validated) } }),
|
|
2381
|
-
...requestOptions
|
|
2382
|
-
}), [200], (value) => isEffectivePermissionResponse(value, validated.itemId));
|
|
2383
|
-
}
|
|
2384
|
-
async function createItemPermission(runtime, input) {
|
|
2385
|
-
const validated = validateCreatePermissionInput(input);
|
|
2386
|
-
return execute(runtime, validated.signal, 412, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions", {
|
|
2387
|
-
...operationOptions("createItemPermission", {
|
|
2388
|
-
params: {
|
|
2389
|
-
path: resourcePath(validated),
|
|
2390
|
-
header: {
|
|
2391
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2392
|
-
"If-Match": validated.ifMatch
|
|
2393
|
-
}
|
|
2394
|
-
},
|
|
2395
|
-
body: {
|
|
2396
|
-
grantee: validated.grantee,
|
|
2397
|
-
actions: validated.actions,
|
|
2398
|
-
expiresAtEpochMilliseconds: validated.expiresAtEpochMilliseconds
|
|
2399
|
-
}
|
|
2400
|
-
}),
|
|
2401
|
-
...requestOptions
|
|
2402
|
-
}), [200, 201], (value, status, headers) => isPermissionMutation(value, validated.itemId) && (status === 201 && value.outcome === "committed" || status === 200 && value.outcome === "replayed") && (status === 200 || value.grant.availability !== "revoked") && mutationValidatorsAreCoherent(headers));
|
|
2403
|
-
}
|
|
2404
|
-
async function updateItemPermission(runtime, input) {
|
|
2405
|
-
const validated = validateUpdatePermissionInput(input);
|
|
2406
|
-
const body = {};
|
|
2407
|
-
if (validated.actions !== void 0) body.actions = validated.actions;
|
|
2408
|
-
if (validated.expiresAtEpochMilliseconds !== void 0) body.expiresAtEpochMilliseconds = validated.expiresAtEpochMilliseconds;
|
|
2409
|
-
return execute(runtime, validated.signal, 412, (api, requestOptions) => api.PATCH("/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/{grantId}", {
|
|
2410
|
-
...operationOptions("updateItemPermission", {
|
|
2411
|
-
params: {
|
|
2412
|
-
path: {
|
|
2413
|
-
...resourcePath(validated),
|
|
2414
|
-
grantId: validated.grantId
|
|
2415
|
-
},
|
|
2416
|
-
header: {
|
|
2417
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2418
|
-
"If-Match": validated.ifMatch
|
|
2419
|
-
}
|
|
2420
|
-
},
|
|
2421
|
-
body
|
|
2422
|
-
}),
|
|
2423
|
-
...requestOptions
|
|
2424
|
-
}), [200], (value, _status, headers) => isPermissionMutation(value, validated.itemId, validated.grantId) && value.grant.availability !== "revoked" && mutationValidatorsAreCoherent(headers));
|
|
2425
|
-
}
|
|
2426
|
-
async function revokeItemPermission(runtime, input) {
|
|
2427
|
-
const validated = validateGrantMutationInput(input);
|
|
2428
|
-
return execute(runtime, validated.signal, 412, (api, requestOptions) => api.DELETE("/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/{grantId}", {
|
|
2429
|
-
...operationOptions("revokeItemPermission", { params: {
|
|
2430
|
-
path: {
|
|
2431
|
-
...resourcePath(validated),
|
|
2432
|
-
grantId: validated.grantId
|
|
2433
|
-
},
|
|
2434
|
-
header: {
|
|
2435
|
-
"Idempotency-Key": validated.idempotencyKey,
|
|
2436
|
-
"If-Match": validated.ifMatch
|
|
2437
|
-
}
|
|
2438
|
-
} }),
|
|
2439
|
-
...requestOptions
|
|
2440
|
-
}), [200], (value, _status, headers) => isPermissionMutation(value, validated.itemId, validated.grantId) && value.grant.availability === "revoked" && parseCollectionEtag(headers.get("drive-permission-collection-etag") ?? "") !== void 0 && headers.get("drive-permission-grant-etag") === null);
|
|
2441
|
-
}
|
|
2442
|
-
async function createUpload(runtime, input) {
|
|
2443
|
-
const validated = validateCreateUploadInput(input);
|
|
2444
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/uploads", {
|
|
2445
|
-
...operationOptions("createUpload", {
|
|
2446
|
-
params: {
|
|
2447
|
-
path: { workspaceId: validated.workspaceId },
|
|
2448
|
-
header: { "Idempotency-Key": validated.idempotencyKey }
|
|
2449
|
-
},
|
|
2450
|
-
body: {
|
|
2451
|
-
parentItemId: validated.parentItemId,
|
|
2452
|
-
expectedByteLength: validated.expectedByteLength,
|
|
2453
|
-
displayFilename: validated.displayFilename,
|
|
2454
|
-
mediaType: validated.mediaType,
|
|
2455
|
-
callerDeclaredContentDigest: validated.callerDeclaredContentDigest,
|
|
2456
|
-
protectionClassification: validated.protectionClassification
|
|
2457
|
-
}
|
|
2458
|
-
}),
|
|
2459
|
-
...requestOptions
|
|
2460
|
-
}), [200, 201], (value) => isUploadSession(value, validated.expectedByteLength), true, CREATE_UPLOAD_ERROR_CODES);
|
|
2461
|
-
}
|
|
2462
|
-
async function getUploadStatus(runtime, input) {
|
|
2463
|
-
const validated = validateGetUploadStatusInput(input);
|
|
2464
|
-
const afterPartNumber = validated.afterPartNumber ?? 0;
|
|
2465
|
-
const limit = validated.limit ?? 100;
|
|
2466
|
-
return execute(runtime, validated.signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/uploads/{uploadId}", {
|
|
2467
|
-
...operationOptions("getUploadStatus", { params: {
|
|
2468
|
-
path: {
|
|
2469
|
-
workspaceId: validated.workspaceId,
|
|
2470
|
-
uploadId: validated.uploadId
|
|
2471
|
-
},
|
|
2472
|
-
query: {
|
|
2473
|
-
...validated.afterPartNumber === void 0 ? {} : { afterPartNumber: String(validated.afterPartNumber) },
|
|
2474
|
-
...validated.limit === void 0 ? {} : { limit: String(validated.limit) }
|
|
2475
|
-
}
|
|
2476
|
-
} }),
|
|
2477
|
-
...requestOptions
|
|
2478
|
-
}), [200], (value) => isUploadStatus(value, afterPartNumber, limit) && value.uploadId === validated.uploadId, false, STATUS_ERROR_CODES);
|
|
2479
|
-
}
|
|
2480
|
-
async function createUploadPartDescriptor(runtime, input) {
|
|
2481
|
-
const validated = validateCreateUploadPartDescriptorInput(input);
|
|
2482
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/parts", {
|
|
2483
|
-
...operationOptions("createUploadPartDescriptor", {
|
|
2484
|
-
params: { path: {
|
|
2485
|
-
workspaceId: validated.workspaceId,
|
|
2486
|
-
uploadId: validated.uploadId
|
|
2487
|
-
} },
|
|
2488
|
-
body: {
|
|
2489
|
-
partNumber: validated.partNumber,
|
|
2490
|
-
checksumSha256: validated.checksumSha256,
|
|
2491
|
-
contentMd5: validated.contentMd5
|
|
2492
|
-
}
|
|
2493
|
-
}),
|
|
2494
|
-
...requestOptions
|
|
2495
|
-
}), [200], (value) => isUploadPartDescriptor(value, validated.partNumber, new URL(runtime.baseUrl).protocol === "http:", validated.contentMd5), false, TRANSFER_ERROR_CODES);
|
|
2496
|
-
}
|
|
2497
|
-
async function recordUploadPart(runtime, input) {
|
|
2498
|
-
const validated = validateRecordUploadPartInput(input);
|
|
2499
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/parts/{partNumber}", {
|
|
2500
|
-
...operationOptions("recordUploadPart", {
|
|
2501
|
-
params: { path: {
|
|
2502
|
-
workspaceId: validated.workspaceId,
|
|
2503
|
-
uploadId: validated.uploadId,
|
|
2504
|
-
partNumber: String(validated.partNumber)
|
|
2505
|
-
} },
|
|
2506
|
-
body: {
|
|
2507
|
-
expectedUploadRevision: validated.expectedUploadRevision,
|
|
2508
|
-
byteLength: validated.byteLength,
|
|
2509
|
-
etag: validated.etag,
|
|
2510
|
-
checksumSha256: validated.checksumSha256
|
|
2511
|
-
}
|
|
2512
|
-
}),
|
|
2513
|
-
...requestOptions
|
|
2514
|
-
}), [200], (value) => isUploadPartResult(value, validated.partNumber, validated.expectedUploadRevision), false, TRANSFER_ERROR_CODES);
|
|
2515
|
-
}
|
|
2516
|
-
async function completeUpload(runtime, input) {
|
|
2517
|
-
const validated = validateCompleteUploadInput(input);
|
|
2518
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/complete", {
|
|
2519
|
-
...operationOptions("completeUpload", { params: {
|
|
2520
|
-
path: {
|
|
2521
|
-
workspaceId: validated.workspaceId,
|
|
2522
|
-
uploadId: validated.uploadId
|
|
2523
|
-
},
|
|
2524
|
-
header: { "Idempotency-Key": validated.idempotencyKey }
|
|
2525
|
-
} }),
|
|
2526
|
-
...requestOptions
|
|
2527
|
-
}), [200, 202], (value, status) => status === 202 ? isPendingUpload(value, validated.uploadId) : isReadyUpload(value, { uploadId: validated.uploadId }), false, COMPLETE_UPLOAD_ERROR_CODES);
|
|
2528
|
-
}
|
|
2529
|
-
async function abortUpload(runtime, input) {
|
|
2530
|
-
const validated = validateAbortUploadInput(input);
|
|
2531
|
-
return execute(runtime, validated.signal, 409, (api, requestOptions) => api.DELETE("/api/v1/workspaces/{workspaceId}/uploads/{uploadId}", {
|
|
2532
|
-
...operationOptions("abortUpload", { params: { path: {
|
|
2533
|
-
workspaceId: validated.workspaceId,
|
|
2534
|
-
uploadId: validated.uploadId
|
|
2535
|
-
} } }),
|
|
2536
|
-
...requestOptions
|
|
2537
|
-
}), [204], null, false, TRANSFER_ERROR_CODES);
|
|
2538
|
-
}
|
|
2539
|
-
//#endregion
|
|
2540
|
-
//#region ../../node_modules/.pnpm/@noble+hashes@2.3.0/node_modules/@noble/hashes/_u64.js
|
|
2541
|
-
const fromNumH = (n) => n / 2 ** 32 | 0;
|
|
2542
|
-
const fromNumL = (n) => n >>> 0;
|
|
2543
|
-
function setU64FromNum(view, byteOffset, n, isLE) {
|
|
2544
|
-
const h = fromNumH(n);
|
|
2545
|
-
const l = fromNumL(n);
|
|
2546
|
-
view.setUint32(byteOffset, isLE ? l : h, isLE);
|
|
2547
|
-
view.setUint32(byteOffset + 4, isLE ? h : l, isLE);
|
|
2548
|
-
}
|
|
2549
|
-
//#endregion
|
|
2550
|
-
//#region ../../node_modules/.pnpm/@noble+hashes@2.3.0/node_modules/@noble/hashes/utils.js
|
|
2551
|
-
function isBytes(a) {
|
|
2552
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
2553
|
-
}
|
|
2554
|
-
const atitle = (title) => title ? `"${title}" ` : "";
|
|
2555
|
-
function anumber(n, title = "") {
|
|
2556
|
-
if (typeof n !== "number") throw new TypeError(atitle(title) + "expected number, got " + typeof n);
|
|
2557
|
-
if (!Number.isSafeInteger(n) || n < 0) throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
|
|
2558
|
-
return n;
|
|
2559
|
-
}
|
|
2560
|
-
function abytes(value, length, title = "") {
|
|
2561
|
-
if (isBytes(value) && (length === void 0 || value.length === length)) return value;
|
|
2562
|
-
if (length !== void 0) anumber(length, "length");
|
|
2563
|
-
const bytes = isBytes(value);
|
|
2564
|
-
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
2565
|
-
const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
|
|
2566
|
-
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
2567
|
-
if (!bytes) throw new TypeError(message);
|
|
2568
|
-
throw new RangeError(message);
|
|
2569
|
-
}
|
|
2570
|
-
const aobject = (value, label) => {
|
|
2571
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
2572
|
-
};
|
|
2573
|
-
function aexists(instance, checkFinished = true) {
|
|
2574
|
-
if (instance.destroyed) throw new Error("hash was destroyed");
|
|
2575
|
-
if (checkFinished && instance.finished) throw new Error("digest() was already called");
|
|
2576
|
-
}
|
|
2577
|
-
function aoutput(out, instance) {
|
|
2578
|
-
abytes(out, void 0, "output");
|
|
2579
|
-
const min = instance.outputLen;
|
|
2580
|
-
if (!(out.length >= min)) throw new RangeError("\"output\" expected length >= " + min);
|
|
2581
|
-
}
|
|
2582
|
-
function clean(...arrays) {
|
|
2583
|
-
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
2584
|
-
}
|
|
2585
|
-
function createView(arr) {
|
|
2586
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2587
|
-
}
|
|
2588
|
-
function rotr(word, shift) {
|
|
2589
|
-
return word << 32 - shift | word >>> shift;
|
|
2590
|
-
}
|
|
2591
|
-
function rotl(word, shift) {
|
|
2592
|
-
return word << shift | word >>> 32 - shift >>> 0;
|
|
2593
|
-
}
|
|
2594
|
-
const hasHexBuiltin = (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
|
|
2595
|
-
const hexes = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
2596
|
-
function bytesToHex(bytes) {
|
|
2597
|
-
abytes(bytes);
|
|
2598
|
-
if (hasHexBuiltin) return bytes.toHex();
|
|
2599
|
-
let hex = "";
|
|
2600
|
-
for (let i = 0; i < bytes.length; i++) hex += hexes[bytes[i]];
|
|
2601
|
-
return hex;
|
|
2602
|
-
}
|
|
2603
|
-
function checkOpts(defaults, opts, title = "opts") {
|
|
2604
|
-
aobject(defaults, "defaults");
|
|
2605
|
-
if (opts !== void 0) aobject(opts, title);
|
|
2606
|
-
return Object.assign(defaults, opts);
|
|
2607
|
-
}
|
|
2608
|
-
function createHasher(hashCons, info = {}) {
|
|
2609
|
-
if (typeof hashCons !== "function") throw new TypeError("\"hashCons\" expected function, got type=" + typeof hashCons);
|
|
2610
|
-
info = checkOpts({}, info, "info");
|
|
2611
|
-
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
2612
|
-
const tmp = hashCons(void 0);
|
|
2613
|
-
hashC.outputLen = tmp.outputLen;
|
|
2614
|
-
hashC.blockLen = tmp.blockLen;
|
|
2615
|
-
hashC.canXOF = tmp.canXOF;
|
|
2616
|
-
hashC.create = (opts) => hashCons(opts);
|
|
2617
|
-
Object.assign(hashC, info);
|
|
2618
|
-
return Object.freeze(hashC);
|
|
2619
|
-
}
|
|
2620
|
-
const oidNist = (suffix) => ({ oid: Uint8Array.from([
|
|
2621
|
-
6,
|
|
2622
|
-
9,
|
|
2623
|
-
96,
|
|
2624
|
-
134,
|
|
2625
|
-
72,
|
|
2626
|
-
1,
|
|
2627
|
-
101,
|
|
2628
|
-
3,
|
|
2629
|
-
4,
|
|
2630
|
-
2,
|
|
2631
|
-
suffix
|
|
2632
|
-
]) });
|
|
2633
|
-
//#endregion
|
|
2634
|
-
//#region ../../node_modules/.pnpm/@noble+hashes@2.3.0/node_modules/@noble/hashes/_md.js
|
|
2635
|
-
function Chi(a, b, c) {
|
|
2636
|
-
return a & b ^ ~a & c;
|
|
2637
|
-
}
|
|
2638
|
-
function Maj(a, b, c) {
|
|
2639
|
-
return a & b ^ a & c ^ b & c;
|
|
2640
|
-
}
|
|
2641
|
-
var HashMD = class {
|
|
2642
|
-
blockLen;
|
|
2643
|
-
outputLen;
|
|
2644
|
-
canXOF = false;
|
|
2645
|
-
padOffset;
|
|
2646
|
-
isLE;
|
|
2647
|
-
buffer;
|
|
2648
|
-
view;
|
|
2649
|
-
finished = false;
|
|
2650
|
-
length = 0;
|
|
2651
|
-
pos = 0;
|
|
2652
|
-
destroyed = false;
|
|
2653
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
2654
|
-
this.blockLen = blockLen;
|
|
2655
|
-
this.outputLen = outputLen;
|
|
2656
|
-
this.padOffset = padOffset;
|
|
2657
|
-
this.isLE = isLE;
|
|
2658
|
-
this.buffer = new Uint8Array(blockLen);
|
|
2659
|
-
this.view = createView(this.buffer);
|
|
2660
|
-
}
|
|
2661
|
-
update(data) {
|
|
2662
|
-
aexists(this);
|
|
2663
|
-
abytes(data);
|
|
2664
|
-
const { view, buffer, blockLen } = this;
|
|
2665
|
-
const len = data.length;
|
|
2666
|
-
let processed = false;
|
|
2667
|
-
for (let pos = 0; pos < len;) {
|
|
2668
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
2669
|
-
if (take === blockLen) {
|
|
2670
|
-
const dataView = createView(data);
|
|
2671
|
-
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
|
2672
|
-
processed = true;
|
|
2673
|
-
continue;
|
|
2674
|
-
}
|
|
2675
|
-
buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
|
|
2676
|
-
this.pos += take;
|
|
2677
|
-
pos += take;
|
|
2678
|
-
if (this.pos === blockLen) {
|
|
2679
|
-
this.process(view, 0);
|
|
2680
|
-
this.pos = 0;
|
|
2681
|
-
processed = true;
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
this.length += data.length;
|
|
2685
|
-
if (processed) this.roundClean();
|
|
2686
|
-
return this;
|
|
2687
|
-
}
|
|
2688
|
-
digestInto(out) {
|
|
2689
|
-
aexists(this);
|
|
2690
|
-
aoutput(out, this);
|
|
2691
|
-
this.finished = true;
|
|
2692
|
-
const { buffer, view, blockLen, isLE } = this;
|
|
2693
|
-
let { pos } = this;
|
|
2694
|
-
buffer[pos++] = 128;
|
|
2695
|
-
buffer.fill(0, pos);
|
|
2696
|
-
if (this.padOffset > blockLen - pos) {
|
|
2697
|
-
this.process(view, 0);
|
|
2698
|
-
buffer.fill(0);
|
|
2699
|
-
}
|
|
2700
|
-
setU64FromNum(view, blockLen - 8, this.length * 8, isLE);
|
|
2701
|
-
this.process(view, 0);
|
|
2702
|
-
this.roundClean();
|
|
2703
|
-
const oview = out === buffer ? view : createView(out);
|
|
2704
|
-
const len = this.outputLen;
|
|
2705
|
-
const outLen = len / 4;
|
|
2706
|
-
const state = this.get();
|
|
2707
|
-
if (len % 4 || outLen > state.length) throw new Error("invalid outputLen");
|
|
2708
|
-
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
|
2709
|
-
}
|
|
2710
|
-
digest() {
|
|
2711
|
-
const { buffer, outputLen } = this;
|
|
2712
|
-
this.digestInto(buffer);
|
|
2713
|
-
const res = buffer.slice(0, outputLen);
|
|
2714
|
-
this.destroy();
|
|
2715
|
-
return res;
|
|
2716
|
-
}
|
|
2717
|
-
_cloneIntoMeta(to) {
|
|
2718
|
-
const { buffer, length, finished, destroyed, pos } = this;
|
|
2719
|
-
to.destroyed = destroyed;
|
|
2720
|
-
to.finished = finished;
|
|
2721
|
-
to.length = length;
|
|
2722
|
-
to.pos = pos;
|
|
2723
|
-
if (pos) to.buffer.set(buffer);
|
|
2724
|
-
return to;
|
|
2725
|
-
}
|
|
2726
|
-
clone() {
|
|
2727
|
-
return this._cloneInto();
|
|
2728
|
-
}
|
|
2729
|
-
};
|
|
2730
|
-
const SHA256_IV = Uint32Array.from([
|
|
2731
|
-
1779033703,
|
|
2732
|
-
3144134277,
|
|
2733
|
-
1013904242,
|
|
2734
|
-
2773480762,
|
|
2735
|
-
1359893119,
|
|
2736
|
-
2600822924,
|
|
2737
|
-
528734635,
|
|
2738
|
-
1541459225
|
|
2739
|
-
]);
|
|
2740
|
-
//#endregion
|
|
2741
|
-
//#region ../../node_modules/.pnpm/@noble+hashes@2.3.0/node_modules/@noble/hashes/sha2.js
|
|
2742
|
-
const SHA256_K = Uint32Array.from([
|
|
2743
|
-
1116352408,
|
|
2744
|
-
1899447441,
|
|
2745
|
-
3049323471,
|
|
2746
|
-
3921009573,
|
|
2747
|
-
961987163,
|
|
2748
|
-
1508970993,
|
|
2749
|
-
2453635748,
|
|
2750
|
-
2870763221,
|
|
2751
|
-
3624381080,
|
|
2752
|
-
310598401,
|
|
2753
|
-
607225278,
|
|
2754
|
-
1426881987,
|
|
2755
|
-
1925078388,
|
|
2756
|
-
2162078206,
|
|
2757
|
-
2614888103,
|
|
2758
|
-
3248222580,
|
|
2759
|
-
3835390401,
|
|
2760
|
-
4022224774,
|
|
2761
|
-
264347078,
|
|
2762
|
-
604807628,
|
|
2763
|
-
770255983,
|
|
2764
|
-
1249150122,
|
|
2765
|
-
1555081692,
|
|
2766
|
-
1996064986,
|
|
2767
|
-
2554220882,
|
|
2768
|
-
2821834349,
|
|
2769
|
-
2952996808,
|
|
2770
|
-
3210313671,
|
|
2771
|
-
3336571891,
|
|
2772
|
-
3584528711,
|
|
2773
|
-
113926993,
|
|
2774
|
-
338241895,
|
|
2775
|
-
666307205,
|
|
2776
|
-
773529912,
|
|
2777
|
-
1294757372,
|
|
2778
|
-
1396182291,
|
|
2779
|
-
1695183700,
|
|
2780
|
-
1986661051,
|
|
2781
|
-
2177026350,
|
|
2782
|
-
2456956037,
|
|
2783
|
-
2730485921,
|
|
2784
|
-
2820302411,
|
|
2785
|
-
3259730800,
|
|
2786
|
-
3345764771,
|
|
2787
|
-
3516065817,
|
|
2788
|
-
3600352804,
|
|
2789
|
-
4094571909,
|
|
2790
|
-
275423344,
|
|
2791
|
-
430227734,
|
|
2792
|
-
506948616,
|
|
2793
|
-
659060556,
|
|
2794
|
-
883997877,
|
|
2795
|
-
958139571,
|
|
2796
|
-
1322822218,
|
|
2797
|
-
1537002063,
|
|
2798
|
-
1747873779,
|
|
2799
|
-
1955562222,
|
|
2800
|
-
2024104815,
|
|
2801
|
-
2227730452,
|
|
2802
|
-
2361852424,
|
|
2803
|
-
2428436474,
|
|
2804
|
-
2756734187,
|
|
2805
|
-
3204031479,
|
|
2806
|
-
3329325298
|
|
2807
|
-
]);
|
|
2808
|
-
const SHA256_W = new Uint32Array(64);
|
|
2809
|
-
var SHA2_32B = class extends HashMD {
|
|
2810
|
-
A = 0;
|
|
2811
|
-
B = 0;
|
|
2812
|
-
C = 0;
|
|
2813
|
-
D = 0;
|
|
2814
|
-
E = 0;
|
|
2815
|
-
F = 0;
|
|
2816
|
-
G = 0;
|
|
2817
|
-
H = 0;
|
|
2818
|
-
constructor(outputLen, IV) {
|
|
2819
|
-
super(64, outputLen, 8, false);
|
|
2820
|
-
this.A = IV[0] | 0;
|
|
2821
|
-
this.B = IV[1] | 0;
|
|
2822
|
-
this.C = IV[2] | 0;
|
|
2823
|
-
this.D = IV[3] | 0;
|
|
2824
|
-
this.E = IV[4] | 0;
|
|
2825
|
-
this.F = IV[5] | 0;
|
|
2826
|
-
this.G = IV[6] | 0;
|
|
2827
|
-
this.H = IV[7] | 0;
|
|
2828
|
-
}
|
|
2829
|
-
get() {
|
|
2830
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
2831
|
-
return [
|
|
2832
|
-
A,
|
|
2833
|
-
B,
|
|
2834
|
-
C,
|
|
2835
|
-
D,
|
|
2836
|
-
E,
|
|
2837
|
-
F,
|
|
2838
|
-
G,
|
|
2839
|
-
H
|
|
2840
|
-
];
|
|
2841
|
-
}
|
|
2842
|
-
set(A, B, C, D, E, F, G, H) {
|
|
2843
|
-
this.A = A | 0;
|
|
2844
|
-
this.B = B | 0;
|
|
2845
|
-
this.C = C | 0;
|
|
2846
|
-
this.D = D | 0;
|
|
2847
|
-
this.E = E | 0;
|
|
2848
|
-
this.F = F | 0;
|
|
2849
|
-
this.G = G | 0;
|
|
2850
|
-
this.H = H | 0;
|
|
2851
|
-
}
|
|
2852
|
-
_cloneInto(to) {
|
|
2853
|
-
(to ||= new this.constructor()).set(...this.get());
|
|
2854
|
-
return this._cloneIntoMeta(to);
|
|
2855
|
-
}
|
|
2856
|
-
process(view, offset) {
|
|
2857
|
-
for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);
|
|
2858
|
-
for (let i = 16; i < 64; i++) {
|
|
2859
|
-
const W15 = SHA256_W[i - 15];
|
|
2860
|
-
const W2 = SHA256_W[i - 2];
|
|
2861
|
-
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
2862
|
-
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
2863
|
-
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
2864
|
-
}
|
|
2865
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
2866
|
-
for (let i = 0; i < 64; i++) {
|
|
2867
|
-
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
2868
|
-
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
2869
|
-
const T2 = (rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22)) + Maj(A, B, C) | 0;
|
|
2870
|
-
H = G;
|
|
2871
|
-
G = F;
|
|
2872
|
-
F = E;
|
|
2873
|
-
E = D + T1 | 0;
|
|
2874
|
-
D = C;
|
|
2875
|
-
C = B;
|
|
2876
|
-
B = A;
|
|
2877
|
-
A = T1 + T2 | 0;
|
|
2878
|
-
}
|
|
2879
|
-
A = A + this.A | 0;
|
|
2880
|
-
B = B + this.B | 0;
|
|
2881
|
-
C = C + this.C | 0;
|
|
2882
|
-
D = D + this.D | 0;
|
|
2883
|
-
E = E + this.E | 0;
|
|
2884
|
-
F = F + this.F | 0;
|
|
2885
|
-
G = G + this.G | 0;
|
|
2886
|
-
H = H + this.H | 0;
|
|
2887
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
2888
|
-
}
|
|
2889
|
-
roundClean() {
|
|
2890
|
-
clean(SHA256_W);
|
|
2891
|
-
}
|
|
2892
|
-
destroy() {
|
|
2893
|
-
this.destroyed = true;
|
|
2894
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
2895
|
-
clean(this.buffer);
|
|
2896
|
-
}
|
|
2897
|
-
};
|
|
2898
|
-
var _SHA256 = class extends SHA2_32B {
|
|
2899
|
-
constructor() {
|
|
2900
|
-
super(32, SHA256_IV);
|
|
2901
|
-
}
|
|
2902
|
-
};
|
|
2903
|
-
const sha256 = createHasher(() => new _SHA256(), oidNist(1));
|
|
2904
|
-
//#endregion
|
|
2905
|
-
//#region ../../node_modules/.pnpm/@noble+hashes@2.3.0/node_modules/@noble/hashes/legacy.js
|
|
2906
|
-
const SHA1_IV = Uint32Array.from([
|
|
2907
|
-
1732584193,
|
|
2908
|
-
4023233417,
|
|
2909
|
-
2562383102,
|
|
2910
|
-
271733878,
|
|
2911
|
-
3285377520
|
|
2912
|
-
]);
|
|
2913
|
-
const p32 = Math.pow(2, 32);
|
|
2914
|
-
const K = Array.from({ length: 64 }, (_, i) => Math.floor(p32 * Math.abs(Math.sin(i + 1))));
|
|
2915
|
-
const MD5_IV = SHA1_IV.slice(0, 4);
|
|
2916
|
-
const MD5_W = new Uint32Array(16);
|
|
2917
|
-
const MD5_SHIFTS = (() => {
|
|
2918
|
-
const S = [
|
|
2919
|
-
[
|
|
2920
|
-
7,
|
|
2921
|
-
12,
|
|
2922
|
-
17,
|
|
2923
|
-
22
|
|
2924
|
-
],
|
|
2925
|
-
[
|
|
2926
|
-
5,
|
|
2927
|
-
9,
|
|
2928
|
-
14,
|
|
2929
|
-
20
|
|
2930
|
-
],
|
|
2931
|
-
[
|
|
2932
|
-
4,
|
|
2933
|
-
11,
|
|
2934
|
-
16,
|
|
2935
|
-
23
|
|
2936
|
-
],
|
|
2937
|
-
[
|
|
2938
|
-
6,
|
|
2939
|
-
10,
|
|
2940
|
-
15,
|
|
2941
|
-
21
|
|
2942
|
-
]
|
|
2943
|
-
];
|
|
2944
|
-
return Uint8Array.from({ length: 64 }, (_, i) => S[Math.floor(i / 16)][i % 4]);
|
|
2945
|
-
})();
|
|
2946
|
-
var _MD5 = class extends HashMD {
|
|
2947
|
-
A = MD5_IV[0] | 0;
|
|
2948
|
-
B = MD5_IV[1] | 0;
|
|
2949
|
-
C = MD5_IV[2] | 0;
|
|
2950
|
-
D = MD5_IV[3] | 0;
|
|
2951
|
-
constructor() {
|
|
2952
|
-
super(64, 16, 8, true);
|
|
2953
|
-
}
|
|
2954
|
-
get() {
|
|
2955
|
-
const { A, B, C, D } = this;
|
|
2956
|
-
return [
|
|
2957
|
-
A,
|
|
2958
|
-
B,
|
|
2959
|
-
C,
|
|
2960
|
-
D
|
|
2961
|
-
];
|
|
2962
|
-
}
|
|
2963
|
-
set(A, B, C, D) {
|
|
2964
|
-
this.A = A | 0;
|
|
2965
|
-
this.B = B | 0;
|
|
2966
|
-
this.C = C | 0;
|
|
2967
|
-
this.D = D | 0;
|
|
2968
|
-
}
|
|
2969
|
-
_cloneInto(to) {
|
|
2970
|
-
(to ||= new this.constructor()).set(...this.get());
|
|
2971
|
-
return this._cloneIntoMeta(to);
|
|
2972
|
-
}
|
|
2973
|
-
process(view, offset) {
|
|
2974
|
-
for (let i = 0; i < 16; i++, offset += 4) MD5_W[i] = view.getUint32(offset, true);
|
|
2975
|
-
let { A, B, C, D } = this;
|
|
2976
|
-
for (let i = 0; i < 64; i++) {
|
|
2977
|
-
let F, g;
|
|
2978
|
-
if (i < 16) {
|
|
2979
|
-
F = Chi(B, C, D);
|
|
2980
|
-
g = i;
|
|
2981
|
-
} else if (i < 32) {
|
|
2982
|
-
F = Chi(D, B, C);
|
|
2983
|
-
g = (5 * i + 1) % 16;
|
|
2984
|
-
} else if (i < 48) {
|
|
2985
|
-
F = B ^ C ^ D;
|
|
2986
|
-
g = (3 * i + 5) % 16;
|
|
2987
|
-
} else {
|
|
2988
|
-
F = C ^ (B | ~D);
|
|
2989
|
-
g = 7 * i % 16;
|
|
2990
|
-
}
|
|
2991
|
-
F = F + A + K[i] + MD5_W[g];
|
|
2992
|
-
A = D;
|
|
2993
|
-
D = C;
|
|
2994
|
-
C = B;
|
|
2995
|
-
B = B + rotl(F, MD5_SHIFTS[i]);
|
|
2996
|
-
}
|
|
2997
|
-
A = A + this.A | 0;
|
|
2998
|
-
B = B + this.B | 0;
|
|
2999
|
-
C = C + this.C | 0;
|
|
3000
|
-
D = D + this.D | 0;
|
|
3001
|
-
this.set(A, B, C, D);
|
|
3002
|
-
}
|
|
3003
|
-
roundClean() {
|
|
3004
|
-
clean(MD5_W);
|
|
3005
|
-
}
|
|
3006
|
-
destroy() {
|
|
3007
|
-
this.destroyed = true;
|
|
3008
|
-
this.set(0, 0, 0, 0);
|
|
3009
|
-
clean(this.buffer);
|
|
3010
|
-
}
|
|
3011
|
-
};
|
|
3012
|
-
const md5 = createHasher(() => new _MD5());
|
|
3013
|
-
//#endregion
|
|
3014
|
-
//#region src/internal/client/upload.ts
|
|
3015
|
-
const UPLOAD_PART_BYTE_LENGTH = 32 * 1024 * 1024;
|
|
3016
|
-
const STATUS_PAGE_LIMIT = 100;
|
|
3017
|
-
const STATUS_PAGE_MAXIMUM = 100;
|
|
3018
|
-
const ABORT_DEADLINE_MILLISECONDS = 5e3;
|
|
3019
|
-
async function uploadFileInternal(runtime, input, controls) {
|
|
3020
|
-
const validated = validateUploadFileInput(input);
|
|
3021
|
-
const totalPartCount = Math.ceil(validated.byteLength / UPLOAD_PART_BYTE_LENGTH);
|
|
3022
|
-
emitProgress(validated.onProgress, "preparing", 0, validated.byteLength, 0, totalPartCount);
|
|
3023
|
-
let session;
|
|
3024
|
-
try {
|
|
3025
|
-
const digests = await hashSource(validated.source, validated.byteLength, totalPartCount, validated.signal);
|
|
3026
|
-
const created = await controls.createUpload({
|
|
3027
|
-
workspaceId: validated.workspaceId,
|
|
3028
|
-
parentItemId: validated.parentItemId,
|
|
3029
|
-
expectedByteLength: validated.byteLength,
|
|
3030
|
-
displayFilename: validated.displayFilename,
|
|
3031
|
-
mediaType: validated.mediaType,
|
|
3032
|
-
callerDeclaredContentDigest: digests.callerDeclaredContentDigest,
|
|
3033
|
-
protectionClassification: validated.protectionClassification,
|
|
3034
|
-
idempotencyKey: validated.idempotencyKey,
|
|
3035
|
-
...validated.signal === void 0 ? {} : { signal: validated.signal }
|
|
3036
|
-
});
|
|
3037
|
-
session = created.data;
|
|
3038
|
-
assertSessionPolicy(session, validated.byteLength, totalPartCount, created.status, created.requestId);
|
|
3039
|
-
const resumed = await readResumeState(controls, validated, session, digests);
|
|
3040
|
-
emitProgress(validated.onProgress, "uploading", resumed.confirmedByteLength, validated.byteLength, resumed.confirmedParts.size, totalPartCount);
|
|
3041
|
-
if (resumed.readyResult) {
|
|
3042
|
-
emitProgress(validated.onProgress, "completing", resumed.confirmedByteLength, validated.byteLength, resumed.confirmedParts.size, totalPartCount);
|
|
3043
|
-
return resumed.readyResult;
|
|
3044
|
-
}
|
|
3045
|
-
let revision = resumed.revision;
|
|
3046
|
-
let confirmedByteLength = resumed.confirmedByteLength;
|
|
3047
|
-
let confirmedPartCount = resumed.confirmedParts.size;
|
|
3048
|
-
if (resumed.lifecycle === "uploading") for (const partNumber of pendingUploadPartNumbers(session.partCount, resumed.confirmedParts)) {
|
|
3049
|
-
const index = partNumber - 1;
|
|
3050
|
-
throwIfCallerAborted(validated.signal);
|
|
3051
|
-
const start = index * session.partByteLength;
|
|
3052
|
-
const end = Math.min(start + session.partByteLength, validated.byteLength);
|
|
3053
|
-
const expectedByteLength = end - start;
|
|
3054
|
-
const checksumSha256 = digests.partChecksums[index];
|
|
3055
|
-
if (!checksumSha256) throw new DriveError("invalid_response");
|
|
3056
|
-
const descriptorResult = await controls.createUploadPartDescriptor({
|
|
3057
|
-
workspaceId: validated.workspaceId,
|
|
3058
|
-
uploadId: session.uploadId,
|
|
3059
|
-
partNumber,
|
|
3060
|
-
checksumSha256,
|
|
3061
|
-
contentMd5: digests.partMd5s[index],
|
|
3062
|
-
...validated.signal === void 0 ? {} : { signal: validated.signal }
|
|
3063
|
-
});
|
|
3064
|
-
const descriptor = descriptorResult.data;
|
|
3065
|
-
if (descriptor.expectedByteLength !== expectedByteLength || descriptor.expiresAtEpochMilliseconds > session.expiresAtEpochMilliseconds) throw new DriveError("invalid_response", {
|
|
3066
|
-
status: descriptorResult.status,
|
|
3067
|
-
requestId: descriptorResult.requestId
|
|
3068
|
-
});
|
|
3069
|
-
const etag = await putPart(runtime, descriptor, slicePart(validated.source, start, end, expectedByteLength), validated.signal);
|
|
3070
|
-
revision = await recordPartWithReconciliation(controls, validated, session, partNumber, revision, expectedByteLength, etag, checksumSha256);
|
|
3071
|
-
confirmedByteLength += expectedByteLength;
|
|
3072
|
-
confirmedPartCount += 1;
|
|
3073
|
-
emitProgress(validated.onProgress, "uploading", confirmedByteLength, validated.byteLength, confirmedPartCount, totalPartCount);
|
|
3074
|
-
}
|
|
3075
|
-
emitProgress(validated.onProgress, "completing", confirmedByteLength, validated.byteLength, confirmedPartCount, totalPartCount);
|
|
3076
|
-
const completed = await completeWithReconciliation(controls, validated, session, digests);
|
|
3077
|
-
if (completed.data.state === "verifying") emitProgress(validated.onProgress, "verifying", confirmedByteLength, validated.byteLength, confirmedPartCount, totalPartCount);
|
|
3078
|
-
return completed;
|
|
3079
|
-
} catch (error) {
|
|
3080
|
-
if (validated.signal?.aborted && session) await bestEffortAbort(controls, validated.workspaceId, session.uploadId);
|
|
3081
|
-
if (error instanceof DriveError) throw error;
|
|
3082
|
-
throw validated.signal?.aborted ? new DriveError("aborted") : new DriveError("invalid_input");
|
|
3083
|
-
}
|
|
3084
|
-
}
|
|
3085
|
-
function* pendingUploadPartNumbers(partCount, confirmedParts) {
|
|
3086
|
-
for (let partNumber = 1; partNumber <= partCount; partNumber += 1) if (!confirmedParts.has(partNumber)) yield partNumber;
|
|
3087
|
-
}
|
|
3088
|
-
async function readResumeState(controls, input, session, digests) {
|
|
3089
|
-
const confirmedParts = new Set();
|
|
3090
|
-
let confirmedByteLength = 0;
|
|
3091
|
-
let afterPartNumber = 0;
|
|
3092
|
-
let baseline;
|
|
3093
|
-
let baselineRequestId;
|
|
3094
|
-
let readyResult;
|
|
3095
|
-
for (let pageNumber = 0; pageNumber < STATUS_PAGE_MAXIMUM; pageNumber += 1) {
|
|
3096
|
-
const result = await controls.getUploadStatus({
|
|
3097
|
-
workspaceId: input.workspaceId,
|
|
3098
|
-
uploadId: session.uploadId,
|
|
3099
|
-
afterPartNumber,
|
|
3100
|
-
limit: STATUS_PAGE_LIMIT,
|
|
3101
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
3102
|
-
});
|
|
3103
|
-
const status = result.data;
|
|
3104
|
-
assertStatusMatchesSession(status, session);
|
|
3105
|
-
if (baseline) assertSameStatusSnapshot(status, baseline);
|
|
3106
|
-
else {
|
|
3107
|
-
baseline = status;
|
|
3108
|
-
baselineRequestId = result.requestId;
|
|
3109
|
-
}
|
|
3110
|
-
for (const part of status.confirmedParts) {
|
|
3111
|
-
const expectedChecksum = digests.partChecksums[part.partNumber - 1];
|
|
3112
|
-
if (!expectedChecksum || part.checksumSha256 !== expectedChecksum || confirmedParts.has(part.partNumber)) throw new DriveError("invalid_response", {
|
|
3113
|
-
status: result.status,
|
|
3114
|
-
requestId: result.requestId
|
|
3115
|
-
});
|
|
3116
|
-
confirmedParts.add(part.partNumber);
|
|
3117
|
-
confirmedByteLength += expectedPartByteLength(input.byteLength, part.partNumber);
|
|
3118
|
-
}
|
|
3119
|
-
if (status.lifecycle === "ready" && status.ready) {
|
|
3120
|
-
assertReadyMatchesInput(status.ready, session, input, digests, result.requestId);
|
|
3121
|
-
readyResult = resultFromStatus(result, status.ready);
|
|
3122
|
-
}
|
|
3123
|
-
if (status.nextAfterPartNumber === null) break;
|
|
3124
|
-
if (pageNumber === STATUS_PAGE_MAXIMUM - 1) throw new DriveError("invalid_response", {
|
|
3125
|
-
status: result.status,
|
|
3126
|
-
requestId: result.requestId
|
|
3127
|
-
});
|
|
3128
|
-
afterPartNumber = status.nextAfterPartNumber;
|
|
3129
|
-
}
|
|
3130
|
-
if (!baseline) throw new DriveError("invalid_response");
|
|
3131
|
-
if (session.mode === "presigned-multipart" && [
|
|
3132
|
-
"completing",
|
|
3133
|
-
"provider-completed",
|
|
3134
|
-
"verifying",
|
|
3135
|
-
"ready"
|
|
3136
|
-
].includes(baseline.lifecycle) && confirmedParts.size !== session.partCount) throw new DriveError("invalid_response");
|
|
3137
|
-
failForTerminalStatus(baseline.lifecycle, baselineRequestId);
|
|
3138
|
-
return Object.freeze({
|
|
3139
|
-
revision: baseline.revision,
|
|
3140
|
-
confirmedParts,
|
|
3141
|
-
confirmedByteLength,
|
|
3142
|
-
lifecycle: baseline.lifecycle,
|
|
3143
|
-
...readyResult === void 0 ? {} : { readyResult }
|
|
3144
|
-
});
|
|
3145
|
-
}
|
|
3146
|
-
async function recordPartWithReconciliation(controls, input, session, partNumber, expectedUploadRevision, byteLength, etag, checksumSha256) {
|
|
3147
|
-
const record = (revision) => controls.recordUploadPart({
|
|
3148
|
-
workspaceId: input.workspaceId,
|
|
3149
|
-
uploadId: session.uploadId,
|
|
3150
|
-
partNumber,
|
|
3151
|
-
expectedUploadRevision: revision,
|
|
3152
|
-
byteLength,
|
|
3153
|
-
etag,
|
|
3154
|
-
checksumSha256,
|
|
3155
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
3156
|
-
});
|
|
3157
|
-
try {
|
|
3158
|
-
return (await record(expectedUploadRevision)).data.revision;
|
|
3159
|
-
} catch (error) {
|
|
3160
|
-
if (!isAmbiguousControlFailure(error) || input.signal?.aborted) throw error;
|
|
3161
|
-
const statusResult = await controls.getUploadStatus({
|
|
3162
|
-
workspaceId: input.workspaceId,
|
|
3163
|
-
uploadId: session.uploadId,
|
|
3164
|
-
afterPartNumber: partNumber - 1,
|
|
3165
|
-
limit: 1,
|
|
3166
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
3167
|
-
});
|
|
3168
|
-
const status = statusResult.data;
|
|
3169
|
-
assertStatusMatchesSession(status, session);
|
|
3170
|
-
failForTerminalStatus(status.lifecycle, statusResult.requestId);
|
|
3171
|
-
const confirmed = status.confirmedParts.find((part) => part.partNumber === partNumber);
|
|
3172
|
-
if (confirmed) {
|
|
3173
|
-
if (confirmed.checksumSha256 !== checksumSha256) throw new DriveError("invalid_response", {
|
|
3174
|
-
status: statusResult.status,
|
|
3175
|
-
requestId: statusResult.requestId
|
|
3176
|
-
});
|
|
3177
|
-
return status.revision;
|
|
3178
|
-
}
|
|
3179
|
-
if (status.lifecycle !== "uploading") throw new DriveError("precondition_failed");
|
|
3180
|
-
return (await record(status.revision)).data.revision;
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
async function completeWithReconciliation(controls, input, session, digests) {
|
|
3184
|
-
try {
|
|
3185
|
-
const completed = await controls.completeUpload({
|
|
3186
|
-
workspaceId: input.workspaceId,
|
|
3187
|
-
uploadId: session.uploadId,
|
|
3188
|
-
idempotencyKey: input.completionIdempotencyKey,
|
|
3189
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
3190
|
-
});
|
|
3191
|
-
if (completed.data.state === "ready") assertReadyMatchesInput(completed.data, session, input, digests, completed.requestId);
|
|
3192
|
-
else if (completed.data.itemId !== session.itemId || completed.data.versionId !== session.versionId || completed.data.uploadId !== session.uploadId || completed.data.totalByteLength !== input.byteLength) throw new DriveError("invalid_response");
|
|
3193
|
-
return completed;
|
|
3194
|
-
} catch (error) {
|
|
3195
|
-
if (!isAmbiguousControlFailure(error) || input.signal?.aborted) throw error;
|
|
3196
|
-
const statusResult = await controls.getUploadStatus({
|
|
3197
|
-
workspaceId: input.workspaceId,
|
|
3198
|
-
uploadId: session.uploadId,
|
|
3199
|
-
afterPartNumber: 0,
|
|
3200
|
-
limit: 1,
|
|
3201
|
-
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
3202
|
-
});
|
|
3203
|
-
const status = statusResult.data;
|
|
3204
|
-
assertStatusMatchesSession(status, session);
|
|
3205
|
-
if (status.lifecycle !== "ready" || !status.ready) throw error;
|
|
3206
|
-
assertReadyMatchesInput(status.ready, session, input, digests, statusResult.requestId);
|
|
3207
|
-
return resultFromStatus(statusResult, status.ready);
|
|
3208
|
-
}
|
|
3209
|
-
}
|
|
3210
|
-
async function hashSource(source, byteLength, partCount, signal) {
|
|
3211
|
-
const fullHash = sha256.create();
|
|
3212
|
-
const partChecksums = [];
|
|
3213
|
-
const partMd5s = [];
|
|
3214
|
-
for (let index = 0; index < partCount; index += 1) {
|
|
3215
|
-
throwIfCallerAborted(signal);
|
|
3216
|
-
const start = index * UPLOAD_PART_BYTE_LENGTH;
|
|
3217
|
-
const end = Math.min(start + UPLOAD_PART_BYTE_LENGTH, byteLength);
|
|
3218
|
-
const part = slicePart(source, start, end, end - start);
|
|
3219
|
-
let buffer;
|
|
3220
|
-
try {
|
|
3221
|
-
buffer = signal ? await raceWithAbort(part.arrayBuffer(), signal) : await part.arrayBuffer();
|
|
3222
|
-
} catch (error) {
|
|
3223
|
-
if (error instanceof DriveError) throw error;
|
|
3224
|
-
throw signal?.aborted ? new DriveError("aborted") : new DriveError("invalid_input");
|
|
3225
|
-
}
|
|
3226
|
-
if (buffer.byteLength !== end - start) throw new DriveError("invalid_input");
|
|
3227
|
-
const bytes = new Uint8Array(buffer);
|
|
3228
|
-
fullHash.update(bytes);
|
|
3229
|
-
partChecksums.push(toBase64(sha256(bytes)));
|
|
3230
|
-
partMd5s.push(toBase64(md5(bytes)));
|
|
3231
|
-
}
|
|
3232
|
-
return Object.freeze({
|
|
3233
|
-
callerDeclaredContentDigest: `sha256:${bytesToHex(fullHash.digest())}`,
|
|
3234
|
-
partChecksums: Object.freeze(partChecksums),
|
|
3235
|
-
partMd5s: Object.freeze(partMd5s)
|
|
3236
|
-
});
|
|
3237
|
-
}
|
|
3238
|
-
async function putPart(runtime, descriptor, part, callerSignal) {
|
|
3239
|
-
const remainingMilliseconds = descriptor.expiresAtEpochMilliseconds - Date.now();
|
|
3240
|
-
if (remainingMilliseconds < 1) throw new DriveError("invalid_response");
|
|
3241
|
-
const operation = createOperationSignal(callerSignal, Math.min(runtime.timeoutMilliseconds, remainingMilliseconds));
|
|
3242
|
-
let response;
|
|
3243
|
-
try {
|
|
3244
|
-
response = await raceWithAbort(runtime.fetchImplementation(descriptor.url, {
|
|
3245
|
-
method: descriptor.method,
|
|
3246
|
-
body: part,
|
|
3247
|
-
headers: descriptor.headers,
|
|
3248
|
-
credentials: "omit",
|
|
3249
|
-
cache: "no-store",
|
|
3250
|
-
redirect: "error",
|
|
3251
|
-
referrerPolicy: "no-referrer",
|
|
3252
|
-
signal: operation.signal
|
|
3253
|
-
}), operation.signal);
|
|
3254
|
-
if (!(response instanceof Response)) throw new DriveError("invalid_response");
|
|
3255
|
-
const etag = response.headers.get("etag");
|
|
3256
|
-
const md5Response = response.headers.get("content-md5");
|
|
3257
|
-
const checksumMatches = md5Response === null || md5Response === descriptor.headers["content-md5"];
|
|
3258
|
-
if (response.status < 200 || response.status > 299 || !isEtag(etag) || !checksumMatches) throw new DriveError("invalid_response", { status: response.status });
|
|
3259
|
-
return etag;
|
|
3260
|
-
} catch (error) {
|
|
3261
|
-
if (operation.didTimeout()) throw new DriveError("timeout");
|
|
3262
|
-
if (callerSignal?.aborted) throw new DriveError("aborted");
|
|
3263
|
-
if (error instanceof DriveError) throw error;
|
|
3264
|
-
throw new DriveError("network_error");
|
|
3265
|
-
} finally {
|
|
3266
|
-
operation.dispose();
|
|
3267
|
-
response?.body?.cancel().catch(() => {});
|
|
3268
|
-
}
|
|
3269
|
-
}
|
|
3270
|
-
function assertSessionPolicy(session, byteLength, partCount, status, requestId) {
|
|
3271
|
-
const expectedMode = byteLength === 0 ? "server-mediated-zero-byte" : "presigned-multipart";
|
|
3272
|
-
if (session.mode !== expectedMode || session.partByteLength !== UPLOAD_PART_BYTE_LENGTH || session.partCount !== partCount || session.expiresAtEpochMilliseconds <= Date.now()) throw new DriveError("invalid_response", {
|
|
3273
|
-
status,
|
|
3274
|
-
requestId
|
|
3275
|
-
});
|
|
3276
|
-
}
|
|
3277
|
-
function assertStatusMatchesSession(status, session) {
|
|
3278
|
-
if (status.itemId !== session.itemId || status.versionId !== session.versionId || status.uploadId !== session.uploadId || status.mode !== session.mode || status.revision < session.revision || status.partPolicy.partByteLength !== session.partByteLength || status.partPolicy.partCount !== session.partCount || status.partPolicy.maxParts !== 1e4 || status.expiresAtEpochMilliseconds !== session.expiresAtEpochMilliseconds) throw new DriveError("invalid_response");
|
|
3279
|
-
}
|
|
3280
|
-
function assertSameStatusSnapshot(status, baseline) {
|
|
3281
|
-
if (status.itemId !== baseline.itemId || status.versionId !== baseline.versionId || status.uploadId !== baseline.uploadId || status.mode !== baseline.mode || status.lifecycle !== baseline.lifecycle || status.revision !== baseline.revision || status.partPolicy.partByteLength !== baseline.partPolicy.partByteLength || status.partPolicy.partCount !== baseline.partPolicy.partCount || status.partPolicy.maxParts !== baseline.partPolicy.maxParts || status.expiresAtEpochMilliseconds !== baseline.expiresAtEpochMilliseconds || JSON.stringify(status.ready) !== JSON.stringify(baseline.ready)) throw new DriveError("invalid_response");
|
|
3282
|
-
}
|
|
3283
|
-
function assertReadyMatchesInput(ready, session, input, digests, requestId) {
|
|
3284
|
-
if (ready.itemId !== session.itemId || ready.versionId !== session.versionId || ready.uploadId !== session.uploadId || ready.byteLength !== input.byteLength || ready.callerDeclaredContentDigest !== digests.callerDeclaredContentDigest || ready.displayFilename !== input.displayFilename || ready.mediaType !== input.mediaType) throw new DriveError("invalid_response", {
|
|
3285
|
-
status: 200,
|
|
3286
|
-
requestId
|
|
3287
|
-
});
|
|
3288
|
-
}
|
|
3289
|
-
function failForTerminalStatus(lifecycle, requestId) {
|
|
3290
|
-
if (lifecycle === "initiating" || lifecycle === "recovery-required") throw new DriveError("upload_recovery_required", {
|
|
3291
|
-
status: 409,
|
|
3292
|
-
...requestId === void 0 ? {} : { requestId }
|
|
3293
|
-
});
|
|
3294
|
-
if (lifecycle === "aborting" || lifecycle === "aborted" || lifecycle === "failed") throw new DriveError("precondition_failed", {
|
|
3295
|
-
status: 409,
|
|
3296
|
-
...requestId === void 0 ? {} : { requestId }
|
|
3297
|
-
});
|
|
3298
|
-
}
|
|
3299
|
-
function resultFromStatus(status, ready) {
|
|
3300
|
-
return Object.freeze({
|
|
3301
|
-
data: ready,
|
|
3302
|
-
status: status.status,
|
|
3303
|
-
requestId: status.requestId,
|
|
3304
|
-
validators: status.validators
|
|
3305
|
-
});
|
|
3306
|
-
}
|
|
3307
|
-
function expectedPartByteLength(byteLength, partNumber) {
|
|
3308
|
-
return Math.min(UPLOAD_PART_BYTE_LENGTH, byteLength - (partNumber - 1) * UPLOAD_PART_BYTE_LENGTH);
|
|
3309
|
-
}
|
|
3310
|
-
function slicePart(source, start, end, expectedByteLength) {
|
|
3311
|
-
try {
|
|
3312
|
-
const part = source.slice(start, end);
|
|
3313
|
-
if (!(part instanceof Blob) || part.size !== expectedByteLength) throw new DriveError("invalid_input");
|
|
3314
|
-
return part;
|
|
3315
|
-
} catch (error) {
|
|
3316
|
-
if (error instanceof DriveError) throw error;
|
|
3317
|
-
throw new DriveError("invalid_input");
|
|
3318
|
-
}
|
|
3319
|
-
}
|
|
3320
|
-
function emitProgress(callback, phase, confirmedByteLength, totalByteLength, confirmedPartCount, totalPartCount) {
|
|
3321
|
-
if (!callback) return;
|
|
3322
|
-
const progress = Object.freeze({
|
|
3323
|
-
phase,
|
|
3324
|
-
confirmedByteLength,
|
|
3325
|
-
totalByteLength,
|
|
3326
|
-
confirmedPartCount,
|
|
3327
|
-
totalPartCount
|
|
3328
|
-
});
|
|
3329
|
-
try {
|
|
3330
|
-
callback(progress);
|
|
3331
|
-
} catch {}
|
|
3332
|
-
}
|
|
3333
|
-
async function bestEffortAbort(controls, workspaceId, uploadId) {
|
|
3334
|
-
const controller = new AbortController();
|
|
3335
|
-
const timeout = setTimeout(() => controller.abort(), ABORT_DEADLINE_MILLISECONDS);
|
|
3336
|
-
try {
|
|
3337
|
-
await controls.abortUpload({
|
|
3338
|
-
workspaceId,
|
|
3339
|
-
uploadId,
|
|
3340
|
-
signal: controller.signal
|
|
3341
|
-
});
|
|
3342
|
-
} catch {} finally {
|
|
3343
|
-
clearTimeout(timeout);
|
|
3344
|
-
}
|
|
3345
|
-
}
|
|
3346
|
-
function isAmbiguousControlFailure(value) {
|
|
3347
|
-
return value instanceof DriveError && (value.code === "network_error" || value.code === "timeout" || value.code === "invalid_response");
|
|
3348
|
-
}
|
|
3349
|
-
function throwIfCallerAborted(signal) {
|
|
3350
|
-
if (signal?.aborted) throw new DriveError("aborted");
|
|
3351
|
-
}
|
|
3352
|
-
function toBase64(bytes) {
|
|
3353
|
-
let binary = "";
|
|
3354
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
3355
|
-
return btoa(binary);
|
|
3356
|
-
}
|
|
3357
|
-
function isEtag(value) {
|
|
3358
|
-
return value !== null && value.length >= 1 && value.length <= 1024 && /^[\x20-\x7e]+$/.test(value);
|
|
3359
|
-
}
|
|
3360
|
-
//#endregion
|
|
3361
|
-
//#region src/client.ts
|
|
3362
|
-
function createDriveClient(config) {
|
|
3363
|
-
const runtime = createClientRuntime(config);
|
|
3364
|
-
const operations = createDriveOperations(runtime);
|
|
3365
|
-
return Object.freeze({
|
|
3366
|
-
...operations,
|
|
3367
|
-
uploadFile: (input) => uploadFileInternal(runtime, input, operations)
|
|
3368
|
-
});
|
|
3369
|
-
}
|
|
3370
|
-
//#endregion
|
|
3371
|
-
export { DRIVE_API_ERROR_CODES, DRIVE_API_ERROR_MESSAGES, DriveError, createDriveClient };
|
|
1
|
+
const e=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`recipient_unavailable`,`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({authentication_required:`Authentication is required.`,identity_authority_unavailable:`Authentication is temporarily unavailable.`,recipient_unavailable:`The recipient is unavailable.`,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.`}),n=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 r=class extends Error{code;status;requestId;details;constructor(e,r={}){super(e in t?t[e]:n[e]),this.name=`DriveError`,this.code=e,this.status=r.status??null,this.requestId=r.requestId??null,this.details=Object.freeze({})}};const i=/^[A-Za-z0-9_-]{16,128}$/,a=/^"drive\.permission-collection\.v1\.(0|[1-9][0-9]*)"$/,o=/^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/,s=/^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/,c=/^"drive\.item\.v1\.(0|[1-9][0-9]*)"$/;async function l(e,t,n,i,a,o,s){let c=ee(e.headers.get(`x-request-id`));if(c===null)throw v(e),new r(`invalid_response`,{status:e.status});if(!i.includes(e.status))throw await m(e,c,t,n,o,s);if(e.status===304){let t=e.headers.get(`content-length`),n=e.headers.get(`etag`),i=e.status;if(e.body!==null||t!==null&&t!==`0`||e.headers.has(`content-type`)||n===null||!/^"[\x21\x23-\x7e]{1,1022}"$/.test(n)||!a(void 0,i,e.headers))throw v(e),new r(`invalid_response`,{status:i,requestId:c});return Object.freeze({data:void 0,status:i,requestId:c,validators:Object.freeze({etag:n})})}let{value:l}=await g(e,262144,e.status,c,t),u=e.status;if(!a(l,u,e.headers))throw new r(`invalid_response`,{status:u,requestId:c});return Object.freeze({data:l,status:u,requestId:c,validators:te(e.headers)})}async function u(e,t,n,i,a){let o=ee(e.headers.get(`x-request-id`));if(o===null)throw v(e),new r(`invalid_response`,{status:e.status});if(!i.includes(e.status))throw await m(e,o,t,n,!1,a);let s=e.headers.get(`content-length`);if(e.body!==null||s!==null&&s!==`0`||e.headers.has(`content-type`))throw v(e),new r(`invalid_response`,{status:e.status,requestId:o});return Object.freeze({data:void 0,status:e.status,requestId:o,validators:Object.freeze({})})}function d(e){let t=a.exec(e);if(!t)return;let n=Number(t[1]);return Number.isSafeInteger(n)?n:void 0}function f(e){let t=o.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 p(e){let t=c.exec(e);if(!t)return;let n=Number(t[1]);return Number.isSafeInteger(n)?n:void 0}async function m(n,a,o,s,c,l){let u;try{u=await g(n,16384,n.status,a,o)}catch(e){return e instanceof r&&e.code===`aborted`?e:new r(`invalid_response`,{status:n.status,requestId:a})}let d=u.value;if(!y(d,[`error`])||!y(d.error,[`code`,`message`,`requestId`,`details`]))return new r(`invalid_response`,{status:n.status,requestId:a});let f=d.error;return typeof f.code!=`string`||!e.includes(f.code)||f.message!==t[f.code]||!i.test(String(f.requestId))||f.requestId!==a||!y(f.details,[])||!h(f.code,n.status,s,c,l)||u.text!==JSON.stringify(d)?new r(`invalid_response`,{status:n.status,requestId:a}):new r(f.code,{status:n.status,requestId:f.requestId})}function h(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],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 g(e,t,n,i,a){if(!e.body)throw new r(`invalid_response`,{status:n,requestId:i});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 r(`invalid_response`,{status:n,requestId:i});let f=new AbortController,p=setTimeout(()=>f.abort(),5e3);try{for(;;){if(a?.aborted)throw new r(`aborted`);let{done:e,value:d}=await _(o,a,f.signal);if(e)break;if(l+=1,c+=d.byteLength,l>256||c>t)throw new r(`invalid_response`,{status:n,requestId:i});u+=s.decode(d,{stream:!0})}return u+=s.decode(),{value:JSON.parse(u),text:u}}catch(e){throw e instanceof r?e.code===`aborted`||a?.aborted?new r(`aborted`):e:new r(`invalid_response`,{status:n,requestId:i})}finally{clearTimeout(p),o.cancel().catch(()=>{})}}async function _(e,t,n){if(t?.aborted)throw new r(`aborted`);if(n.aborted)throw new r(`invalid_response`);let i=()=>{},a=()=>{},o=new Promise((e,n)=>{if(!t)return;let a=()=>n(new r(`aborted`));t.addEventListener(`abort`,a,{once:!0}),i=()=>t.removeEventListener(`abort`,a)}),s=new Promise((e,t)=>{let i=()=>t(new r(`invalid_response`));n.addEventListener(`abort`,i,{once:!0}),a=()=>n.removeEventListener(`abort`,i)});try{return await Promise.race([e.read(),o,s])}finally{i(),a()}}function v(e){e.body?.cancel().catch(()=>{})}function ee(e){return e!==null&&i.test(e)?e:null}function te(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&&(s.test(t)||p(t)!==void 0)?{etag:t}:{},...n!==null&&d(n)!==void 0?{permissionCollectionEtag:n}:{},...r!==null&&f(r)!==void 0?{permissionGrantEtag:r}:{}})}function y(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 b=/^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,x=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,S=/^drive\.volume\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,C=/^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,ne=/^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,w=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,re=/^drive\.retrieval\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,T=/^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/,E=/^[A-Za-z0-9_-]{1,128}$/,D=/^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/,O=/^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/,k=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:read`,`items:update`]),A=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:manage`,`items:permissions:read`,`items:update`]),j=33554432e4,M=32*1024*1024,ie=/^sha256:[0-9a-f]{64}$/,ae=new TextEncoder;function oe(e){if(!I(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(!I(n,[`workspaceId`,`itemId`])||typeof n.workspaceId!=`string`||!x.test(n.workspaceId)||typeof n.itemId!=`string`||!b.test(n.itemId))return!1;let e=`${n.workspaceId}/${n.itemId}`;if(t&&t>=e)return!1;t=e}return!0}function se(e){if(!I(e,[`workspaceId`,`provider`,`usedBytes`,`reservedBytes`,`limitBytes`,`availableBytes`,`accounting`,`reservedBytesIncludeUnresolvedUploads`,`unresolvedReservedBytes`,`warnings`])||typeof e.workspaceId!=`string`||!x.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 ce(e){if(!I(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(!I(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`||!S.test(e.volumeId)||e.provider!==`managed`||e.creatorUserId!==null&&(typeof e.creatorUserId!=`string`||!E.test(e.creatorUserId))||![e.createdAtEpochMilliseconds,e.modifiedAtEpochMilliseconds,e.trashedAtEpochMilliseconds,e.purgeAfterEpochMilliseconds].every(e=>e===null||F(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`||!x.test(n.workspaceId)||typeof n.itemId!=`string`||!b.test(n.itemId)||n.parentId===null||n.parentId===n.itemId||!_e(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:!F(e.trashedAtEpochMilliseconds)||!F(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}function le(e){if(!I(e,[`workspace`,`volumes`,`knownProviders`,`externalConnectionsSupported`])||!ue(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 I(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 ue(e){if(!I(e,[`workspaceId`,`rootVolumeId`,`rootItemId`,`workspaceReference`])||typeof e.workspaceId!=`string`||!x.test(e.workspaceId)||typeof e.rootVolumeId!=`string`||!S.test(e.rootVolumeId)||typeof e.rootItemId!=`string`||!b.test(e.rootItemId))return!1;let t=e.workspaceReference;return I(t,[`type`,`userId`])&&t.type===`personal`&&typeof t.userId==`string`&&E.test(t.userId)||I(t,[`type`,`organizationId`])&&t.type===`organization`&&typeof t.organizationId==`string`&&E.test(t.organizationId)}function de(e){return!I(e,[`mode`,`method`,`url`,`headers`,`expiresAtEpochMilliseconds`,`response`])||e.mode!==`presigned-single`||e.method!==`GET`&&e.method!==`HEAD`||typeof e.url!=`string`||!Ze(e.url)||!F(e.expiresAtEpochMilliseconds)||!I(e.headers,[`if-match`])&&!I(e.headers,[`if-match`,`range`])||typeof e.headers[`if-match`]!=`string`||!Xe(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))||!I(e.response,[`status`,`versionId`,`byteLength`,`contentLength`,`contentType`,`contentDisposition`,`etag`,`acceptRanges`,`contentRange`])||e.response.status!==200&&e.response.status!==206||typeof e.response.versionId!=`string`||!w.test(e.response.versionId)||!F(e.response.byteLength)||!F(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`||!fe(e)?!1:(Object.freeze(e.headers),Object.freeze(e.response),Object.freeze(e),!0)}function fe(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(F)&&i===o&&a===s&&c===t.byteLength&&i<=a&&a<c&&t.contentLength===a-i+1}function pe(e){return I(e,[`mode`,`operationId`,`versionId`,`state`,`pollAfterSeconds`])&&e.mode===`restore-pending`&&typeof e.operationId==`string`&&re.test(e.operationId)&&typeof e.versionId==`string`&&w.test(e.versionId)&&(e.state===`pending`||e.state===`restoring`)&&F(e.pollAfterSeconds)&&e.pollAfterSeconds>=1&&e.pollAfterSeconds<=60}function me(e,t,n){return I(e,[`items`,`nextCursor`])&&Array.isArray(e.items)&&e.items.length<=50&&e.items.every(he)&&(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&T.test(e.nextCursor))?e.items.every(e=>e.workspaceId===t&&e.parentItemId===n)&&Ye(e.items,e=>e.itemId):!1}function he(e){return I(e,[`workspaceId`,`volumeId`,`itemId`,`parentItemId`,`kind`,`name`,`visibility`,`revision`])&&typeof e.workspaceId==`string`&&x.test(e.workspaceId)&&typeof e.volumeId==`string`&&S.test(e.volumeId)&&typeof e.itemId==`string`&&b.test(e.itemId)&&typeof e.parentItemId==`string`&&b.test(e.parentItemId)&&(e.kind===`file`||e.kind===`folder`)&&P(e.name)&&(e.visibility===`workspace`||e.visibility===`restricted`)&&F(e.revision)}function ge(e,t,n,r){return!I(e,[`workspaceId`,`volumeId`,`itemId`,`parentItemId`,`kind`,`name`,`state`,`revision`,`purgeAfterEpochMilliseconds`])||e.workspaceId!==t||e.itemId!==n||typeof e.volumeId!=`string`||!S.test(e.volumeId)||typeof e.parentItemId!=`string`||!b.test(e.parentItemId)||e.kind!==`file`&&e.kind!==`folder`||!P(e.name)||e.state!==r||!F(e.revision)||(e.state===`active`?e.purgeAfterEpochMilliseconds!==null:!F(e.purgeAfterEpochMilliseconds))?!1:(Object.freeze(e),!0)}function _e(e,t,n){return!I(e,[`workspaceId`,`itemId`,`parentId`,`type`,`name`,`lifecycleState`,`revision`,`currentVersion`])||e.workspaceId!==t||e.itemId!==n||!(e.parentId===null||typeof e.parentId==`string`&&b.test(e.parentId))||e.type!==`file`&&e.type!==`folder`||!P(e.name)||e.lifecycleState!==`active`||!F(e.revision)||(e.type===`folder`?e.currentVersion!==null:!ye(e.currentVersion))?!1:(e.currentVersion!==null&&Object.freeze(e.currentVersion),Object.freeze(e),!0)}function ve(e,t,n,r){if(!I(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>r||!e.items.every(e=>be(e,t,n))||!(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&T.test(e.nextCursor))||e.items.length===0&&e.nextCursor!==null||new Set(e.items.map(e=>e.itemId)).size!==e.items.length||!xe(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 N(e,t){let n=e.get(`etag`);return n!==null&&p(n)===t}function ye(e){return I(e,[`versionId`,`state`,`byteLength`,`mediaType`,`protectionClassification`])&&typeof e.versionId==`string`&&w.test(e.versionId)&&e.state===`current`&&F(e.byteLength)&&Ke(e.mediaType)&&(e.protectionClassification===`ordinary`||e.protectionClassification===`opaque-encrypted`)}function be(e,t,n){return I(e,[`workspaceId`,`volumeId`,`provider`,`itemId`,`parentId`,`type`,`name`,`lifecycleState`,`revision`,`currentVersion`])&&e.workspaceId===t&&typeof e.volumeId==`string`&&S.test(e.volumeId)&&e.provider===`managed`&&typeof e.itemId==`string`&&b.test(e.itemId)&&(e.parentId===null||typeof e.parentId==`string`&&b.test(e.parentId))&&(e.type===`file`||e.type===`folder`)&&P(e.name)&&e.name.startsWith(n)&&e.lifecycleState===`active`&&F(e.revision)&&(e.type===`folder`?e.currentVersion===null:ye(e.currentVersion))}function xe(e){for(let t=1;t<e.length;t+=1){let n=e[t-1],r=e[t],i=Se(n.name,r.name);if(i>0||i===0&&n.itemId>=r.itemId)return!1}return!0}function Se(e,t){let n=ae.encode(e),r=ae.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 Ce(e,t){if(!I(e,[`items`,`nextCursor`])||!Array.isArray(e.items)||e.items.length>t||!e.items.every(Ie)||!(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&T.test(e.nextCursor))||e.nextCursor!==null&&e.items.length===0||!Ye(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 we(e,t){return!I(e,[`itemRevision`,`currentVersionId`])||!F(e.itemRevision)||e.currentVersionId!==t?!1:(Object.freeze(e),!0)}function Te(e,t,n,r=O){if(!(I(e,[`items`,`nextCursor`,`collectionRevision`,`collectionEtag`])&&Array.isArray(e.items)&&e.items.length<=50&&e.items.every(Ve)&&(e.nextCursor===null||typeof e.nextCursor==`string`&&e.nextCursor.length<=699&&T.test(e.nextCursor))&&F(e.collectionRevision)&&typeof e.collectionEtag==`string`&&d(e.collectionEtag)===e.collectionRevision))return!1;let i=t.get(`drive-permission-collection-etag`),a=t.get(`etag`),o=e.collectionRevision;return F(o)?i===e.collectionEtag&&a!==null&&r.test(a)&&e.items.every(e=>(e.source===`direct`?e.sourceItemId===n:e.sourceItemId!==n)&&e.etag===Ge(o,e.revision))&&Ye(e.items,e=>`${e.sourceItemId}\0${e.grantId}`):!1}function Ee(e,t,n){if(!I(e,[`items`,`nextCursor`,`collectionRevision`,`collectionEtag`])||!Array.isArray(e.items)||e.items.length>50)return!1;let r=[];for(let t of e.items){if(!I(t,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`,`etag`,`recipient`]))return!1;let{recipient:e,...n}=t;if(!Ve(n)||e!==null&&(!I(e,[`userId`,`name`,`email`,`resolvedAt`,`expiresAt`])||n.grantee.type!==`user`||e.userId!==n.grantee.userId||typeof e.name!=`string`||e.name.length<1||ae.encode(e.name).byteLength>1024||typeof e.email!=`string`||e.email.length<3||ae.encode(e.email).byteLength>320||!e.email.includes(`@`)||!F(e.resolvedAt)||!F(e.expiresAt)||e.expiresAt!==e.resolvedAt+864e5))return!1;r.push(n)}return Te({...e,items:r},t,n,/^"drive\.sharing-people\.v1\.[0-9a-f]{64}"$/)}function De(e,t,n){if(!I(e,[`outcome`,`grant`,`collectionRevision`])||e.outcome!==`committed`&&e.outcome!==`replayed`||!F(e.collectionRevision))return!1;let r=e.grant;return I(r,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`])&&r.source===`direct`&&typeof r.sourceItemId==`string`&&r.sourceItemId===t&&typeof r.grantId==`string`&&C.test(r.grantId)&&(n===void 0||r.grantId===n)&&He(r.grantee)&&Ue(r.actions)&&[`active`,`expired`,`revoked`].includes(String(r.availability))&&(r.expiresAtEpochMilliseconds===null||F(r.expiresAtEpochMilliseconds))&&F(r.revision)}function Oe(e,t){if(!I(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||!I(r,[`action`,`allowed`,`basis`,`sourceItemId`,`grantId`])||r.action!==A[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`&&b.test(r.sourceItemId))||!(r.grantId===null||typeof r.grantId==`string`&&C.test(r.grantId))||!We(r,t))return!1}return!0}function ke(e,t){return!I(e,[`itemId`,`versionId`,`uploadId`,`mode`,`partByteLength`,`partCount`,`revision`,`expiresAtEpochMilliseconds`])||typeof e.itemId!=`string`||!b.test(e.itemId)||typeof e.versionId!=`string`||!w.test(e.versionId)||typeof e.uploadId!=`string`||!ne.test(e.uploadId)||e.mode!==`presigned-multipart`&&e.mode!==`server-mediated-zero-byte`||e.partByteLength!==M||!F(e.partCount)||e.partCount>1e4||e.partCount!==Math.ceil(t/M)||(t===0?e.mode!==`server-mediated-zero-byte`:e.mode!==`presigned-multipart`)||!F(e.revision)||!F(e.expiresAtEpochMilliseconds)||e.expiresAtEpochMilliseconds<=Date.now()?!1:(Object.freeze(e),!0)}function Ae(e,t,n){if(!I(e,[`itemId`,`versionId`,`uploadId`,`mode`,`lifecycle`,`revision`,`partPolicy`,`confirmedParts`,`nextAfterPartNumber`,`expiresAtEpochMilliseconds`,`ready`],[`verification`])||typeof e.itemId!=`string`||!b.test(e.itemId)||typeof e.versionId!=`string`||!w.test(e.versionId)||typeof e.uploadId!=`string`||!ne.test(e.uploadId)||e.mode!==`presigned-multipart`&&e.mode!==`server-mediated-zero-byte`||![`initiating`,`recovery-required`,`uploading`,`completing`,`provider-completed`,`verifying`,`failed`,`ready`,`aborting`,`aborted`].includes(String(e.lifecycle))||!F(e.revision)||!I(e.partPolicy,[`partByteLength`,`partCount`,`maxParts`])||e.partPolicy.partByteLength!==M||!F(e.partPolicy.partCount)||e.partPolicy.partCount>1e4||e.partPolicy.maxParts!==1e4||(e.mode===`server-mediated-zero-byte`?e.partPolicy.partCount!==0:e.partPolicy.partCount<1)||!Array.isArray(e.confirmedParts)||e.confirmedParts.length>n||!F(e.expiresAtEpochMilliseconds))return!1;let r=t;if(e.verification!==void 0){let t=e.verification;if(!I(t,[`state`,`verifiedByteLength`,`totalByteLength`,`revision`])||![`pending`,`verified`,`failed`].includes(String(t.state))||!F(t.verifiedByteLength)||!F(t.totalByteLength)||t.totalByteLength>j||t.verifiedByteLength>t.totalByteLength||!F(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(!I(t,[`partNumber`,`checksumSha256`])||!F(t.partNumber)||t.partNumber<=r||t.partNumber>e.partPolicy.partCount||!Fe(t.checksumSha256))return!1;r=t.partNumber}if(!(e.nextAfterPartNumber===null||F(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&&(!Ne(e.ready,{uploadId:e.uploadId})||e.ready.itemId!==e.itemId||e.ready.versionId!==e.versionId||!I(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 je(e,t,n,r){return!I(e,[`url`,`method`,`headers`,`partNumber`,`expectedByteLength`,`expiresAtEpochMilliseconds`])||!qe(e.url,n)||e.method!==`PUT`||!r||!I(e.headers,[`content-md5`])||e.headers[`content-md5`]!==r||e.partNumber!==t||!F(e.expectedByteLength)||e.expectedByteLength<1||e.expectedByteLength>M||!F(e.expiresAtEpochMilliseconds)||e.expiresAtEpochMilliseconds<=Date.now()?!1:(Object.freeze(e.headers),Object.freeze(e),!0)}function Me(e,t,n){return!I(e,[`partNumber`,`revision`])||e.partNumber!==t||e.revision!==n+1||!F(e.revision)?!1:(Object.freeze(e),!0)}function Ne(e,t){return!I(e,[`itemId`,`versionId`,`uploadId`,`byteLength`,`callerDeclaredContentDigest`,`displayFilename`,`mediaType`,`state`])||typeof e.itemId!=`string`||!b.test(e.itemId)||typeof e.versionId!=`string`||!w.test(e.versionId)||e.uploadId!==t.uploadId||!F(e.byteLength)||e.byteLength<0||e.byteLength>j||typeof e.callerDeclaredContentDigest!=`string`||!ie.test(e.callerDeclaredContentDigest)||!P(e.displayFilename)||!Ke(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 Pe(e,t){return!I(e,[`itemId`,`versionId`,`uploadId`,`state`,`verifiedByteLength`,`totalByteLength`,`verificationRevision`])||typeof e.itemId!=`string`||!b.test(e.itemId)||typeof e.versionId!=`string`||!w.test(e.versionId)||e.uploadId!==t||e.state!==`verifying`||!F(e.verifiedByteLength)||!F(e.totalByteLength)||e.totalByteLength>j||e.verifiedByteLength>e.totalByteLength||!F(e.verificationRevision)?!1:(Object.freeze(e),!0)}function Fe(e){return typeof e==`string`&&/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/.test(e)}function Ie(e){let t=I(e,Re)&&ze(e);return t&&Object.freeze(e),t}function Le(e,t,n,r){let i=I(e,[...Re,`workspaceId`,`itemId`])&&e.workspaceId===t&&e.itemId===n&&e.versionId===r&&ze(e);return i&&Object.freeze(e),i}const Re=Object.freeze([`versionId`,`state`,`revision`,`byteLength`,`contentDigest`,`mediaType`,`displayFilename`,`protectionClassification`,`archiveState`]);function ze(e){return typeof e.versionId==`string`&&w.test(e.versionId)&&(e.state===`current`||e.state===`superseded`)&&F(e.revision)&&F(e.byteLength)&&typeof e.contentDigest==`string`&&ie.test(e.contentDigest)&&Ke(e.mediaType)&&P(e.displayFilename)&&(e.protectionClassification===`ordinary`||e.protectionClassification===`opaque-encrypted`)&&[`available`,`cold`,`restoring`,`unavailable`,`corrupt`].includes(String(e.archiveState))}function Be(e){let t=e.get(`drive-permission-collection-etag`),n=e.get(`drive-permission-grant-etag`),r=t===null?void 0:d(t);if(r===void 0)return!1;if(n===null)return!0;let i=f(n);return i!==void 0&&i[0]===r}function Ve(e){return I(e,[`source`,`sourceItemId`,`grantId`,`grantee`,`actions`,`availability`,`expiresAtEpochMilliseconds`,`revision`,`etag`])&&(e.source===`direct`||e.source===`inherited`)&&typeof e.sourceItemId==`string`&&b.test(e.sourceItemId)&&typeof e.grantId==`string`&&C.test(e.grantId)&&He(e.grantee)&&Ue(e.actions)&&[`active`,`expired`,`revoked`].includes(String(e.availability))&&(e.expiresAtEpochMilliseconds===null||F(e.expiresAtEpochMilliseconds))&&F(e.revision)&&typeof e.etag==`string`&&D.test(e.etag)}function He(e){return I(e,[`type`,`userId`])&&e.type===`user`&&typeof e.userId==`string`&&E.test(e.userId)||I(e,[`type`,`teamId`])&&e.type===`team`&&typeof e.teamId==`string`&&E.test(e.teamId)}function Ue(e){return Array.isArray(e)&&e.length>=1&&e.length<=6&&new Set(e).size===e.length&&e.every(e=>k.includes(e))&&e.every((t,n)=>n===0||k.indexOf(t)>k.indexOf(e[n-1]))}function We(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 Ge(e,t){return`"drive.permission-grant.v1.${e}.${t}"`}function P(e){if(typeof e!=`string`||e.length===0||e.length>510||e.normalize(`NFC`)!==e||e.endsWith(`.`)||e.endsWith(` `)||Je(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 Ke(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 qe(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 Je(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 Ye(e,t){return e.every((n,r)=>r===0||t(e[r-1])<t(n))}function F(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function Xe(e){return/^"[\x21\x23-\x7e]{1,1022}"$/.test(e)}function Ze(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 I(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))}const Qe=/^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,L=/^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,$e=/^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,et=/^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,tt=/^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,nt=/^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/,rt=/^[A-Za-z0-9_-]{1,128}$/,it=Object.freeze([`items:content:read`,`items:create`,`items:delete`,`items:metadata:read`,`items:permissions:read`,`items:update`]),at=/^[A-Za-z0-9_-]{16,128}$/,ot=/^sha256:[0-9a-f]{64}$/,st=/^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/,ct=33554432e4;function lt(e){let t=U(H(e===void 0?{}:e,[],[`signal`]).signal);return t===void 0?{}:{signal:t}}function ut(e){let t=H(e===void 0?{}:e,[],[`signal`,`limit`,`cursor`]),n=U(t.signal);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 r(`invalid_input`);return{signal:n,query:{...t.limit===void 0?{}:{limit:t.limit},...t.cursor===void 0?{}:{cursor:t.cursor}}}}function dt(e,t){let n=H(e,[`workspaceId`],t?[`signal`,`view`,`kind`,`creatorUserId`,`limit`,`cursor`]:[`signal`]),i=U(n.signal);if(typeof n.workspaceId!=`string`||!L.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`||!rt.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 r(`invalid_input`);return{workspaceId:n.workspaceId,signal:i,query:{...n.view===void 0?{}:{view:n.view},...n.kind===void 0?{}:{kind:n.kind},...n.creatorUserId===void 0?{}:{creatorUserId:n.creatorUserId},...n.limit===void 0?{}:{limit:n.limit},...n.cursor===void 0?{}:{cursor:n.cursor}}}}function R(e){let t=H(e,[`workspaceId`,`itemId`],[`signal`]),n=t.workspaceId,i=t.itemId,a=U(t.signal);if(typeof n!=`string`||!L.test(n)||typeof i!=`string`||!Qe.test(i))throw new r(`invalid_input`);return{workspaceId:n,itemId:i,...a===void 0?{}:{signal:a}}}function ft(e){let t=H(e,[`workspaceId`,`itemId`,`versionId`],[`signal`]),n=R({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.versionId!=`string`||!tt.test(t.versionId))throw new r(`invalid_input`);return{...n,versionId:t.versionId}}function pt(e){let t=H(e,[`workspaceId`,`itemId`,`idempotencyKey`],[`versionId`,`method`,`range`,`ifMatch`,`ifNoneMatch`,`ifRange`,`signal`]),n=R({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),i=t.method??`GET`;if(!W(t.idempotencyKey)||t.versionId!==void 0&&(typeof t.versionId!=`string`||!tt.test(t.versionId))||i!==`GET`&&i!==`HEAD`||t.range!==void 0&&(typeof t.range!=`string`||t.range.length>128||!/^bytes=(?:[0-9]+-[0-9]*|-[0-9]+)$/.test(t.range))||!Ht(t.ifMatch)||!Ht(t.ifNoneMatch)||!Ht(t.ifRange))throw new r(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey,method:i,...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 mt(e){let t=H(e,[`workspaceId`,`query`],[`limit`,`cursor`,`signal`]),n=U(t.signal);if(typeof t.workspaceId!=`string`||!L.test(t.workspaceId)||!Rt(t.query)||t.limit!==void 0&&(!K(t.limit)||t.limit<1||t.limit>50)||t.cursor!==void 0&&(typeof t.cursor!=`string`||t.cursor.length>699||!nt.test(t.cursor)))throw new r(`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 ht(e){let t=H(e,[`workspaceId`,`itemId`],[`signal`,`limit`,`cursor`]),n=R({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),i=t.limit,a=t.cursor;if(i!==void 0&&(!Number.isSafeInteger(i)||typeof i!=`number`||i<1||i>50)||a!==void 0&&(typeof a!=`string`||a.length>699||!nt.test(a)))throw new r(`invalid_input`);return{...n,...i===void 0?{}:{limit:i},...a===void 0?{}:{cursor:a}}}function gt(e){let t=H(e,[`workspaceId`,`itemId`,`name`,`idempotencyKey`],[`signal`]),n=R({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(!Bt(t.name)||!W(t.idempotencyKey))throw new r(`invalid_input`);return{...n,name:t.name,idempotencyKey:t.idempotencyKey}}function _t(e){let t=H(e,[`workspaceId`,`itemId`,`name`,`parentItemId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=z({workspaceId:t.workspaceId,itemId:t.itemId,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch,...t.signal===void 0?{}:{signal:t.signal}});if(!Bt(t.name)||typeof t.parentItemId!=`string`||!Qe.test(t.parentItemId))throw new r(`invalid_input`);return{...n,name:t.name,parentItemId:t.parentItemId}}function z(e){let t=H(e,[`workspaceId`,`itemId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=R({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(!W(t.idempotencyKey)||typeof t.ifMatch!=`string`||p(t.ifMatch)===void 0)throw new r(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch}}function vt(e){let t=H(e,[`workspaceId`,`itemId`,`versionId`,`idempotencyKey`,`ifMatch`],[`signal`]),n=z({workspaceId:t.workspaceId,itemId:t.itemId,idempotencyKey:t.idempotencyKey,ifMatch:t.ifMatch,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.versionId!=`string`||!tt.test(t.versionId))throw new r(`invalid_input`);return{...n,versionId:t.versionId}}function yt(e){let t=H(e,[`workspaceId`,`itemId`,`grantee`,`actions`,`expiresAtEpochMilliseconds`,`ifMatch`,`idempotencyKey`],[`signal`]),n=R({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}}),i=jt(t.grantee),a=Mt(t.actions),o=t.expiresAtEpochMilliseconds;if(!zt(o)||typeof t.ifMatch!=`string`||d(t.ifMatch)===void 0||!W(t.idempotencyKey))throw new r(`invalid_input`);return{...n,grantee:i,actions:a,expiresAtEpochMilliseconds:o,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function bt(e){let t=H(e,[`workspaceId`,`itemId`,`email`,`role`,`ifMatch`,`idempotencyKey`],[`signal`]),n=R({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`||d(t.ifMatch)===void 0||!W(t.idempotencyKey))throw new r(`invalid_input`);let i=t.email.trim().toLowerCase();if(!i.includes(`@`)||/\s/.test(i)||new TextEncoder().encode(i).byteLength>320)throw new r(`invalid_input`);return{...n,email:i,role:t.role,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function xt(e){let t=H(e,[`workspaceId`,`itemId`,`grantId`,`ifMatch`,`idempotencyKey`],[`signal`]),n=R({workspaceId:t.workspaceId,itemId:t.itemId,...t.signal===void 0?{}:{signal:t.signal}});if(typeof t.grantId!=`string`||!$e.test(t.grantId)||typeof t.ifMatch!=`string`||f(t.ifMatch)===void 0||!W(t.idempotencyKey))throw new r(`invalid_input`);return{...n,grantId:t.grantId,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey}}function St(e){let t=H(e,[`workspaceId`,`itemId`,`grantId`,`ifMatch`,`idempotencyKey`],[`signal`,`actions`,`expiresAtEpochMilliseconds`]),n=xt({workspaceId:t.workspaceId,itemId:t.itemId,grantId:t.grantId,ifMatch:t.ifMatch,idempotencyKey:t.idempotencyKey,...t.signal===void 0?{}:{signal:t.signal}}),i=t.actions===void 0?void 0:Mt(t.actions),a=t.expiresAtEpochMilliseconds;if(i===void 0&&a===void 0||a!==void 0&&!zt(a))throw new r(`invalid_input`);return{...n,...i===void 0?{}:{actions:i},...a===void 0?{}:{expiresAtEpochMilliseconds:a}}}function Ct(e){let t=H(e,[`workspaceId`,`parentItemId`,`expectedByteLength`,`displayFilename`,`mediaType`,`callerDeclaredContentDigest`,`protectionClassification`,`idempotencyKey`],[`signal`]),n=U(t.signal);if(typeof t.workspaceId!=`string`||!L.test(t.workspaceId)||typeof t.parentItemId!=`string`||!Qe.test(t.parentItemId)||typeof t.expectedByteLength!=`number`||!Number.isSafeInteger(t.expectedByteLength)||t.expectedByteLength<0||t.expectedByteLength>ct||!Bt(t.displayFilename)||!Lt(t.mediaType)||typeof t.callerDeclaredContentDigest!=`string`||!ot.test(t.callerDeclaredContentDigest)||t.protectionClassification!==`ordinary`&&t.protectionClassification!==`opaque-encrypted`||!W(t.idempotencyKey))throw new r(`invalid_input`);return{workspaceId:t.workspaceId,parentItemId:t.parentItemId,expectedByteLength:t.expectedByteLength,displayFilename:t.displayFilename,mediaType:t.mediaType,callerDeclaredContentDigest:t.callerDeclaredContentDigest,protectionClassification:t.protectionClassification,idempotencyKey:t.idempotencyKey,...n===void 0?{}:{signal:n}}}function wt(e){let t=H(e,[`workspaceId`,`uploadId`],[`afterPartNumber`,`limit`,`signal`]),n=G(t.workspaceId,t.uploadId,t.signal);if(t.afterPartNumber!==void 0&&(!K(t.afterPartNumber)||t.afterPartNumber>1e4)||t.limit!==void 0&&(!K(t.limit)||t.limit<1||t.limit>100))throw new r(`invalid_input`);return{...n,...t.afterPartNumber===void 0?{}:{afterPartNumber:t.afterPartNumber},...t.limit===void 0?{}:{limit:t.limit}}}function Tt(e){let t=H(e,[`workspaceId`,`uploadId`,`partNumber`,`checksumSha256`,`contentMd5`],[`signal`]),n=G(t.workspaceId,t.uploadId,t.signal);if(!Pt(t.partNumber)||!Ft(t.checksumSha256)||typeof t.contentMd5!=`string`||!/^[A-Za-z0-9+/]{21}[AQgw]==$/.test(t.contentMd5))throw new r(`invalid_input`);return{...n,partNumber:t.partNumber,checksumSha256:t.checksumSha256,contentMd5:t.contentMd5}}function Et(e){let t=H(e,[`workspaceId`,`uploadId`,`partNumber`,`expectedUploadRevision`,`byteLength`,`etag`,`checksumSha256`],[`signal`]),n=G(t.workspaceId,t.uploadId,t.signal);if(!Pt(t.partNumber)||!K(t.expectedUploadRevision)||t.expectedUploadRevision>=2**53-1||!K(t.byteLength)||t.byteLength<1||t.byteLength>33554432||!It(t.etag)||!Ft(t.checksumSha256))throw new r(`invalid_input`);return{...n,partNumber:t.partNumber,expectedUploadRevision:t.expectedUploadRevision,byteLength:t.byteLength,etag:t.etag,checksumSha256:t.checksumSha256}}function Dt(e){let t=H(e,[`workspaceId`,`uploadId`,`idempotencyKey`],[`signal`]),n=G(t.workspaceId,t.uploadId,t.signal);if(!W(t.idempotencyKey))throw new r(`invalid_input`);return{...n,idempotencyKey:t.idempotencyKey}}function Ot(e){let t=H(e,[`workspaceId`,`uploadId`],[`signal`]);return G(t.workspaceId,t.uploadId,t.signal)}function kt(e){let t=H(e,[`workspaceId`,`parentItemId`,`source`,`displayFilename`,`idempotencyKey`,`completionIdempotencyKey`],[`mediaType`,`protectionClassification`,`signal`,`onProgress`]),n=U(t.signal),i=t.mediaType??`application/octet-stream`,a=t.protectionClassification??`ordinary`,o,s;try{if(!(t.source instanceof Blob))throw new r(`invalid_input`);o=t.source,s=o.size}catch(e){throw e instanceof r?e:new r(`invalid_input`)}if(typeof t.workspaceId!=`string`||!L.test(t.workspaceId)||typeof t.parentItemId!=`string`||!Qe.test(t.parentItemId)||!Number.isSafeInteger(s)||s<0||s>ct||!Bt(t.displayFilename)||!Lt(i)||a!==`ordinary`&&a!==`opaque-encrypted`||!W(t.idempotencyKey)||!W(t.completionIdempotencyKey)||t.onProgress!==void 0&&typeof t.onProgress!=`function`)throw new r(`invalid_input`);return{workspaceId:t.workspaceId,parentItemId:t.parentItemId,source:o,byteLength:s,displayFilename:t.displayFilename,mediaType:i,protectionClassification:a,idempotencyKey:t.idempotencyKey,completionIdempotencyKey:t.completionIdempotencyKey,...n===void 0?{}:{signal:n},...t.onProgress===void 0?{}:{onProgress:t.onProgress}}}function B(e){return{workspaceId:e.workspaceId,itemId:e.itemId}}function At(e){return{...e.limit===void 0?{}:{limit:e.limit},...e.cursor===void 0?{}:{cursor:e.cursor}}}function V(e,t){return t}function H(e,t,n){try{if(typeof e!=`object`&&typeof e!=`function`||e===null||Array.isArray(e))throw new r(`invalid_input`);let i=Object.getOwnPropertyDescriptors(e),a=Reflect.ownKeys(i),o=new Set([...t,...n]);if(a.some(e=>typeof e!=`string`||!o.has(e))||t.some(e=>!Object.hasOwn(i,e)))throw new r(`invalid_input`);let s={};for(let e of a){if(typeof e!=`string`)throw new r(`invalid_input`);let t=i[e];if(!t||!(`value`in t)||!t.enumerable)throw new r(`invalid_input`);s[e]=t.value}return s}catch(e){throw e instanceof r?e:new r(`invalid_input`)}}function U(e){if(e!==void 0){if(!(e instanceof AbortSignal))throw new r(`invalid_input`);return e}}function jt(e){let t=H(e,[`type`],[`userId`,`teamId`]);if(t.type===`user`){let t=H(e,[`type`,`userId`],[]);if(typeof t.userId==`string`&&rt.test(t.userId))return{type:`user`,userId:t.userId}}if(t.type===`team`){let t=H(e,[`type`,`teamId`],[]);if(typeof t.teamId==`string`&&rt.test(t.teamId))return{type:`team`,teamId:t.teamId}}throw new r(`invalid_input`)}function Mt(e){let t=Nt(e);if(t.length<1||t.length>it.length||new Set(t).size!==t.length||!t.every(e=>it.includes(e)))throw new r(`invalid_input`);return t}function Nt(e){try{if(!Array.isArray(e))throw new r(`invalid_input`);let t=Object.getOwnPropertyDescriptors(e);if(Reflect.ownKeys(t).some(e=>typeof e!=`string`))throw new r(`invalid_input`);let n=[];for(let i=0;i<e.length;i+=1){let e=t[String(i)];if(!e||!(`value`in e)||!e.enumerable)throw new r(`invalid_input`);n.push(e.value)}if(Reflect.ownKeys(t).length!==e.length+1)throw new r(`invalid_input`);return n}catch(e){throw e instanceof r?e:new r(`invalid_input`)}}function W(e){return typeof e==`string`&&at.test(e)}function G(e,t,n){let i=U(n);if(typeof e!=`string`||!L.test(e)||typeof t!=`string`||!et.test(t))throw new r(`invalid_input`);return{workspaceId:e,uploadId:t,...i===void 0?{}:{signal:i}}}function Pt(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=1&&e<=1e4}function Ft(e){return typeof e==`string`&&st.test(e)}function It(e){return typeof e==`string`&&e.length>=1&&e.length<=1024&&/^[\x20-\x7e]+$/.test(e)}function Lt(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 Rt(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 zt(e){return e===null||K(e)}function Bt(e){if(typeof e!=`string`||e.length===0||e.length>510||e.normalize(`NFC`)!==e||e.endsWith(`.`)||e.endsWith(` `)||Vt(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 Vt(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 K(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function Ht(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 Ut=/\{[^{}]+\}/g,Wt=()=>typeof process==`object`&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function Gt(){return Math.random().toString(36).slice(2,11)}function Kt(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=Wt()?c:void 0,t=tn(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??Qt,pathSerializer:te,body:y,middleware:b=[],...x}=d||{},S=t;f&&(S=tn(f)??t);let C=typeof i==`function`?i:Xt(i);v&&(C=typeof v==`function`?v:Xt({...typeof i==`object`?i:{},...v}));let ne=te||o||Zt,w=y===void 0?void 0:ee(y,en(s,h,g.header)),re=en(w===void 0||w instanceof FormData?{}:{"Content-Type":`application/json`},s,h,g.header),T=[...u,...b],E={redirect:`follow`,...l,...x,body:w,headers:re},D,O,k=new m($t(e,{baseUrl:S,params:g,querySerializer:C,pathSerializer:ne}),E),A;for(let e in x)e in k||(k[e]=x[e]);if(T.length){D=Gt(),O=Object.freeze({baseUrl:S,fetch:p,parseAs:_,querySerializer:C,bodySerializer:ee,pathSerializer:ne});for(let t of T)if(t&&typeof t==`object`&&typeof t.onRequest==`function`){let n=await t.onRequest({request:k,schemaPath:e,params:g,options:O,id:D});if(n)if(n instanceof m)k=n;else if(n instanceof Response){A=n;break}else throw Error(`onRequest: must return new Request() or Response() when modifying the request`)}}if(!A){try{A=await p(k,c)}catch(t){let n=t;if(T.length)for(let t=T.length-1;t>=0;t--){let r=T[t];if(r&&typeof r==`object`&&typeof r.onError==`function`){let t=await r.onError({request:k,error:n,schemaPath:e,params:g,options:O,id:D});if(t){if(t instanceof Response){n=void 0,A=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(T.length)for(let t=T.length-1;t>=0;t--){let n=T[t];if(n&&typeof n==`object`&&typeof n.onResponse==`function`){let t=await n.onResponse({request:k,response:A,schemaPath:e,params:g,options:O,id:D});if(t){if(!(t instanceof Response))throw Error(`onResponse: must return new Response() when modifying the response`);A=t}}}}let j=A.headers.get(`Content-Length`);if(A.status===204||k.method===`HEAD`||j===`0`&&!A.headers.get(`Transfer-Encoding`)?.includes(`chunked`))return A.ok?{data:void 0,response:A}:{error:void 0,response:A};if(A.ok)return{data:await(async()=>{if(_===`stream`)return A.body;if(_===`json`&&!j){let e=await A.text();return e?JSON.parse(e):void 0}return await A[_]()})(),response:A};let M=await A.text();try{M=JSON.parse(M)}catch{}return{error:M,response:A}}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 qt(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 Jt(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(qt(a,t[i],n))}let a=r.join(i);return n.style===`label`||n.style===`matrix`?`${i}${a}`:a}function Yt(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(qt(e,r,n));return n.style===`label`||n.style===`matrix`?`${r}${i.join(r)}`:i.join(r)}function Xt(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(Yt(r,i,{style:`form`,explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==`object`){n.push(Jt(r,i,{style:`deepObject`,explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}n.push(qt(r,i,e))}}return n.join(`&`)}}function Zt(e,t){let n=e;for(let r of e.match(Ut)??[]){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,Yt(e,o,{style:a,explode:i}));continue}if(typeof o==`object`){n=n.replace(r,Jt(e,o,{style:a,explode:i}));continue}if(a===`matrix`){n=n.replace(r,`;${qt(e,o)}`);continue}n=n.replace(r,a===`label`?`.${encodeURIComponent(o)}`:encodeURIComponent(o))}return n}function Qt(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 $t(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 en(...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 tn(e){return e.endsWith(`/`)?e.substring(0,e.length-1):e}String.fromCharCode;const nn=/\/$|\/\?|\/#/,rn=/^\.?\//;function an(e=``,t){return t?nn.test(e):e.endsWith(`/`)}function on(e=``,t){if(!t)return e.endsWith(`/`)?e:e+`/`;if(an(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 sn(e){return e&&e!==`/`}function cn(e,...t){let n=e||``;for(let e of t.filter(e=>sn(e)))if(n){let t=e.replace(rn,``);n=on(n)+t}else n=e;return n}function ln(e){let t;try{t=Object.freeze({baseUrl:fn(e.baseUrl),fetchImplementation:e.fetch??globalThis.fetch.bind(globalThis),getCredential:e.getCredential,timeoutMilliseconds:un(e.timeoutMilliseconds)})}catch{throw new r(`invalid_input`)}if(typeof t.fetchImplementation!=`function`||typeof t.getCredential!=`function`)throw new r(`invalid_input`);return t}async function q(e,t,n,i,a,o,s=!1,c){let d=dn(t,e.timeoutMilliseconds);try{let t=d.signal;mn(t);let f=await pn(e.getCredential,t),p;if(await i(Kt({baseUrl:e.baseUrl,fetch:async n=>{try{let i=await J(e.fetchImplementation(n),t);if(!(i instanceof Response))throw new r(`invalid_response`);p=i}catch(e){throw e instanceof r?e:t.aborted?new r(`aborted`):new r(`network_error`)}return new Response(null,{status:204})}}),{cache:`no-store`,credentials:`omit`,headers:new Headers({authorization:`Bearer ${f}`}),signal:t}),!p)throw new r(`network_error`);return o===null?await u(p,t,n,a,c):await l(p,t,n,a,o,s,c)}catch(e){throw d.didTimeout()?new r(`timeout`):e instanceof r?e:d.signal.aborted?new r(`aborted`):new r(`network_error`)}finally{d.dispose()}}function un(e){if(e===void 0)return 3e4;if(!Number.isSafeInteger(e)||e<1||e>12e4)throw new r(`invalid_input`);return e}function dn(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 fn(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 cn(t.origin,t.pathname)}async function pn(e,t){mn(t);let n;try{n=await J(e({signal:t}),t)}catch(e){throw e instanceof r&&e.code===`aborted`?e:t.aborted?new r(`aborted`):new r(`credential_unavailable`)}if(typeof n!=`string`||n.length<1||n.length>16384||!/^[\x21-\x7e]+$/.test(n))throw new r(`credential_unavailable`);return n}function mn(e){if(e.aborted)throw new r(`aborted`)}async function J(e,t){mn(t);let n=()=>{},i=new Promise((e,i)=>{let a=()=>i(new r(`aborted`));t.addEventListener(`abort`,a,{once:!0}),n=()=>t.removeEventListener(`abort`,a)});try{return await Promise.race([e,i])}finally{n()}}const hn=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`service_unavailable`]),gn=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`service_unavailable`]),Y=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_pagination_cursor`,`precondition_failed`,`service_unavailable`]),_n=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`upload_recovery_required`,`service_unavailable`]),vn=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`service_unavailable`]),yn=Object.freeze([..._n,`invalid_idempotency_key`,`idempotency_conflict`,`quota_exceeded`]),bn=Object.freeze([..._n,`invalid_idempotency_key`]),xn=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`invalid_idempotency_key`,`idempotency_conflict`,`precondition_failed`,`service_unavailable`]),Sn=Object.freeze([`authentication_required`,`identity_authority_unavailable`,`permission_denied`,`resource_not_found`,`invalid_request`,`precondition_failed`,`service_unavailable`]),Cn=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 wn(e){return Object.freeze({registerItemRecipient:t=>Xn(e,t),listItemSharingPeople:t=>Zn(e,t),listIncomingShares:t=>Tn(e,t),getCurrentWorkspace:t=>Fn(e,t),listWorkspaceItems:t=>Nn(e,t),getWorkspaceUsage:t=>Pn(e,t),getCurrentWorkspaceSources:t=>Mn(e,t),getItem:t=>In(e,t),searchWorkspaceItems:t=>Ln(e,t),listFolderChildren:t=>Rn(e,t),createFolder:t=>zn(e,t),updateItem:t=>Bn(e,t),trashItem:t=>Vn(e,t),restoreItem:t=>Hn(e,t),deleteItem:t=>Un(e,t),listItemVersions:t=>Wn(e,t),getItemVersion:t=>Gn(e,t),restoreItemVersion:t=>Kn(e,t),createDownload:t=>En(e,t),downloadItem:t=>Dn(e,t),listItemPermissions:t=>qn(e,t),readEffectiveItemPermissions:t=>Jn(e,t),createItemPermission:t=>Yn(e,t),updateItemPermission:t=>Qn(e,t),revokeItemPermission:t=>$n(e,t),createUpload:t=>er(e,t),getUploadStatus:t=>tr(e,t),createUploadPartDescriptor:t=>nr(e,t),recordUploadPart:t=>rr(e,t),completeUpload:t=>ir(e,t),abortUpload:t=>ar(e,t)})}async function Tn(e,t){let n=ut(t);return q(e,n.signal,409,(e,t)=>e.GET(`/api/v1/shares/incoming`,{...V(`listIncomingShares`,{params:{query:n.query}}),...t}),[200],oe,!1,Y)}async function En(e,t){let n=pt(t);return q(e,n.signal,412,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/downloads`,{...V(`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?de(e):t===202?pe(e):e===void 0,!1,Cn)}async function Dn(e,t){let n=pt(t),i=await En(e,t);if(i.status===202||i.status===304)return i;let a=i.data;if(a.expiresAtEpochMilliseconds<=Date.now())throw new r(`invalid_response`);let o=dn(n.signal,e.timeoutMilliseconds);try{let t=await J(e.fetchImplementation(kn(a,o.signal)),o.signal);if(!An(t,a))throw await t.body?.cancel().catch(()=>void 0),new r(`invalid_response`);let i=On(a);if(a.method===`HEAD`)return await t.body?.cancel().catch(()=>void 0),o.dispose(),new Response(null,{status:t.status,headers:i});if(!t.body){if(o.dispose(),a.response.contentLength!==0)throw new r(`invalid_response`);return new Response(null,{status:t.status,headers:i})}return o.dispose(),new Response(jn(t.body,a.response.contentLength,n.signal),{status:t.status,headers:i})}catch(e){throw o.dispose(),o.didTimeout()?new r(`timeout`):e instanceof r?e:o.signal.aborted?new r(o.didTimeout()?`timeout`:`aborted`):new r(`network_error`)}}function On(e){let t=e.response,n=new Headers;return 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 kn(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 An(e,t){let n=t.response,r=e.headers.get(`content-encoding`);return 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 jn(e,t,n){let i=e.getReader(),a=0,o=!1,s=()=>{};return new ReadableStream({start(e){if(!n)return;let t=()=>{o||(o=!0,s(),i.cancel().catch(()=>void 0),e.error(new r(`aborted`)))};n.aborted?t():(n.addEventListener(`abort`,t,{once:!0}),s=()=>n.removeEventListener(`abort`,t))},async pull(e){if(!o)try{let n=await i.read();if(o)return;if(n.done)o=!0,s(),i.releaseLock(),a===t?e.close():e.error(new r(`invalid_response`));else{if(a+=n.value.byteLength,!Number.isSafeInteger(a)||a>t){o=!0,s(),await i.cancel().catch(()=>void 0),e.error(new r(`invalid_response`));return}e.enqueue(n.value)}}catch(t){if(o)return;o=!0,s(),await i.cancel().catch(()=>void 0),e.error(t instanceof r?t:n?.aborted?new r(`aborted`):new r(`network_error`))}},async cancel(e){o||(o=!0,s(),await i.cancel(e).catch(()=>void 0))}})}async function Mn(e,t){return q(e,lt(t).signal,null,(e,t)=>e.GET(`/api/v1/workspaces/current/sources`,{...V(`getCurrentWorkspaceSources`,{params:{}}),...t}),[200],le,!1,hn)}async function Nn(e,t){let n=dt(t,!0);return q(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items`,{...V(`listWorkspaceItems`,{params:{path:{workspaceId:n.workspaceId},query:n.query}}),...t}),[200],e=>ce(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.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,Y)}async function Pn(e,t){let n=dt(t,!1);return q(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/usage`,{...V(`getWorkspaceUsage`,{params:{path:{workspaceId:n.workspaceId}}}),...t}),[200],e=>se(e)&&e.workspaceId===n.workspaceId,!1,Y)}async function Fn(e,t){return q(e,lt(t).signal,null,(e,t)=>e.GET(`/api/v1/workspaces/current`,{...V(`getCurrentWorkspace`,{params:{}}),...t}),[200],ue,!1,hn)}async function In(e,t){let n=R(t);return q(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...V(`getItem`,{params:{path:B(n)}}),...t}),[200],(e,t,r)=>_e(e,n.workspaceId,n.itemId)&&N(r,e.revision),!1,gn)}async function Ln(e,t){let n=mt(t);return q(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/search`,{...V(`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=>ve(e,n.workspaceId,n.query,n.limit??50),!1,Y)}async function Rn(e,t){let n=ht(t);return q(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/children`,{...V(`listFolderChildren`,{params:{path:B(n),query:At(n)}}),...t}),[200],e=>me(e,n.workspaceId,n.itemId))}async function zn(e,t){let n=gt(t);return q(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/children`,{...V(`createFolder`,{params:{path:B(n),header:{"Idempotency-Key":n.idempotencyKey}},body:{name:n.name}}),...t}),[200,201],e=>he(e)&&e.workspaceId===n.workspaceId&&e.parentItemId===n.itemId&&e.kind===`folder`&&e.name===n.name)}async function Bn(e,t){let n=_t(t);return q(e,n.signal,409,(e,t)=>e.PATCH(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...V(`updateItem`,{params:{path:B(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:{name:n.name,parentItemId:n.parentItemId}}),...t}),[200],(e,t,r)=>ge(e,n.workspaceId,n.itemId,`active`)&&e.name===n.name&&e.parentItemId===n.parentItemId&&N(r,e.revision),!1,xn)}async function Vn(e,t){let n=z(t);return q(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/trash`,{...V(`trashItem`,{params:{path:B(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>ge(e,n.workspaceId,n.itemId,`trashed`)&&N(r,e.revision),!1,xn)}async function Hn(e,t){let n=z(t);return q(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/restore`,{...V(`restoreItem`,{params:{path:B(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>ge(e,n.workspaceId,n.itemId,`active`)&&N(r,e.revision),!1,xn)}async function Un(e,t){let n=z(t);return q(e,n.signal,409,(e,t)=>e.DELETE(`/api/v1/workspaces/{workspaceId}/items/{itemId}`,{...V(`deleteItem`,{params:{path:B(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200,202],(e,t,r)=>ge(e,n.workspaceId,n.itemId,`deleting`)&&N(r,e.revision),!1,xn)}async function Wn(e,t){let n=ht(t);return q(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions`,{...V(`listItemVersions`,{params:{path:B(n),query:At(n)}}),...t}),[200],e=>Ce(e,n.limit??50),!1,Sn)}async function Gn(e,t){let n=ft(t);return q(e,n.signal,409,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}`,{...V(`getItemVersion`,{params:{path:{...B(n),versionId:n.versionId}}}),...t}),[200],e=>Le(e,n.workspaceId,n.itemId,n.versionId),!1,Sn)}async function Kn(e,t){let n=vt(t);return q(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}/restore`,{...V(`restoreItemVersion`,{params:{path:{...B(n),versionId:n.versionId},header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>we(e,n.versionId)&&N(r,e.itemRevision),!1,xn)}async function qn(e,t){let n=ht(t);return q(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions`,{...V(`listItemPermissions`,{params:{path:B(n),query:At(n)}}),...t}),[200],(e,t,r)=>Te(e,r,n.itemId))}async function Jn(e,t){let n=R(t);return q(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/effective`,{...V(`readEffectiveItemPermissions`,{params:{path:B(n)}}),...t}),[200],e=>Oe(e,n.itemId))}async function Yn(e,t){let n=yt(t);return q(e,n.signal,412,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions`,{...V(`createItemPermission`,{params:{path:B(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)=>De(e,n.itemId)&&(t===201&&e.outcome===`committed`||t===200&&e.outcome===`replayed`)&&(t===200||e.grant.availability!==`revoked`)&&Be(r))}async function Xn(e,t){let n=bt(t);return q(e,n.signal,412,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/items/{itemId}/sharing`,{...V(`registerItemRecipient`,{params:{path:B(n),header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:{email:n.email,role:n.role}}),...t}),[200,201],(e,t,r)=>De(e,n.itemId)&&(t===201&&e.outcome===`committed`||t===200&&e.outcome===`replayed`)&&(t===200||e.grant.availability!==`revoked`)&&Be(r),!1,[...Y,`recipient_unavailable`,`rate_limited`,`idempotency_conflict`,`invalid_idempotency_key`])}async function Zn(e,t){let n=ht(t);return q(e,n.signal,412,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/items/{itemId}/sharing/people`,{...V(`listItemSharingPeople`,{params:{path:B(n),query:At(n)}}),...t}),[200],(e,t,r)=>Ee(e,r,n.itemId))}async function Qn(e,t){let n=St(t),r={};return n.actions!==void 0&&(r.actions=n.actions),n.expiresAtEpochMilliseconds!==void 0&&(r.expiresAtEpochMilliseconds=n.expiresAtEpochMilliseconds),q(e,n.signal,412,(e,t)=>e.PATCH(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/{grantId}`,{...V(`updateItemPermission`,{params:{path:{...B(n),grantId:n.grantId},header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}},body:r}),...t}),[200],(e,t,r)=>De(e,n.itemId,n.grantId)&&e.grant.availability!==`revoked`&&Be(r))}async function $n(e,t){let n=xt(t);return q(e,n.signal,412,(e,t)=>e.DELETE(`/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions/{grantId}`,{...V(`revokeItemPermission`,{params:{path:{...B(n),grantId:n.grantId},header:{"Idempotency-Key":n.idempotencyKey,"If-Match":n.ifMatch}}}),...t}),[200],(e,t,r)=>De(e,n.itemId,n.grantId)&&e.grant.availability===`revoked`&&d(r.get(`drive-permission-collection-etag`)??``)!==void 0&&r.get(`drive-permission-grant-etag`)===null)}async function er(e,t){let n=Ct(t);return q(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads`,{...V(`createUpload`,{params:{path:{workspaceId:n.workspaceId},header:{"Idempotency-Key":n.idempotencyKey}},body:{parentItemId:n.parentItemId,expectedByteLength:n.expectedByteLength,displayFilename:n.displayFilename,mediaType:n.mediaType,callerDeclaredContentDigest:n.callerDeclaredContentDigest,protectionClassification:n.protectionClassification}}),...t}),[200,201],e=>ke(e,n.expectedByteLength),!0,yn)}async function tr(e,t){let n=wt(t),r=n.afterPartNumber??0,i=n.limit??100;return q(e,n.signal,null,(e,t)=>e.GET(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}`,{...V(`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=>Ae(e,r,i)&&e.uploadId===n.uploadId,!1,vn)}async function nr(e,t){let n=Tt(t);return q(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/parts`,{...V(`createUploadPartDescriptor`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId}},body:{partNumber:n.partNumber,checksumSha256:n.checksumSha256,contentMd5:n.contentMd5}}),...t}),[200],t=>je(t,n.partNumber,new URL(e.baseUrl).protocol===`http:`,n.contentMd5),!1,_n)}async function rr(e,t){let n=Et(t);return q(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/parts/{partNumber}`,{...V(`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=>Me(e,n.partNumber,n.expectedUploadRevision),!1,_n)}async function ir(e,t){let n=Dt(t);return q(e,n.signal,409,(e,t)=>e.POST(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}/complete`,{...V(`completeUpload`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId},header:{"Idempotency-Key":n.idempotencyKey}}}),...t}),[200,202],(e,t)=>t===202?Pe(e,n.uploadId):Ne(e,{uploadId:n.uploadId}),!1,bn)}async function ar(e,t){let n=Ot(t);return q(e,n.signal,409,(e,t)=>e.DELETE(`/api/v1/workspaces/{workspaceId}/uploads/{uploadId}`,{...V(`abortUpload`,{params:{path:{workspaceId:n.workspaceId,uploadId:n.uploadId}}}),...t}),[204],null,!1,_n)}const or=e=>e/2**32|0,sr=e=>e>>>0;function cr(e,t,n,r){let i=or(n),a=sr(n);e.setUint32(t,r?a:i,r),e.setUint32(t+4,r?i:a,r)}function lr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}const ur=e=>e?`"${e}" `:``;function dr(e,t=``){if(typeof e!=`number`)throw TypeError(ur(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(ur(t)+`expected integer >= 0, got `+e);return e}function fr(e,t,n=``){if(lr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&dr(t,`length`);let r=lr(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=ur(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}const pr=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`"${t}" `)+`expected object, got type=`+typeof e)};function mr(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function hr(e,t){fr(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function gr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function _r(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function X(e,t){return e<<32-t|e>>>t}function vr(e,t){return e<<t|e>>>32-t>>>0}const yr=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,br=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function xr(e){if(fr(e),yr)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=br[e[n]];return t}function Sr(e,t,n=`opts`){return pr(e,`defaults`),t!==void 0&&pr(t,n),Object.assign(e,t)}function Cr(e,t={}){if(typeof e!=`function`)throw TypeError(`"hashCons" expected function, got type=`+typeof e);t=Sr({},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 wr=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Tr(e,t,n){return e&t^~e&n}function Er(e,t,n){return e&t^e&n^t&n}var Dr=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=_r(this.buffer)}update(e){mr(this),fr(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=_r(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){mr(this),hr(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)),cr(n,r-8,this.length*8,i),this.process(n,0),this.roundClean();let o=e===t?n:_r(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 Or=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),kr=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 Ar=class extends Dr{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+Tr(o,s,c)+kr[e]+Z[e]|0,d=(X(n,2)^X(n,13)^X(n,22))+Er(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(){gr(Z)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),gr(this.buffer)}},jr=class extends Ar{constructor(){super(32,Or)}};const Mr=Cr(()=>new jr,wr(1)),Nr=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),Pr=2**32,Fr=Array.from({length:64},(e,t)=>Math.floor(Pr*Math.abs(Math.sin(t+1)))),Ir=Nr.slice(0,4),Lr=new Uint32Array(16),Rr=(()=>{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 zr=class extends Dr{A=Ir[0]|0;B=Ir[1]|0;C=Ir[2]|0;D=Ir[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)Lr[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=Tr(r,i,a),o=e):e<32?(t=Tr(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+Fr[e]+Lr[o],n=a,a=i,i=r,r+=vr(t,Rr[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(){gr(Lr)}destroy(){this.destroyed=!0,this.set(0,0,0,0),gr(this.buffer)}};const Br=Cr(()=>new zr),Q=32*1024*1024;async function Vr(e,t,n){let i=kt(t),a=Math.ceil(i.byteLength/Q);$(i.onProgress,`preparing`,0,i.byteLength,0,a);let o;try{let t=await Kr(i.source,i.byteLength,a,i.signal),s=await n.createUpload({workspaceId:i.workspaceId,parentItemId:i.parentItemId,expectedByteLength:i.byteLength,displayFilename:i.displayFilename,mediaType:i.mediaType,callerDeclaredContentDigest:t.callerDeclaredContentDigest,protectionClassification:i.protectionClassification,idempotencyKey:i.idempotencyKey,...i.signal===void 0?{}:{signal:i.signal}});o=s.data,Jr(o,i.byteLength,a,s.status,s.requestId);let c=await Ur(n,i,o,t);if($(i.onProgress,`uploading`,c.confirmedByteLength,i.byteLength,c.confirmedParts.size,a),c.readyResult)return $(i.onProgress,`completing`,c.confirmedByteLength,i.byteLength,c.confirmedParts.size,a),c.readyResult;let l=c.revision,u=c.confirmedByteLength,d=c.confirmedParts.size;if(c.lifecycle===`uploading`)for(let s of Hr(o.partCount,c.confirmedParts)){let c=s-1;ii(i.signal);let f=c*o.partByteLength,p=Math.min(f+o.partByteLength,i.byteLength),m=p-f,h=t.partChecksums[c];if(!h)throw new r(`invalid_response`);let g=await n.createUploadPartDescriptor({workspaceId:i.workspaceId,uploadId:o.uploadId,partNumber:s,checksumSha256:h,contentMd5:t.partMd5s[c],...i.signal===void 0?{}:{signal:i.signal}}),_=g.data;if(_.expectedByteLength!==m||_.expiresAtEpochMilliseconds>o.expiresAtEpochMilliseconds)throw new r(`invalid_response`,{status:g.status,requestId:g.requestId});let v=await qr(e,_,ti(i.source,f,p,m),i.signal);l=await Wr(n,i,o,s,l,m,v,h),u+=m,d+=1,$(i.onProgress,`uploading`,u,i.byteLength,d,a)}$(i.onProgress,`completing`,u,i.byteLength,d,a);let f=await Gr(n,i,o,t);return f.data.state===`verifying`&&$(i.onProgress,`verifying`,u,i.byteLength,d,a),f}catch(e){throw i.signal?.aborted&&o&&await ni(n,i.workspaceId,o.uploadId),e instanceof r?e:i.signal?.aborted?new r(`aborted`):new r(`invalid_input`)}}function*Hr(e,t){for(let n=1;n<=e;n+=1)t.has(n)||(yield n)}async function Ur(e,t,n,i){let a=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;Yr(p,n),c?Xr(p,c):(c=p,l=f.requestId);for(let e of p.confirmedParts){let n=i.partChecksums[e.partNumber-1];if(!n||e.checksumSha256!==n||a.has(e.partNumber))throw new r(`invalid_response`,{status:f.status,requestId:f.requestId});a.add(e.partNumber),o+=ei(t.byteLength,e.partNumber)}if(p.lifecycle===`ready`&&p.ready&&(Zr(p.ready,n,t,i,f.requestId),u=$r(f,p.ready)),p.nextAfterPartNumber===null)break;if(d===99)throw new r(`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)&&a.size!==n.partCount)throw new r(`invalid_response`);return Qr(c.lifecycle,l),Object.freeze({revision:c.revision,confirmedParts:a,confirmedByteLength:o,lifecycle:c.lifecycle,...u===void 0?{}:{readyResult:u}})}async function Wr(e,t,n,i,a,o,s,c){let l=r=>e.recordUploadPart({workspaceId:t.workspaceId,uploadId:n.uploadId,partNumber:i,expectedUploadRevision:r,byteLength:o,etag:s,checksumSha256:c,...t.signal===void 0?{}:{signal:t.signal}});try{return(await l(a)).data.revision}catch(a){if(!ri(a)||t.signal?.aborted)throw a;let o=await e.getUploadStatus({workspaceId:t.workspaceId,uploadId:n.uploadId,afterPartNumber:i-1,limit:1,...t.signal===void 0?{}:{signal:t.signal}}),s=o.data;Yr(s,n),Qr(s.lifecycle,o.requestId);let u=s.confirmedParts.find(e=>e.partNumber===i);if(u){if(u.checksumSha256!==c)throw new r(`invalid_response`,{status:o.status,requestId:o.requestId});return s.revision}if(s.lifecycle!==`uploading`)throw new r(`precondition_failed`);return(await l(s.revision)).data.revision}}async function Gr(e,t,n,i){try{let a=await e.completeUpload({workspaceId:t.workspaceId,uploadId:n.uploadId,idempotencyKey:t.completionIdempotencyKey,...t.signal===void 0?{}:{signal:t.signal}});if(a.data.state===`ready`)Zr(a.data,n,t,i,a.requestId);else if(a.data.itemId!==n.itemId||a.data.versionId!==n.versionId||a.data.uploadId!==n.uploadId||a.data.totalByteLength!==t.byteLength)throw new r(`invalid_response`);return a}catch(r){if(!ri(r)||t.signal?.aborted)throw r;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(Yr(o,n),o.lifecycle!==`ready`||!o.ready)throw r;return Zr(o.ready,n,t,i,a.requestId),$r(a,o.ready)}}async function Kr(e,t,n,i){let a=Mr.create(),o=[],s=[];for(let c=0;c<n;c+=1){ii(i);let n=c*Q,l=Math.min(n+Q,t),u=ti(e,n,l,l-n),d;try{d=i?await J(u.arrayBuffer(),i):await u.arrayBuffer()}catch(e){throw e instanceof r?e:i?.aborted?new r(`aborted`):new r(`invalid_input`)}if(d.byteLength!==l-n)throw new r(`invalid_input`);let f=new Uint8Array(d);a.update(f),o.push(ai(Mr(f))),s.push(ai(Br(f)))}return Object.freeze({callerDeclaredContentDigest:`sha256:${xr(a.digest())}`,partChecksums:Object.freeze(o),partMd5s:Object.freeze(s)})}async function qr(e,t,n,i){let a=t.expiresAtEpochMilliseconds-Date.now();if(a<1)throw new r(`invalid_response`);let o=dn(i,Math.min(e.timeoutMilliseconds,a)),s;try{if(s=await J(e.fetchImplementation(t.url,{method:t.method,body:n,headers:t.headers,credentials:`omit`,cache:`no-store`,redirect:`error`,referrerPolicy:`no-referrer`,signal:o.signal}),o.signal),!(s instanceof Response))throw new r(`invalid_response`);let i=s.headers.get(`etag`),a=s.headers.get(`content-md5`),c=a===null||a===t.headers[`content-md5`];if(s.status<200||s.status>299||!oi(i)||!c)throw new r(`invalid_response`,{status:s.status});return i}catch(e){throw o.didTimeout()?new r(`timeout`):i?.aborted?new r(`aborted`):e instanceof r?e:new r(`network_error`)}finally{o.dispose(),s?.body?.cancel().catch(()=>{})}}function Jr(e,t,n,i,a){let o=t===0?`server-mediated-zero-byte`:`presigned-multipart`;if(e.mode!==o||e.partByteLength!==Q||e.partCount!==n||e.expiresAtEpochMilliseconds<=Date.now())throw new r(`invalid_response`,{status:i,requestId:a})}function Yr(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 r(`invalid_response`)}function Xr(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 r(`invalid_response`)}function Zr(e,t,n,i,a){if(e.itemId!==t.itemId||e.versionId!==t.versionId||e.uploadId!==t.uploadId||e.byteLength!==n.byteLength||e.callerDeclaredContentDigest!==i.callerDeclaredContentDigest||e.displayFilename!==n.displayFilename||e.mediaType!==n.mediaType)throw new r(`invalid_response`,{status:200,requestId:a})}function Qr(e,t){if(e===`initiating`||e===`recovery-required`)throw new r(`upload_recovery_required`,{status:409,...t===void 0?{}:{requestId:t}});if(e===`aborting`||e===`aborted`||e===`failed`)throw new r(`precondition_failed`,{status:409,...t===void 0?{}:{requestId:t}})}function $r(e,t){return Object.freeze({data:t,status:e.status,requestId:e.requestId,validators:e.validators})}function ei(e,t){return Math.min(Q,e-(t-1)*Q)}function ti(e,t,n,i){try{let a=e.slice(t,n);if(!(a instanceof Blob)||a.size!==i)throw new r(`invalid_input`);return a}catch(e){throw e instanceof r?e:new r(`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 ni(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 ri(e){return e instanceof r&&(e.code===`network_error`||e.code===`timeout`||e.code===`invalid_response`)}function ii(e){if(e?.aborted)throw new r(`aborted`)}function ai(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t)}function oi(e){return e!==null&&e.length>=1&&e.length<=1024&&/^[\x20-\x7e]+$/.test(e)}function si(e){let t=ln(e),n=wn(t);return Object.freeze({...n,uploadFile:e=>Vr(t,e,n)})}export{e as DRIVE_API_ERROR_CODES,t as DRIVE_API_ERROR_MESSAGES,r as DriveError,si as createDriveClient};
|