@finueva/auth 0.18.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/dist/device.js +425 -403
- package/dist/index.js +35 -7
- package/dist/server.js +1827 -1827
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -213,1959 +213,1959 @@ var AuthError = class extends Error {
|
|
|
213
213
|
}
|
|
214
214
|
};
|
|
215
215
|
//#endregion
|
|
216
|
-
//#region src/
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
//#region src/shared.ts
|
|
217
|
+
const DRIVE_CREDENTIAL_LIFETIME_SECONDS = 840;
|
|
218
|
+
const id = /^[A-Za-z0-9_-]{1,128}$/;
|
|
219
|
+
const email = /^[^\s@]+@[^\s@]+$/;
|
|
220
|
+
const MAX_SOCIAL_ID_TOKEN_BYTES = 16 * 1024;
|
|
221
|
+
function normalizeEmail(value) {
|
|
222
|
+
if (typeof value !== "string") throw new TypeError("email is invalid");
|
|
223
|
+
const normalized = value.trim().toLowerCase();
|
|
224
|
+
if (normalized.length === 0 || normalized.length > 320 || !email.test(normalized)) throw new TypeError("email is invalid");
|
|
225
|
+
return normalized;
|
|
220
226
|
}
|
|
221
|
-
function
|
|
222
|
-
if (!
|
|
227
|
+
function normalizeSocialIdTokenInput(value) {
|
|
228
|
+
if (!isObject$1(value)) throw new TypeError("social ID token input is invalid");
|
|
229
|
+
const keys = Object.keys(value);
|
|
230
|
+
if (keys.length !== 3 && keys.length !== 4 || keys.some((key) => key !== "provider" && key !== "idToken" && key !== "nonce" && key !== "signUp") || value.provider !== "google" && value.provider !== "apple" || typeof value.signUp !== "boolean" || typeof value.idToken !== "string" || value.idToken.length < 1 || new TextEncoder().encode(value.idToken).byteLength > MAX_SOCIAL_ID_TOKEN_BYTES || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value.idToken) || value.nonce !== void 0 && (typeof value.nonce !== "string" || value.nonce.length < 1 || value.nonce.length > 256 || !/^[\x20-\x7e]+$/.test(value.nonce))) throw new TypeError("social ID token input is invalid");
|
|
231
|
+
return {
|
|
232
|
+
provider: value.provider,
|
|
233
|
+
idToken: value.idToken,
|
|
234
|
+
...value.nonce === void 0 ? {} : { nonce: value.nonce },
|
|
235
|
+
signUp: value.signUp
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function socialIdTokenRequest(value) {
|
|
239
|
+
return {
|
|
240
|
+
provider: value.provider,
|
|
241
|
+
idToken: {
|
|
242
|
+
token: value.idToken,
|
|
243
|
+
...value.nonce === void 0 ? {} : { nonce: value.nonce }
|
|
244
|
+
},
|
|
245
|
+
requestSignUp: value.signUp
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function normalizeOrigin(value, name) {
|
|
249
|
+
if (value.length === 0 || value.length > 2048 || /[^\x20-\x7e]/.test(value)) throw new TypeError(`${name} must be an ASCII HTTP origin`);
|
|
250
|
+
let url;
|
|
251
|
+
try {
|
|
252
|
+
url = new URL(value);
|
|
253
|
+
} catch {
|
|
254
|
+
throw new TypeError(`${name} must be an ASCII HTTP origin`);
|
|
255
|
+
}
|
|
256
|
+
const local = url.hostname === "localhost" || url.hostname.endsWith(".localhost") || url.hostname === "127.0.0.1";
|
|
257
|
+
if (url.protocol !== "https:" && !(local && url.protocol === "http:") || url.username || url.password || url.pathname !== "/" || url.search || url.hash || url.origin !== value) throw new TypeError(`${name} must be an ASCII HTTP origin`);
|
|
258
|
+
return url.origin;
|
|
259
|
+
}
|
|
260
|
+
function normalizeTimeout(value) {
|
|
261
|
+
const timeout = value ?? 1e4;
|
|
262
|
+
if (!Number.isSafeInteger(timeout) || timeout < 1 || timeout > 6e4) throw new TypeError("timeoutMs must be an integer from 1 to 60000");
|
|
263
|
+
return timeout;
|
|
264
|
+
}
|
|
265
|
+
function normalizeSession(value) {
|
|
266
|
+
if (value === null) return null;
|
|
267
|
+
if (!isObject$1(value) || !isObject$1(value.session) || !isObject$1(value.user)) throw authorityUnavailable();
|
|
268
|
+
const expiresAt = toDate(value.session.expiresAt);
|
|
269
|
+
const image = value.user.image;
|
|
270
|
+
if (!isId(value.session.id) || !expiresAt || !isId(value.user.id) || typeof value.user.name !== "string" || value.user.name.length > 256 || typeof value.user.email !== "string" || value.user.email.length > 320 || !email.test(value.user.email) || typeof value.user.emailVerified !== "boolean" || image !== null && image !== void 0 && (typeof image !== "string" || image.length > 2048)) throw authorityUnavailable();
|
|
271
|
+
return {
|
|
272
|
+
id: value.session.id,
|
|
273
|
+
expiresAt,
|
|
274
|
+
user: {
|
|
275
|
+
id: value.user.id,
|
|
276
|
+
name: value.user.name,
|
|
277
|
+
email: value.user.email,
|
|
278
|
+
emailVerified: value.user.emailVerified,
|
|
279
|
+
image: image ?? null
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function normalizeDriveCredential(value, now) {
|
|
284
|
+
if (!isObject$1(value) || value.tokenType !== "Bearer" || value.expiresIn !== DRIVE_CREDENTIAL_LIFETIME_SECONDS || typeof value.token !== "string" || value.token.length === 0 || new TextEncoder().encode(`Bearer ${value.token}`).byteLength > 16 * 1024) throw authorityUnavailable();
|
|
223
285
|
return {
|
|
224
286
|
tokenType: "Bearer",
|
|
225
287
|
token: value.token,
|
|
226
|
-
expiresAt: new Date(
|
|
288
|
+
expiresAt: new Date(now + value.expiresIn * 1e3)
|
|
227
289
|
};
|
|
228
290
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
for (const buffer of buffers) {
|
|
238
|
-
buf.set(buffer, i);
|
|
239
|
-
i += buffer.length;
|
|
291
|
+
function normalizeOrganizationPageInput(value) {
|
|
292
|
+
if (value === void 0) return new URLSearchParams();
|
|
293
|
+
if (!isObject$1(value) || Object.keys(value).some((key) => key !== "limit" && key !== "cursor")) throw new AuthError("invalid_request", 400);
|
|
294
|
+
const input = value;
|
|
295
|
+
const query = new URLSearchParams();
|
|
296
|
+
if (input.limit !== void 0) {
|
|
297
|
+
if (!Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 100) throw new AuthError("invalid_request", 400);
|
|
298
|
+
query.set("limit", String(input.limit));
|
|
240
299
|
}
|
|
241
|
-
|
|
300
|
+
if (input.cursor !== void 0) {
|
|
301
|
+
if (typeof input.cursor !== "string" || input.cursor.length < 1 || input.cursor.length > 820 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(input.cursor)) throw new AuthError("invalid_request", 400);
|
|
302
|
+
query.set("cursor", input.cursor);
|
|
303
|
+
}
|
|
304
|
+
return query;
|
|
242
305
|
}
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
306
|
+
function normalizeIdInput(value) {
|
|
307
|
+
if (!isId(value)) throw new AuthError("invalid_request", 400);
|
|
308
|
+
return value;
|
|
309
|
+
}
|
|
310
|
+
function normalizeOrganization(value) {
|
|
311
|
+
exact$3(value, [
|
|
312
|
+
"capabilities",
|
|
313
|
+
"id",
|
|
314
|
+
"lifecycle",
|
|
315
|
+
"logo",
|
|
316
|
+
"name",
|
|
317
|
+
"role",
|
|
318
|
+
"slug"
|
|
319
|
+
]);
|
|
320
|
+
if (!isId(value.id) || !boundedString(value.name, 255) || !boundedString(value.slug, 255) || value.lifecycle !== "ordinary" && value.lifecycle !== "managed" || !role(value.role) || !isObject$1(value.capabilities)) throw authorityUnavailable();
|
|
321
|
+
exact$3(value.capabilities, [
|
|
322
|
+
"readInvitations",
|
|
323
|
+
"readMembers",
|
|
324
|
+
"readTeams"
|
|
325
|
+
]);
|
|
326
|
+
if (value.capabilities.readMembers !== true || value.capabilities.readTeams !== true || typeof value.capabilities.readInvitations !== "boolean") throw authorityUnavailable();
|
|
327
|
+
return {
|
|
328
|
+
id: value.id,
|
|
329
|
+
name: value.name,
|
|
330
|
+
slug: value.slug,
|
|
331
|
+
logo: nullableHttpsUrl(value.logo),
|
|
332
|
+
lifecycle: value.lifecycle,
|
|
333
|
+
role: value.role,
|
|
334
|
+
capabilities: {
|
|
335
|
+
readMembers: true,
|
|
336
|
+
readTeams: true,
|
|
337
|
+
readInvitations: value.capabilities.readInvitations
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function normalizeOrganizationDisplayInput(value) {
|
|
342
|
+
if (!isObject$1(value) || Object.keys(value).sort().join(",") !== "logo,name,slug") throw new AuthError("invalid_request", 400);
|
|
343
|
+
if (!boundedString(value.name, 255) || !boundedString(value.slug, 255)) throw new AuthError("invalid_request", 400);
|
|
344
|
+
let logo;
|
|
345
|
+
try {
|
|
346
|
+
logo = nullableHttpsUrl(value.logo);
|
|
347
|
+
} catch {
|
|
348
|
+
throw new AuthError("invalid_request", 400);
|
|
249
349
|
}
|
|
250
|
-
return
|
|
350
|
+
return {
|
|
351
|
+
name: value.name,
|
|
352
|
+
slug: value.slug,
|
|
353
|
+
logo
|
|
354
|
+
};
|
|
251
355
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
for (let i = 0; i < input.length; i += CHUNK_SIZE) arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
259
|
-
return btoa(arr.join(""));
|
|
356
|
+
function normalizeOrganizationDisplay(value) {
|
|
357
|
+
try {
|
|
358
|
+
return normalizeOrganizationDisplayInput(value);
|
|
359
|
+
} catch {
|
|
360
|
+
throw authorityUnavailable();
|
|
361
|
+
}
|
|
260
362
|
}
|
|
261
|
-
function
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
const bytes = new Uint8Array(binary.length);
|
|
265
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
266
|
-
return bytes;
|
|
363
|
+
function normalizeOrganizationTeamDisplayInput(value) {
|
|
364
|
+
if (!isObject$1(value) || Object.keys(value).join(",") !== "name" || !boundedString(value.name, 255)) throw new AuthError("invalid_request", 400);
|
|
365
|
+
return { name: value.name };
|
|
267
366
|
}
|
|
268
|
-
|
|
269
|
-
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/util/base64url.js
|
|
270
|
-
function decode(input) {
|
|
271
|
-
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
|
|
272
|
-
let encoded = input;
|
|
273
|
-
if (encoded instanceof Uint8Array) encoded = decoder.decode(encoded);
|
|
274
|
-
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
367
|
+
function normalizeOrganizationTeamDisplay(value) {
|
|
275
368
|
try {
|
|
276
|
-
return
|
|
369
|
+
return normalizeOrganizationTeamDisplayInput(value);
|
|
277
370
|
} catch {
|
|
278
|
-
throw
|
|
371
|
+
throw authorityUnavailable();
|
|
279
372
|
}
|
|
280
373
|
}
|
|
281
|
-
function
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
374
|
+
function normalizeOrganizationCreationInput(name, slug, idempotencyKey) {
|
|
375
|
+
if (!boundedString(name, 255) || !boundedString(idempotencyKey, 255) || typeof slug !== "string" || !/^[a-z0-9-]{1,128}$/.test(slug)) throw new AuthError("invalid_request", 400);
|
|
376
|
+
return {
|
|
377
|
+
name,
|
|
378
|
+
slug,
|
|
379
|
+
idempotencyKey
|
|
380
|
+
};
|
|
289
381
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
382
|
+
function normalizeCreatedOrganization(value) {
|
|
383
|
+
exact$3(value, [
|
|
384
|
+
"id",
|
|
385
|
+
"name",
|
|
386
|
+
"slug"
|
|
387
|
+
]);
|
|
388
|
+
if (!isId(value.id) || !boundedString(value.name, 255) || !boundedString(value.slug, 128)) throw authorityUnavailable();
|
|
389
|
+
return {
|
|
390
|
+
id: value.id,
|
|
391
|
+
name: value.name,
|
|
392
|
+
slug: value.slug
|
|
393
|
+
};
|
|
296
394
|
}
|
|
297
|
-
function
|
|
298
|
-
if (
|
|
395
|
+
function normalizeOrganizationTeamCreationInput(name, idempotencyKey) {
|
|
396
|
+
if (!boundedString(name, 255) || !boundedString(idempotencyKey, 255)) throw new AuthError("invalid_request", 400);
|
|
397
|
+
return {
|
|
398
|
+
name,
|
|
399
|
+
idempotencyKey
|
|
400
|
+
};
|
|
299
401
|
}
|
|
300
|
-
function
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
402
|
+
function normalizeCreatedOrganizationTeam(value) {
|
|
403
|
+
exact$3(value, ["id", "name"]);
|
|
404
|
+
if (!isId(value.id) || !boundedString(value.name, 255)) throw authorityUnavailable();
|
|
405
|
+
return {
|
|
406
|
+
id: value.id,
|
|
407
|
+
name: value.name
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function normalizeOrganizationMemberInvitationCreationInput(value) {
|
|
411
|
+
if (!isObject$1(value)) throw new AuthError("invalid_request", 400);
|
|
412
|
+
const keys = Object.keys(value).sort().join(",");
|
|
413
|
+
if (keys !== "email,idempotencyKey" && keys !== "email,idempotencyKey,teamIds") throw new AuthError("invalid_request", 400);
|
|
414
|
+
let normalizedEmail;
|
|
415
|
+
try {
|
|
416
|
+
normalizedEmail = normalizeEmail(value.email);
|
|
417
|
+
} catch {
|
|
418
|
+
throw new AuthError("invalid_request", 400);
|
|
306
419
|
}
|
|
420
|
+
if (new TextEncoder().encode(normalizedEmail).byteLength > 320 || !boundedString(value.idempotencyKey, 255) || value.teamIds !== void 0 && (!Array.isArray(value.teamIds) || value.teamIds.length > 100)) throw new AuthError("invalid_request", 400);
|
|
421
|
+
const teamIds = value.teamIds?.map((teamId) => normalizeIdInput(teamId));
|
|
422
|
+
if (teamIds && new Set(teamIds).size !== teamIds.length) throw new AuthError("invalid_request", 400);
|
|
423
|
+
return {
|
|
424
|
+
email: normalizedEmail,
|
|
425
|
+
...teamIds === void 0 ? {} : { teamIds },
|
|
426
|
+
idempotencyKey: value.idempotencyKey
|
|
427
|
+
};
|
|
307
428
|
}
|
|
308
|
-
function
|
|
309
|
-
|
|
429
|
+
function normalizeCreatedOrganizationMemberInvitation(value) {
|
|
430
|
+
exact$3(value, ["expiresAt", "id"]);
|
|
431
|
+
if (!isId(value.id)) throw authorityUnavailable();
|
|
432
|
+
return {
|
|
433
|
+
id: value.id,
|
|
434
|
+
expiresAt: responseDate(value.expiresAt)
|
|
435
|
+
};
|
|
310
436
|
}
|
|
311
|
-
function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
case "HS512":
|
|
316
|
-
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
317
|
-
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
318
|
-
break;
|
|
319
|
-
case "RS256":
|
|
320
|
-
case "RS384":
|
|
321
|
-
case "RS512":
|
|
322
|
-
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
323
|
-
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
324
|
-
break;
|
|
325
|
-
case "PS256":
|
|
326
|
-
case "PS384":
|
|
327
|
-
case "PS512":
|
|
328
|
-
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
329
|
-
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
330
|
-
break;
|
|
331
|
-
case "Ed25519":
|
|
332
|
-
case "EdDSA":
|
|
333
|
-
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
334
|
-
break;
|
|
335
|
-
case "ML-DSA-44":
|
|
336
|
-
case "ML-DSA-65":
|
|
337
|
-
case "ML-DSA-87":
|
|
338
|
-
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
339
|
-
break;
|
|
340
|
-
case "ES256":
|
|
341
|
-
case "ES384":
|
|
342
|
-
case "ES512": {
|
|
343
|
-
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
344
|
-
const expected = getNamedCurve(alg);
|
|
345
|
-
if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
default: throw new TypeError("CryptoKey does not support this operation");
|
|
349
|
-
}
|
|
350
|
-
checkUsage(key, usage);
|
|
437
|
+
function normalizeResentOrganizationInvitation(value, invitationId) {
|
|
438
|
+
const invitation = normalizeCreatedOrganizationMemberInvitation(value);
|
|
439
|
+
if (invitation.id !== invitationId) throw authorityUnavailable();
|
|
440
|
+
return invitation;
|
|
351
441
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
types = types.filter(Boolean);
|
|
356
|
-
if (types.length > 2) {
|
|
357
|
-
const last = types.pop();
|
|
358
|
-
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
359
|
-
} else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
360
|
-
else msg += `of type ${types[0]}.`;
|
|
361
|
-
if (actual == null) msg += ` Received ${actual}`;
|
|
362
|
-
else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
|
|
363
|
-
else if (typeof actual === "object" && actual != null) {
|
|
364
|
-
if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
|
|
365
|
-
}
|
|
366
|
-
return msg;
|
|
442
|
+
function normalizeOrganizationInvitationAdministrationInput(idempotencyKey) {
|
|
443
|
+
if (!boundedString(idempotencyKey, 255)) throw new AuthError("invalid_request", 400);
|
|
444
|
+
return { idempotencyKey };
|
|
367
445
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
var JOSEError = class extends Error {
|
|
373
|
-
static code = "ERR_JOSE_GENERIC";
|
|
374
|
-
code = "ERR_JOSE_GENERIC";
|
|
375
|
-
constructor(message, options) {
|
|
376
|
-
super(message, options);
|
|
377
|
-
this.name = this.constructor.name;
|
|
378
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
var JWTClaimValidationFailed = class extends JOSEError {
|
|
382
|
-
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
383
|
-
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
384
|
-
claim;
|
|
385
|
-
reason;
|
|
386
|
-
payload;
|
|
387
|
-
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
388
|
-
super(message, { cause: {
|
|
389
|
-
claim,
|
|
390
|
-
reason,
|
|
391
|
-
payload
|
|
392
|
-
} });
|
|
393
|
-
this.claim = claim;
|
|
394
|
-
this.reason = reason;
|
|
395
|
-
this.payload = payload;
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
var JWTExpired = class extends JOSEError {
|
|
399
|
-
static code = "ERR_JWT_EXPIRED";
|
|
400
|
-
code = "ERR_JWT_EXPIRED";
|
|
401
|
-
claim;
|
|
402
|
-
reason;
|
|
403
|
-
payload;
|
|
404
|
-
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
405
|
-
super(message, { cause: {
|
|
406
|
-
claim,
|
|
407
|
-
reason,
|
|
408
|
-
payload
|
|
409
|
-
} });
|
|
410
|
-
this.claim = claim;
|
|
411
|
-
this.reason = reason;
|
|
412
|
-
this.payload = payload;
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
416
|
-
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
417
|
-
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
418
|
-
};
|
|
419
|
-
var JOSENotSupported = class extends JOSEError {
|
|
420
|
-
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
421
|
-
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
422
|
-
};
|
|
423
|
-
var JWSInvalid = class extends JOSEError {
|
|
424
|
-
static code = "ERR_JWS_INVALID";
|
|
425
|
-
code = "ERR_JWS_INVALID";
|
|
426
|
-
};
|
|
427
|
-
var JWTInvalid = class extends JOSEError {
|
|
428
|
-
static code = "ERR_JWT_INVALID";
|
|
429
|
-
code = "ERR_JWT_INVALID";
|
|
430
|
-
};
|
|
431
|
-
var JWKInvalid = class extends JOSEError {
|
|
432
|
-
static code = "ERR_JWK_INVALID";
|
|
433
|
-
code = "ERR_JWK_INVALID";
|
|
434
|
-
};
|
|
435
|
-
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
436
|
-
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
437
|
-
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
438
|
-
constructor(message = "signature verification failed", options) {
|
|
439
|
-
super(message, options);
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
//#endregion
|
|
443
|
-
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
444
|
-
const isCryptoKey = (key) => {
|
|
445
|
-
if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
|
|
446
|
-
try {
|
|
447
|
-
return key instanceof CryptoKey;
|
|
448
|
-
} catch {
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
const isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
453
|
-
const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
454
|
-
//#endregion
|
|
455
|
-
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/helpers.js
|
|
456
|
-
function decodeBase64url(value, label, ErrorClass) {
|
|
457
|
-
try {
|
|
458
|
-
return decode(value);
|
|
459
|
-
} catch {
|
|
460
|
-
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
461
|
-
}
|
|
446
|
+
function normalizeCanceledOrganizationInvitation(value) {
|
|
447
|
+
exact$3(value, ["status"]);
|
|
448
|
+
if (value.status !== "canceled") throw authorityUnavailable();
|
|
449
|
+
return { status: "canceled" };
|
|
462
450
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
return
|
|
451
|
+
function normalizeOrganizationMembershipRemovalInput(idempotencyKey) {
|
|
452
|
+
if (!boundedString(idempotencyKey, 255)) throw new AuthError("invalid_request", 400);
|
|
453
|
+
return { idempotencyKey };
|
|
466
454
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
|
|
472
|
-
if (Object.getPrototypeOf(input) === null) return true;
|
|
473
|
-
let proto = input;
|
|
474
|
-
while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
|
|
475
|
-
return Object.getPrototypeOf(input) === proto;
|
|
455
|
+
function normalizeRemovedOrganizationMember(value) {
|
|
456
|
+
exact$3(value, ["status"]);
|
|
457
|
+
if (value.status !== "removed") throw authorityUnavailable();
|
|
458
|
+
return { status: "removed" };
|
|
476
459
|
}
|
|
477
|
-
function
|
|
478
|
-
|
|
479
|
-
if (
|
|
480
|
-
|
|
481
|
-
for (const header of sources) {
|
|
482
|
-
const parameters = Object.keys(header);
|
|
483
|
-
if (!acc || acc.size === 0) {
|
|
484
|
-
acc = new Set(parameters);
|
|
485
|
-
continue;
|
|
486
|
-
}
|
|
487
|
-
for (const parameter of parameters) {
|
|
488
|
-
if (acc.has(parameter)) return false;
|
|
489
|
-
acc.add(parameter);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
return true;
|
|
460
|
+
function normalizeOrganizationDeparture(value) {
|
|
461
|
+
exact$3(value, ["status"]);
|
|
462
|
+
if (value.status !== "left") throw authorityUnavailable();
|
|
463
|
+
return { status: "left" };
|
|
493
464
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
502
|
-
const { modulusLength } = key.algorithm;
|
|
503
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
504
|
-
}
|
|
465
|
+
function normalizeOrganizations(value) {
|
|
466
|
+
exact$3(value, ["nextCursor", "organizations"]);
|
|
467
|
+
if (!Array.isArray(value.organizations) || value.organizations.length > 100) throw authorityUnavailable();
|
|
468
|
+
return {
|
|
469
|
+
organizations: unique(value.organizations.map(normalizeOrganization), (item) => item.id),
|
|
470
|
+
nextCursor: nullableCursor(value.nextCursor)
|
|
471
|
+
};
|
|
505
472
|
}
|
|
506
|
-
function
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
case "ML-DSA-65":
|
|
539
|
-
case "ML-DSA-87": return { name: alg };
|
|
540
|
-
default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
541
|
-
}
|
|
473
|
+
function normalizeOrganizationMembers(value) {
|
|
474
|
+
exact$3(value, ["members", "nextCursor"]);
|
|
475
|
+
if (!Array.isArray(value.members) || value.members.length > 100) throw authorityUnavailable();
|
|
476
|
+
return {
|
|
477
|
+
members: unique(value.members.map((member) => {
|
|
478
|
+
exact$3(member, [
|
|
479
|
+
"email",
|
|
480
|
+
"id",
|
|
481
|
+
"image",
|
|
482
|
+
"joinedAt",
|
|
483
|
+
"name",
|
|
484
|
+
"owner",
|
|
485
|
+
"role",
|
|
486
|
+
"teamIds",
|
|
487
|
+
"userId"
|
|
488
|
+
]);
|
|
489
|
+
if (!isId(member.id) || !isId(member.userId) || !boundedString(member.name, 255) || typeof member.email !== "string" || member.email.length > 320 || !email.test(member.email) || !role(member.role) || typeof member.owner !== "boolean" || !Array.isArray(member.teamIds) || member.teamIds.length > 100) throw authorityUnavailable();
|
|
490
|
+
const teamIds = unique(member.teamIds.map((teamId) => normalizeResponseId(teamId)), (item) => item);
|
|
491
|
+
return {
|
|
492
|
+
id: member.id,
|
|
493
|
+
userId: member.userId,
|
|
494
|
+
name: member.name,
|
|
495
|
+
email: member.email,
|
|
496
|
+
image: nullableHttpsUrl(member.image),
|
|
497
|
+
role: member.role,
|
|
498
|
+
owner: member.owner,
|
|
499
|
+
joinedAt: responseDate(member.joinedAt),
|
|
500
|
+
teamIds
|
|
501
|
+
};
|
|
502
|
+
}), (item) => item.id),
|
|
503
|
+
nextCursor: nullableCursor(value.nextCursor)
|
|
504
|
+
};
|
|
542
505
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
506
|
+
function normalizeOrganizationTeams(value) {
|
|
507
|
+
exact$3(value, ["nextCursor", "teams"]);
|
|
508
|
+
if (!Array.isArray(value.teams) || value.teams.length > 100) throw authorityUnavailable();
|
|
509
|
+
return {
|
|
510
|
+
teams: unique(value.teams.map((team) => {
|
|
511
|
+
exact$3(team, [
|
|
512
|
+
"category",
|
|
513
|
+
"createdAt",
|
|
514
|
+
"id",
|
|
515
|
+
"name"
|
|
516
|
+
]);
|
|
517
|
+
if (!isId(team.id) || !boundedString(team.name, 255) || team.category !== "manual" && team.category !== "managed") throw authorityUnavailable();
|
|
518
|
+
return {
|
|
519
|
+
id: team.id,
|
|
520
|
+
name: team.name,
|
|
521
|
+
category: team.category,
|
|
522
|
+
createdAt: responseDate(team.createdAt)
|
|
523
|
+
};
|
|
524
|
+
}), (item) => item.id),
|
|
525
|
+
nextCursor: nullableCursor(value.nextCursor)
|
|
526
|
+
};
|
|
553
527
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}
|
|
561
|
-
return false;
|
|
562
|
-
}
|
|
528
|
+
function normalizeOrganizationTeamMembers(value) {
|
|
529
|
+
exact$3(value, ["memberIds", "nextCursor"]);
|
|
530
|
+
if (!Array.isArray(value.memberIds) || value.memberIds.length > 100) throw authorityUnavailable();
|
|
531
|
+
return {
|
|
532
|
+
memberIds: unique(value.memberIds.map((item) => normalizeResponseId(item)), (item) => item),
|
|
533
|
+
nextCursor: nullableCursor(value.nextCursor)
|
|
534
|
+
};
|
|
563
535
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
break;
|
|
579
|
-
default: throw new JOSENotSupported(unsupportedAlg);
|
|
580
|
-
}
|
|
581
|
-
break;
|
|
582
|
-
case "RSA":
|
|
583
|
-
switch (jwk.alg) {
|
|
584
|
-
case "PS256":
|
|
585
|
-
case "PS384":
|
|
586
|
-
case "PS512":
|
|
587
|
-
algorithm = {
|
|
588
|
-
name: "RSA-PSS",
|
|
589
|
-
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
590
|
-
};
|
|
591
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
592
|
-
break;
|
|
593
|
-
case "RS256":
|
|
594
|
-
case "RS384":
|
|
595
|
-
case "RS512":
|
|
596
|
-
algorithm = {
|
|
597
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
598
|
-
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
599
|
-
};
|
|
600
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
601
|
-
break;
|
|
602
|
-
case "RSA-OAEP":
|
|
603
|
-
case "RSA-OAEP-256":
|
|
604
|
-
case "RSA-OAEP-384":
|
|
605
|
-
case "RSA-OAEP-512":
|
|
606
|
-
algorithm = {
|
|
607
|
-
name: "RSA-OAEP",
|
|
608
|
-
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
609
|
-
};
|
|
610
|
-
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
611
|
-
break;
|
|
612
|
-
default: throw new JOSENotSupported(unsupportedAlg);
|
|
613
|
-
}
|
|
614
|
-
break;
|
|
615
|
-
case "EC":
|
|
616
|
-
switch (jwk.alg) {
|
|
617
|
-
case "ES256":
|
|
618
|
-
case "ES384":
|
|
619
|
-
case "ES512":
|
|
620
|
-
algorithm = {
|
|
621
|
-
name: "ECDSA",
|
|
622
|
-
namedCurve: {
|
|
623
|
-
ES256: "P-256",
|
|
624
|
-
ES384: "P-384",
|
|
625
|
-
ES512: "P-521"
|
|
626
|
-
}[jwk.alg]
|
|
627
|
-
};
|
|
628
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
629
|
-
break;
|
|
630
|
-
case "ECDH-ES":
|
|
631
|
-
case "ECDH-ES+A128KW":
|
|
632
|
-
case "ECDH-ES+A192KW":
|
|
633
|
-
case "ECDH-ES+A256KW":
|
|
634
|
-
algorithm = {
|
|
635
|
-
name: "ECDH",
|
|
636
|
-
namedCurve: jwk.crv
|
|
637
|
-
};
|
|
638
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
639
|
-
break;
|
|
640
|
-
default: throw new JOSENotSupported(unsupportedAlg);
|
|
641
|
-
}
|
|
642
|
-
break;
|
|
643
|
-
case "OKP":
|
|
644
|
-
switch (jwk.alg) {
|
|
645
|
-
case "Ed25519":
|
|
646
|
-
case "EdDSA":
|
|
647
|
-
algorithm = { name: "Ed25519" };
|
|
648
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
649
|
-
break;
|
|
650
|
-
case "ECDH-ES":
|
|
651
|
-
case "ECDH-ES+A128KW":
|
|
652
|
-
case "ECDH-ES+A192KW":
|
|
653
|
-
case "ECDH-ES+A256KW":
|
|
654
|
-
algorithm = { name: jwk.crv };
|
|
655
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
656
|
-
break;
|
|
657
|
-
default: throw new JOSENotSupported(unsupportedAlg);
|
|
658
|
-
}
|
|
659
|
-
break;
|
|
660
|
-
default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
|
|
661
|
-
}
|
|
536
|
+
function normalizeOrganizationInvitation(value) {
|
|
537
|
+
exact$3(value, [
|
|
538
|
+
"createdAt",
|
|
539
|
+
"email",
|
|
540
|
+
"expiresAt",
|
|
541
|
+
"id",
|
|
542
|
+
"inviter",
|
|
543
|
+
"role",
|
|
544
|
+
"status",
|
|
545
|
+
"teamIds"
|
|
546
|
+
]);
|
|
547
|
+
if (!isId(value.id) || typeof value.email !== "string" || value.email.length > 320 || !email.test(value.email) || !role(value.role) || value.status !== "pending" || !Array.isArray(value.teamIds) || value.teamIds.length > 100 || !isObject$1(value.inviter)) throw authorityUnavailable();
|
|
548
|
+
exact$3(value.inviter, ["membershipId", "name"]);
|
|
549
|
+
if (!isId(value.inviter.membershipId) || !boundedString(value.inviter.name, 255)) throw authorityUnavailable();
|
|
662
550
|
return {
|
|
663
|
-
|
|
664
|
-
|
|
551
|
+
id: value.id,
|
|
552
|
+
email: value.email,
|
|
553
|
+
role: value.role,
|
|
554
|
+
teamIds: unique(value.teamIds.map(normalizeResponseId), (item) => item),
|
|
555
|
+
inviter: {
|
|
556
|
+
membershipId: value.inviter.membershipId,
|
|
557
|
+
name: value.inviter.name
|
|
558
|
+
},
|
|
559
|
+
createdAt: responseDate(value.createdAt),
|
|
560
|
+
expiresAt: responseDate(value.expiresAt),
|
|
561
|
+
status: "pending"
|
|
665
562
|
};
|
|
666
563
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
564
|
+
function normalizeOrganizationInvitations(value) {
|
|
565
|
+
exact$3(value, ["invitations", "nextCursor"]);
|
|
566
|
+
if (!Array.isArray(value.invitations) || value.invitations.length > 100) throw authorityUnavailable();
|
|
567
|
+
return {
|
|
568
|
+
invitations: unique(value.invitations.map(normalizeOrganizationInvitation), (item) => item.id),
|
|
569
|
+
nextCursor: nullableCursor(value.nextCursor)
|
|
570
|
+
};
|
|
674
571
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
}
|
|
713
|
-
switch (keyObject.asymmetricKeyType) {
|
|
714
|
-
case "ml-dsa-44":
|
|
715
|
-
case "ml-dsa-65":
|
|
716
|
-
case "ml-dsa-87":
|
|
717
|
-
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) throw new TypeError(unusableForAlg);
|
|
718
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
719
|
-
}
|
|
720
|
-
if (keyObject.asymmetricKeyType === "rsa") {
|
|
721
|
-
let hash;
|
|
722
|
-
switch (alg) {
|
|
723
|
-
case "RSA-OAEP":
|
|
724
|
-
hash = "SHA-1";
|
|
725
|
-
break;
|
|
726
|
-
case "RS256":
|
|
727
|
-
case "PS256":
|
|
728
|
-
case "RSA-OAEP-256":
|
|
729
|
-
hash = "SHA-256";
|
|
730
|
-
break;
|
|
731
|
-
case "RS384":
|
|
732
|
-
case "PS384":
|
|
733
|
-
case "RSA-OAEP-384":
|
|
734
|
-
hash = "SHA-384";
|
|
735
|
-
break;
|
|
736
|
-
case "RS512":
|
|
737
|
-
case "PS512":
|
|
738
|
-
case "RSA-OAEP-512":
|
|
739
|
-
hash = "SHA-512";
|
|
740
|
-
break;
|
|
741
|
-
default: throw new TypeError(unusableForAlg);
|
|
742
|
-
}
|
|
743
|
-
if (alg.startsWith("RSA-OAEP")) return keyObject.toCryptoKey({
|
|
744
|
-
name: "RSA-OAEP",
|
|
745
|
-
hash
|
|
746
|
-
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
747
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
748
|
-
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
749
|
-
hash
|
|
750
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
751
|
-
}
|
|
752
|
-
if (keyObject.asymmetricKeyType === "ec") {
|
|
753
|
-
const namedCurve = new Map([
|
|
754
|
-
["prime256v1", "P-256"],
|
|
755
|
-
["secp384r1", "P-384"],
|
|
756
|
-
["secp521r1", "P-521"]
|
|
757
|
-
]).get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
758
|
-
if (!namedCurve) throw new TypeError(unusableForAlg);
|
|
759
|
-
const expectedCurve = {
|
|
760
|
-
ES256: "P-256",
|
|
761
|
-
ES384: "P-384",
|
|
762
|
-
ES512: "P-521"
|
|
763
|
-
};
|
|
764
|
-
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) cryptoKey = keyObject.toCryptoKey({
|
|
765
|
-
name: "ECDSA",
|
|
766
|
-
namedCurve
|
|
767
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
768
|
-
if (alg.startsWith("ECDH-ES")) cryptoKey = keyObject.toCryptoKey({
|
|
769
|
-
name: "ECDH",
|
|
770
|
-
namedCurve
|
|
771
|
-
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
772
|
-
}
|
|
773
|
-
if (!cryptoKey) throw new TypeError(unusableForAlg);
|
|
774
|
-
if (!cached) cache.set(keyObject, { [alg]: cryptoKey });
|
|
775
|
-
else cached[alg] = cryptoKey;
|
|
776
|
-
return cryptoKey;
|
|
777
|
-
};
|
|
778
|
-
async function normalizeKey(key, alg) {
|
|
779
|
-
if (key instanceof Uint8Array) return key;
|
|
780
|
-
if (isCryptoKey(key)) return key;
|
|
781
|
-
if (isKeyObject(key)) {
|
|
782
|
-
if (key.type === "secret") return key.export();
|
|
783
|
-
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") try {
|
|
784
|
-
return handleKeyObject(key, alg);
|
|
785
|
-
} catch (err) {
|
|
786
|
-
if (err instanceof TypeError) throw err;
|
|
787
|
-
}
|
|
788
|
-
let jwk = key.export({ format: "jwk" });
|
|
789
|
-
return handleJWK(key, jwk, alg);
|
|
790
|
-
}
|
|
791
|
-
if (isJWK(key)) {
|
|
792
|
-
if (key.k) return decode(key.k);
|
|
793
|
-
return handleJWK(key, key, alg, true);
|
|
794
|
-
}
|
|
795
|
-
throw new Error("unreachable");
|
|
572
|
+
function normalizeReceivedInvitation(value) {
|
|
573
|
+
exact$3(value, [
|
|
574
|
+
"expiresAt",
|
|
575
|
+
"id",
|
|
576
|
+
"inviterName",
|
|
577
|
+
"organization",
|
|
578
|
+
"role",
|
|
579
|
+
"teams"
|
|
580
|
+
]);
|
|
581
|
+
if (!isId(value.id) || !boundedString(value.inviterName, 255) || !role(value.role) || !Array.isArray(value.teams) || value.teams.length > 100 || !isObject$1(value.organization)) throw authorityUnavailable();
|
|
582
|
+
exact$3(value.organization, [
|
|
583
|
+
"id",
|
|
584
|
+
"logo",
|
|
585
|
+
"name",
|
|
586
|
+
"slug"
|
|
587
|
+
]);
|
|
588
|
+
if (!isId(value.organization.id) || !boundedString(value.organization.name, 255) || !boundedString(value.organization.slug, 255)) throw authorityUnavailable();
|
|
589
|
+
return {
|
|
590
|
+
id: value.id,
|
|
591
|
+
organization: {
|
|
592
|
+
id: value.organization.id,
|
|
593
|
+
name: value.organization.name,
|
|
594
|
+
slug: value.organization.slug,
|
|
595
|
+
logo: nullableHttpsUrl(value.organization.logo)
|
|
596
|
+
},
|
|
597
|
+
role: value.role,
|
|
598
|
+
teams: unique(value.teams.map((team) => {
|
|
599
|
+
exact$3(team, ["id", "name"]);
|
|
600
|
+
if (!isId(team.id) || !boundedString(team.name, 255)) throw authorityUnavailable();
|
|
601
|
+
return {
|
|
602
|
+
id: team.id,
|
|
603
|
+
name: team.name
|
|
604
|
+
};
|
|
605
|
+
}), (item) => item.id),
|
|
606
|
+
inviterName: value.inviterName,
|
|
607
|
+
expiresAt: responseDate(value.expiresAt)
|
|
608
|
+
};
|
|
796
609
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
switch (jwk.kty) {
|
|
805
|
-
case "oct":
|
|
806
|
-
if (typeof jwk.k !== "string" || !jwk.k) throw new TypeError("missing \"k\" (Key Value) Parameter value");
|
|
807
|
-
return decode(jwk.k);
|
|
808
|
-
case "RSA":
|
|
809
|
-
if ("oth" in jwk && jwk.oth !== void 0) throw new JOSENotSupported("RSA JWK \"oth\" (Other Primes Info) Parameter value is not supported");
|
|
810
|
-
return jwkToKey({
|
|
811
|
-
...jwk,
|
|
812
|
-
alg,
|
|
813
|
-
ext
|
|
814
|
-
});
|
|
815
|
-
case "AKP":
|
|
816
|
-
if (typeof jwk.alg !== "string" || !jwk.alg) throw new TypeError("missing \"alg\" (Algorithm) Parameter value");
|
|
817
|
-
if (alg !== void 0 && alg !== jwk.alg) throw new TypeError("JWK alg and alg option value mismatch");
|
|
818
|
-
return jwkToKey({
|
|
819
|
-
...jwk,
|
|
820
|
-
ext
|
|
821
|
-
});
|
|
822
|
-
case "EC":
|
|
823
|
-
case "OKP": return jwkToKey({
|
|
824
|
-
...jwk,
|
|
825
|
-
alg,
|
|
826
|
-
ext
|
|
827
|
-
});
|
|
828
|
-
default: throw new JOSENotSupported("Unsupported \"kty\" (Key Type) Parameter value");
|
|
829
|
-
}
|
|
610
|
+
function normalizeReceivedInvitations(value) {
|
|
611
|
+
exact$3(value, ["invitations", "nextCursor"]);
|
|
612
|
+
if (!Array.isArray(value.invitations) || value.invitations.length > 100) throw authorityUnavailable();
|
|
613
|
+
return {
|
|
614
|
+
invitations: unique(value.invitations.map(normalizeReceivedInvitation), (item) => item.id),
|
|
615
|
+
nextCursor: nullableCursor(value.nextCursor)
|
|
616
|
+
};
|
|
830
617
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
return Object.fromEntries(Object.entries(jwk).filter(([, value]) => value !== void 0));
|
|
618
|
+
function normalizeInvitationInput(value) {
|
|
619
|
+
if (!isObject$1(value) || Object.keys(value).length !== 1 || !isId(value.invitationId)) throw new AuthError("invalid_invitation", 422);
|
|
620
|
+
return { invitationId: value.invitationId };
|
|
835
621
|
}
|
|
836
|
-
|
|
837
|
-
if (
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
622
|
+
function normalizeInvitationAcceptance(value, invitationId) {
|
|
623
|
+
if (!isObject$1(value) || !isObject$1(value.invitation) || !isObject$1(value.member) || value.invitation.id !== invitationId || value.invitation.status !== "accepted" || !isId(value.invitation.organizationId) || value.member.organizationId !== value.invitation.organizationId) throw authorityUnavailable();
|
|
624
|
+
return { organizationId: value.invitation.organizationId };
|
|
625
|
+
}
|
|
626
|
+
function normalizeWorkspaceSelection(value) {
|
|
627
|
+
if (!isObject$1(value)) throw new AuthError("invalid_workspace_selection", 422);
|
|
628
|
+
const keys = Object.keys(value);
|
|
629
|
+
if (value.type === "personal" && keys.length === 1 && keys[0] === "type") return { type: "personal" };
|
|
630
|
+
if (value.type === "organization" && keys.length === 2 && keys.includes("type") && keys.includes("organizationId") && typeof value.organizationId === "string" && id.test(value.organizationId)) return {
|
|
631
|
+
type: "organization",
|
|
632
|
+
organizationId: value.organizationId
|
|
842
633
|
};
|
|
843
|
-
|
|
844
|
-
if (!key.extractable) throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
845
|
-
const { ext, key_ops, alg, use, ...jwk } = omitUndefinedProperties(await crypto.subtle.exportKey("jwk", key));
|
|
846
|
-
if (jwk.kty === "AKP") jwk.alg = alg;
|
|
847
|
-
return jwk;
|
|
634
|
+
throw new AuthError("invalid_workspace_selection", 422);
|
|
848
635
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
return keyToJWK(key);
|
|
636
|
+
function fromAuthorityError(value, fallbackStatus, retryAfter) {
|
|
637
|
+
const mapped = mapError(isObject$1(value) && typeof value.code === "string" ? value.code : void 0, fallbackStatus);
|
|
638
|
+
return new AuthError(mapped.code, mapped.status, parseRetryAfter(retryAfter));
|
|
853
639
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
if (
|
|
858
|
-
if (
|
|
859
|
-
if (
|
|
860
|
-
|
|
861
|
-
if (
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
}
|
|
868
|
-
return new Set(protectedHeader.crit);
|
|
640
|
+
function fromAccountAuthorityError(value, status, retryAfter) {
|
|
641
|
+
const code = isObject$1(value) && typeof value.code === "string" ? value.code : void 0;
|
|
642
|
+
if (status === 403 && (code === "INVALID_ORIGIN" || code === "MISSING_OR_NULL_ORIGIN")) return new AuthError("request_origin_denied", 403);
|
|
643
|
+
if (code === "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL") return new AuthError("account_conflict", 409);
|
|
644
|
+
if (code === "INVALID_TOKEN") return new AuthError("password_reset_invalid", 422);
|
|
645
|
+
if (code === "INVALID_PASSWORD" || code === "INVALID_EMAIL_OR_PASSWORD") return new AuthError("invalid_credentials", 401);
|
|
646
|
+
if (code === "INVALID_EMAIL" || code === "PASSWORD_TOO_SHORT" || code === "PASSWORD_TOO_LONG" || code === "BODY_MUST_BE_AN_OBJECT" || code === "EMAIL_CAN_NOT_BE_UPDATED") return new AuthError("invalid_auth_input", 422);
|
|
647
|
+
if (status === 401) return new AuthError("authentication_required", 401);
|
|
648
|
+
if (status === 403) return new AuthError("access_denied", 403);
|
|
649
|
+
if (status === 409) return new AuthError("state_conflict", 409);
|
|
650
|
+
if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
|
|
651
|
+
if (status === 400 || status === 422) return new AuthError("invalid_auth_input", 422);
|
|
652
|
+
return authorityUnavailable();
|
|
869
653
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
if (
|
|
874
|
-
|
|
875
|
-
return new Set(algorithms);
|
|
654
|
+
function fromSocialIdTokenAuthorityError(value, status, retryAfter) {
|
|
655
|
+
const code = isObject$1(value) && typeof value.code === "string" ? value.code : void 0;
|
|
656
|
+
if (code === "INVALID_TOKEN" || code === "FAILED_TO_GET_USER_INFO" || code === "USER_EMAIL_NOT_FOUND") return new AuthError("invalid_credentials", 401);
|
|
657
|
+
if (code === "OAUTH_LINK_ERROR") return new AuthError("account_conflict", 409);
|
|
658
|
+
return fromAccountAuthorityError(value, status, retryAfter);
|
|
876
659
|
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
const tag = (key) => key?.[Symbol.toStringTag];
|
|
880
|
-
const jwkMatchesOp = (alg, key, usage) => {
|
|
881
|
-
if (key.use !== void 0) {
|
|
882
|
-
let expected;
|
|
883
|
-
switch (usage) {
|
|
884
|
-
case "sign":
|
|
885
|
-
case "verify":
|
|
886
|
-
expected = "sig";
|
|
887
|
-
break;
|
|
888
|
-
case "encrypt":
|
|
889
|
-
case "decrypt":
|
|
890
|
-
expected = "enc";
|
|
891
|
-
break;
|
|
892
|
-
}
|
|
893
|
-
if (key.use !== expected) throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
894
|
-
}
|
|
895
|
-
if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
896
|
-
if (Array.isArray(key.key_ops)) {
|
|
897
|
-
let expectedKeyOp;
|
|
898
|
-
switch (true) {
|
|
899
|
-
case usage === "sign" || usage === "verify":
|
|
900
|
-
case alg === "dir":
|
|
901
|
-
case alg.includes("CBC-HS"):
|
|
902
|
-
expectedKeyOp = usage;
|
|
903
|
-
break;
|
|
904
|
-
case alg.startsWith("PBES2"):
|
|
905
|
-
expectedKeyOp = "deriveBits";
|
|
906
|
-
break;
|
|
907
|
-
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
908
|
-
if (!alg.includes("GCM") && alg.endsWith("KW")) expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
909
|
-
else expectedKeyOp = usage;
|
|
910
|
-
break;
|
|
911
|
-
case usage === "encrypt" && alg.startsWith("RSA"):
|
|
912
|
-
expectedKeyOp = "wrapKey";
|
|
913
|
-
break;
|
|
914
|
-
case usage === "decrypt":
|
|
915
|
-
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
916
|
-
break;
|
|
917
|
-
}
|
|
918
|
-
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
919
|
-
}
|
|
920
|
-
return true;
|
|
921
|
-
};
|
|
922
|
-
const symmetricTypeCheck = (alg, key, usage) => {
|
|
923
|
-
if (key instanceof Uint8Array) return;
|
|
924
|
-
if (isJWK(key)) {
|
|
925
|
-
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
926
|
-
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
927
|
-
}
|
|
928
|
-
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
929
|
-
if (key.type !== "secret") throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
930
|
-
};
|
|
931
|
-
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
932
|
-
if (isJWK(key)) switch (usage) {
|
|
933
|
-
case "decrypt":
|
|
934
|
-
case "sign":
|
|
935
|
-
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
936
|
-
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
937
|
-
case "encrypt":
|
|
938
|
-
case "verify":
|
|
939
|
-
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
940
|
-
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
941
|
-
}
|
|
942
|
-
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
943
|
-
if (key.type === "secret") throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
944
|
-
if (key.type === "public") switch (usage) {
|
|
945
|
-
case "sign": throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
946
|
-
case "decrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
947
|
-
}
|
|
948
|
-
if (key.type === "private") switch (usage) {
|
|
949
|
-
case "verify": throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
950
|
-
case "encrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
function checkKeyType(alg, key, usage) {
|
|
954
|
-
switch (alg.substring(0, 2)) {
|
|
955
|
-
case "A1":
|
|
956
|
-
case "A2":
|
|
957
|
-
case "di":
|
|
958
|
-
case "HS":
|
|
959
|
-
case "PB":
|
|
960
|
-
symmetricTypeCheck(alg, key, usage);
|
|
961
|
-
break;
|
|
962
|
-
default: asymmetricTypeCheck(alg, key, usage);
|
|
963
|
-
}
|
|
660
|
+
function authorityUnavailable() {
|
|
661
|
+
return new AuthError("identity_authority_unavailable", 503);
|
|
964
662
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
if (jws.protected === void 0 && jws.header === void 0) throw new JWSInvalid("Flattened JWS must have either of the \"protected\" or \"header\" members");
|
|
970
|
-
if (jws.protected !== void 0 && typeof jws.protected !== "string") throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
971
|
-
if (jws.payload === void 0) throw new JWSInvalid("JWS Payload missing");
|
|
972
|
-
if (typeof jws.signature !== "string") throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
973
|
-
if (jws.header !== void 0 && !isObject$1(jws.header)) throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
974
|
-
let parsedProt = {};
|
|
975
|
-
if (jws.protected) try {
|
|
976
|
-
const protectedHeader = decode(jws.protected);
|
|
977
|
-
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
978
|
-
} catch {
|
|
979
|
-
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
980
|
-
}
|
|
981
|
-
if (!isDisjoint(parsedProt, jws.header)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
982
|
-
const joseHeader = {
|
|
983
|
-
...parsedProt,
|
|
984
|
-
...jws.header
|
|
985
|
-
};
|
|
986
|
-
const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
987
|
-
let b64 = true;
|
|
988
|
-
if (extensions.has("b64")) {
|
|
989
|
-
b64 = parsedProt.b64;
|
|
990
|
-
if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
|
|
991
|
-
}
|
|
992
|
-
const { alg } = joseHeader;
|
|
993
|
-
if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
994
|
-
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
995
|
-
if (algorithms && !algorithms.has(alg)) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
|
|
996
|
-
if (b64) {
|
|
997
|
-
if (typeof jws.payload !== "string") throw new JWSInvalid("JWS Payload must be a string");
|
|
998
|
-
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
999
|
-
let resolvedKey = false;
|
|
1000
|
-
if (typeof key === "function") {
|
|
1001
|
-
key = await key(parsedProt, jws);
|
|
1002
|
-
resolvedKey = true;
|
|
1003
|
-
}
|
|
1004
|
-
checkKeyType(alg, key, "verify");
|
|
1005
|
-
const data = concat(jws.protected !== void 0 ? encode$1(jws.protected) : new Uint8Array(), encode$1("."), typeof jws.payload === "string" ? b64 ? encode$1(jws.payload) : encoder$1.encode(jws.payload) : jws.payload);
|
|
1006
|
-
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
1007
|
-
const k = await normalizeKey(key, alg);
|
|
1008
|
-
if (!await verify(alg, k, signature, data)) throw new JWSSignatureVerificationFailed();
|
|
1009
|
-
let payload;
|
|
1010
|
-
if (b64) payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
|
|
1011
|
-
else if (typeof jws.payload === "string") payload = encoder$1.encode(jws.payload);
|
|
1012
|
-
else payload = jws.payload;
|
|
1013
|
-
const result = { payload };
|
|
1014
|
-
if (jws.protected !== void 0) result.protectedHeader = parsedProt;
|
|
1015
|
-
if (jws.header !== void 0) result.unprotectedHeader = jws.header;
|
|
1016
|
-
if (resolvedKey) return {
|
|
1017
|
-
...result,
|
|
1018
|
-
key: k
|
|
1019
|
-
};
|
|
1020
|
-
return result;
|
|
663
|
+
function fromOrganizationListError(error) {
|
|
664
|
+
if (error instanceof AuthError && error.status === 401) return new AuthError("authentication_required", 401);
|
|
665
|
+
if (error instanceof AuthError) return error;
|
|
666
|
+
return authorityUnavailable();
|
|
1021
667
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
if (
|
|
1026
|
-
|
|
1027
|
-
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
1028
|
-
if (length !== 3) throw new JWSInvalid("Invalid Compact JWS");
|
|
1029
|
-
const verified = await flattenedVerify({
|
|
1030
|
-
payload,
|
|
1031
|
-
protected: protectedHeader,
|
|
1032
|
-
signature
|
|
1033
|
-
}, key, options);
|
|
1034
|
-
const result = {
|
|
1035
|
-
payload: verified.payload,
|
|
1036
|
-
protectedHeader: verified.protectedHeader
|
|
1037
|
-
};
|
|
1038
|
-
if (typeof key === "function") return {
|
|
1039
|
-
...result,
|
|
1040
|
-
key: verified.key
|
|
1041
|
-
};
|
|
1042
|
-
return result;
|
|
668
|
+
function fromOrganizationReadAuthorityError(value, status) {
|
|
669
|
+
if (status === 400) return new AuthError("invalid_request", 400);
|
|
670
|
+
if (status === 401) return new AuthError("authentication_required", 401);
|
|
671
|
+
if (status === 403) return new AuthError("access_denied", 403);
|
|
672
|
+
return authorityUnavailable();
|
|
1043
673
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
const year = day * 365.25;
|
|
1052
|
-
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
1053
|
-
function secs(str) {
|
|
1054
|
-
const matched = REGEX.exec(str);
|
|
1055
|
-
if (!matched || matched[4] && matched[1]) throw new TypeError("Invalid time period format");
|
|
1056
|
-
const value = parseFloat(matched[2]);
|
|
1057
|
-
const unit = matched[3].toLowerCase();
|
|
1058
|
-
let numericDate;
|
|
1059
|
-
switch (unit) {
|
|
1060
|
-
case "sec":
|
|
1061
|
-
case "secs":
|
|
1062
|
-
case "second":
|
|
1063
|
-
case "seconds":
|
|
1064
|
-
case "s":
|
|
1065
|
-
numericDate = Math.round(value);
|
|
1066
|
-
break;
|
|
1067
|
-
case "minute":
|
|
1068
|
-
case "minutes":
|
|
1069
|
-
case "min":
|
|
1070
|
-
case "mins":
|
|
1071
|
-
case "m":
|
|
1072
|
-
numericDate = Math.round(value * minute);
|
|
1073
|
-
break;
|
|
1074
|
-
case "hour":
|
|
1075
|
-
case "hours":
|
|
1076
|
-
case "hr":
|
|
1077
|
-
case "hrs":
|
|
1078
|
-
case "h":
|
|
1079
|
-
numericDate = Math.round(value * hour);
|
|
1080
|
-
break;
|
|
1081
|
-
case "day":
|
|
1082
|
-
case "days":
|
|
1083
|
-
case "d":
|
|
1084
|
-
numericDate = Math.round(value * day);
|
|
1085
|
-
break;
|
|
1086
|
-
case "week":
|
|
1087
|
-
case "weeks":
|
|
1088
|
-
case "w":
|
|
1089
|
-
numericDate = Math.round(value * week);
|
|
1090
|
-
break;
|
|
1091
|
-
default:
|
|
1092
|
-
numericDate = Math.round(value * year);
|
|
1093
|
-
break;
|
|
1094
|
-
}
|
|
1095
|
-
if (matched[1] === "-" || matched[4] === "ago") return -numericDate;
|
|
1096
|
-
return numericDate;
|
|
674
|
+
function fromOrganizationMutationAuthorityError(value, status, retryAfter) {
|
|
675
|
+
if (status === 400 || status === 413 || status === 415) return new AuthError("invalid_request", 400);
|
|
676
|
+
if (status === 409) return new AuthError("state_conflict", 409);
|
|
677
|
+
if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
|
|
678
|
+
const code = isObject$1(value) && typeof value.code === "string" ? value.code : void 0;
|
|
679
|
+
if (status === 403 && code === "REQUEST_ORIGIN_DENIED") return new AuthError("request_origin_denied", 403);
|
|
680
|
+
return fromOrganizationReadAuthorityError(value, status);
|
|
1097
681
|
}
|
|
1098
|
-
|
|
1099
|
-
if (value.
|
|
1100
|
-
return
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
if (
|
|
1104
|
-
|
|
1105
|
-
return false;
|
|
1106
|
-
};
|
|
1107
|
-
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
1108
|
-
let payload;
|
|
1109
|
-
try {
|
|
1110
|
-
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
1111
|
-
} catch {}
|
|
1112
|
-
if (!isObject$1(payload)) throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
1113
|
-
const { typ } = options;
|
|
1114
|
-
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) throw new JWTClaimValidationFailed("unexpected \"typ\" JWT header value", payload, "typ", "check_failed");
|
|
1115
|
-
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
1116
|
-
const presenceCheck = [...requiredClaims];
|
|
1117
|
-
if (maxTokenAge !== void 0) presenceCheck.push("iat");
|
|
1118
|
-
if (audience !== void 0) presenceCheck.push("aud");
|
|
1119
|
-
if (subject !== void 0) presenceCheck.push("sub");
|
|
1120
|
-
if (issuer !== void 0) presenceCheck.push("iss");
|
|
1121
|
-
for (const claim of new Set(presenceCheck.reverse())) if (!(claim in payload)) throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
1122
|
-
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) throw new JWTClaimValidationFailed("unexpected \"iss\" claim value", payload, "iss", "check_failed");
|
|
1123
|
-
if (subject && payload.sub !== subject) throw new JWTClaimValidationFailed("unexpected \"sub\" claim value", payload, "sub", "check_failed");
|
|
1124
|
-
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) throw new JWTClaimValidationFailed("unexpected \"aud\" claim value", payload, "aud", "check_failed");
|
|
1125
|
-
let tolerance;
|
|
1126
|
-
switch (typeof options.clockTolerance) {
|
|
1127
|
-
case "string":
|
|
1128
|
-
tolerance = secs(options.clockTolerance);
|
|
1129
|
-
break;
|
|
1130
|
-
case "number":
|
|
1131
|
-
tolerance = options.clockTolerance;
|
|
1132
|
-
break;
|
|
1133
|
-
case "undefined":
|
|
1134
|
-
tolerance = 0;
|
|
1135
|
-
break;
|
|
1136
|
-
default: throw new TypeError("Invalid clockTolerance option type");
|
|
1137
|
-
}
|
|
1138
|
-
const { currentDate } = options;
|
|
1139
|
-
const now = epoch(currentDate || new Date());
|
|
1140
|
-
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") throw new JWTClaimValidationFailed("\"iat\" claim must be a number", payload, "iat", "invalid");
|
|
1141
|
-
if (payload.nbf !== void 0) {
|
|
1142
|
-
if (typeof payload.nbf !== "number") throw new JWTClaimValidationFailed("\"nbf\" claim must be a number", payload, "nbf", "invalid");
|
|
1143
|
-
if (payload.nbf > now + tolerance) throw new JWTClaimValidationFailed("\"nbf\" claim timestamp check failed", payload, "nbf", "check_failed");
|
|
1144
|
-
}
|
|
1145
|
-
if (payload.exp !== void 0) {
|
|
1146
|
-
if (typeof payload.exp !== "number") throw new JWTClaimValidationFailed("\"exp\" claim must be a number", payload, "exp", "invalid");
|
|
1147
|
-
if (payload.exp <= now - tolerance) throw new JWTExpired("\"exp\" claim timestamp check failed", payload, "exp", "check_failed");
|
|
1148
|
-
}
|
|
1149
|
-
if (maxTokenAge) {
|
|
1150
|
-
const age = now - payload.iat;
|
|
1151
|
-
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
1152
|
-
if (age - tolerance > max) throw new JWTExpired("\"iat\" claim timestamp check failed (too far in the past)", payload, "iat", "check_failed");
|
|
1153
|
-
if (age < 0 - tolerance) throw new JWTClaimValidationFailed("\"iat\" claim timestamp check failed (it should be in the past)", payload, "iat", "check_failed");
|
|
1154
|
-
}
|
|
1155
|
-
return payload;
|
|
682
|
+
function fromOrganizationInvitationAdministrationError(value, status, retryAfter) {
|
|
683
|
+
if (status === 422 && isObject$1(value) && value.code === "RECOVERY_REQUIRED") return new AuthError("invitation_recovery_required", 422);
|
|
684
|
+
return fromOrganizationMutationAuthorityError(value, status, retryAfter);
|
|
685
|
+
}
|
|
686
|
+
function fromOrganizationMembershipRemovalError(value, status, retryAfter) {
|
|
687
|
+
if (status === 422 && isObject$1(value) && value.code === "RECOVERY_REQUIRED") return new AuthError("membership_removal_recovery_required", 422);
|
|
688
|
+
return fromOrganizationMutationAuthorityError(value, status, retryAfter);
|
|
1156
689
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
690
|
+
function normalizeOrganizationMemberAuthority(value, organizationId, memberId) {
|
|
691
|
+
exact$3(value, [
|
|
692
|
+
"organizationId",
|
|
693
|
+
"actor",
|
|
694
|
+
"target"
|
|
695
|
+
]);
|
|
696
|
+
if (!isId(value.organizationId) || value.organizationId !== organizationId) throw authorityUnavailable();
|
|
697
|
+
const actor = normalizeOrganizationAuthorityMemberOutcome(value.actor);
|
|
698
|
+
const target = normalizeOrganizationAuthorityMemberOutcome(value.target);
|
|
699
|
+
if (target.memberId !== memberId || actor.manualRole !== "owner" && actor.manualRole !== "admin") throw authorityUnavailable();
|
|
700
|
+
for (const member of [actor, target]) if (member.manualRole === "member" ? member.role === "owner" : member.role !== member.manualRole) throw authorityUnavailable();
|
|
701
|
+
if (actor.memberId === target.memberId && (actor.manualRole !== target.manualRole || actor.role !== target.role || actor.authorityRevision !== target.authorityRevision)) throw authorityUnavailable();
|
|
702
|
+
return {
|
|
703
|
+
organizationId: value.organizationId,
|
|
704
|
+
actor,
|
|
705
|
+
target
|
|
1165
706
|
};
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
707
|
+
}
|
|
708
|
+
function normalizeOrganizationAuthorityMemberOutcome(value, includesStatus = false) {
|
|
709
|
+
exact$3(value, [
|
|
710
|
+
"memberId",
|
|
711
|
+
"manualRole",
|
|
712
|
+
"role",
|
|
713
|
+
"authorityRevision",
|
|
714
|
+
...includesStatus ? ["status"] : []
|
|
715
|
+
]);
|
|
716
|
+
if (!isId(value.memberId) || value.manualRole !== "owner" && value.manualRole !== "admin" && value.manualRole !== "member" || value.role !== "owner" && value.role !== "admin" && value.role !== "member") throw authorityUnavailable();
|
|
717
|
+
return {
|
|
718
|
+
memberId: value.memberId,
|
|
719
|
+
manualRole: value.manualRole,
|
|
720
|
+
role: value.role,
|
|
721
|
+
authorityRevision: normalizeAuthorityResultRevision(value.authorityRevision)
|
|
1169
722
|
};
|
|
1170
|
-
return result;
|
|
1171
723
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
if (typeof value !== "string" || !value) throw new JWKInvalid(`${description} missing or invalid`);
|
|
1176
|
-
};
|
|
1177
|
-
async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
1178
|
-
let jwk;
|
|
1179
|
-
if (isJWK(key)) jwk = key;
|
|
1180
|
-
else if (isKeyLike(key)) jwk = await exportJWK(key);
|
|
1181
|
-
else throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1182
|
-
digestAlgorithm ??= "sha256";
|
|
1183
|
-
if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") throw new TypeError("digestAlgorithm must one of \"sha256\", \"sha384\", or \"sha512\"");
|
|
1184
|
-
let components;
|
|
1185
|
-
switch (jwk.kty) {
|
|
1186
|
-
case "AKP":
|
|
1187
|
-
check(jwk.alg, "\"alg\" (Algorithm) Parameter");
|
|
1188
|
-
check(jwk.pub, "\"pub\" (Public key) Parameter");
|
|
1189
|
-
components = {
|
|
1190
|
-
alg: jwk.alg,
|
|
1191
|
-
kty: jwk.kty,
|
|
1192
|
-
pub: jwk.pub
|
|
1193
|
-
};
|
|
1194
|
-
break;
|
|
1195
|
-
case "EC":
|
|
1196
|
-
check(jwk.crv, "\"crv\" (Curve) Parameter");
|
|
1197
|
-
check(jwk.x, "\"x\" (X Coordinate) Parameter");
|
|
1198
|
-
check(jwk.y, "\"y\" (Y Coordinate) Parameter");
|
|
1199
|
-
components = {
|
|
1200
|
-
crv: jwk.crv,
|
|
1201
|
-
kty: jwk.kty,
|
|
1202
|
-
x: jwk.x,
|
|
1203
|
-
y: jwk.y
|
|
1204
|
-
};
|
|
1205
|
-
break;
|
|
1206
|
-
case "OKP":
|
|
1207
|
-
check(jwk.crv, "\"crv\" (Subtype of Key Pair) Parameter");
|
|
1208
|
-
check(jwk.x, "\"x\" (Public Key) Parameter");
|
|
1209
|
-
components = {
|
|
1210
|
-
crv: jwk.crv,
|
|
1211
|
-
kty: jwk.kty,
|
|
1212
|
-
x: jwk.x
|
|
1213
|
-
};
|
|
1214
|
-
break;
|
|
1215
|
-
case "RSA":
|
|
1216
|
-
check(jwk.e, "\"e\" (Exponent) Parameter");
|
|
1217
|
-
check(jwk.n, "\"n\" (Modulus) Parameter");
|
|
1218
|
-
components = {
|
|
1219
|
-
e: jwk.e,
|
|
1220
|
-
kty: jwk.kty,
|
|
1221
|
-
n: jwk.n
|
|
1222
|
-
};
|
|
1223
|
-
break;
|
|
1224
|
-
case "oct":
|
|
1225
|
-
check(jwk.k, "\"k\" (Key Value) Parameter");
|
|
1226
|
-
components = {
|
|
1227
|
-
k: jwk.k,
|
|
1228
|
-
kty: jwk.kty
|
|
1229
|
-
};
|
|
1230
|
-
break;
|
|
1231
|
-
default: throw new JOSENotSupported("\"kty\" (Key Type) Parameter missing or unsupported");
|
|
1232
|
-
}
|
|
1233
|
-
const data = encode$1(JSON.stringify(components));
|
|
1234
|
-
return encode(await digest(digestAlgorithm, data));
|
|
724
|
+
function normalizeAuthorityResultRevision(value) {
|
|
725
|
+
if (!Number.isSafeInteger(value) || value < 0 || value >= Number.MAX_SAFE_INTEGER) throw authorityUnavailable();
|
|
726
|
+
return value;
|
|
1235
727
|
}
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
if (
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
else throw new TypeError("Token does not contain a Protected Header");
|
|
1245
|
-
try {
|
|
1246
|
-
if (typeof protectedB64u !== "string" || !protectedB64u) throw new Error();
|
|
1247
|
-
const result = JSON.parse(decoder.decode(decode(protectedB64u)));
|
|
1248
|
-
if (!isObject$1(result)) throw new Error();
|
|
1249
|
-
return result;
|
|
1250
|
-
} catch {
|
|
1251
|
-
throw new TypeError("Invalid Token or Protected Header formatting");
|
|
1252
|
-
}
|
|
728
|
+
function fromInvitationAuthorityError(value, status) {
|
|
729
|
+
const code = isObject$1(value) && typeof value.code === "string" ? value.code : void 0;
|
|
730
|
+
if (status === 401 && code === "UNAUTHORIZED") return new AuthError("authentication_required", 401);
|
|
731
|
+
if (status === 403 && (code === "INVALID_ORIGIN" || code === "MISSING_OR_NULL_ORIGIN")) return new AuthError("request_origin_denied", 403);
|
|
732
|
+
if (status === 403 && code === "YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION") return new AuthError("invitation_recipient_mismatch", 403);
|
|
733
|
+
if (status === 403 && code === "EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION") return new AuthError("email_verification_required", 403);
|
|
734
|
+
if (status === 400 && (code === "INVITATION_NOT_FOUND" || code === "ORGANIZATION_NOT_FOUND" || code === "TEAM_NOT_FOUND")) return new AuthError("invitation_unavailable", 409);
|
|
735
|
+
return authorityUnavailable();
|
|
1253
736
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
function decodeJwt(jwt) {
|
|
1257
|
-
if (typeof jwt !== "string") throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
1258
|
-
const { 1: payload, length } = jwt.split(".");
|
|
1259
|
-
if (length === 5) throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
|
|
1260
|
-
if (length !== 3) throw new JWTInvalid("Invalid JWT");
|
|
1261
|
-
if (!payload) throw new JWTInvalid("JWTs must contain a payload");
|
|
1262
|
-
let decoded;
|
|
1263
|
-
try {
|
|
1264
|
-
decoded = decode(payload);
|
|
1265
|
-
} catch {
|
|
1266
|
-
throw new JWTInvalid("Failed to base64url decode the payload");
|
|
1267
|
-
}
|
|
1268
|
-
let result;
|
|
1269
|
-
try {
|
|
1270
|
-
result = JSON.parse(decoder.decode(decoded));
|
|
1271
|
-
} catch {
|
|
1272
|
-
throw new JWTInvalid("Failed to parse the decoded payload as JSON");
|
|
1273
|
-
}
|
|
1274
|
-
if (!isObject$1(result)) throw new JWTInvalid("Invalid JWT Claims Set");
|
|
1275
|
-
return result;
|
|
737
|
+
function fromInvitationError(error) {
|
|
738
|
+
return error instanceof AuthError ? error : authorityUnavailable();
|
|
1276
739
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
740
|
+
function mapError(code, status) {
|
|
741
|
+
if (code === "authentication_required") return {
|
|
742
|
+
code,
|
|
743
|
+
status: 401
|
|
744
|
+
};
|
|
745
|
+
if (code === "request_origin_denied") return {
|
|
746
|
+
code,
|
|
747
|
+
status: 403
|
|
748
|
+
};
|
|
749
|
+
if (code === "invalid_workspace_selection") return {
|
|
750
|
+
code,
|
|
751
|
+
status: 422
|
|
752
|
+
};
|
|
753
|
+
if (code === "organization_context_too_large") return {
|
|
754
|
+
code,
|
|
755
|
+
status: 422
|
|
756
|
+
};
|
|
757
|
+
if (code === "credential_rate_limited") return {
|
|
758
|
+
code,
|
|
759
|
+
status: 429
|
|
760
|
+
};
|
|
761
|
+
if (code === "identity_authority_unavailable") return {
|
|
762
|
+
code,
|
|
763
|
+
status: 503
|
|
764
|
+
};
|
|
765
|
+
if (status === 401 || status === 400) return {
|
|
766
|
+
code: "invalid_credentials",
|
|
767
|
+
status: 401
|
|
768
|
+
};
|
|
769
|
+
if (status === 403) return {
|
|
770
|
+
code: "access_denied",
|
|
771
|
+
status: 403
|
|
772
|
+
};
|
|
773
|
+
if (status === 409) return {
|
|
774
|
+
code: "state_conflict",
|
|
775
|
+
status: 409
|
|
776
|
+
};
|
|
777
|
+
if (status === 422) return {
|
|
778
|
+
code: "invalid_workspace_selection",
|
|
779
|
+
status: 422
|
|
780
|
+
};
|
|
781
|
+
if (status === 429) return {
|
|
782
|
+
code: "credential_rate_limited",
|
|
783
|
+
status: 429
|
|
784
|
+
};
|
|
785
|
+
return {
|
|
786
|
+
code: "identity_authority_unavailable",
|
|
787
|
+
status: 503
|
|
788
|
+
};
|
|
1288
789
|
}
|
|
1289
|
-
function
|
|
1290
|
-
|
|
790
|
+
function parseRetryAfter(value) {
|
|
791
|
+
if (!value || !/^\d+$/.test(value)) return void 0;
|
|
792
|
+
const seconds = Number(value);
|
|
793
|
+
return Number.isSafeInteger(seconds) && seconds >= 1 && seconds <= 3600 ? seconds : void 0;
|
|
1291
794
|
}
|
|
1292
|
-
function
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
case "false": return false;
|
|
1299
|
-
case "undefined": return;
|
|
1300
|
-
case "null": return null;
|
|
1301
|
-
case "nan": return NaN;
|
|
1302
|
-
case "infinity": return Number.POSITIVE_INFINITY;
|
|
1303
|
-
case "-infinity": return Number.NEGATIVE_INFINITY;
|
|
1304
|
-
}
|
|
1305
|
-
if (!JsonSigRx.test(value)) {
|
|
1306
|
-
if (options.strict) throw new SyntaxError("[destr] Invalid JSON");
|
|
1307
|
-
return value;
|
|
1308
|
-
}
|
|
1309
|
-
try {
|
|
1310
|
-
if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
|
|
1311
|
-
if (options.strict) throw new Error("[destr] Possible prototype pollution");
|
|
1312
|
-
return JSON.parse(value, jsonParseTransform);
|
|
1313
|
-
}
|
|
1314
|
-
return JSON.parse(value);
|
|
1315
|
-
} catch (error) {
|
|
1316
|
-
if (options.strict) throw error;
|
|
1317
|
-
return value;
|
|
1318
|
-
}
|
|
795
|
+
function toDate(value) {
|
|
796
|
+
const result = value instanceof Date ? value : typeof value === "string" ? new Date(value) : void 0;
|
|
797
|
+
return result && Number.isFinite(result.getTime()) ? result : void 0;
|
|
798
|
+
}
|
|
799
|
+
function isId(value) {
|
|
800
|
+
return typeof value === "string" && id.test(value);
|
|
1319
801
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
802
|
+
function exact$3(value, keys) {
|
|
803
|
+
if (!isObject$1(value) || Object.keys(value).sort().join(",") !== [...keys].sort().join(",")) throw authorityUnavailable();
|
|
804
|
+
}
|
|
805
|
+
function boundedString(value, maximum) {
|
|
806
|
+
return typeof value === "string" && value.length > 0 && new TextEncoder().encode(value).byteLength <= maximum;
|
|
807
|
+
}
|
|
808
|
+
function role(value) {
|
|
809
|
+
return value === "owner" || value === "admin" || value === "member";
|
|
810
|
+
}
|
|
811
|
+
function nullableHttpsUrl(value) {
|
|
812
|
+
if (value === null) return null;
|
|
813
|
+
if (typeof value !== "string" || value.length > 2048) throw authorityUnavailable();
|
|
814
|
+
let url;
|
|
815
|
+
try {
|
|
816
|
+
url = new URL(value);
|
|
817
|
+
} catch {
|
|
818
|
+
throw authorityUnavailable();
|
|
1327
819
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
|
|
1331
|
-
const method = ctx.request?.method || ctx.options?.method || "GET";
|
|
1332
|
-
const url = ctx.request?.url || String(ctx.request) || "/";
|
|
1333
|
-
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);
|
|
1334
|
-
for (const key of [
|
|
1335
|
-
"request",
|
|
1336
|
-
"options",
|
|
1337
|
-
"response"
|
|
1338
|
-
]) Object.defineProperty(fetchError, key, { get() {
|
|
1339
|
-
return ctx[key];
|
|
1340
|
-
} });
|
|
1341
|
-
for (const [key, refKey] of [
|
|
1342
|
-
["data", "_data"],
|
|
1343
|
-
["status", "status"],
|
|
1344
|
-
["statusCode", "status"],
|
|
1345
|
-
["statusText", "statusText"],
|
|
1346
|
-
["statusMessage", "statusText"]
|
|
1347
|
-
]) Object.defineProperty(fetchError, key, { get() {
|
|
1348
|
-
return ctx.response && ctx.response[refKey];
|
|
1349
|
-
} });
|
|
1350
|
-
return fetchError;
|
|
820
|
+
if (url.protocol !== "https:" || url.username || url.password || url.toString() !== value) throw authorityUnavailable();
|
|
821
|
+
return value;
|
|
1351
822
|
}
|
|
1352
|
-
|
|
1353
|
-
"
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
]));
|
|
1358
|
-
function isPayloadMethod(method = "GET") {
|
|
1359
|
-
return payloadMethods.has(method.toUpperCase());
|
|
823
|
+
function responseDate(value) {
|
|
824
|
+
if (typeof value !== "string") throw authorityUnavailable();
|
|
825
|
+
const date = new Date(value);
|
|
826
|
+
if (!Number.isFinite(date.getTime()) || date.toISOString() !== value) throw authorityUnavailable();
|
|
827
|
+
return date;
|
|
1360
828
|
}
|
|
1361
|
-
function
|
|
1362
|
-
if (value ===
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
if (t !== "object") return false;
|
|
1366
|
-
if (Array.isArray(value)) return true;
|
|
1367
|
-
if (value.buffer) return false;
|
|
1368
|
-
if (value instanceof FormData || value instanceof URLSearchParams) return false;
|
|
1369
|
-
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
829
|
+
function nullableCursor(value) {
|
|
830
|
+
if (value === null) return null;
|
|
831
|
+
if (typeof value !== "string" || value.length < 1 || value.length > 820 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value)) throw authorityUnavailable();
|
|
832
|
+
return value;
|
|
1370
833
|
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
"application/xhtml",
|
|
1375
|
-
"application/html"
|
|
1376
|
-
]);
|
|
1377
|
-
const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
|
|
1378
|
-
function detectResponseType(_contentType = "") {
|
|
1379
|
-
if (!_contentType) return "json";
|
|
1380
|
-
const contentType = _contentType.split(";").shift() || "";
|
|
1381
|
-
if (JSON_RE.test(contentType)) return "json";
|
|
1382
|
-
if (contentType === "text/event-stream") return "stream";
|
|
1383
|
-
if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
|
|
1384
|
-
return "blob";
|
|
834
|
+
function normalizeResponseId(value) {
|
|
835
|
+
if (!isId(value)) throw authorityUnavailable();
|
|
836
|
+
return value;
|
|
1385
837
|
}
|
|
1386
|
-
function
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
if (defaults?.query || defaults?.params || input?.params || input?.query) query = {
|
|
1390
|
-
...defaults?.params,
|
|
1391
|
-
...defaults?.query,
|
|
1392
|
-
...input?.params,
|
|
1393
|
-
...input?.query
|
|
1394
|
-
};
|
|
1395
|
-
return {
|
|
1396
|
-
...defaults,
|
|
1397
|
-
...input,
|
|
1398
|
-
query,
|
|
1399
|
-
params: query,
|
|
1400
|
-
headers
|
|
1401
|
-
};
|
|
838
|
+
function unique(items, key) {
|
|
839
|
+
if (new Set(items.map(key)).size !== items.length) throw authorityUnavailable();
|
|
840
|
+
return items;
|
|
1402
841
|
}
|
|
1403
|
-
function
|
|
1404
|
-
|
|
1405
|
-
const headers = new Headers(defaults);
|
|
1406
|
-
if (input) for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) headers.set(key, value);
|
|
1407
|
-
return headers;
|
|
842
|
+
function isObject$1(value) {
|
|
843
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1408
844
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
845
|
+
//#endregion
|
|
846
|
+
//#region src/user-api/credential.ts
|
|
847
|
+
function userApiApplication(input) {
|
|
848
|
+
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");
|
|
849
|
+
return input.applicationId;
|
|
1412
850
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
502,
|
|
1420
|
-
503,
|
|
1421
|
-
504
|
|
1422
|
-
]);
|
|
1423
|
-
const nullBodyResponses = new Set([
|
|
1424
|
-
101,
|
|
1425
|
-
204,
|
|
1426
|
-
205,
|
|
1427
|
-
304
|
|
1428
|
-
]);
|
|
1429
|
-
function createFetch(globalOptions = {}) {
|
|
1430
|
-
const { fetch = globalThis.fetch, Headers = globalThis.Headers, AbortController = globalThis.AbortController } = globalOptions;
|
|
1431
|
-
async function onError(context) {
|
|
1432
|
-
const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
|
|
1433
|
-
if (context.options.retry !== false && !isAbort) {
|
|
1434
|
-
let retries;
|
|
1435
|
-
if (typeof context.options.retry === "number") retries = context.options.retry;
|
|
1436
|
-
else retries = isPayloadMethod(context.options.method) ? 0 : 1;
|
|
1437
|
-
const responseCode = context.response && context.response.status || 500;
|
|
1438
|
-
if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
|
|
1439
|
-
const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
|
|
1440
|
-
if (retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
1441
|
-
return $fetchRaw(context.request, {
|
|
1442
|
-
...context.options,
|
|
1443
|
-
retry: retries - 1
|
|
1444
|
-
});
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
const error = createFetchError(context);
|
|
1448
|
-
if (Error.captureStackTrace) Error.captureStackTrace(error, $fetchRaw);
|
|
1449
|
-
throw error;
|
|
1450
|
-
}
|
|
1451
|
-
const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
|
|
1452
|
-
const context = {
|
|
1453
|
-
request: _request,
|
|
1454
|
-
options: resolveFetchOptions(_request, _options, globalOptions.defaults, Headers),
|
|
1455
|
-
response: void 0,
|
|
1456
|
-
error: void 0
|
|
1457
|
-
};
|
|
1458
|
-
if (context.options.method) context.options.method = context.options.method.toUpperCase();
|
|
1459
|
-
if (context.options.onRequest) {
|
|
1460
|
-
await callHooks(context, context.options.onRequest);
|
|
1461
|
-
if (!(context.options.headers instanceof Headers)) context.options.headers = new Headers(context.options.headers || {});
|
|
1462
|
-
}
|
|
1463
|
-
if (typeof context.request === "string") {
|
|
1464
|
-
if (context.options.baseURL) context.request = withBase(context.request, context.options.baseURL);
|
|
1465
|
-
if (context.options.query) {
|
|
1466
|
-
context.request = withQuery(context.request, context.options.query);
|
|
1467
|
-
delete context.options.query;
|
|
1468
|
-
}
|
|
1469
|
-
if ("query" in context.options) delete context.options.query;
|
|
1470
|
-
if ("params" in context.options) delete context.options.params;
|
|
1471
|
-
}
|
|
1472
|
-
if (context.options.body && isPayloadMethod(context.options.method)) {
|
|
1473
|
-
if (isJSONSerializable(context.options.body)) {
|
|
1474
|
-
const contentType = context.options.headers.get("content-type");
|
|
1475
|
-
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);
|
|
1476
|
-
if (!contentType) context.options.headers.set("content-type", "application/json");
|
|
1477
|
-
if (!context.options.headers.has("accept")) context.options.headers.set("accept", "application/json");
|
|
1478
|
-
} else if ("pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || typeof context.options.body.pipe === "function") {
|
|
1479
|
-
if (!("duplex" in context.options)) context.options.duplex = "half";
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
let abortTimeout;
|
|
1483
|
-
if (!context.options.signal && context.options.timeout) {
|
|
1484
|
-
const controller = new AbortController();
|
|
1485
|
-
abortTimeout = setTimeout(() => {
|
|
1486
|
-
const error = new Error("[TimeoutError]: The operation was aborted due to timeout");
|
|
1487
|
-
error.name = "TimeoutError";
|
|
1488
|
-
error.code = 23;
|
|
1489
|
-
controller.abort(error);
|
|
1490
|
-
}, context.options.timeout);
|
|
1491
|
-
context.options.signal = controller.signal;
|
|
1492
|
-
}
|
|
1493
|
-
try {
|
|
1494
|
-
context.response = await fetch(context.request, context.options);
|
|
1495
|
-
} catch (error) {
|
|
1496
|
-
context.error = error;
|
|
1497
|
-
if (context.options.onRequestError) await callHooks(context, context.options.onRequestError);
|
|
1498
|
-
return await onError(context);
|
|
1499
|
-
} finally {
|
|
1500
|
-
if (abortTimeout) clearTimeout(abortTimeout);
|
|
1501
|
-
}
|
|
1502
|
-
if ((context.response.body || context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD") {
|
|
1503
|
-
const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
|
|
1504
|
-
switch (responseType) {
|
|
1505
|
-
case "json": {
|
|
1506
|
-
const data = await context.response.text();
|
|
1507
|
-
const parseFunction = context.options.parseResponse || destr;
|
|
1508
|
-
context.response._data = parseFunction(data);
|
|
1509
|
-
break;
|
|
1510
|
-
}
|
|
1511
|
-
case "stream":
|
|
1512
|
-
context.response._data = context.response.body || context.response._bodyInit;
|
|
1513
|
-
break;
|
|
1514
|
-
default: context.response._data = await context.response[responseType]();
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
if (context.options.onResponse) await callHooks(context, context.options.onResponse);
|
|
1518
|
-
if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
|
|
1519
|
-
if (context.options.onResponseError) await callHooks(context, context.options.onResponseError);
|
|
1520
|
-
return await onError(context);
|
|
1521
|
-
}
|
|
1522
|
-
return context.response;
|
|
1523
|
-
};
|
|
1524
|
-
const $fetch = async function $fetch2(request, options) {
|
|
1525
|
-
return (await $fetchRaw(request, options))._data;
|
|
851
|
+
function normalizeUserApiCredential(value, startedAt) {
|
|
852
|
+
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);
|
|
853
|
+
return {
|
|
854
|
+
tokenType: "Bearer",
|
|
855
|
+
token: value.token,
|
|
856
|
+
expiresAt: new Date(startedAt + value.expiresIn * 1e3)
|
|
1526
857
|
};
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
858
|
+
}
|
|
859
|
+
//#endregion
|
|
860
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
861
|
+
const encoder$1 = new TextEncoder();
|
|
862
|
+
const decoder = new TextDecoder();
|
|
863
|
+
function concat(...buffers) {
|
|
864
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
865
|
+
const buf = new Uint8Array(size);
|
|
866
|
+
let i = 0;
|
|
867
|
+
for (const buffer of buffers) {
|
|
868
|
+
buf.set(buffer, i);
|
|
869
|
+
i += buffer.length;
|
|
870
|
+
}
|
|
871
|
+
return buf;
|
|
872
|
+
}
|
|
873
|
+
function encode$1(string) {
|
|
874
|
+
const bytes = new Uint8Array(string.length);
|
|
875
|
+
for (let i = 0; i < string.length; i++) {
|
|
876
|
+
const code = string.charCodeAt(i);
|
|
877
|
+
if (code > 127) throw new TypeError("non-ASCII string encountered in encode()");
|
|
878
|
+
bytes[i] = code;
|
|
879
|
+
}
|
|
880
|
+
return bytes;
|
|
881
|
+
}
|
|
882
|
+
//#endregion
|
|
883
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/base64.js
|
|
884
|
+
function encodeBase64(input) {
|
|
885
|
+
if (Uint8Array.prototype.toBase64) return input.toBase64();
|
|
886
|
+
const CHUNK_SIZE = 32768;
|
|
887
|
+
const arr = [];
|
|
888
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
889
|
+
return btoa(arr.join(""));
|
|
890
|
+
}
|
|
891
|
+
function decodeBase64(encoded) {
|
|
892
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded);
|
|
893
|
+
const binary = atob(encoded);
|
|
894
|
+
const bytes = new Uint8Array(binary.length);
|
|
895
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
896
|
+
return bytes;
|
|
897
|
+
}
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/util/base64url.js
|
|
900
|
+
function decode(input) {
|
|
901
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
|
|
902
|
+
let encoded = input;
|
|
903
|
+
if (encoded instanceof Uint8Array) encoded = decoder.decode(encoded);
|
|
904
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
905
|
+
try {
|
|
906
|
+
return decodeBase64(encoded);
|
|
907
|
+
} catch {
|
|
908
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
function encode(input) {
|
|
912
|
+
let unencoded = input;
|
|
913
|
+
if (typeof unencoded === "string") unencoded = encoder$1.encode(unencoded);
|
|
914
|
+
if (Uint8Array.prototype.toBase64) return unencoded.toBase64({
|
|
915
|
+
alphabet: "base64url",
|
|
916
|
+
omitPadding: true
|
|
1537
917
|
});
|
|
1538
|
-
return
|
|
918
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1539
919
|
}
|
|
1540
920
|
//#endregion
|
|
1541
|
-
//#region
|
|
1542
|
-
const
|
|
1543
|
-
const
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
function normalizeEmail(value) {
|
|
1547
|
-
if (typeof value !== "string") throw new TypeError("email is invalid");
|
|
1548
|
-
const normalized = value.trim().toLowerCase();
|
|
1549
|
-
if (normalized.length === 0 || normalized.length > 320 || !email.test(normalized)) throw new TypeError("email is invalid");
|
|
1550
|
-
return normalized;
|
|
921
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
922
|
+
const unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
923
|
+
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
924
|
+
function getHashLength(hash) {
|
|
925
|
+
return parseInt(hash.name.slice(4), 10);
|
|
1551
926
|
}
|
|
1552
|
-
function
|
|
1553
|
-
if (
|
|
1554
|
-
const keys = Object.keys(value);
|
|
1555
|
-
if (keys.length !== 3 && keys.length !== 4 || keys.some((key) => key !== "provider" && key !== "idToken" && key !== "nonce" && key !== "signUp") || value.provider !== "google" && value.provider !== "apple" || typeof value.signUp !== "boolean" || typeof value.idToken !== "string" || value.idToken.length < 1 || new TextEncoder().encode(value.idToken).byteLength > MAX_SOCIAL_ID_TOKEN_BYTES || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value.idToken) || value.nonce !== void 0 && (typeof value.nonce !== "string" || value.nonce.length < 1 || value.nonce.length > 256 || !/^[\x20-\x7e]+$/.test(value.nonce))) throw new TypeError("social ID token input is invalid");
|
|
1556
|
-
return {
|
|
1557
|
-
provider: value.provider,
|
|
1558
|
-
idToken: value.idToken,
|
|
1559
|
-
...value.nonce === void 0 ? {} : { nonce: value.nonce },
|
|
1560
|
-
signUp: value.signUp
|
|
1561
|
-
};
|
|
927
|
+
function checkHashLength(algorithm, expected) {
|
|
928
|
+
if (getHashLength(algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
1562
929
|
}
|
|
1563
|
-
function
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
requestSignUp: value.signUp
|
|
1571
|
-
};
|
|
930
|
+
function getNamedCurve(alg) {
|
|
931
|
+
switch (alg) {
|
|
932
|
+
case "ES256": return "P-256";
|
|
933
|
+
case "ES384": return "P-384";
|
|
934
|
+
case "ES512": return "P-521";
|
|
935
|
+
default: throw new Error("unreachable");
|
|
936
|
+
}
|
|
1572
937
|
}
|
|
1573
|
-
function
|
|
1574
|
-
if (
|
|
1575
|
-
|
|
938
|
+
function checkUsage(key, usage) {
|
|
939
|
+
if (usage && !key.usages.includes(usage)) throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
940
|
+
}
|
|
941
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
942
|
+
switch (alg) {
|
|
943
|
+
case "HS256":
|
|
944
|
+
case "HS384":
|
|
945
|
+
case "HS512":
|
|
946
|
+
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
947
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
948
|
+
break;
|
|
949
|
+
case "RS256":
|
|
950
|
+
case "RS384":
|
|
951
|
+
case "RS512":
|
|
952
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
953
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
954
|
+
break;
|
|
955
|
+
case "PS256":
|
|
956
|
+
case "PS384":
|
|
957
|
+
case "PS512":
|
|
958
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
959
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
960
|
+
break;
|
|
961
|
+
case "Ed25519":
|
|
962
|
+
case "EdDSA":
|
|
963
|
+
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
964
|
+
break;
|
|
965
|
+
case "ML-DSA-44":
|
|
966
|
+
case "ML-DSA-65":
|
|
967
|
+
case "ML-DSA-87":
|
|
968
|
+
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
969
|
+
break;
|
|
970
|
+
case "ES256":
|
|
971
|
+
case "ES384":
|
|
972
|
+
case "ES512": {
|
|
973
|
+
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
974
|
+
const expected = getNamedCurve(alg);
|
|
975
|
+
if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
978
|
+
default: throw new TypeError("CryptoKey does not support this operation");
|
|
979
|
+
}
|
|
980
|
+
checkUsage(key, usage);
|
|
981
|
+
}
|
|
982
|
+
//#endregion
|
|
983
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
984
|
+
function message(msg, actual, ...types) {
|
|
985
|
+
types = types.filter(Boolean);
|
|
986
|
+
if (types.length > 2) {
|
|
987
|
+
const last = types.pop();
|
|
988
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
989
|
+
} else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
990
|
+
else msg += `of type ${types[0]}.`;
|
|
991
|
+
if (actual == null) msg += ` Received ${actual}`;
|
|
992
|
+
else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
|
|
993
|
+
else if (typeof actual === "object" && actual != null) {
|
|
994
|
+
if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
|
|
995
|
+
}
|
|
996
|
+
return msg;
|
|
997
|
+
}
|
|
998
|
+
const invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
999
|
+
const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
1000
|
+
//#endregion
|
|
1001
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/util/errors.js
|
|
1002
|
+
var JOSEError = class extends Error {
|
|
1003
|
+
static code = "ERR_JOSE_GENERIC";
|
|
1004
|
+
code = "ERR_JOSE_GENERIC";
|
|
1005
|
+
constructor(message, options) {
|
|
1006
|
+
super(message, options);
|
|
1007
|
+
this.name = this.constructor.name;
|
|
1008
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
var JWTClaimValidationFailed = class extends JOSEError {
|
|
1012
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
1013
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
1014
|
+
claim;
|
|
1015
|
+
reason;
|
|
1016
|
+
payload;
|
|
1017
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
1018
|
+
super(message, { cause: {
|
|
1019
|
+
claim,
|
|
1020
|
+
reason,
|
|
1021
|
+
payload
|
|
1022
|
+
} });
|
|
1023
|
+
this.claim = claim;
|
|
1024
|
+
this.reason = reason;
|
|
1025
|
+
this.payload = payload;
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
var JWTExpired = class extends JOSEError {
|
|
1029
|
+
static code = "ERR_JWT_EXPIRED";
|
|
1030
|
+
code = "ERR_JWT_EXPIRED";
|
|
1031
|
+
claim;
|
|
1032
|
+
reason;
|
|
1033
|
+
payload;
|
|
1034
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
1035
|
+
super(message, { cause: {
|
|
1036
|
+
claim,
|
|
1037
|
+
reason,
|
|
1038
|
+
payload
|
|
1039
|
+
} });
|
|
1040
|
+
this.claim = claim;
|
|
1041
|
+
this.reason = reason;
|
|
1042
|
+
this.payload = payload;
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
1046
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
1047
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
1048
|
+
};
|
|
1049
|
+
var JOSENotSupported = class extends JOSEError {
|
|
1050
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
1051
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
1052
|
+
};
|
|
1053
|
+
var JWSInvalid = class extends JOSEError {
|
|
1054
|
+
static code = "ERR_JWS_INVALID";
|
|
1055
|
+
code = "ERR_JWS_INVALID";
|
|
1056
|
+
};
|
|
1057
|
+
var JWTInvalid = class extends JOSEError {
|
|
1058
|
+
static code = "ERR_JWT_INVALID";
|
|
1059
|
+
code = "ERR_JWT_INVALID";
|
|
1060
|
+
};
|
|
1061
|
+
var JWKInvalid = class extends JOSEError {
|
|
1062
|
+
static code = "ERR_JWK_INVALID";
|
|
1063
|
+
code = "ERR_JWK_INVALID";
|
|
1064
|
+
};
|
|
1065
|
+
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
1066
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
1067
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
1068
|
+
constructor(message = "signature verification failed", options) {
|
|
1069
|
+
super(message, options);
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
//#endregion
|
|
1073
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
1074
|
+
const isCryptoKey = (key) => {
|
|
1075
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
|
|
1576
1076
|
try {
|
|
1577
|
-
|
|
1077
|
+
return key instanceof CryptoKey;
|
|
1578
1078
|
} catch {
|
|
1579
|
-
|
|
1079
|
+
return false;
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
const isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
1083
|
+
const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
1084
|
+
//#endregion
|
|
1085
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/helpers.js
|
|
1086
|
+
function decodeBase64url(value, label, ErrorClass) {
|
|
1087
|
+
try {
|
|
1088
|
+
return decode(value);
|
|
1089
|
+
} catch {
|
|
1090
|
+
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
1580
1091
|
}
|
|
1581
|
-
const local = url.hostname === "localhost" || url.hostname.endsWith(".localhost") || url.hostname === "127.0.0.1";
|
|
1582
|
-
if (url.protocol !== "https:" && !(local && url.protocol === "http:") || url.username || url.password || url.pathname !== "/" || url.search || url.hash || url.origin !== value) throw new TypeError(`${name} must be an ASCII HTTP origin`);
|
|
1583
|
-
return url.origin;
|
|
1584
|
-
}
|
|
1585
|
-
function normalizeTimeout(value) {
|
|
1586
|
-
const timeout = value ?? 1e4;
|
|
1587
|
-
if (!Number.isSafeInteger(timeout) || timeout < 1 || timeout > 6e4) throw new TypeError("timeoutMs must be an integer from 1 to 60000");
|
|
1588
|
-
return timeout;
|
|
1589
1092
|
}
|
|
1590
|
-
function
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
const expiresAt = toDate(value.session.expiresAt);
|
|
1594
|
-
const image = value.user.image;
|
|
1595
|
-
if (!isId(value.session.id) || !expiresAt || !isId(value.user.id) || typeof value.user.name !== "string" || value.user.name.length > 256 || typeof value.user.email !== "string" || value.user.email.length > 320 || !email.test(value.user.email) || typeof value.user.emailVerified !== "boolean" || image !== null && image !== void 0 && (typeof image !== "string" || image.length > 2048)) throw authorityUnavailable();
|
|
1596
|
-
return {
|
|
1597
|
-
id: value.session.id,
|
|
1598
|
-
expiresAt,
|
|
1599
|
-
user: {
|
|
1600
|
-
id: value.user.id,
|
|
1601
|
-
name: value.user.name,
|
|
1602
|
-
email: value.user.email,
|
|
1603
|
-
emailVerified: value.user.emailVerified,
|
|
1604
|
-
image: image ?? null
|
|
1605
|
-
}
|
|
1606
|
-
};
|
|
1093
|
+
async function digest(algorithm, data) {
|
|
1094
|
+
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
1095
|
+
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
1607
1096
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1097
|
+
//#endregion
|
|
1098
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/type_checks.js
|
|
1099
|
+
const isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
1100
|
+
function isObject(input) {
|
|
1101
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
|
|
1102
|
+
if (Object.getPrototypeOf(input) === null) return true;
|
|
1103
|
+
let proto = input;
|
|
1104
|
+
while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
|
|
1105
|
+
return Object.getPrototypeOf(input) === proto;
|
|
1615
1106
|
}
|
|
1616
|
-
function
|
|
1617
|
-
|
|
1618
|
-
if (
|
|
1619
|
-
|
|
1620
|
-
const
|
|
1621
|
-
|
|
1622
|
-
if (!
|
|
1623
|
-
|
|
1107
|
+
function isDisjoint(...headers) {
|
|
1108
|
+
const sources = headers.filter(Boolean);
|
|
1109
|
+
if (sources.length === 0 || sources.length === 1) return true;
|
|
1110
|
+
let acc;
|
|
1111
|
+
for (const header of sources) {
|
|
1112
|
+
const parameters = Object.keys(header);
|
|
1113
|
+
if (!acc || acc.size === 0) {
|
|
1114
|
+
acc = new Set(parameters);
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1117
|
+
for (const parameter of parameters) {
|
|
1118
|
+
if (acc.has(parameter)) return false;
|
|
1119
|
+
acc.add(parameter);
|
|
1120
|
+
}
|
|
1624
1121
|
}
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1122
|
+
return true;
|
|
1123
|
+
}
|
|
1124
|
+
const isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
1125
|
+
const isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
1126
|
+
const isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
1127
|
+
const isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
1128
|
+
//#endregion
|
|
1129
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/signing.js
|
|
1130
|
+
function checkKeyLength(alg, key) {
|
|
1131
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
1132
|
+
const { modulusLength } = key.algorithm;
|
|
1133
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
1628
1134
|
}
|
|
1629
|
-
return query;
|
|
1630
1135
|
}
|
|
1631
|
-
function
|
|
1632
|
-
|
|
1633
|
-
|
|
1136
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
1137
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
1138
|
+
switch (alg) {
|
|
1139
|
+
case "HS256":
|
|
1140
|
+
case "HS384":
|
|
1141
|
+
case "HS512": return {
|
|
1142
|
+
hash,
|
|
1143
|
+
name: "HMAC"
|
|
1144
|
+
};
|
|
1145
|
+
case "PS256":
|
|
1146
|
+
case "PS384":
|
|
1147
|
+
case "PS512": return {
|
|
1148
|
+
hash,
|
|
1149
|
+
name: "RSA-PSS",
|
|
1150
|
+
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
1151
|
+
};
|
|
1152
|
+
case "RS256":
|
|
1153
|
+
case "RS384":
|
|
1154
|
+
case "RS512": return {
|
|
1155
|
+
hash,
|
|
1156
|
+
name: "RSASSA-PKCS1-v1_5"
|
|
1157
|
+
};
|
|
1158
|
+
case "ES256":
|
|
1159
|
+
case "ES384":
|
|
1160
|
+
case "ES512": return {
|
|
1161
|
+
hash,
|
|
1162
|
+
name: "ECDSA",
|
|
1163
|
+
namedCurve: algorithm.namedCurve
|
|
1164
|
+
};
|
|
1165
|
+
case "Ed25519":
|
|
1166
|
+
case "EdDSA": return { name: "Ed25519" };
|
|
1167
|
+
case "ML-DSA-44":
|
|
1168
|
+
case "ML-DSA-65":
|
|
1169
|
+
case "ML-DSA-87": return { name: alg };
|
|
1170
|
+
default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
1171
|
+
}
|
|
1634
1172
|
}
|
|
1635
|
-
function
|
|
1636
|
-
|
|
1637
|
-
"
|
|
1638
|
-
"
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
if (!isId(value.id) || !boundedString(value.name, 255) || !boundedString(value.slug, 255) || value.lifecycle !== "ordinary" && value.lifecycle !== "managed" || !role(value.role) || !isObject(value.capabilities)) throw authorityUnavailable();
|
|
1646
|
-
exact$3(value.capabilities, [
|
|
1647
|
-
"readInvitations",
|
|
1648
|
-
"readMembers",
|
|
1649
|
-
"readTeams"
|
|
1650
|
-
]);
|
|
1651
|
-
if (value.capabilities.readMembers !== true || value.capabilities.readTeams !== true || typeof value.capabilities.readInvitations !== "boolean") throw authorityUnavailable();
|
|
1652
|
-
return {
|
|
1653
|
-
id: value.id,
|
|
1654
|
-
name: value.name,
|
|
1655
|
-
slug: value.slug,
|
|
1656
|
-
logo: nullableHttpsUrl(value.logo),
|
|
1657
|
-
lifecycle: value.lifecycle,
|
|
1658
|
-
role: value.role,
|
|
1659
|
-
capabilities: {
|
|
1660
|
-
readMembers: true,
|
|
1661
|
-
readTeams: true,
|
|
1662
|
-
readInvitations: value.capabilities.readInvitations
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1173
|
+
async function getSigKey(alg, key, usage) {
|
|
1174
|
+
if (key instanceof Uint8Array) {
|
|
1175
|
+
if (!alg.startsWith("HS")) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1176
|
+
return crypto.subtle.importKey("raw", key, {
|
|
1177
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
1178
|
+
name: "HMAC"
|
|
1179
|
+
}, false, [usage]);
|
|
1180
|
+
}
|
|
1181
|
+
checkSigCryptoKey(key, alg, usage);
|
|
1182
|
+
return key;
|
|
1665
1183
|
}
|
|
1666
|
-
function
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1184
|
+
async function verify(alg, key, signature, data) {
|
|
1185
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
1186
|
+
checkKeyLength(alg, cryptoKey);
|
|
1187
|
+
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
1670
1188
|
try {
|
|
1671
|
-
|
|
1189
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
1672
1190
|
} catch {
|
|
1673
|
-
|
|
1191
|
+
return false;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
//#endregion
|
|
1195
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
1196
|
+
const unsupportedAlg = "Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value";
|
|
1197
|
+
function subtleMapping(jwk) {
|
|
1198
|
+
let algorithm;
|
|
1199
|
+
let keyUsages;
|
|
1200
|
+
switch (jwk.kty) {
|
|
1201
|
+
case "AKP":
|
|
1202
|
+
switch (jwk.alg) {
|
|
1203
|
+
case "ML-DSA-44":
|
|
1204
|
+
case "ML-DSA-65":
|
|
1205
|
+
case "ML-DSA-87":
|
|
1206
|
+
algorithm = { name: jwk.alg };
|
|
1207
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
1208
|
+
break;
|
|
1209
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
1210
|
+
}
|
|
1211
|
+
break;
|
|
1212
|
+
case "RSA":
|
|
1213
|
+
switch (jwk.alg) {
|
|
1214
|
+
case "PS256":
|
|
1215
|
+
case "PS384":
|
|
1216
|
+
case "PS512":
|
|
1217
|
+
algorithm = {
|
|
1218
|
+
name: "RSA-PSS",
|
|
1219
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
1220
|
+
};
|
|
1221
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1222
|
+
break;
|
|
1223
|
+
case "RS256":
|
|
1224
|
+
case "RS384":
|
|
1225
|
+
case "RS512":
|
|
1226
|
+
algorithm = {
|
|
1227
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
1228
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
1229
|
+
};
|
|
1230
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1231
|
+
break;
|
|
1232
|
+
case "RSA-OAEP":
|
|
1233
|
+
case "RSA-OAEP-256":
|
|
1234
|
+
case "RSA-OAEP-384":
|
|
1235
|
+
case "RSA-OAEP-512":
|
|
1236
|
+
algorithm = {
|
|
1237
|
+
name: "RSA-OAEP",
|
|
1238
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
1239
|
+
};
|
|
1240
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
1241
|
+
break;
|
|
1242
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
1243
|
+
}
|
|
1244
|
+
break;
|
|
1245
|
+
case "EC":
|
|
1246
|
+
switch (jwk.alg) {
|
|
1247
|
+
case "ES256":
|
|
1248
|
+
case "ES384":
|
|
1249
|
+
case "ES512":
|
|
1250
|
+
algorithm = {
|
|
1251
|
+
name: "ECDSA",
|
|
1252
|
+
namedCurve: {
|
|
1253
|
+
ES256: "P-256",
|
|
1254
|
+
ES384: "P-384",
|
|
1255
|
+
ES512: "P-521"
|
|
1256
|
+
}[jwk.alg]
|
|
1257
|
+
};
|
|
1258
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1259
|
+
break;
|
|
1260
|
+
case "ECDH-ES":
|
|
1261
|
+
case "ECDH-ES+A128KW":
|
|
1262
|
+
case "ECDH-ES+A192KW":
|
|
1263
|
+
case "ECDH-ES+A256KW":
|
|
1264
|
+
algorithm = {
|
|
1265
|
+
name: "ECDH",
|
|
1266
|
+
namedCurve: jwk.crv
|
|
1267
|
+
};
|
|
1268
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1269
|
+
break;
|
|
1270
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
1271
|
+
}
|
|
1272
|
+
break;
|
|
1273
|
+
case "OKP":
|
|
1274
|
+
switch (jwk.alg) {
|
|
1275
|
+
case "Ed25519":
|
|
1276
|
+
case "EdDSA":
|
|
1277
|
+
algorithm = { name: "Ed25519" };
|
|
1278
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1279
|
+
break;
|
|
1280
|
+
case "ECDH-ES":
|
|
1281
|
+
case "ECDH-ES+A128KW":
|
|
1282
|
+
case "ECDH-ES+A192KW":
|
|
1283
|
+
case "ECDH-ES+A256KW":
|
|
1284
|
+
algorithm = { name: jwk.crv };
|
|
1285
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1286
|
+
break;
|
|
1287
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
1288
|
+
}
|
|
1289
|
+
break;
|
|
1290
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
|
|
1674
1291
|
}
|
|
1675
1292
|
return {
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
logo
|
|
1293
|
+
algorithm,
|
|
1294
|
+
keyUsages
|
|
1679
1295
|
};
|
|
1680
1296
|
}
|
|
1681
|
-
function
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
function normalizeOrganizationTeamDisplayInput(value) {
|
|
1689
|
-
if (!isObject(value) || Object.keys(value).join(",") !== "name" || !boundedString(value.name, 255)) throw new AuthError("invalid_request", 400);
|
|
1690
|
-
return { name: value.name };
|
|
1297
|
+
async function jwkToKey(jwk) {
|
|
1298
|
+
if (!jwk.alg) throw new TypeError("\"alg\" argument is required when \"jwk.alg\" is not present");
|
|
1299
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
1300
|
+
const keyData = { ...jwk };
|
|
1301
|
+
if (keyData.kty !== "AKP") delete keyData.alg;
|
|
1302
|
+
delete keyData.use;
|
|
1303
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
1691
1304
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1305
|
+
//#endregion
|
|
1306
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
1307
|
+
const unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
|
|
1308
|
+
let cache;
|
|
1309
|
+
const handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
1310
|
+
cache ||= new WeakMap();
|
|
1311
|
+
let cached = cache.get(key);
|
|
1312
|
+
if (cached?.[alg]) return cached[alg];
|
|
1313
|
+
const cryptoKey = await jwkToKey({
|
|
1314
|
+
...jwk,
|
|
1315
|
+
alg
|
|
1316
|
+
});
|
|
1317
|
+
if (freeze) Object.freeze(key);
|
|
1318
|
+
if (!cached) cache.set(key, { [alg]: cryptoKey });
|
|
1319
|
+
else cached[alg] = cryptoKey;
|
|
1320
|
+
return cryptoKey;
|
|
1321
|
+
};
|
|
1322
|
+
const handleKeyObject = (keyObject, alg) => {
|
|
1323
|
+
cache ||= new WeakMap();
|
|
1324
|
+
let cached = cache.get(keyObject);
|
|
1325
|
+
if (cached?.[alg]) return cached[alg];
|
|
1326
|
+
const isPublic = keyObject.type === "public";
|
|
1327
|
+
const extractable = isPublic ? true : false;
|
|
1328
|
+
let cryptoKey;
|
|
1329
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
1330
|
+
switch (alg) {
|
|
1331
|
+
case "ECDH-ES":
|
|
1332
|
+
case "ECDH-ES+A128KW":
|
|
1333
|
+
case "ECDH-ES+A192KW":
|
|
1334
|
+
case "ECDH-ES+A256KW": break;
|
|
1335
|
+
default: throw new TypeError(unusableForAlg);
|
|
1336
|
+
}
|
|
1337
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1697
1338
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
return {
|
|
1702
|
-
name,
|
|
1703
|
-
slug,
|
|
1704
|
-
idempotencyKey
|
|
1705
|
-
};
|
|
1706
|
-
}
|
|
1707
|
-
function normalizeCreatedOrganization(value) {
|
|
1708
|
-
exact$3(value, [
|
|
1709
|
-
"id",
|
|
1710
|
-
"name",
|
|
1711
|
-
"slug"
|
|
1712
|
-
]);
|
|
1713
|
-
if (!isId(value.id) || !boundedString(value.name, 255) || !boundedString(value.slug, 128)) throw authorityUnavailable();
|
|
1714
|
-
return {
|
|
1715
|
-
id: value.id,
|
|
1716
|
-
name: value.name,
|
|
1717
|
-
slug: value.slug
|
|
1718
|
-
};
|
|
1719
|
-
}
|
|
1720
|
-
function normalizeOrganizationTeamCreationInput(name, idempotencyKey) {
|
|
1721
|
-
if (!boundedString(name, 255) || !boundedString(idempotencyKey, 255)) throw new AuthError("invalid_request", 400);
|
|
1722
|
-
return {
|
|
1723
|
-
name,
|
|
1724
|
-
idempotencyKey
|
|
1725
|
-
};
|
|
1726
|
-
}
|
|
1727
|
-
function normalizeCreatedOrganizationTeam(value) {
|
|
1728
|
-
exact$3(value, ["id", "name"]);
|
|
1729
|
-
if (!isId(value.id) || !boundedString(value.name, 255)) throw authorityUnavailable();
|
|
1730
|
-
return {
|
|
1731
|
-
id: value.id,
|
|
1732
|
-
name: value.name
|
|
1733
|
-
};
|
|
1734
|
-
}
|
|
1735
|
-
function normalizeOrganizationMemberInvitationCreationInput(value) {
|
|
1736
|
-
if (!isObject(value)) throw new AuthError("invalid_request", 400);
|
|
1737
|
-
const keys = Object.keys(value).sort().join(",");
|
|
1738
|
-
if (keys !== "email,idempotencyKey" && keys !== "email,idempotencyKey,teamIds") throw new AuthError("invalid_request", 400);
|
|
1739
|
-
let normalizedEmail;
|
|
1740
|
-
try {
|
|
1741
|
-
normalizedEmail = normalizeEmail(value.email);
|
|
1742
|
-
} catch {
|
|
1743
|
-
throw new AuthError("invalid_request", 400);
|
|
1339
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
1340
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") throw new TypeError(unusableForAlg);
|
|
1341
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
1744
1342
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1343
|
+
switch (keyObject.asymmetricKeyType) {
|
|
1344
|
+
case "ml-dsa-44":
|
|
1345
|
+
case "ml-dsa-65":
|
|
1346
|
+
case "ml-dsa-87":
|
|
1347
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) throw new TypeError(unusableForAlg);
|
|
1348
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
1349
|
+
}
|
|
1350
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
1351
|
+
let hash;
|
|
1352
|
+
switch (alg) {
|
|
1353
|
+
case "RSA-OAEP":
|
|
1354
|
+
hash = "SHA-1";
|
|
1355
|
+
break;
|
|
1356
|
+
case "RS256":
|
|
1357
|
+
case "PS256":
|
|
1358
|
+
case "RSA-OAEP-256":
|
|
1359
|
+
hash = "SHA-256";
|
|
1360
|
+
break;
|
|
1361
|
+
case "RS384":
|
|
1362
|
+
case "PS384":
|
|
1363
|
+
case "RSA-OAEP-384":
|
|
1364
|
+
hash = "SHA-384";
|
|
1365
|
+
break;
|
|
1366
|
+
case "RS512":
|
|
1367
|
+
case "PS512":
|
|
1368
|
+
case "RSA-OAEP-512":
|
|
1369
|
+
hash = "SHA-512";
|
|
1370
|
+
break;
|
|
1371
|
+
default: throw new TypeError(unusableForAlg);
|
|
1372
|
+
}
|
|
1373
|
+
if (alg.startsWith("RSA-OAEP")) return keyObject.toCryptoKey({
|
|
1374
|
+
name: "RSA-OAEP",
|
|
1375
|
+
hash
|
|
1376
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
1377
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1378
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
1379
|
+
hash
|
|
1380
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1381
|
+
}
|
|
1382
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
1383
|
+
const namedCurve = new Map([
|
|
1384
|
+
["prime256v1", "P-256"],
|
|
1385
|
+
["secp384r1", "P-384"],
|
|
1386
|
+
["secp521r1", "P-521"]
|
|
1387
|
+
]).get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
1388
|
+
if (!namedCurve) throw new TypeError(unusableForAlg);
|
|
1389
|
+
const expectedCurve = {
|
|
1390
|
+
ES256: "P-256",
|
|
1391
|
+
ES384: "P-384",
|
|
1392
|
+
ES512: "P-521"
|
|
1393
|
+
};
|
|
1394
|
+
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) cryptoKey = keyObject.toCryptoKey({
|
|
1395
|
+
name: "ECDSA",
|
|
1396
|
+
namedCurve
|
|
1397
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1398
|
+
if (alg.startsWith("ECDH-ES")) cryptoKey = keyObject.toCryptoKey({
|
|
1399
|
+
name: "ECDH",
|
|
1400
|
+
namedCurve
|
|
1401
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1402
|
+
}
|
|
1403
|
+
if (!cryptoKey) throw new TypeError(unusableForAlg);
|
|
1404
|
+
if (!cached) cache.set(keyObject, { [alg]: cryptoKey });
|
|
1405
|
+
else cached[alg] = cryptoKey;
|
|
1406
|
+
return cryptoKey;
|
|
1407
|
+
};
|
|
1408
|
+
async function normalizeKey(key, alg) {
|
|
1409
|
+
if (key instanceof Uint8Array) return key;
|
|
1410
|
+
if (isCryptoKey(key)) return key;
|
|
1411
|
+
if (isKeyObject(key)) {
|
|
1412
|
+
if (key.type === "secret") return key.export();
|
|
1413
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") try {
|
|
1414
|
+
return handleKeyObject(key, alg);
|
|
1415
|
+
} catch (err) {
|
|
1416
|
+
if (err instanceof TypeError) throw err;
|
|
1417
|
+
}
|
|
1418
|
+
let jwk = key.export({ format: "jwk" });
|
|
1419
|
+
return handleJWK(key, jwk, alg);
|
|
1420
|
+
}
|
|
1421
|
+
if (isJWK(key)) {
|
|
1422
|
+
if (key.k) return decode(key.k);
|
|
1423
|
+
return handleJWK(key, key, alg, true);
|
|
1424
|
+
}
|
|
1425
|
+
throw new Error("unreachable");
|
|
1779
1426
|
}
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1427
|
+
//#endregion
|
|
1428
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/key/import.js
|
|
1429
|
+
async function importJWK(jwk, alg, options) {
|
|
1430
|
+
if (!isObject(jwk)) throw new TypeError("JWK must be an object");
|
|
1431
|
+
let ext;
|
|
1432
|
+
alg ??= jwk.alg;
|
|
1433
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
1434
|
+
switch (jwk.kty) {
|
|
1435
|
+
case "oct":
|
|
1436
|
+
if (typeof jwk.k !== "string" || !jwk.k) throw new TypeError("missing \"k\" (Key Value) Parameter value");
|
|
1437
|
+
return decode(jwk.k);
|
|
1438
|
+
case "RSA":
|
|
1439
|
+
if ("oth" in jwk && jwk.oth !== void 0) throw new JOSENotSupported("RSA JWK \"oth\" (Other Primes Info) Parameter value is not supported");
|
|
1440
|
+
return jwkToKey({
|
|
1441
|
+
...jwk,
|
|
1442
|
+
alg,
|
|
1443
|
+
ext
|
|
1444
|
+
});
|
|
1445
|
+
case "AKP":
|
|
1446
|
+
if (typeof jwk.alg !== "string" || !jwk.alg) throw new TypeError("missing \"alg\" (Algorithm) Parameter value");
|
|
1447
|
+
if (alg !== void 0 && alg !== jwk.alg) throw new TypeError("JWK alg and alg option value mismatch");
|
|
1448
|
+
return jwkToKey({
|
|
1449
|
+
...jwk,
|
|
1450
|
+
ext
|
|
1451
|
+
});
|
|
1452
|
+
case "EC":
|
|
1453
|
+
case "OKP": return jwkToKey({
|
|
1454
|
+
...jwk,
|
|
1455
|
+
alg,
|
|
1456
|
+
ext
|
|
1457
|
+
});
|
|
1458
|
+
default: throw new JOSENotSupported("Unsupported \"kty\" (Key Type) Parameter value");
|
|
1459
|
+
}
|
|
1784
1460
|
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
return
|
|
1461
|
+
//#endregion
|
|
1462
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
1463
|
+
function omitUndefinedProperties(jwk) {
|
|
1464
|
+
return Object.fromEntries(Object.entries(jwk).filter(([, value]) => value !== void 0));
|
|
1789
1465
|
}
|
|
1790
|
-
function
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
return {
|
|
1794
|
-
|
|
1795
|
-
|
|
1466
|
+
async function keyToJWK(key) {
|
|
1467
|
+
if (isKeyObject(key)) if (key.type === "secret") key = key.export();
|
|
1468
|
+
else return key.export({ format: "jwk" });
|
|
1469
|
+
if (key instanceof Uint8Array) return {
|
|
1470
|
+
kty: "oct",
|
|
1471
|
+
k: encode(key)
|
|
1796
1472
|
};
|
|
1473
|
+
if (!isCryptoKey(key)) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
1474
|
+
if (!key.extractable) throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
1475
|
+
const { ext, key_ops, alg, use, ...jwk } = omitUndefinedProperties(await crypto.subtle.exportKey("jwk", key));
|
|
1476
|
+
if (jwk.kty === "AKP") jwk.alg = alg;
|
|
1477
|
+
return jwk;
|
|
1797
1478
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
return
|
|
1802
|
-
members: unique(value.members.map((member) => {
|
|
1803
|
-
exact$3(member, [
|
|
1804
|
-
"email",
|
|
1805
|
-
"id",
|
|
1806
|
-
"image",
|
|
1807
|
-
"joinedAt",
|
|
1808
|
-
"name",
|
|
1809
|
-
"owner",
|
|
1810
|
-
"role",
|
|
1811
|
-
"teamIds",
|
|
1812
|
-
"userId"
|
|
1813
|
-
]);
|
|
1814
|
-
if (!isId(member.id) || !isId(member.userId) || !boundedString(member.name, 255) || typeof member.email !== "string" || member.email.length > 320 || !email.test(member.email) || !role(member.role) || typeof member.owner !== "boolean" || !Array.isArray(member.teamIds) || member.teamIds.length > 100) throw authorityUnavailable();
|
|
1815
|
-
const teamIds = unique(member.teamIds.map((teamId) => normalizeResponseId(teamId)), (item) => item);
|
|
1816
|
-
return {
|
|
1817
|
-
id: member.id,
|
|
1818
|
-
userId: member.userId,
|
|
1819
|
-
name: member.name,
|
|
1820
|
-
email: member.email,
|
|
1821
|
-
image: nullableHttpsUrl(member.image),
|
|
1822
|
-
role: member.role,
|
|
1823
|
-
owner: member.owner,
|
|
1824
|
-
joinedAt: responseDate(member.joinedAt),
|
|
1825
|
-
teamIds
|
|
1826
|
-
};
|
|
1827
|
-
}), (item) => item.id),
|
|
1828
|
-
nextCursor: nullableCursor(value.nextCursor)
|
|
1829
|
-
};
|
|
1479
|
+
//#endregion
|
|
1480
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/key/export.js
|
|
1481
|
+
async function exportJWK(key) {
|
|
1482
|
+
return keyToJWK(key);
|
|
1830
1483
|
}
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
category: team.category,
|
|
1847
|
-
createdAt: responseDate(team.createdAt)
|
|
1848
|
-
};
|
|
1849
|
-
}), (item) => item.id),
|
|
1850
|
-
nextCursor: nullableCursor(value.nextCursor)
|
|
1851
|
-
};
|
|
1484
|
+
//#endregion
|
|
1485
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1486
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1487
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
|
|
1488
|
+
if (!protectedHeader || protectedHeader.crit === void 0) return new Set();
|
|
1489
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
|
|
1490
|
+
let recognized;
|
|
1491
|
+
if (recognizedOption !== void 0) recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
1492
|
+
else recognized = recognizedDefault;
|
|
1493
|
+
for (const parameter of protectedHeader.crit) {
|
|
1494
|
+
if (!recognized.has(parameter)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1495
|
+
if (joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1496
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1497
|
+
}
|
|
1498
|
+
return new Set(protectedHeader.crit);
|
|
1852
1499
|
}
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
};
|
|
1500
|
+
//#endregion
|
|
1501
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
1502
|
+
function validateAlgorithms(option, algorithms) {
|
|
1503
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) throw new TypeError(`"${option}" option must be an array of strings`);
|
|
1504
|
+
if (!algorithms) return;
|
|
1505
|
+
return new Set(algorithms);
|
|
1860
1506
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1507
|
+
//#endregion
|
|
1508
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
1509
|
+
const tag = (key) => key?.[Symbol.toStringTag];
|
|
1510
|
+
const jwkMatchesOp = (alg, key, usage) => {
|
|
1511
|
+
if (key.use !== void 0) {
|
|
1512
|
+
let expected;
|
|
1513
|
+
switch (usage) {
|
|
1514
|
+
case "sign":
|
|
1515
|
+
case "verify":
|
|
1516
|
+
expected = "sig";
|
|
1517
|
+
break;
|
|
1518
|
+
case "encrypt":
|
|
1519
|
+
case "decrypt":
|
|
1520
|
+
expected = "enc";
|
|
1521
|
+
break;
|
|
1522
|
+
}
|
|
1523
|
+
if (key.use !== expected) throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
1524
|
+
}
|
|
1525
|
+
if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
1526
|
+
if (Array.isArray(key.key_ops)) {
|
|
1527
|
+
let expectedKeyOp;
|
|
1528
|
+
switch (true) {
|
|
1529
|
+
case usage === "sign" || usage === "verify":
|
|
1530
|
+
case alg === "dir":
|
|
1531
|
+
case alg.includes("CBC-HS"):
|
|
1532
|
+
expectedKeyOp = usage;
|
|
1533
|
+
break;
|
|
1534
|
+
case alg.startsWith("PBES2"):
|
|
1535
|
+
expectedKeyOp = "deriveBits";
|
|
1536
|
+
break;
|
|
1537
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
1538
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
1539
|
+
else expectedKeyOp = usage;
|
|
1540
|
+
break;
|
|
1541
|
+
case usage === "encrypt" && alg.startsWith("RSA"):
|
|
1542
|
+
expectedKeyOp = "wrapKey";
|
|
1543
|
+
break;
|
|
1544
|
+
case usage === "decrypt":
|
|
1545
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
1546
|
+
break;
|
|
1547
|
+
}
|
|
1548
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
1549
|
+
}
|
|
1550
|
+
return true;
|
|
1551
|
+
};
|
|
1552
|
+
const symmetricTypeCheck = (alg, key, usage) => {
|
|
1553
|
+
if (key instanceof Uint8Array) return;
|
|
1554
|
+
if (isJWK(key)) {
|
|
1555
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
1556
|
+
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
1557
|
+
}
|
|
1558
|
+
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
1559
|
+
if (key.type !== "secret") throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
1560
|
+
};
|
|
1561
|
+
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
1562
|
+
if (isJWK(key)) switch (usage) {
|
|
1563
|
+
case "decrypt":
|
|
1564
|
+
case "sign":
|
|
1565
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
1566
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
1567
|
+
case "encrypt":
|
|
1568
|
+
case "verify":
|
|
1569
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
1570
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
1571
|
+
}
|
|
1572
|
+
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1573
|
+
if (key.type === "secret") throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
1574
|
+
if (key.type === "public") switch (usage) {
|
|
1575
|
+
case "sign": throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
1576
|
+
case "decrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
1577
|
+
}
|
|
1578
|
+
if (key.type === "private") switch (usage) {
|
|
1579
|
+
case "verify": throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
1580
|
+
case "encrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
function checkKeyType(alg, key, usage) {
|
|
1584
|
+
switch (alg.substring(0, 2)) {
|
|
1585
|
+
case "A1":
|
|
1586
|
+
case "A2":
|
|
1587
|
+
case "di":
|
|
1588
|
+
case "HS":
|
|
1589
|
+
case "PB":
|
|
1590
|
+
symmetricTypeCheck(alg, key, usage);
|
|
1591
|
+
break;
|
|
1592
|
+
default: asymmetricTypeCheck(alg, key, usage);
|
|
1593
|
+
}
|
|
1888
1594
|
}
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1595
|
+
//#endregion
|
|
1596
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
1597
|
+
async function flattenedVerify(jws, key, options) {
|
|
1598
|
+
if (!isObject(jws)) throw new JWSInvalid("Flattened JWS must be an object");
|
|
1599
|
+
if (jws.protected === void 0 && jws.header === void 0) throw new JWSInvalid("Flattened JWS must have either of the \"protected\" or \"header\" members");
|
|
1600
|
+
if (jws.protected !== void 0 && typeof jws.protected !== "string") throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
1601
|
+
if (jws.payload === void 0) throw new JWSInvalid("JWS Payload missing");
|
|
1602
|
+
if (typeof jws.signature !== "string") throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
1603
|
+
if (jws.header !== void 0 && !isObject(jws.header)) throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
1604
|
+
let parsedProt = {};
|
|
1605
|
+
if (jws.protected) try {
|
|
1606
|
+
const protectedHeader = decode(jws.protected);
|
|
1607
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
1608
|
+
} catch {
|
|
1609
|
+
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
1610
|
+
}
|
|
1611
|
+
if (!isDisjoint(parsedProt, jws.header)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
1612
|
+
const joseHeader = {
|
|
1613
|
+
...parsedProt,
|
|
1614
|
+
...jws.header
|
|
1895
1615
|
};
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
"
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
if (
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
};
|
|
1930
|
-
}), (item) => item.id),
|
|
1931
|
-
inviterName: value.inviterName,
|
|
1932
|
-
expiresAt: responseDate(value.expiresAt)
|
|
1616
|
+
const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
1617
|
+
let b64 = true;
|
|
1618
|
+
if (extensions.has("b64")) {
|
|
1619
|
+
b64 = parsedProt.b64;
|
|
1620
|
+
if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
|
|
1621
|
+
}
|
|
1622
|
+
const { alg } = joseHeader;
|
|
1623
|
+
if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
1624
|
+
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
1625
|
+
if (algorithms && !algorithms.has(alg)) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
|
|
1626
|
+
if (b64) {
|
|
1627
|
+
if (typeof jws.payload !== "string") throw new JWSInvalid("JWS Payload must be a string");
|
|
1628
|
+
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
1629
|
+
let resolvedKey = false;
|
|
1630
|
+
if (typeof key === "function") {
|
|
1631
|
+
key = await key(parsedProt, jws);
|
|
1632
|
+
resolvedKey = true;
|
|
1633
|
+
}
|
|
1634
|
+
checkKeyType(alg, key, "verify");
|
|
1635
|
+
const data = concat(jws.protected !== void 0 ? encode$1(jws.protected) : new Uint8Array(), encode$1("."), typeof jws.payload === "string" ? b64 ? encode$1(jws.payload) : encoder$1.encode(jws.payload) : jws.payload);
|
|
1636
|
+
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
1637
|
+
const k = await normalizeKey(key, alg);
|
|
1638
|
+
if (!await verify(alg, k, signature, data)) throw new JWSSignatureVerificationFailed();
|
|
1639
|
+
let payload;
|
|
1640
|
+
if (b64) payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
|
|
1641
|
+
else if (typeof jws.payload === "string") payload = encoder$1.encode(jws.payload);
|
|
1642
|
+
else payload = jws.payload;
|
|
1643
|
+
const result = { payload };
|
|
1644
|
+
if (jws.protected !== void 0) result.protectedHeader = parsedProt;
|
|
1645
|
+
if (jws.header !== void 0) result.unprotectedHeader = jws.header;
|
|
1646
|
+
if (resolvedKey) return {
|
|
1647
|
+
...result,
|
|
1648
|
+
key: k
|
|
1933
1649
|
};
|
|
1650
|
+
return result;
|
|
1934
1651
|
}
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1652
|
+
//#endregion
|
|
1653
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
1654
|
+
async function compactVerify(jws, key, options) {
|
|
1655
|
+
if (jws instanceof Uint8Array) jws = decoder.decode(jws);
|
|
1656
|
+
if (typeof jws !== "string") throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
1657
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
1658
|
+
if (length !== 3) throw new JWSInvalid("Invalid Compact JWS");
|
|
1659
|
+
const verified = await flattenedVerify({
|
|
1660
|
+
payload,
|
|
1661
|
+
protected: protectedHeader,
|
|
1662
|
+
signature
|
|
1663
|
+
}, key, options);
|
|
1664
|
+
const result = {
|
|
1665
|
+
payload: verified.payload,
|
|
1666
|
+
protectedHeader: verified.protectedHeader
|
|
1941
1667
|
};
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
return { invitationId: value.invitationId };
|
|
1946
|
-
}
|
|
1947
|
-
function normalizeInvitationAcceptance(value, invitationId) {
|
|
1948
|
-
if (!isObject(value) || !isObject(value.invitation) || !isObject(value.member) || value.invitation.id !== invitationId || value.invitation.status !== "accepted" || !isId(value.invitation.organizationId) || value.member.organizationId !== value.invitation.organizationId) throw authorityUnavailable();
|
|
1949
|
-
return { organizationId: value.invitation.organizationId };
|
|
1950
|
-
}
|
|
1951
|
-
function normalizeWorkspaceSelection(value) {
|
|
1952
|
-
if (!isObject(value)) throw new AuthError("invalid_workspace_selection", 422);
|
|
1953
|
-
const keys = Object.keys(value);
|
|
1954
|
-
if (value.type === "personal" && keys.length === 1 && keys[0] === "type") return { type: "personal" };
|
|
1955
|
-
if (value.type === "organization" && keys.length === 2 && keys.includes("type") && keys.includes("organizationId") && typeof value.organizationId === "string" && id.test(value.organizationId)) return {
|
|
1956
|
-
type: "organization",
|
|
1957
|
-
organizationId: value.organizationId
|
|
1668
|
+
if (typeof key === "function") return {
|
|
1669
|
+
...result,
|
|
1670
|
+
key: verified.key
|
|
1958
1671
|
};
|
|
1959
|
-
|
|
1960
|
-
}
|
|
1961
|
-
function fromAuthorityError(value, fallbackStatus, retryAfter) {
|
|
1962
|
-
const mapped = mapError(isObject(value) && typeof value.code === "string" ? value.code : void 0, fallbackStatus);
|
|
1963
|
-
return new AuthError(mapped.code, mapped.status, parseRetryAfter(retryAfter));
|
|
1964
|
-
}
|
|
1965
|
-
function fromAccountAuthorityError(value, status, retryAfter) {
|
|
1966
|
-
const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
|
|
1967
|
-
if (status === 403 && (code === "INVALID_ORIGIN" || code === "MISSING_OR_NULL_ORIGIN")) return new AuthError("request_origin_denied", 403);
|
|
1968
|
-
if (code === "USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL") return new AuthError("account_conflict", 409);
|
|
1969
|
-
if (code === "INVALID_TOKEN") return new AuthError("password_reset_invalid", 422);
|
|
1970
|
-
if (code === "INVALID_PASSWORD" || code === "INVALID_EMAIL_OR_PASSWORD") return new AuthError("invalid_credentials", 401);
|
|
1971
|
-
if (code === "INVALID_EMAIL" || code === "PASSWORD_TOO_SHORT" || code === "PASSWORD_TOO_LONG" || code === "BODY_MUST_BE_AN_OBJECT" || code === "EMAIL_CAN_NOT_BE_UPDATED") return new AuthError("invalid_auth_input", 422);
|
|
1972
|
-
if (status === 401) return new AuthError("authentication_required", 401);
|
|
1973
|
-
if (status === 403) return new AuthError("access_denied", 403);
|
|
1974
|
-
if (status === 409) return new AuthError("state_conflict", 409);
|
|
1975
|
-
if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
|
|
1976
|
-
if (status === 400 || status === 422) return new AuthError("invalid_auth_input", 422);
|
|
1977
|
-
return authorityUnavailable();
|
|
1978
|
-
}
|
|
1979
|
-
function fromSocialIdTokenAuthorityError(value, status, retryAfter) {
|
|
1980
|
-
const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
|
|
1981
|
-
if (code === "INVALID_TOKEN" || code === "FAILED_TO_GET_USER_INFO" || code === "USER_EMAIL_NOT_FOUND") return new AuthError("invalid_credentials", 401);
|
|
1982
|
-
if (code === "OAUTH_LINK_ERROR") return new AuthError("account_conflict", 409);
|
|
1983
|
-
return fromAccountAuthorityError(value, status, retryAfter);
|
|
1984
|
-
}
|
|
1985
|
-
function authorityUnavailable() {
|
|
1986
|
-
return new AuthError("identity_authority_unavailable", 503);
|
|
1987
|
-
}
|
|
1988
|
-
function fromOrganizationListError(error) {
|
|
1989
|
-
if (error instanceof AuthError && error.status === 401) return new AuthError("authentication_required", 401);
|
|
1990
|
-
if (error instanceof AuthError) return error;
|
|
1991
|
-
return authorityUnavailable();
|
|
1992
|
-
}
|
|
1993
|
-
function fromOrganizationReadAuthorityError(value, status) {
|
|
1994
|
-
if (status === 400) return new AuthError("invalid_request", 400);
|
|
1995
|
-
if (status === 401) return new AuthError("authentication_required", 401);
|
|
1996
|
-
if (status === 403) return new AuthError("access_denied", 403);
|
|
1997
|
-
return authorityUnavailable();
|
|
1998
|
-
}
|
|
1999
|
-
function fromOrganizationMutationAuthorityError(value, status, retryAfter) {
|
|
2000
|
-
if (status === 400 || status === 413 || status === 415) return new AuthError("invalid_request", 400);
|
|
2001
|
-
if (status === 409) return new AuthError("state_conflict", 409);
|
|
2002
|
-
if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
|
|
2003
|
-
const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
|
|
2004
|
-
if (status === 403 && code === "REQUEST_ORIGIN_DENIED") return new AuthError("request_origin_denied", 403);
|
|
2005
|
-
return fromOrganizationReadAuthorityError(value, status);
|
|
1672
|
+
return result;
|
|
2006
1673
|
}
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
1674
|
+
//#endregion
|
|
1675
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1676
|
+
const epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
1677
|
+
const minute = 60;
|
|
1678
|
+
const hour = minute * 60;
|
|
1679
|
+
const day = hour * 24;
|
|
1680
|
+
const week = day * 7;
|
|
1681
|
+
const year = day * 365.25;
|
|
1682
|
+
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
1683
|
+
function secs(str) {
|
|
1684
|
+
const matched = REGEX.exec(str);
|
|
1685
|
+
if (!matched || matched[4] && matched[1]) throw new TypeError("Invalid time period format");
|
|
1686
|
+
const value = parseFloat(matched[2]);
|
|
1687
|
+
const unit = matched[3].toLowerCase();
|
|
1688
|
+
let numericDate;
|
|
1689
|
+
switch (unit) {
|
|
1690
|
+
case "sec":
|
|
1691
|
+
case "secs":
|
|
1692
|
+
case "second":
|
|
1693
|
+
case "seconds":
|
|
1694
|
+
case "s":
|
|
1695
|
+
numericDate = Math.round(value);
|
|
1696
|
+
break;
|
|
1697
|
+
case "minute":
|
|
1698
|
+
case "minutes":
|
|
1699
|
+
case "min":
|
|
1700
|
+
case "mins":
|
|
1701
|
+
case "m":
|
|
1702
|
+
numericDate = Math.round(value * minute);
|
|
1703
|
+
break;
|
|
1704
|
+
case "hour":
|
|
1705
|
+
case "hours":
|
|
1706
|
+
case "hr":
|
|
1707
|
+
case "hrs":
|
|
1708
|
+
case "h":
|
|
1709
|
+
numericDate = Math.round(value * hour);
|
|
1710
|
+
break;
|
|
1711
|
+
case "day":
|
|
1712
|
+
case "days":
|
|
1713
|
+
case "d":
|
|
1714
|
+
numericDate = Math.round(value * day);
|
|
1715
|
+
break;
|
|
1716
|
+
case "week":
|
|
1717
|
+
case "weeks":
|
|
1718
|
+
case "w":
|
|
1719
|
+
numericDate = Math.round(value * week);
|
|
1720
|
+
break;
|
|
1721
|
+
default:
|
|
1722
|
+
numericDate = Math.round(value * year);
|
|
1723
|
+
break;
|
|
1724
|
+
}
|
|
1725
|
+
if (matched[1] === "-" || matched[4] === "ago") return -numericDate;
|
|
1726
|
+
return numericDate;
|
|
2010
1727
|
}
|
|
2011
|
-
|
|
2012
|
-
if (
|
|
2013
|
-
return
|
|
1728
|
+
const normalizeTyp = (value) => {
|
|
1729
|
+
if (value.includes("/")) return value.toLowerCase();
|
|
1730
|
+
return `application/${value.toLowerCase()}`;
|
|
1731
|
+
};
|
|
1732
|
+
const checkAudiencePresence = (audPayload, audOption) => {
|
|
1733
|
+
if (typeof audPayload === "string") return audOption.includes(audPayload);
|
|
1734
|
+
if (Array.isArray(audPayload)) return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
1735
|
+
return false;
|
|
1736
|
+
};
|
|
1737
|
+
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
1738
|
+
let payload;
|
|
1739
|
+
try {
|
|
1740
|
+
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
1741
|
+
} catch {}
|
|
1742
|
+
if (!isObject(payload)) throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
1743
|
+
const { typ } = options;
|
|
1744
|
+
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) throw new JWTClaimValidationFailed("unexpected \"typ\" JWT header value", payload, "typ", "check_failed");
|
|
1745
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
1746
|
+
const presenceCheck = [...requiredClaims];
|
|
1747
|
+
if (maxTokenAge !== void 0) presenceCheck.push("iat");
|
|
1748
|
+
if (audience !== void 0) presenceCheck.push("aud");
|
|
1749
|
+
if (subject !== void 0) presenceCheck.push("sub");
|
|
1750
|
+
if (issuer !== void 0) presenceCheck.push("iss");
|
|
1751
|
+
for (const claim of new Set(presenceCheck.reverse())) if (!(claim in payload)) throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
1752
|
+
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) throw new JWTClaimValidationFailed("unexpected \"iss\" claim value", payload, "iss", "check_failed");
|
|
1753
|
+
if (subject && payload.sub !== subject) throw new JWTClaimValidationFailed("unexpected \"sub\" claim value", payload, "sub", "check_failed");
|
|
1754
|
+
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) throw new JWTClaimValidationFailed("unexpected \"aud\" claim value", payload, "aud", "check_failed");
|
|
1755
|
+
let tolerance;
|
|
1756
|
+
switch (typeof options.clockTolerance) {
|
|
1757
|
+
case "string":
|
|
1758
|
+
tolerance = secs(options.clockTolerance);
|
|
1759
|
+
break;
|
|
1760
|
+
case "number":
|
|
1761
|
+
tolerance = options.clockTolerance;
|
|
1762
|
+
break;
|
|
1763
|
+
case "undefined":
|
|
1764
|
+
tolerance = 0;
|
|
1765
|
+
break;
|
|
1766
|
+
default: throw new TypeError("Invalid clockTolerance option type");
|
|
1767
|
+
}
|
|
1768
|
+
const { currentDate } = options;
|
|
1769
|
+
const now = epoch(currentDate || new Date());
|
|
1770
|
+
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") throw new JWTClaimValidationFailed("\"iat\" claim must be a number", payload, "iat", "invalid");
|
|
1771
|
+
if (payload.nbf !== void 0) {
|
|
1772
|
+
if (typeof payload.nbf !== "number") throw new JWTClaimValidationFailed("\"nbf\" claim must be a number", payload, "nbf", "invalid");
|
|
1773
|
+
if (payload.nbf > now + tolerance) throw new JWTClaimValidationFailed("\"nbf\" claim timestamp check failed", payload, "nbf", "check_failed");
|
|
1774
|
+
}
|
|
1775
|
+
if (payload.exp !== void 0) {
|
|
1776
|
+
if (typeof payload.exp !== "number") throw new JWTClaimValidationFailed("\"exp\" claim must be a number", payload, "exp", "invalid");
|
|
1777
|
+
if (payload.exp <= now - tolerance) throw new JWTExpired("\"exp\" claim timestamp check failed", payload, "exp", "check_failed");
|
|
1778
|
+
}
|
|
1779
|
+
if (maxTokenAge) {
|
|
1780
|
+
const age = now - payload.iat;
|
|
1781
|
+
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
1782
|
+
if (age - tolerance > max) throw new JWTExpired("\"iat\" claim timestamp check failed (too far in the past)", payload, "iat", "check_failed");
|
|
1783
|
+
if (age < 0 - tolerance) throw new JWTClaimValidationFailed("\"iat\" claim timestamp check failed (it should be in the past)", payload, "iat", "check_failed");
|
|
1784
|
+
}
|
|
1785
|
+
return payload;
|
|
2014
1786
|
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
const target = normalizeOrganizationAuthorityMemberOutcome(value.target);
|
|
2024
|
-
if (target.memberId !== memberId || actor.manualRole !== "owner" && actor.manualRole !== "admin") throw authorityUnavailable();
|
|
2025
|
-
for (const member of [actor, target]) if (member.manualRole === "member" ? member.role === "owner" : member.role !== member.manualRole) throw authorityUnavailable();
|
|
2026
|
-
if (actor.memberId === target.memberId && (actor.manualRole !== target.manualRole || actor.role !== target.role || actor.authorityRevision !== target.authorityRevision)) throw authorityUnavailable();
|
|
2027
|
-
return {
|
|
2028
|
-
organizationId: value.organizationId,
|
|
2029
|
-
actor,
|
|
2030
|
-
target
|
|
1787
|
+
//#endregion
|
|
1788
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/jwt/verify.js
|
|
1789
|
+
async function jwtVerify(jwt, key, options) {
|
|
1790
|
+
const verified = await compactVerify(jwt, key, options);
|
|
1791
|
+
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
1792
|
+
const result = {
|
|
1793
|
+
payload: validateClaimsSet(verified.protectedHeader, verified.payload, options),
|
|
1794
|
+
protectedHeader: verified.protectedHeader
|
|
2031
1795
|
};
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
"memberId",
|
|
2036
|
-
"manualRole",
|
|
2037
|
-
"role",
|
|
2038
|
-
"authorityRevision",
|
|
2039
|
-
...includesStatus ? ["status"] : []
|
|
2040
|
-
]);
|
|
2041
|
-
if (!isId(value.memberId) || value.manualRole !== "owner" && value.manualRole !== "admin" && value.manualRole !== "member" || value.role !== "owner" && value.role !== "admin" && value.role !== "member") throw authorityUnavailable();
|
|
2042
|
-
return {
|
|
2043
|
-
memberId: value.memberId,
|
|
2044
|
-
manualRole: value.manualRole,
|
|
2045
|
-
role: value.role,
|
|
2046
|
-
authorityRevision: normalizeAuthorityResultRevision(value.authorityRevision)
|
|
1796
|
+
if (typeof key === "function") return {
|
|
1797
|
+
...result,
|
|
1798
|
+
key: verified.key
|
|
2047
1799
|
};
|
|
1800
|
+
return result;
|
|
2048
1801
|
}
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
}
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
if (
|
|
2057
|
-
if (
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
1802
|
+
//#endregion
|
|
1803
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/jwk/thumbprint.js
|
|
1804
|
+
const check = (value, description) => {
|
|
1805
|
+
if (typeof value !== "string" || !value) throw new JWKInvalid(`${description} missing or invalid`);
|
|
1806
|
+
};
|
|
1807
|
+
async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
1808
|
+
let jwk;
|
|
1809
|
+
if (isJWK(key)) jwk = key;
|
|
1810
|
+
else if (isKeyLike(key)) jwk = await exportJWK(key);
|
|
1811
|
+
else throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1812
|
+
digestAlgorithm ??= "sha256";
|
|
1813
|
+
if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") throw new TypeError("digestAlgorithm must one of \"sha256\", \"sha384\", or \"sha512\"");
|
|
1814
|
+
let components;
|
|
1815
|
+
switch (jwk.kty) {
|
|
1816
|
+
case "AKP":
|
|
1817
|
+
check(jwk.alg, "\"alg\" (Algorithm) Parameter");
|
|
1818
|
+
check(jwk.pub, "\"pub\" (Public key) Parameter");
|
|
1819
|
+
components = {
|
|
1820
|
+
alg: jwk.alg,
|
|
1821
|
+
kty: jwk.kty,
|
|
1822
|
+
pub: jwk.pub
|
|
1823
|
+
};
|
|
1824
|
+
break;
|
|
1825
|
+
case "EC":
|
|
1826
|
+
check(jwk.crv, "\"crv\" (Curve) Parameter");
|
|
1827
|
+
check(jwk.x, "\"x\" (X Coordinate) Parameter");
|
|
1828
|
+
check(jwk.y, "\"y\" (Y Coordinate) Parameter");
|
|
1829
|
+
components = {
|
|
1830
|
+
crv: jwk.crv,
|
|
1831
|
+
kty: jwk.kty,
|
|
1832
|
+
x: jwk.x,
|
|
1833
|
+
y: jwk.y
|
|
1834
|
+
};
|
|
1835
|
+
break;
|
|
1836
|
+
case "OKP":
|
|
1837
|
+
check(jwk.crv, "\"crv\" (Subtype of Key Pair) Parameter");
|
|
1838
|
+
check(jwk.x, "\"x\" (Public Key) Parameter");
|
|
1839
|
+
components = {
|
|
1840
|
+
crv: jwk.crv,
|
|
1841
|
+
kty: jwk.kty,
|
|
1842
|
+
x: jwk.x
|
|
1843
|
+
};
|
|
1844
|
+
break;
|
|
1845
|
+
case "RSA":
|
|
1846
|
+
check(jwk.e, "\"e\" (Exponent) Parameter");
|
|
1847
|
+
check(jwk.n, "\"n\" (Modulus) Parameter");
|
|
1848
|
+
components = {
|
|
1849
|
+
e: jwk.e,
|
|
1850
|
+
kty: jwk.kty,
|
|
1851
|
+
n: jwk.n
|
|
1852
|
+
};
|
|
1853
|
+
break;
|
|
1854
|
+
case "oct":
|
|
1855
|
+
check(jwk.k, "\"k\" (Key Value) Parameter");
|
|
1856
|
+
components = {
|
|
1857
|
+
k: jwk.k,
|
|
1858
|
+
kty: jwk.kty
|
|
1859
|
+
};
|
|
1860
|
+
break;
|
|
1861
|
+
default: throw new JOSENotSupported("\"kty\" (Key Type) Parameter missing or unsupported");
|
|
1862
|
+
}
|
|
1863
|
+
const data = encode$1(JSON.stringify(components));
|
|
1864
|
+
return encode(await digest(digestAlgorithm, data));
|
|
2064
1865
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
}
|
|
2082
|
-
if (code === "credential_rate_limited") return {
|
|
2083
|
-
code,
|
|
2084
|
-
status: 429
|
|
2085
|
-
};
|
|
2086
|
-
if (code === "identity_authority_unavailable") return {
|
|
2087
|
-
code,
|
|
2088
|
-
status: 503
|
|
2089
|
-
};
|
|
2090
|
-
if (status === 401 || status === 400) return {
|
|
2091
|
-
code: "invalid_credentials",
|
|
2092
|
-
status: 401
|
|
2093
|
-
};
|
|
2094
|
-
if (status === 403) return {
|
|
2095
|
-
code: "access_denied",
|
|
2096
|
-
status: 403
|
|
2097
|
-
};
|
|
2098
|
-
if (status === 409) return {
|
|
2099
|
-
code: "state_conflict",
|
|
2100
|
-
status: 409
|
|
2101
|
-
};
|
|
2102
|
-
if (status === 422) return {
|
|
2103
|
-
code: "invalid_workspace_selection",
|
|
2104
|
-
status: 422
|
|
2105
|
-
};
|
|
2106
|
-
if (status === 429) return {
|
|
2107
|
-
code: "credential_rate_limited",
|
|
2108
|
-
status: 429
|
|
2109
|
-
};
|
|
2110
|
-
return {
|
|
2111
|
-
code: "identity_authority_unavailable",
|
|
2112
|
-
status: 503
|
|
2113
|
-
};
|
|
1866
|
+
//#endregion
|
|
1867
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/util/decode_protected_header.js
|
|
1868
|
+
function decodeProtectedHeader(token) {
|
|
1869
|
+
let protectedB64u;
|
|
1870
|
+
if (typeof token === "string") {
|
|
1871
|
+
const parts = token.split(".");
|
|
1872
|
+
if (parts.length === 3 || parts.length === 5) [protectedB64u] = parts;
|
|
1873
|
+
} else if (typeof token === "object" && token) if ("protected" in token) protectedB64u = token.protected;
|
|
1874
|
+
else throw new TypeError("Token does not contain a Protected Header");
|
|
1875
|
+
try {
|
|
1876
|
+
if (typeof protectedB64u !== "string" || !protectedB64u) throw new Error();
|
|
1877
|
+
const result = JSON.parse(decoder.decode(decode(protectedB64u)));
|
|
1878
|
+
if (!isObject(result)) throw new Error();
|
|
1879
|
+
return result;
|
|
1880
|
+
} catch {
|
|
1881
|
+
throw new TypeError("Invalid Token or Protected Header formatting");
|
|
1882
|
+
}
|
|
2114
1883
|
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
1884
|
+
//#endregion
|
|
1885
|
+
//#region ../../node_modules/.pnpm/jose@6.2.4/node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
1886
|
+
function decodeJwt(jwt) {
|
|
1887
|
+
if (typeof jwt !== "string") throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
1888
|
+
const { 1: payload, length } = jwt.split(".");
|
|
1889
|
+
if (length === 5) throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
|
|
1890
|
+
if (length !== 3) throw new JWTInvalid("Invalid JWT");
|
|
1891
|
+
if (!payload) throw new JWTInvalid("JWTs must contain a payload");
|
|
1892
|
+
let decoded;
|
|
1893
|
+
try {
|
|
1894
|
+
decoded = decode(payload);
|
|
1895
|
+
} catch {
|
|
1896
|
+
throw new JWTInvalid("Failed to base64url decode the payload");
|
|
1897
|
+
}
|
|
1898
|
+
let result;
|
|
1899
|
+
try {
|
|
1900
|
+
result = JSON.parse(decoder.decode(decoded));
|
|
1901
|
+
} catch {
|
|
1902
|
+
throw new JWTInvalid("Failed to parse the decoded payload as JSON");
|
|
1903
|
+
}
|
|
1904
|
+
if (!isObject(result)) throw new JWTInvalid("Invalid JWT Claims Set");
|
|
1905
|
+
return result;
|
|
2119
1906
|
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
1907
|
+
//#endregion
|
|
1908
|
+
//#region ../../node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs
|
|
1909
|
+
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*:/;
|
|
1910
|
+
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*:/;
|
|
1911
|
+
const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
1912
|
+
function jsonParseTransform(key, value) {
|
|
1913
|
+
if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
|
|
1914
|
+
warnKeyDropped(key);
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1917
|
+
return value;
|
|
2123
1918
|
}
|
|
2124
|
-
function
|
|
2125
|
-
|
|
1919
|
+
function warnKeyDropped(key) {
|
|
1920
|
+
console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
|
|
2126
1921
|
}
|
|
2127
|
-
function
|
|
2128
|
-
if (
|
|
1922
|
+
function destr(value, options = {}) {
|
|
1923
|
+
if (typeof value !== "string") return value;
|
|
1924
|
+
if (value[0] === "\"" && value[value.length - 1] === "\"" && value.indexOf("\\") === -1) return value.slice(1, -1);
|
|
1925
|
+
const _value = value.trim();
|
|
1926
|
+
if (_value.length <= 9) switch (_value.toLowerCase()) {
|
|
1927
|
+
case "true": return true;
|
|
1928
|
+
case "false": return false;
|
|
1929
|
+
case "undefined": return;
|
|
1930
|
+
case "null": return null;
|
|
1931
|
+
case "nan": return NaN;
|
|
1932
|
+
case "infinity": return Number.POSITIVE_INFINITY;
|
|
1933
|
+
case "-infinity": return Number.NEGATIVE_INFINITY;
|
|
1934
|
+
}
|
|
1935
|
+
if (!JsonSigRx.test(value)) {
|
|
1936
|
+
if (options.strict) throw new SyntaxError("[destr] Invalid JSON");
|
|
1937
|
+
return value;
|
|
1938
|
+
}
|
|
1939
|
+
try {
|
|
1940
|
+
if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
|
|
1941
|
+
if (options.strict) throw new Error("[destr] Possible prototype pollution");
|
|
1942
|
+
return JSON.parse(value, jsonParseTransform);
|
|
1943
|
+
}
|
|
1944
|
+
return JSON.parse(value);
|
|
1945
|
+
} catch (error) {
|
|
1946
|
+
if (options.strict) throw error;
|
|
1947
|
+
return value;
|
|
1948
|
+
}
|
|
2129
1949
|
}
|
|
2130
|
-
|
|
2131
|
-
|
|
1950
|
+
//#endregion
|
|
1951
|
+
//#region ../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs
|
|
1952
|
+
var FetchError = class extends Error {
|
|
1953
|
+
constructor(message, opts) {
|
|
1954
|
+
super(message, opts);
|
|
1955
|
+
this.name = "FetchError";
|
|
1956
|
+
if (opts?.cause && !this.cause) this.cause = opts.cause;
|
|
1957
|
+
}
|
|
1958
|
+
};
|
|
1959
|
+
function createFetchError(ctx) {
|
|
1960
|
+
const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
|
|
1961
|
+
const method = ctx.request?.method || ctx.options?.method || "GET";
|
|
1962
|
+
const url = ctx.request?.url || String(ctx.request) || "/";
|
|
1963
|
+
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);
|
|
1964
|
+
for (const key of [
|
|
1965
|
+
"request",
|
|
1966
|
+
"options",
|
|
1967
|
+
"response"
|
|
1968
|
+
]) Object.defineProperty(fetchError, key, { get() {
|
|
1969
|
+
return ctx[key];
|
|
1970
|
+
} });
|
|
1971
|
+
for (const [key, refKey] of [
|
|
1972
|
+
["data", "_data"],
|
|
1973
|
+
["status", "status"],
|
|
1974
|
+
["statusCode", "status"],
|
|
1975
|
+
["statusText", "statusText"],
|
|
1976
|
+
["statusMessage", "statusText"]
|
|
1977
|
+
]) Object.defineProperty(fetchError, key, { get() {
|
|
1978
|
+
return ctx.response && ctx.response[refKey];
|
|
1979
|
+
} });
|
|
1980
|
+
return fetchError;
|
|
2132
1981
|
}
|
|
2133
|
-
|
|
2134
|
-
|
|
1982
|
+
const payloadMethods = new Set(Object.freeze([
|
|
1983
|
+
"PATCH",
|
|
1984
|
+
"POST",
|
|
1985
|
+
"PUT",
|
|
1986
|
+
"DELETE"
|
|
1987
|
+
]));
|
|
1988
|
+
function isPayloadMethod(method = "GET") {
|
|
1989
|
+
return payloadMethods.has(method.toUpperCase());
|
|
2135
1990
|
}
|
|
2136
|
-
function
|
|
2137
|
-
if (value ===
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
if (url.protocol !== "https:" || url.username || url.password || url.toString() !== value) throw authorityUnavailable();
|
|
2146
|
-
return value;
|
|
1991
|
+
function isJSONSerializable(value) {
|
|
1992
|
+
if (value === void 0) return false;
|
|
1993
|
+
const t = typeof value;
|
|
1994
|
+
if (t === "string" || t === "number" || t === "boolean" || t === null) return true;
|
|
1995
|
+
if (t !== "object") return false;
|
|
1996
|
+
if (Array.isArray(value)) return true;
|
|
1997
|
+
if (value.buffer) return false;
|
|
1998
|
+
if (value instanceof FormData || value instanceof URLSearchParams) return false;
|
|
1999
|
+
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
2147
2000
|
}
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2001
|
+
const textTypes = new Set([
|
|
2002
|
+
"image/svg",
|
|
2003
|
+
"application/xml",
|
|
2004
|
+
"application/xhtml",
|
|
2005
|
+
"application/html"
|
|
2006
|
+
]);
|
|
2007
|
+
const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
|
|
2008
|
+
function detectResponseType(_contentType = "") {
|
|
2009
|
+
if (!_contentType) return "json";
|
|
2010
|
+
const contentType = _contentType.split(";").shift() || "";
|
|
2011
|
+
if (JSON_RE.test(contentType)) return "json";
|
|
2012
|
+
if (contentType === "text/event-stream") return "stream";
|
|
2013
|
+
if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
|
|
2014
|
+
return "blob";
|
|
2153
2015
|
}
|
|
2154
|
-
function
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2016
|
+
function resolveFetchOptions(request, input, defaults, Headers) {
|
|
2017
|
+
const headers = mergeHeaders(input?.headers ?? request?.headers, defaults?.headers, Headers);
|
|
2018
|
+
let query;
|
|
2019
|
+
if (defaults?.query || defaults?.params || input?.params || input?.query) query = {
|
|
2020
|
+
...defaults?.params,
|
|
2021
|
+
...defaults?.query,
|
|
2022
|
+
...input?.params,
|
|
2023
|
+
...input?.query
|
|
2024
|
+
};
|
|
2025
|
+
return {
|
|
2026
|
+
...defaults,
|
|
2027
|
+
...input,
|
|
2028
|
+
query,
|
|
2029
|
+
params: query,
|
|
2030
|
+
headers
|
|
2031
|
+
};
|
|
2158
2032
|
}
|
|
2159
|
-
function
|
|
2160
|
-
if (!
|
|
2161
|
-
|
|
2033
|
+
function mergeHeaders(input, defaults, Headers) {
|
|
2034
|
+
if (!defaults) return new Headers(input);
|
|
2035
|
+
const headers = new Headers(defaults);
|
|
2036
|
+
if (input) for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) headers.set(key, value);
|
|
2037
|
+
return headers;
|
|
2162
2038
|
}
|
|
2163
|
-
function
|
|
2164
|
-
if (
|
|
2165
|
-
|
|
2039
|
+
async function callHooks(context, hooks) {
|
|
2040
|
+
if (hooks) if (Array.isArray(hooks)) for (const hook of hooks) await hook(context);
|
|
2041
|
+
else await hooks(context);
|
|
2166
2042
|
}
|
|
2167
|
-
|
|
2168
|
-
|
|
2043
|
+
const retryStatusCodes = new Set([
|
|
2044
|
+
408,
|
|
2045
|
+
409,
|
|
2046
|
+
425,
|
|
2047
|
+
429,
|
|
2048
|
+
500,
|
|
2049
|
+
502,
|
|
2050
|
+
503,
|
|
2051
|
+
504
|
|
2052
|
+
]);
|
|
2053
|
+
const nullBodyResponses = new Set([
|
|
2054
|
+
101,
|
|
2055
|
+
204,
|
|
2056
|
+
205,
|
|
2057
|
+
304
|
|
2058
|
+
]);
|
|
2059
|
+
function createFetch(globalOptions = {}) {
|
|
2060
|
+
const { fetch = globalThis.fetch, Headers = globalThis.Headers, AbortController = globalThis.AbortController } = globalOptions;
|
|
2061
|
+
async function onError(context) {
|
|
2062
|
+
const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
|
|
2063
|
+
if (context.options.retry !== false && !isAbort) {
|
|
2064
|
+
let retries;
|
|
2065
|
+
if (typeof context.options.retry === "number") retries = context.options.retry;
|
|
2066
|
+
else retries = isPayloadMethod(context.options.method) ? 0 : 1;
|
|
2067
|
+
const responseCode = context.response && context.response.status || 500;
|
|
2068
|
+
if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
|
|
2069
|
+
const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
|
|
2070
|
+
if (retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
2071
|
+
return $fetchRaw(context.request, {
|
|
2072
|
+
...context.options,
|
|
2073
|
+
retry: retries - 1
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
const error = createFetchError(context);
|
|
2078
|
+
if (Error.captureStackTrace) Error.captureStackTrace(error, $fetchRaw);
|
|
2079
|
+
throw error;
|
|
2080
|
+
}
|
|
2081
|
+
const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
|
|
2082
|
+
const context = {
|
|
2083
|
+
request: _request,
|
|
2084
|
+
options: resolveFetchOptions(_request, _options, globalOptions.defaults, Headers),
|
|
2085
|
+
response: void 0,
|
|
2086
|
+
error: void 0
|
|
2087
|
+
};
|
|
2088
|
+
if (context.options.method) context.options.method = context.options.method.toUpperCase();
|
|
2089
|
+
if (context.options.onRequest) {
|
|
2090
|
+
await callHooks(context, context.options.onRequest);
|
|
2091
|
+
if (!(context.options.headers instanceof Headers)) context.options.headers = new Headers(context.options.headers || {});
|
|
2092
|
+
}
|
|
2093
|
+
if (typeof context.request === "string") {
|
|
2094
|
+
if (context.options.baseURL) context.request = withBase(context.request, context.options.baseURL);
|
|
2095
|
+
if (context.options.query) {
|
|
2096
|
+
context.request = withQuery(context.request, context.options.query);
|
|
2097
|
+
delete context.options.query;
|
|
2098
|
+
}
|
|
2099
|
+
if ("query" in context.options) delete context.options.query;
|
|
2100
|
+
if ("params" in context.options) delete context.options.params;
|
|
2101
|
+
}
|
|
2102
|
+
if (context.options.body && isPayloadMethod(context.options.method)) {
|
|
2103
|
+
if (isJSONSerializable(context.options.body)) {
|
|
2104
|
+
const contentType = context.options.headers.get("content-type");
|
|
2105
|
+
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);
|
|
2106
|
+
if (!contentType) context.options.headers.set("content-type", "application/json");
|
|
2107
|
+
if (!context.options.headers.has("accept")) context.options.headers.set("accept", "application/json");
|
|
2108
|
+
} else if ("pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || typeof context.options.body.pipe === "function") {
|
|
2109
|
+
if (!("duplex" in context.options)) context.options.duplex = "half";
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
let abortTimeout;
|
|
2113
|
+
if (!context.options.signal && context.options.timeout) {
|
|
2114
|
+
const controller = new AbortController();
|
|
2115
|
+
abortTimeout = setTimeout(() => {
|
|
2116
|
+
const error = new Error("[TimeoutError]: The operation was aborted due to timeout");
|
|
2117
|
+
error.name = "TimeoutError";
|
|
2118
|
+
error.code = 23;
|
|
2119
|
+
controller.abort(error);
|
|
2120
|
+
}, context.options.timeout);
|
|
2121
|
+
context.options.signal = controller.signal;
|
|
2122
|
+
}
|
|
2123
|
+
try {
|
|
2124
|
+
context.response = await fetch(context.request, context.options);
|
|
2125
|
+
} catch (error) {
|
|
2126
|
+
context.error = error;
|
|
2127
|
+
if (context.options.onRequestError) await callHooks(context, context.options.onRequestError);
|
|
2128
|
+
return await onError(context);
|
|
2129
|
+
} finally {
|
|
2130
|
+
if (abortTimeout) clearTimeout(abortTimeout);
|
|
2131
|
+
}
|
|
2132
|
+
if ((context.response.body || context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD") {
|
|
2133
|
+
const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
|
|
2134
|
+
switch (responseType) {
|
|
2135
|
+
case "json": {
|
|
2136
|
+
const data = await context.response.text();
|
|
2137
|
+
const parseFunction = context.options.parseResponse || destr;
|
|
2138
|
+
context.response._data = parseFunction(data);
|
|
2139
|
+
break;
|
|
2140
|
+
}
|
|
2141
|
+
case "stream":
|
|
2142
|
+
context.response._data = context.response.body || context.response._bodyInit;
|
|
2143
|
+
break;
|
|
2144
|
+
default: context.response._data = await context.response[responseType]();
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
if (context.options.onResponse) await callHooks(context, context.options.onResponse);
|
|
2148
|
+
if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
|
|
2149
|
+
if (context.options.onResponseError) await callHooks(context, context.options.onResponseError);
|
|
2150
|
+
return await onError(context);
|
|
2151
|
+
}
|
|
2152
|
+
return context.response;
|
|
2153
|
+
};
|
|
2154
|
+
const $fetch = async function $fetch2(request, options) {
|
|
2155
|
+
return (await $fetchRaw(request, options))._data;
|
|
2156
|
+
};
|
|
2157
|
+
$fetch.raw = $fetchRaw;
|
|
2158
|
+
$fetch.native = (...args) => fetch(...args);
|
|
2159
|
+
$fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
|
|
2160
|
+
...globalOptions,
|
|
2161
|
+
...customGlobalOptions,
|
|
2162
|
+
defaults: {
|
|
2163
|
+
...globalOptions.defaults,
|
|
2164
|
+
...customGlobalOptions.defaults,
|
|
2165
|
+
...defaultOptions
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2168
|
+
return $fetch;
|
|
2169
2169
|
}
|
|
2170
2170
|
//#endregion
|
|
2171
2171
|
//#region src/http.ts
|