@finueva/auth 0.17.0 → 0.18.1
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/README.md +36 -22
- package/dist/device.d.ts +3 -2
- package/dist/device.js +449 -381
- package/dist/index.d.ts +2 -2
- package/dist/index.js +123 -7
- package/dist/server.d.ts +32 -2
- package/dist/server.js +2003 -1792
- package/dist/{types-CqFT4G95.d.ts → types-CrdIcEJ3.d.ts} +16 -2
- package/package.json +1 -1
package/dist/device.js
CHANGED
|
@@ -187,6 +187,7 @@ const messages = {
|
|
|
187
187
|
recipient_unavailable: "The recipient is unavailable.",
|
|
188
188
|
invitation_recipient_mismatch: "The invitation cannot be accepted by this account.",
|
|
189
189
|
invitation_recovery_required: "Invitation administration requires separate recovery.",
|
|
190
|
+
membership_removal_recovery_required: "Membership removal requires separate recovery.",
|
|
190
191
|
email_verification_required: "Email verification is required.",
|
|
191
192
|
invalid_workspace_selection: "The workspace selection is invalid.",
|
|
192
193
|
organization_context_too_large: "The organization context is too large.",
|
|
@@ -212,333 +213,6 @@ var AuthError = class extends Error {
|
|
|
212
213
|
}
|
|
213
214
|
};
|
|
214
215
|
//#endregion
|
|
215
|
-
//#region src/user-api/credential.ts
|
|
216
|
-
function userApiApplication(input) {
|
|
217
|
-
if (!input || typeof input.applicationId !== "string" || !/^[A-Za-z0-9_-]{1,128}$(?![\s\S])/.test(input.applicationId) || input.forceRefresh !== void 0 && typeof input.forceRefresh !== "boolean") throw new TypeError("User API credential input is invalid");
|
|
218
|
-
return input.applicationId;
|
|
219
|
-
}
|
|
220
|
-
function normalizeUserApiCredential(value, startedAt) {
|
|
221
|
-
if (!value || typeof value !== "object" || Array.isArray(value) || !("tokenType" in value) || value.tokenType !== "Bearer" || !("token" in value) || typeof value.token !== "string" || value.token.length + 7 > 16 * 1024 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value.token) || !("expiresIn" in value) || typeof value.expiresIn !== "number" || !Number.isInteger(value.expiresIn) || value.expiresIn < 1 || value.expiresIn > 840 || Object.keys(value).sort().join(",") !== "expiresIn,token,tokenType") throw new AuthError("identity_authority_unavailable", 503);
|
|
222
|
-
return {
|
|
223
|
-
tokenType: "Bearer",
|
|
224
|
-
token: value.token,
|
|
225
|
-
expiresAt: new Date(startedAt + value.expiresIn * 1e3)
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
function createUserApiCredentialCache(issue, now) {
|
|
229
|
-
let generation = 0;
|
|
230
|
-
let cached;
|
|
231
|
-
let pending;
|
|
232
|
-
const copy = (value) => ({
|
|
233
|
-
...value,
|
|
234
|
-
expiresAt: new Date(value.expiresAt)
|
|
235
|
-
});
|
|
236
|
-
return {
|
|
237
|
-
hasAuthority: () => Boolean(cached || pending),
|
|
238
|
-
clear() {
|
|
239
|
-
generation += 1;
|
|
240
|
-
cached = void 0;
|
|
241
|
-
pending = void 0;
|
|
242
|
-
},
|
|
243
|
-
async get(input) {
|
|
244
|
-
const applicationId = userApiApplication(input);
|
|
245
|
-
if (pending) {
|
|
246
|
-
if (pending.applicationId !== applicationId) throw new AuthError("state_conflict", 409);
|
|
247
|
-
return copy(await pending.request);
|
|
248
|
-
}
|
|
249
|
-
const startedAt = now();
|
|
250
|
-
if (!input.forceRefresh && cached?.applicationId === applicationId && cached.expiresAt - startedAt > 12e4) return {
|
|
251
|
-
tokenType: "Bearer",
|
|
252
|
-
token: cached.token,
|
|
253
|
-
expiresAt: new Date(cached.expiresAt)
|
|
254
|
-
};
|
|
255
|
-
cached = void 0;
|
|
256
|
-
const epoch = generation;
|
|
257
|
-
const request = (async () => {
|
|
258
|
-
const value = normalizeUserApiCredential(await issue(applicationId), startedAt);
|
|
259
|
-
if (epoch !== generation) throw new AuthError("state_conflict", 409);
|
|
260
|
-
if (now() < startedAt || value.expiresAt.getTime() <= now()) throw new AuthError("authentication_required", 401);
|
|
261
|
-
cached = {
|
|
262
|
-
applicationId,
|
|
263
|
-
token: value.token,
|
|
264
|
-
expiresAt: value.expiresAt.getTime()
|
|
265
|
-
};
|
|
266
|
-
return value;
|
|
267
|
-
})().finally(() => {
|
|
268
|
-
if (pending?.request === request) pending = void 0;
|
|
269
|
-
});
|
|
270
|
-
pending = {
|
|
271
|
-
applicationId,
|
|
272
|
-
request
|
|
273
|
-
};
|
|
274
|
-
return copy(await request);
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
//#endregion
|
|
279
|
-
//#region ../../node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs
|
|
280
|
-
const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
|
|
281
|
-
const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
282
|
-
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
283
|
-
function jsonParseTransform(key, value) {
|
|
284
|
-
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
285
|
-
warnKeyDropped(key);
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
return value;
|
|
289
|
-
}
|
|
290
|
-
function warnKeyDropped(key) {
|
|
291
|
-
console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
|
|
292
|
-
}
|
|
293
|
-
function destr(value, options = {}) {
|
|
294
|
-
if (typeof value !== "string") return value;
|
|
295
|
-
if (value[0] === "\"" && value[value.length - 1] === "\"" && value.indexOf("\\") === -1) return value.slice(1, -1);
|
|
296
|
-
const _value = value.trim();
|
|
297
|
-
if (_value.length <= 9) switch (_value.toLowerCase()) {
|
|
298
|
-
case "true": return true;
|
|
299
|
-
case "false": return false;
|
|
300
|
-
case "undefined": return;
|
|
301
|
-
case "null": return null;
|
|
302
|
-
case "nan": return NaN;
|
|
303
|
-
case "infinity": return Number.POSITIVE_INFINITY;
|
|
304
|
-
case "-infinity": return Number.NEGATIVE_INFINITY;
|
|
305
|
-
}
|
|
306
|
-
if (!JsonSigRx.test(value)) {
|
|
307
|
-
if (options.strict) throw new SyntaxError("[destr] Invalid JSON");
|
|
308
|
-
return value;
|
|
309
|
-
}
|
|
310
|
-
try {
|
|
311
|
-
if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
|
|
312
|
-
if (options.strict) throw new Error("[destr] Possible prototype pollution");
|
|
313
|
-
return JSON.parse(value, jsonParseTransform);
|
|
314
|
-
}
|
|
315
|
-
return JSON.parse(value);
|
|
316
|
-
} catch (error) {
|
|
317
|
-
if (options.strict) throw error;
|
|
318
|
-
return value;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
//#endregion
|
|
322
|
-
//#region ../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs
|
|
323
|
-
var FetchError = class extends Error {
|
|
324
|
-
constructor(message, opts) {
|
|
325
|
-
super(message, opts);
|
|
326
|
-
this.name = "FetchError";
|
|
327
|
-
if (opts?.cause && !this.cause) this.cause = opts.cause;
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
function createFetchError(ctx) {
|
|
331
|
-
const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
|
|
332
|
-
const method = ctx.request?.method || ctx.options?.method || "GET";
|
|
333
|
-
const url = ctx.request?.url || String(ctx.request) || "/";
|
|
334
|
-
const fetchError = new FetchError(`${`[${method}] ${JSON.stringify(url)}`}: ${ctx.response ? `${ctx.response.status} ${ctx.response.statusText}` : "<no response>"}${errorMessage ? ` ${errorMessage}` : ""}`, ctx.error ? { cause: ctx.error } : void 0);
|
|
335
|
-
for (const key of [
|
|
336
|
-
"request",
|
|
337
|
-
"options",
|
|
338
|
-
"response"
|
|
339
|
-
]) Object.defineProperty(fetchError, key, { get() {
|
|
340
|
-
return ctx[key];
|
|
341
|
-
} });
|
|
342
|
-
for (const [key, refKey] of [
|
|
343
|
-
["data", "_data"],
|
|
344
|
-
["status", "status"],
|
|
345
|
-
["statusCode", "status"],
|
|
346
|
-
["statusText", "statusText"],
|
|
347
|
-
["statusMessage", "statusText"]
|
|
348
|
-
]) Object.defineProperty(fetchError, key, { get() {
|
|
349
|
-
return ctx.response && ctx.response[refKey];
|
|
350
|
-
} });
|
|
351
|
-
return fetchError;
|
|
352
|
-
}
|
|
353
|
-
const payloadMethods = new Set(Object.freeze([
|
|
354
|
-
"PATCH",
|
|
355
|
-
"POST",
|
|
356
|
-
"PUT",
|
|
357
|
-
"DELETE"
|
|
358
|
-
]));
|
|
359
|
-
function isPayloadMethod(method = "GET") {
|
|
360
|
-
return payloadMethods.has(method.toUpperCase());
|
|
361
|
-
}
|
|
362
|
-
function isJSONSerializable(value) {
|
|
363
|
-
if (value === void 0) return false;
|
|
364
|
-
const t = typeof value;
|
|
365
|
-
if (t === "string" || t === "number" || t === "boolean" || t === null) return true;
|
|
366
|
-
if (t !== "object") return false;
|
|
367
|
-
if (Array.isArray(value)) return true;
|
|
368
|
-
if (value.buffer) return false;
|
|
369
|
-
if (value instanceof FormData || value instanceof URLSearchParams) return false;
|
|
370
|
-
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
371
|
-
}
|
|
372
|
-
const textTypes = new Set([
|
|
373
|
-
"image/svg",
|
|
374
|
-
"application/xml",
|
|
375
|
-
"application/xhtml",
|
|
376
|
-
"application/html"
|
|
377
|
-
]);
|
|
378
|
-
const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
|
|
379
|
-
function detectResponseType(_contentType = "") {
|
|
380
|
-
if (!_contentType) return "json";
|
|
381
|
-
const contentType = _contentType.split(";").shift() || "";
|
|
382
|
-
if (JSON_RE.test(contentType)) return "json";
|
|
383
|
-
if (contentType === "text/event-stream") return "stream";
|
|
384
|
-
if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
|
|
385
|
-
return "blob";
|
|
386
|
-
}
|
|
387
|
-
function resolveFetchOptions(request, input, defaults, Headers) {
|
|
388
|
-
const headers = mergeHeaders(input?.headers ?? request?.headers, defaults?.headers, Headers);
|
|
389
|
-
let query;
|
|
390
|
-
if (defaults?.query || defaults?.params || input?.params || input?.query) query = {
|
|
391
|
-
...defaults?.params,
|
|
392
|
-
...defaults?.query,
|
|
393
|
-
...input?.params,
|
|
394
|
-
...input?.query
|
|
395
|
-
};
|
|
396
|
-
return {
|
|
397
|
-
...defaults,
|
|
398
|
-
...input,
|
|
399
|
-
query,
|
|
400
|
-
params: query,
|
|
401
|
-
headers
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
function mergeHeaders(input, defaults, Headers) {
|
|
405
|
-
if (!defaults) return new Headers(input);
|
|
406
|
-
const headers = new Headers(defaults);
|
|
407
|
-
if (input) for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) headers.set(key, value);
|
|
408
|
-
return headers;
|
|
409
|
-
}
|
|
410
|
-
async function callHooks(context, hooks) {
|
|
411
|
-
if (hooks) if (Array.isArray(hooks)) for (const hook of hooks) await hook(context);
|
|
412
|
-
else await hooks(context);
|
|
413
|
-
}
|
|
414
|
-
const retryStatusCodes = new Set([
|
|
415
|
-
408,
|
|
416
|
-
409,
|
|
417
|
-
425,
|
|
418
|
-
429,
|
|
419
|
-
500,
|
|
420
|
-
502,
|
|
421
|
-
503,
|
|
422
|
-
504
|
|
423
|
-
]);
|
|
424
|
-
const nullBodyResponses = new Set([
|
|
425
|
-
101,
|
|
426
|
-
204,
|
|
427
|
-
205,
|
|
428
|
-
304
|
|
429
|
-
]);
|
|
430
|
-
function createFetch(globalOptions = {}) {
|
|
431
|
-
const { fetch = globalThis.fetch, Headers = globalThis.Headers, AbortController = globalThis.AbortController } = globalOptions;
|
|
432
|
-
async function onError(context) {
|
|
433
|
-
const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
|
|
434
|
-
if (context.options.retry !== false && !isAbort) {
|
|
435
|
-
let retries;
|
|
436
|
-
if (typeof context.options.retry === "number") retries = context.options.retry;
|
|
437
|
-
else retries = isPayloadMethod(context.options.method) ? 0 : 1;
|
|
438
|
-
const responseCode = context.response && context.response.status || 500;
|
|
439
|
-
if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
|
|
440
|
-
const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
|
|
441
|
-
if (retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
442
|
-
return $fetchRaw(context.request, {
|
|
443
|
-
...context.options,
|
|
444
|
-
retry: retries - 1
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
const error = createFetchError(context);
|
|
449
|
-
if (Error.captureStackTrace) Error.captureStackTrace(error, $fetchRaw);
|
|
450
|
-
throw error;
|
|
451
|
-
}
|
|
452
|
-
const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
|
|
453
|
-
const context = {
|
|
454
|
-
request: _request,
|
|
455
|
-
options: resolveFetchOptions(_request, _options, globalOptions.defaults, Headers),
|
|
456
|
-
response: void 0,
|
|
457
|
-
error: void 0
|
|
458
|
-
};
|
|
459
|
-
if (context.options.method) context.options.method = context.options.method.toUpperCase();
|
|
460
|
-
if (context.options.onRequest) {
|
|
461
|
-
await callHooks(context, context.options.onRequest);
|
|
462
|
-
if (!(context.options.headers instanceof Headers)) context.options.headers = new Headers(context.options.headers || {});
|
|
463
|
-
}
|
|
464
|
-
if (typeof context.request === "string") {
|
|
465
|
-
if (context.options.baseURL) context.request = withBase(context.request, context.options.baseURL);
|
|
466
|
-
if (context.options.query) {
|
|
467
|
-
context.request = withQuery(context.request, context.options.query);
|
|
468
|
-
delete context.options.query;
|
|
469
|
-
}
|
|
470
|
-
if ("query" in context.options) delete context.options.query;
|
|
471
|
-
if ("params" in context.options) delete context.options.params;
|
|
472
|
-
}
|
|
473
|
-
if (context.options.body && isPayloadMethod(context.options.method)) {
|
|
474
|
-
if (isJSONSerializable(context.options.body)) {
|
|
475
|
-
const contentType = context.options.headers.get("content-type");
|
|
476
|
-
if (typeof context.options.body !== "string") context.options.body = contentType === "application/x-www-form-urlencoded" ? new URLSearchParams(context.options.body).toString() : JSON.stringify(context.options.body);
|
|
477
|
-
if (!contentType) context.options.headers.set("content-type", "application/json");
|
|
478
|
-
if (!context.options.headers.has("accept")) context.options.headers.set("accept", "application/json");
|
|
479
|
-
} else if ("pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || typeof context.options.body.pipe === "function") {
|
|
480
|
-
if (!("duplex" in context.options)) context.options.duplex = "half";
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
let abortTimeout;
|
|
484
|
-
if (!context.options.signal && context.options.timeout) {
|
|
485
|
-
const controller = new AbortController();
|
|
486
|
-
abortTimeout = setTimeout(() => {
|
|
487
|
-
const error = new Error("[TimeoutError]: The operation was aborted due to timeout");
|
|
488
|
-
error.name = "TimeoutError";
|
|
489
|
-
error.code = 23;
|
|
490
|
-
controller.abort(error);
|
|
491
|
-
}, context.options.timeout);
|
|
492
|
-
context.options.signal = controller.signal;
|
|
493
|
-
}
|
|
494
|
-
try {
|
|
495
|
-
context.response = await fetch(context.request, context.options);
|
|
496
|
-
} catch (error) {
|
|
497
|
-
context.error = error;
|
|
498
|
-
if (context.options.onRequestError) await callHooks(context, context.options.onRequestError);
|
|
499
|
-
return await onError(context);
|
|
500
|
-
} finally {
|
|
501
|
-
if (abortTimeout) clearTimeout(abortTimeout);
|
|
502
|
-
}
|
|
503
|
-
if ((context.response.body || context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD") {
|
|
504
|
-
const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
|
|
505
|
-
switch (responseType) {
|
|
506
|
-
case "json": {
|
|
507
|
-
const data = await context.response.text();
|
|
508
|
-
const parseFunction = context.options.parseResponse || destr;
|
|
509
|
-
context.response._data = parseFunction(data);
|
|
510
|
-
break;
|
|
511
|
-
}
|
|
512
|
-
case "stream":
|
|
513
|
-
context.response._data = context.response.body || context.response._bodyInit;
|
|
514
|
-
break;
|
|
515
|
-
default: context.response._data = await context.response[responseType]();
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
if (context.options.onResponse) await callHooks(context, context.options.onResponse);
|
|
519
|
-
if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
|
|
520
|
-
if (context.options.onResponseError) await callHooks(context, context.options.onResponseError);
|
|
521
|
-
return await onError(context);
|
|
522
|
-
}
|
|
523
|
-
return context.response;
|
|
524
|
-
};
|
|
525
|
-
const $fetch = async function $fetch2(request, options) {
|
|
526
|
-
return (await $fetchRaw(request, options))._data;
|
|
527
|
-
};
|
|
528
|
-
$fetch.raw = $fetchRaw;
|
|
529
|
-
$fetch.native = (...args) => fetch(...args);
|
|
530
|
-
$fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
|
|
531
|
-
...globalOptions,
|
|
532
|
-
...customGlobalOptions,
|
|
533
|
-
defaults: {
|
|
534
|
-
...globalOptions.defaults,
|
|
535
|
-
...customGlobalOptions.defaults,
|
|
536
|
-
...defaultOptions
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
return $fetch;
|
|
540
|
-
}
|
|
541
|
-
//#endregion
|
|
542
216
|
//#region src/shared.ts
|
|
543
217
|
const DRIVE_CREDENTIAL_LIFETIME_SECONDS = 840;
|
|
544
218
|
const id = /^[A-Za-z0-9_-]{1,128}$/;
|
|
@@ -716,6 +390,27 @@ function normalizeOrganizationTeamDisplay(value) {
|
|
|
716
390
|
throw authorityUnavailable();
|
|
717
391
|
}
|
|
718
392
|
}
|
|
393
|
+
function normalizeOrganizationCreationInput(name, slug, idempotencyKey) {
|
|
394
|
+
if (!boundedString(name, 255) || !boundedString(idempotencyKey, 255) || typeof slug !== "string" || !/^[a-z0-9-]{1,128}$/.test(slug)) throw new AuthError("invalid_request", 400);
|
|
395
|
+
return {
|
|
396
|
+
name,
|
|
397
|
+
slug,
|
|
398
|
+
idempotencyKey
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function normalizeCreatedOrganization(value) {
|
|
402
|
+
exact(value, [
|
|
403
|
+
"id",
|
|
404
|
+
"name",
|
|
405
|
+
"slug"
|
|
406
|
+
]);
|
|
407
|
+
if (!isId(value.id) || !boundedString(value.name, 255) || !boundedString(value.slug, 128)) throw authorityUnavailable();
|
|
408
|
+
return {
|
|
409
|
+
id: value.id,
|
|
410
|
+
name: value.name,
|
|
411
|
+
slug: value.slug
|
|
412
|
+
};
|
|
413
|
+
}
|
|
719
414
|
function normalizeOrganizationTeamCreationInput(name, idempotencyKey) {
|
|
720
415
|
if (!boundedString(name, 255) || !boundedString(idempotencyKey, 255)) throw new AuthError("invalid_request", 400);
|
|
721
416
|
return {
|
|
@@ -1055,67 +750,416 @@ function parseRetryAfter(value) {
|
|
|
1055
750
|
const seconds = Number(value);
|
|
1056
751
|
return Number.isSafeInteger(seconds) && seconds >= 1 && seconds <= 3600 ? seconds : void 0;
|
|
1057
752
|
}
|
|
1058
|
-
function toDate(value) {
|
|
1059
|
-
const result = value instanceof Date ? value : typeof value === "string" ? new Date(value) : void 0;
|
|
1060
|
-
return result && Number.isFinite(result.getTime()) ? result : void 0;
|
|
753
|
+
function toDate(value) {
|
|
754
|
+
const result = value instanceof Date ? value : typeof value === "string" ? new Date(value) : void 0;
|
|
755
|
+
return result && Number.isFinite(result.getTime()) ? result : void 0;
|
|
756
|
+
}
|
|
757
|
+
function normalizeProfileImage(value) {
|
|
758
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 2048 || /[^\x20-\x7e]/.test(value)) throw new TypeError("profile image is invalid");
|
|
759
|
+
let url;
|
|
760
|
+
try {
|
|
761
|
+
url = new URL(value);
|
|
762
|
+
} catch {
|
|
763
|
+
throw new TypeError("profile image is invalid");
|
|
764
|
+
}
|
|
765
|
+
const local = url.hostname === "localhost" || url.hostname.endsWith(".localhost") || url.hostname === "127.0.0.1";
|
|
766
|
+
if (url.protocol !== "https:" && !(local && url.protocol === "http:") || url.username || url.password || url.toString() !== value) throw new TypeError("profile image is invalid");
|
|
767
|
+
return value;
|
|
768
|
+
}
|
|
769
|
+
function isId(value) {
|
|
770
|
+
return typeof value === "string" && id.test(value);
|
|
771
|
+
}
|
|
772
|
+
function exact(value, keys) {
|
|
773
|
+
if (!isObject(value) || Object.keys(value).sort().join(",") !== [...keys].sort().join(",")) throw authorityUnavailable();
|
|
774
|
+
}
|
|
775
|
+
function boundedString(value, maximum) {
|
|
776
|
+
return typeof value === "string" && value.length > 0 && new TextEncoder().encode(value).byteLength <= maximum;
|
|
777
|
+
}
|
|
778
|
+
function role(value) {
|
|
779
|
+
return value === "owner" || value === "admin" || value === "member";
|
|
780
|
+
}
|
|
781
|
+
function nullableHttpsUrl(value) {
|
|
782
|
+
if (value === null) return null;
|
|
783
|
+
if (typeof value !== "string" || value.length > 2048) throw authorityUnavailable();
|
|
784
|
+
let url;
|
|
785
|
+
try {
|
|
786
|
+
url = new URL(value);
|
|
787
|
+
} catch {
|
|
788
|
+
throw authorityUnavailable();
|
|
789
|
+
}
|
|
790
|
+
if (url.protocol !== "https:" || url.username || url.password || url.toString() !== value) throw authorityUnavailable();
|
|
791
|
+
return value;
|
|
792
|
+
}
|
|
793
|
+
function responseDate(value) {
|
|
794
|
+
if (typeof value !== "string") throw authorityUnavailable();
|
|
795
|
+
const date = new Date(value);
|
|
796
|
+
if (!Number.isFinite(date.getTime()) || date.toISOString() !== value) throw authorityUnavailable();
|
|
797
|
+
return date;
|
|
798
|
+
}
|
|
799
|
+
function nullableCursor(value) {
|
|
800
|
+
if (value === null) return null;
|
|
801
|
+
if (typeof value !== "string" || value.length < 1 || value.length > 820 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value)) throw authorityUnavailable();
|
|
802
|
+
return value;
|
|
803
|
+
}
|
|
804
|
+
function normalizeResponseId(value) {
|
|
805
|
+
if (!isId(value)) throw authorityUnavailable();
|
|
806
|
+
return value;
|
|
807
|
+
}
|
|
808
|
+
function unique(items, key) {
|
|
809
|
+
if (new Set(items.map(key)).size !== items.length) throw authorityUnavailable();
|
|
810
|
+
return items;
|
|
811
|
+
}
|
|
812
|
+
function credentialSessionId(token) {
|
|
813
|
+
const parts = token.split(".");
|
|
814
|
+
if (parts.length !== 3 || !/^[A-Za-z0-9_-]+$/.test(parts[1])) return void 0;
|
|
815
|
+
try {
|
|
816
|
+
const base64 = parts[1].replaceAll("-", "+").replaceAll("_", "/");
|
|
817
|
+
const decoded = atob(base64.padEnd(base64.length + (4 - base64.length % 4) % 4, "="));
|
|
818
|
+
const payload = JSON.parse(decoded);
|
|
819
|
+
return isObject(payload) && typeof payload.sid === "string" && payload.sid.length > 0 ? payload.sid : void 0;
|
|
820
|
+
} catch {
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function isObject(value) {
|
|
825
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
826
|
+
}
|
|
827
|
+
//#endregion
|
|
828
|
+
//#region src/user-api/credential.ts
|
|
829
|
+
function userApiApplication(input) {
|
|
830
|
+
if (!input || typeof input.applicationId !== "string" || !/^[A-Za-z0-9_-]{1,128}$(?![\s\S])/.test(input.applicationId) || input.forceRefresh !== void 0 && typeof input.forceRefresh !== "boolean") throw new TypeError("User API credential input is invalid");
|
|
831
|
+
return input.applicationId;
|
|
832
|
+
}
|
|
833
|
+
function normalizeUserApiCredential(value, startedAt) {
|
|
834
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || !("tokenType" in value) || value.tokenType !== "Bearer" || !("token" in value) || typeof value.token !== "string" || value.token.length + 7 > 16 * 1024 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value.token) || !("expiresIn" in value) || typeof value.expiresIn !== "number" || !Number.isInteger(value.expiresIn) || value.expiresIn < 1 || value.expiresIn > 840 || Object.keys(value).sort().join(",") !== "expiresIn,token,tokenType") throw new AuthError("identity_authority_unavailable", 503);
|
|
835
|
+
return {
|
|
836
|
+
tokenType: "Bearer",
|
|
837
|
+
token: value.token,
|
|
838
|
+
expiresAt: new Date(startedAt + value.expiresIn * 1e3)
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
function createUserApiCredentialCache(issue, now, currentSessionId = () => void 0) {
|
|
842
|
+
let generation = 0;
|
|
843
|
+
let cached;
|
|
844
|
+
let pending;
|
|
845
|
+
const copy = (value) => ({
|
|
846
|
+
...value,
|
|
847
|
+
expiresAt: new Date(value.expiresAt)
|
|
848
|
+
});
|
|
849
|
+
return {
|
|
850
|
+
hasAuthority: () => Boolean(cached || pending),
|
|
851
|
+
retainSession(sessionId) {
|
|
852
|
+
if (cached?.sessionId === sessionId && !pending) return;
|
|
853
|
+
generation += 1;
|
|
854
|
+
cached = void 0;
|
|
855
|
+
pending = void 0;
|
|
856
|
+
},
|
|
857
|
+
clear() {
|
|
858
|
+
generation += 1;
|
|
859
|
+
cached = void 0;
|
|
860
|
+
pending = void 0;
|
|
861
|
+
},
|
|
862
|
+
async get(input) {
|
|
863
|
+
const applicationId = userApiApplication(input);
|
|
864
|
+
if (pending) {
|
|
865
|
+
if (pending.applicationId !== applicationId) throw new AuthError("state_conflict", 409);
|
|
866
|
+
return copy(await pending.request);
|
|
867
|
+
}
|
|
868
|
+
const startedAt = now();
|
|
869
|
+
if (!input.forceRefresh && cached?.applicationId === applicationId && cached.expiresAt - startedAt > 12e4) return {
|
|
870
|
+
tokenType: "Bearer",
|
|
871
|
+
token: cached.token,
|
|
872
|
+
expiresAt: new Date(cached.expiresAt)
|
|
873
|
+
};
|
|
874
|
+
cached = void 0;
|
|
875
|
+
const epoch = generation;
|
|
876
|
+
const request = (async () => {
|
|
877
|
+
const value = normalizeUserApiCredential(await issue(applicationId), startedAt);
|
|
878
|
+
if (epoch !== generation) throw new AuthError("state_conflict", 409);
|
|
879
|
+
if (now() < startedAt || value.expiresAt.getTime() <= now()) throw new AuthError("authentication_required", 401);
|
|
880
|
+
const sessionId = credentialSessionId(value.token);
|
|
881
|
+
const observed = currentSessionId();
|
|
882
|
+
if (observed !== void 0 && sessionId !== void 0 && sessionId !== observed) throw new AuthError("authentication_required", 401);
|
|
883
|
+
cached = {
|
|
884
|
+
applicationId,
|
|
885
|
+
token: value.token,
|
|
886
|
+
expiresAt: value.expiresAt.getTime(),
|
|
887
|
+
sessionId
|
|
888
|
+
};
|
|
889
|
+
return value;
|
|
890
|
+
})().finally(() => {
|
|
891
|
+
if (pending?.request === request) pending = void 0;
|
|
892
|
+
});
|
|
893
|
+
pending = {
|
|
894
|
+
applicationId,
|
|
895
|
+
request
|
|
896
|
+
};
|
|
897
|
+
return copy(await request);
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
//#endregion
|
|
902
|
+
//#region ../../node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs
|
|
903
|
+
const suspectProtoRx = /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/;
|
|
904
|
+
const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
905
|
+
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
906
|
+
function jsonParseTransform(key, value) {
|
|
907
|
+
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
908
|
+
warnKeyDropped(key);
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
return value;
|
|
912
|
+
}
|
|
913
|
+
function warnKeyDropped(key) {
|
|
914
|
+
console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
|
|
915
|
+
}
|
|
916
|
+
function destr(value, options = {}) {
|
|
917
|
+
if (typeof value !== "string") return value;
|
|
918
|
+
if (value[0] === "\"" && value[value.length - 1] === "\"" && value.indexOf("\\") === -1) return value.slice(1, -1);
|
|
919
|
+
const _value = value.trim();
|
|
920
|
+
if (_value.length <= 9) switch (_value.toLowerCase()) {
|
|
921
|
+
case "true": return true;
|
|
922
|
+
case "false": return false;
|
|
923
|
+
case "undefined": return;
|
|
924
|
+
case "null": return null;
|
|
925
|
+
case "nan": return NaN;
|
|
926
|
+
case "infinity": return Number.POSITIVE_INFINITY;
|
|
927
|
+
case "-infinity": return Number.NEGATIVE_INFINITY;
|
|
928
|
+
}
|
|
929
|
+
if (!JsonSigRx.test(value)) {
|
|
930
|
+
if (options.strict) throw new SyntaxError("[destr] Invalid JSON");
|
|
931
|
+
return value;
|
|
932
|
+
}
|
|
933
|
+
try {
|
|
934
|
+
if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
|
|
935
|
+
if (options.strict) throw new Error("[destr] Possible prototype pollution");
|
|
936
|
+
return JSON.parse(value, jsonParseTransform);
|
|
937
|
+
}
|
|
938
|
+
return JSON.parse(value);
|
|
939
|
+
} catch (error) {
|
|
940
|
+
if (options.strict) throw error;
|
|
941
|
+
return value;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
//#endregion
|
|
945
|
+
//#region ../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs
|
|
946
|
+
var FetchError = class extends Error {
|
|
947
|
+
constructor(message, opts) {
|
|
948
|
+
super(message, opts);
|
|
949
|
+
this.name = "FetchError";
|
|
950
|
+
if (opts?.cause && !this.cause) this.cause = opts.cause;
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
function createFetchError(ctx) {
|
|
954
|
+
const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
|
|
955
|
+
const method = ctx.request?.method || ctx.options?.method || "GET";
|
|
956
|
+
const url = ctx.request?.url || String(ctx.request) || "/";
|
|
957
|
+
const fetchError = new FetchError(`${`[${method}] ${JSON.stringify(url)}`}: ${ctx.response ? `${ctx.response.status} ${ctx.response.statusText}` : "<no response>"}${errorMessage ? ` ${errorMessage}` : ""}`, ctx.error ? { cause: ctx.error } : void 0);
|
|
958
|
+
for (const key of [
|
|
959
|
+
"request",
|
|
960
|
+
"options",
|
|
961
|
+
"response"
|
|
962
|
+
]) Object.defineProperty(fetchError, key, { get() {
|
|
963
|
+
return ctx[key];
|
|
964
|
+
} });
|
|
965
|
+
for (const [key, refKey] of [
|
|
966
|
+
["data", "_data"],
|
|
967
|
+
["status", "status"],
|
|
968
|
+
["statusCode", "status"],
|
|
969
|
+
["statusText", "statusText"],
|
|
970
|
+
["statusMessage", "statusText"]
|
|
971
|
+
]) Object.defineProperty(fetchError, key, { get() {
|
|
972
|
+
return ctx.response && ctx.response[refKey];
|
|
973
|
+
} });
|
|
974
|
+
return fetchError;
|
|
975
|
+
}
|
|
976
|
+
const payloadMethods = new Set(Object.freeze([
|
|
977
|
+
"PATCH",
|
|
978
|
+
"POST",
|
|
979
|
+
"PUT",
|
|
980
|
+
"DELETE"
|
|
981
|
+
]));
|
|
982
|
+
function isPayloadMethod(method = "GET") {
|
|
983
|
+
return payloadMethods.has(method.toUpperCase());
|
|
1061
984
|
}
|
|
1062
|
-
function
|
|
1063
|
-
if (
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
if (url.protocol !== "https:" && !(local && url.protocol === "http:") || url.username || url.password || url.toString() !== value) throw new TypeError("profile image is invalid");
|
|
1072
|
-
return value;
|
|
985
|
+
function isJSONSerializable(value) {
|
|
986
|
+
if (value === void 0) return false;
|
|
987
|
+
const t = typeof value;
|
|
988
|
+
if (t === "string" || t === "number" || t === "boolean" || t === null) return true;
|
|
989
|
+
if (t !== "object") return false;
|
|
990
|
+
if (Array.isArray(value)) return true;
|
|
991
|
+
if (value.buffer) return false;
|
|
992
|
+
if (value instanceof FormData || value instanceof URLSearchParams) return false;
|
|
993
|
+
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
1073
994
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
995
|
+
const textTypes = new Set([
|
|
996
|
+
"image/svg",
|
|
997
|
+
"application/xml",
|
|
998
|
+
"application/xhtml",
|
|
999
|
+
"application/html"
|
|
1000
|
+
]);
|
|
1001
|
+
const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
|
|
1002
|
+
function detectResponseType(_contentType = "") {
|
|
1003
|
+
if (!_contentType) return "json";
|
|
1004
|
+
const contentType = _contentType.split(";").shift() || "";
|
|
1005
|
+
if (JSON_RE.test(contentType)) return "json";
|
|
1006
|
+
if (contentType === "text/event-stream") return "stream";
|
|
1007
|
+
if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
|
|
1008
|
+
return "blob";
|
|
1076
1009
|
}
|
|
1077
|
-
function
|
|
1078
|
-
|
|
1010
|
+
function resolveFetchOptions(request, input, defaults, Headers) {
|
|
1011
|
+
const headers = mergeHeaders(input?.headers ?? request?.headers, defaults?.headers, Headers);
|
|
1012
|
+
let query;
|
|
1013
|
+
if (defaults?.query || defaults?.params || input?.params || input?.query) query = {
|
|
1014
|
+
...defaults?.params,
|
|
1015
|
+
...defaults?.query,
|
|
1016
|
+
...input?.params,
|
|
1017
|
+
...input?.query
|
|
1018
|
+
};
|
|
1019
|
+
return {
|
|
1020
|
+
...defaults,
|
|
1021
|
+
...input,
|
|
1022
|
+
query,
|
|
1023
|
+
params: query,
|
|
1024
|
+
headers
|
|
1025
|
+
};
|
|
1079
1026
|
}
|
|
1080
|
-
function
|
|
1081
|
-
|
|
1027
|
+
function mergeHeaders(input, defaults, Headers) {
|
|
1028
|
+
if (!defaults) return new Headers(input);
|
|
1029
|
+
const headers = new Headers(defaults);
|
|
1030
|
+
if (input) for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) headers.set(key, value);
|
|
1031
|
+
return headers;
|
|
1082
1032
|
}
|
|
1083
|
-
function
|
|
1084
|
-
|
|
1033
|
+
async function callHooks(context, hooks) {
|
|
1034
|
+
if (hooks) if (Array.isArray(hooks)) for (const hook of hooks) await hook(context);
|
|
1035
|
+
else await hooks(context);
|
|
1085
1036
|
}
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1037
|
+
const retryStatusCodes = new Set([
|
|
1038
|
+
408,
|
|
1039
|
+
409,
|
|
1040
|
+
425,
|
|
1041
|
+
429,
|
|
1042
|
+
500,
|
|
1043
|
+
502,
|
|
1044
|
+
503,
|
|
1045
|
+
504
|
|
1046
|
+
]);
|
|
1047
|
+
const nullBodyResponses = new Set([
|
|
1048
|
+
101,
|
|
1049
|
+
204,
|
|
1050
|
+
205,
|
|
1051
|
+
304
|
|
1052
|
+
]);
|
|
1053
|
+
function createFetch(globalOptions = {}) {
|
|
1054
|
+
const { fetch = globalThis.fetch, Headers = globalThis.Headers, AbortController = globalThis.AbortController } = globalOptions;
|
|
1055
|
+
async function onError(context) {
|
|
1056
|
+
const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
|
|
1057
|
+
if (context.options.retry !== false && !isAbort) {
|
|
1058
|
+
let retries;
|
|
1059
|
+
if (typeof context.options.retry === "number") retries = context.options.retry;
|
|
1060
|
+
else retries = isPayloadMethod(context.options.method) ? 0 : 1;
|
|
1061
|
+
const responseCode = context.response && context.response.status || 500;
|
|
1062
|
+
if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
|
|
1063
|
+
const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
|
|
1064
|
+
if (retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
1065
|
+
return $fetchRaw(context.request, {
|
|
1066
|
+
...context.options,
|
|
1067
|
+
retry: retries - 1
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
const error = createFetchError(context);
|
|
1072
|
+
if (Error.captureStackTrace) Error.captureStackTrace(error, $fetchRaw);
|
|
1073
|
+
throw error;
|
|
1094
1074
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1075
|
+
const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
|
|
1076
|
+
const context = {
|
|
1077
|
+
request: _request,
|
|
1078
|
+
options: resolveFetchOptions(_request, _options, globalOptions.defaults, Headers),
|
|
1079
|
+
response: void 0,
|
|
1080
|
+
error: void 0
|
|
1081
|
+
};
|
|
1082
|
+
if (context.options.method) context.options.method = context.options.method.toUpperCase();
|
|
1083
|
+
if (context.options.onRequest) {
|
|
1084
|
+
await callHooks(context, context.options.onRequest);
|
|
1085
|
+
if (!(context.options.headers instanceof Headers)) context.options.headers = new Headers(context.options.headers || {});
|
|
1086
|
+
}
|
|
1087
|
+
if (typeof context.request === "string") {
|
|
1088
|
+
if (context.options.baseURL) context.request = withBase(context.request, context.options.baseURL);
|
|
1089
|
+
if (context.options.query) {
|
|
1090
|
+
context.request = withQuery(context.request, context.options.query);
|
|
1091
|
+
delete context.options.query;
|
|
1092
|
+
}
|
|
1093
|
+
if ("query" in context.options) delete context.options.query;
|
|
1094
|
+
if ("params" in context.options) delete context.options.params;
|
|
1095
|
+
}
|
|
1096
|
+
if (context.options.body && isPayloadMethod(context.options.method)) {
|
|
1097
|
+
if (isJSONSerializable(context.options.body)) {
|
|
1098
|
+
const contentType = context.options.headers.get("content-type");
|
|
1099
|
+
if (typeof context.options.body !== "string") context.options.body = contentType === "application/x-www-form-urlencoded" ? new URLSearchParams(context.options.body).toString() : JSON.stringify(context.options.body);
|
|
1100
|
+
if (!contentType) context.options.headers.set("content-type", "application/json");
|
|
1101
|
+
if (!context.options.headers.has("accept")) context.options.headers.set("accept", "application/json");
|
|
1102
|
+
} else if ("pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || typeof context.options.body.pipe === "function") {
|
|
1103
|
+
if (!("duplex" in context.options)) context.options.duplex = "half";
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
let abortTimeout;
|
|
1107
|
+
if (!context.options.signal && context.options.timeout) {
|
|
1108
|
+
const controller = new AbortController();
|
|
1109
|
+
abortTimeout = setTimeout(() => {
|
|
1110
|
+
const error = new Error("[TimeoutError]: The operation was aborted due to timeout");
|
|
1111
|
+
error.name = "TimeoutError";
|
|
1112
|
+
error.code = 23;
|
|
1113
|
+
controller.abort(error);
|
|
1114
|
+
}, context.options.timeout);
|
|
1115
|
+
context.options.signal = controller.signal;
|
|
1116
|
+
}
|
|
1117
|
+
try {
|
|
1118
|
+
context.response = await fetch(context.request, context.options);
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
context.error = error;
|
|
1121
|
+
if (context.options.onRequestError) await callHooks(context, context.options.onRequestError);
|
|
1122
|
+
return await onError(context);
|
|
1123
|
+
} finally {
|
|
1124
|
+
if (abortTimeout) clearTimeout(abortTimeout);
|
|
1125
|
+
}
|
|
1126
|
+
if ((context.response.body || context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD") {
|
|
1127
|
+
const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
|
|
1128
|
+
switch (responseType) {
|
|
1129
|
+
case "json": {
|
|
1130
|
+
const data = await context.response.text();
|
|
1131
|
+
const parseFunction = context.options.parseResponse || destr;
|
|
1132
|
+
context.response._data = parseFunction(data);
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
case "stream":
|
|
1136
|
+
context.response._data = context.response.body || context.response._bodyInit;
|
|
1137
|
+
break;
|
|
1138
|
+
default: context.response._data = await context.response[responseType]();
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
if (context.options.onResponse) await callHooks(context, context.options.onResponse);
|
|
1142
|
+
if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
|
|
1143
|
+
if (context.options.onResponseError) await callHooks(context, context.options.onResponseError);
|
|
1144
|
+
return await onError(context);
|
|
1145
|
+
}
|
|
1146
|
+
return context.response;
|
|
1147
|
+
};
|
|
1148
|
+
const $fetch = async function $fetch2(request, options) {
|
|
1149
|
+
return (await $fetchRaw(request, options))._data;
|
|
1150
|
+
};
|
|
1151
|
+
$fetch.raw = $fetchRaw;
|
|
1152
|
+
$fetch.native = (...args) => fetch(...args);
|
|
1153
|
+
$fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
|
|
1154
|
+
...globalOptions,
|
|
1155
|
+
...customGlobalOptions,
|
|
1156
|
+
defaults: {
|
|
1157
|
+
...globalOptions.defaults,
|
|
1158
|
+
...customGlobalOptions.defaults,
|
|
1159
|
+
...defaultOptions
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
return $fetch;
|
|
1119
1163
|
}
|
|
1120
1164
|
//#endregion
|
|
1121
1165
|
//#region src/http.ts
|
|
@@ -1595,6 +1639,30 @@ function createDeviceAuth(options) {
|
|
|
1595
1639
|
const member = normalizeIdInput(memberId);
|
|
1596
1640
|
return serializeAuthority(() => organizationRead(`${organization}/members/${member}/authority`, void 0, (value) => normalizeOrganizationMemberAuthority(value, organization, member)));
|
|
1597
1641
|
},
|
|
1642
|
+
createOrganization(name, slug, idempotencyKey) {
|
|
1643
|
+
let body;
|
|
1644
|
+
try {
|
|
1645
|
+
body = normalizeOrganizationCreationInput(name, slug, idempotencyKey);
|
|
1646
|
+
} catch (error) {
|
|
1647
|
+
return Promise.reject(error);
|
|
1648
|
+
}
|
|
1649
|
+
return serializeAuthority(async () => {
|
|
1650
|
+
const current = await readToken();
|
|
1651
|
+
if (!current) throw new AuthError("authentication_required", 401);
|
|
1652
|
+
return normalizeCreatedOrganization((await requestJsonResponse(joinURL(authOrigin, "api/v1/auth/organizations"), {
|
|
1653
|
+
fetch: requestFetch,
|
|
1654
|
+
timeoutMs,
|
|
1655
|
+
method: "POST",
|
|
1656
|
+
credentials: "omit",
|
|
1657
|
+
headers: {
|
|
1658
|
+
authorization: `Bearer ${current.accessToken}`,
|
|
1659
|
+
"content-type": "application/json"
|
|
1660
|
+
},
|
|
1661
|
+
body,
|
|
1662
|
+
mapError: fromOrganizationMutationAuthorityError
|
|
1663
|
+
})).value);
|
|
1664
|
+
});
|
|
1665
|
+
},
|
|
1598
1666
|
createOrganizationTeam(organizationId, name, idempotencyKey) {
|
|
1599
1667
|
let id;
|
|
1600
1668
|
let body;
|