@finueva/auth 0.8.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1884,6 +1884,7 @@ const messages = {
1884
1884
  password_reset_invalid: "The password reset request is invalid.",
1885
1885
  authentication_required: "Authentication is required.",
1886
1886
  request_origin_denied: "The request origin is not allowed.",
1887
+ invalid_request: "The request is invalid.",
1887
1888
  invalid_invitation: "The invitation is invalid.",
1888
1889
  invitation_unavailable: "The invitation is not available.",
1889
1890
  invitation_recipient_mismatch: "The invitation cannot be accepted by this account.",
@@ -2282,18 +2283,283 @@ function normalizeDriveCredential(value, now) {
2282
2283
  expiresAt: new Date(now + value.expiresIn * 1e3)
2283
2284
  };
2284
2285
  }
2286
+ function normalizeOrganizationPageInput(value) {
2287
+ if (value === void 0) return new URLSearchParams();
2288
+ if (!isObject(value) || Object.keys(value).some((key) => key !== "limit" && key !== "cursor")) throw new AuthError("invalid_request", 400);
2289
+ const input = value;
2290
+ const query = new URLSearchParams();
2291
+ if (input.limit !== void 0) {
2292
+ if (!Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 100) throw new AuthError("invalid_request", 400);
2293
+ query.set("limit", String(input.limit));
2294
+ }
2295
+ if (input.cursor !== void 0) {
2296
+ 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);
2297
+ query.set("cursor", input.cursor);
2298
+ }
2299
+ return query;
2300
+ }
2301
+ function normalizeIdInput(value) {
2302
+ if (!isId(value)) throw new AuthError("invalid_request", 400);
2303
+ return value;
2304
+ }
2305
+ function normalizeOrganization(value) {
2306
+ exact(value, [
2307
+ "capabilities",
2308
+ "id",
2309
+ "lifecycle",
2310
+ "logo",
2311
+ "name",
2312
+ "role",
2313
+ "slug"
2314
+ ]);
2315
+ 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();
2316
+ exact(value.capabilities, [
2317
+ "readInvitations",
2318
+ "readMembers",
2319
+ "readTeams"
2320
+ ]);
2321
+ if (value.capabilities.readMembers !== true || value.capabilities.readTeams !== true || typeof value.capabilities.readInvitations !== "boolean") throw authorityUnavailable();
2322
+ return {
2323
+ id: value.id,
2324
+ name: value.name,
2325
+ slug: value.slug,
2326
+ logo: nullableHttpsUrl(value.logo),
2327
+ lifecycle: value.lifecycle,
2328
+ role: value.role,
2329
+ capabilities: {
2330
+ readMembers: true,
2331
+ readTeams: true,
2332
+ readInvitations: value.capabilities.readInvitations
2333
+ }
2334
+ };
2335
+ }
2336
+ function normalizeOrganizationDisplayInput(value) {
2337
+ if (!isObject(value) || Object.keys(value).sort().join(",") !== "logo,name,slug") throw new AuthError("invalid_request", 400);
2338
+ if (!boundedString(value.name, 255) || !boundedString(value.slug, 255)) throw new AuthError("invalid_request", 400);
2339
+ let logo;
2340
+ try {
2341
+ logo = nullableHttpsUrl(value.logo);
2342
+ } catch {
2343
+ throw new AuthError("invalid_request", 400);
2344
+ }
2345
+ return {
2346
+ name: value.name,
2347
+ slug: value.slug,
2348
+ logo
2349
+ };
2350
+ }
2351
+ function normalizeOrganizationDisplay(value) {
2352
+ try {
2353
+ return normalizeOrganizationDisplayInput(value);
2354
+ } catch {
2355
+ throw authorityUnavailable();
2356
+ }
2357
+ }
2358
+ function normalizeOrganizationTeamDisplayInput(value) {
2359
+ if (!isObject(value) || Object.keys(value).join(",") !== "name" || !boundedString(value.name, 255)) throw new AuthError("invalid_request", 400);
2360
+ return { name: value.name };
2361
+ }
2362
+ function normalizeOrganizationTeamDisplay(value) {
2363
+ try {
2364
+ return normalizeOrganizationTeamDisplayInput(value);
2365
+ } catch {
2366
+ throw authorityUnavailable();
2367
+ }
2368
+ }
2369
+ function normalizeOrganizationTeamCreationInput(name, idempotencyKey) {
2370
+ if (!boundedString(name, 255) || !boundedString(idempotencyKey, 255)) throw new AuthError("invalid_request", 400);
2371
+ return {
2372
+ name,
2373
+ idempotencyKey
2374
+ };
2375
+ }
2376
+ function normalizeCreatedOrganizationTeam(value) {
2377
+ exact(value, ["id", "name"]);
2378
+ if (!isId(value.id) || !boundedString(value.name, 255)) throw authorityUnavailable();
2379
+ return {
2380
+ id: value.id,
2381
+ name: value.name
2382
+ };
2383
+ }
2384
+ function normalizeOrganizationMemberInvitationCreationInput(value) {
2385
+ if (!isObject(value)) throw new AuthError("invalid_request", 400);
2386
+ const keys = Object.keys(value).sort().join(",");
2387
+ if (keys !== "email,idempotencyKey" && keys !== "email,idempotencyKey,teamIds") throw new AuthError("invalid_request", 400);
2388
+ let normalizedEmail;
2389
+ try {
2390
+ normalizedEmail = normalizeEmail(value.email);
2391
+ } catch {
2392
+ throw new AuthError("invalid_request", 400);
2393
+ }
2394
+ 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);
2395
+ const teamIds = value.teamIds?.map((teamId) => normalizeIdInput(teamId));
2396
+ if (teamIds && new Set(teamIds).size !== teamIds.length) throw new AuthError("invalid_request", 400);
2397
+ return {
2398
+ email: normalizedEmail,
2399
+ ...teamIds === void 0 ? {} : { teamIds },
2400
+ idempotencyKey: value.idempotencyKey
2401
+ };
2402
+ }
2403
+ function normalizeCreatedOrganizationMemberInvitation(value) {
2404
+ exact(value, ["expiresAt", "id"]);
2405
+ if (!isId(value.id)) throw authorityUnavailable();
2406
+ return {
2407
+ id: value.id,
2408
+ expiresAt: responseDate(value.expiresAt)
2409
+ };
2410
+ }
2285
2411
  function normalizeOrganizations(value) {
2286
- if (!Array.isArray(value) || value.length >= 100) throw authorityUnavailable();
2287
- const seen = new Set();
2288
- return value.map((organization) => {
2289
- if (!isObject(organization) || !isId(organization.id) || seen.has(organization.id) || typeof organization.name !== "string" || organization.name.length < 1 || typeof organization.slug !== "string" || organization.slug.length < 1) throw authorityUnavailable();
2290
- seen.add(organization.id);
2291
- return {
2292
- id: organization.id,
2293
- name: organization.name,
2294
- slug: organization.slug
2295
- };
2296
- });
2412
+ exact(value, ["nextCursor", "organizations"]);
2413
+ if (!Array.isArray(value.organizations) || value.organizations.length > 100) throw authorityUnavailable();
2414
+ return {
2415
+ organizations: unique(value.organizations.map(normalizeOrganization), (item) => item.id),
2416
+ nextCursor: nullableCursor(value.nextCursor)
2417
+ };
2418
+ }
2419
+ function normalizeOrganizationMembers(value) {
2420
+ exact(value, ["members", "nextCursor"]);
2421
+ if (!Array.isArray(value.members) || value.members.length > 100) throw authorityUnavailable();
2422
+ return {
2423
+ members: unique(value.members.map((member) => {
2424
+ exact(member, [
2425
+ "email",
2426
+ "id",
2427
+ "image",
2428
+ "joinedAt",
2429
+ "name",
2430
+ "owner",
2431
+ "role",
2432
+ "teamIds",
2433
+ "userId"
2434
+ ]);
2435
+ 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();
2436
+ const teamIds = unique(member.teamIds.map((teamId) => normalizeResponseId(teamId)), (item) => item);
2437
+ return {
2438
+ id: member.id,
2439
+ userId: member.userId,
2440
+ name: member.name,
2441
+ email: member.email,
2442
+ image: nullableHttpsUrl(member.image),
2443
+ role: member.role,
2444
+ owner: member.owner,
2445
+ joinedAt: responseDate(member.joinedAt),
2446
+ teamIds
2447
+ };
2448
+ }), (item) => item.id),
2449
+ nextCursor: nullableCursor(value.nextCursor)
2450
+ };
2451
+ }
2452
+ function normalizeOrganizationTeams(value) {
2453
+ exact(value, ["nextCursor", "teams"]);
2454
+ if (!Array.isArray(value.teams) || value.teams.length > 100) throw authorityUnavailable();
2455
+ return {
2456
+ teams: unique(value.teams.map((team) => {
2457
+ exact(team, [
2458
+ "category",
2459
+ "createdAt",
2460
+ "id",
2461
+ "name"
2462
+ ]);
2463
+ if (!isId(team.id) || !boundedString(team.name, 255) || team.category !== "manual" && team.category !== "managed") throw authorityUnavailable();
2464
+ return {
2465
+ id: team.id,
2466
+ name: team.name,
2467
+ category: team.category,
2468
+ createdAt: responseDate(team.createdAt)
2469
+ };
2470
+ }), (item) => item.id),
2471
+ nextCursor: nullableCursor(value.nextCursor)
2472
+ };
2473
+ }
2474
+ function normalizeOrganizationTeamMembers(value) {
2475
+ exact(value, ["memberIds", "nextCursor"]);
2476
+ if (!Array.isArray(value.memberIds) || value.memberIds.length > 100) throw authorityUnavailable();
2477
+ return {
2478
+ memberIds: unique(value.memberIds.map((item) => normalizeResponseId(item)), (item) => item),
2479
+ nextCursor: nullableCursor(value.nextCursor)
2480
+ };
2481
+ }
2482
+ function normalizeOrganizationInvitation(value) {
2483
+ exact(value, [
2484
+ "createdAt",
2485
+ "email",
2486
+ "expiresAt",
2487
+ "id",
2488
+ "inviter",
2489
+ "role",
2490
+ "status",
2491
+ "teamIds"
2492
+ ]);
2493
+ 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(value.inviter)) throw authorityUnavailable();
2494
+ exact(value.inviter, ["membershipId", "name"]);
2495
+ if (!isId(value.inviter.membershipId) || !boundedString(value.inviter.name, 255)) throw authorityUnavailable();
2496
+ return {
2497
+ id: value.id,
2498
+ email: value.email,
2499
+ role: value.role,
2500
+ teamIds: unique(value.teamIds.map(normalizeResponseId), (item) => item),
2501
+ inviter: {
2502
+ membershipId: value.inviter.membershipId,
2503
+ name: value.inviter.name
2504
+ },
2505
+ createdAt: responseDate(value.createdAt),
2506
+ expiresAt: responseDate(value.expiresAt),
2507
+ status: "pending"
2508
+ };
2509
+ }
2510
+ function normalizeOrganizationInvitations(value) {
2511
+ exact(value, ["invitations", "nextCursor"]);
2512
+ if (!Array.isArray(value.invitations) || value.invitations.length > 100) throw authorityUnavailable();
2513
+ return {
2514
+ invitations: unique(value.invitations.map(normalizeOrganizationInvitation), (item) => item.id),
2515
+ nextCursor: nullableCursor(value.nextCursor)
2516
+ };
2517
+ }
2518
+ function normalizeReceivedInvitation(value) {
2519
+ exact(value, [
2520
+ "expiresAt",
2521
+ "id",
2522
+ "inviterName",
2523
+ "organization",
2524
+ "role",
2525
+ "teams"
2526
+ ]);
2527
+ if (!isId(value.id) || !boundedString(value.inviterName, 255) || !role(value.role) || !Array.isArray(value.teams) || value.teams.length > 100 || !isObject(value.organization)) throw authorityUnavailable();
2528
+ exact(value.organization, [
2529
+ "id",
2530
+ "logo",
2531
+ "name",
2532
+ "slug"
2533
+ ]);
2534
+ if (!isId(value.organization.id) || !boundedString(value.organization.name, 255) || !boundedString(value.organization.slug, 255)) throw authorityUnavailable();
2535
+ return {
2536
+ id: value.id,
2537
+ organization: {
2538
+ id: value.organization.id,
2539
+ name: value.organization.name,
2540
+ slug: value.organization.slug,
2541
+ logo: nullableHttpsUrl(value.organization.logo)
2542
+ },
2543
+ role: value.role,
2544
+ teams: unique(value.teams.map((team) => {
2545
+ exact(team, ["id", "name"]);
2546
+ if (!isId(team.id) || !boundedString(team.name, 255)) throw authorityUnavailable();
2547
+ return {
2548
+ id: team.id,
2549
+ name: team.name
2550
+ };
2551
+ }), (item) => item.id),
2552
+ inviterName: value.inviterName,
2553
+ expiresAt: responseDate(value.expiresAt)
2554
+ };
2555
+ }
2556
+ function normalizeReceivedInvitations(value) {
2557
+ exact(value, ["invitations", "nextCursor"]);
2558
+ if (!Array.isArray(value.invitations) || value.invitations.length > 100) throw authorityUnavailable();
2559
+ return {
2560
+ invitations: unique(value.invitations.map(normalizeReceivedInvitation), (item) => item.id),
2561
+ nextCursor: nullableCursor(value.nextCursor)
2562
+ };
2297
2563
  }
2298
2564
  function normalizeInvitationInput(value) {
2299
2565
  if (!isObject(value) || Object.keys(value).length !== 1 || !isId(value.invitationId)) throw new AuthError("invalid_invitation", 422);
@@ -2359,6 +2625,20 @@ function fromOrganizationListError(error) {
2359
2625
  if (error instanceof AuthError) return error;
2360
2626
  return authorityUnavailable();
2361
2627
  }
2628
+ function fromOrganizationReadAuthorityError(value, status) {
2629
+ if (status === 400) return new AuthError("invalid_request", 400);
2630
+ if (status === 401) return new AuthError("authentication_required", 401);
2631
+ if (status === 403) return new AuthError("access_denied", 403);
2632
+ return authorityUnavailable();
2633
+ }
2634
+ function fromOrganizationMutationAuthorityError(value, status, retryAfter) {
2635
+ if (status === 400 || status === 413 || status === 415) return new AuthError("invalid_request", 400);
2636
+ if (status === 409) return new AuthError("state_conflict", 409);
2637
+ if (status === 429) return new AuthError("auth_request_rate_limited", 429, parseRetryAfter(retryAfter));
2638
+ const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
2639
+ if (status === 403 && code === "REQUEST_ORIGIN_DENIED") return new AuthError("request_origin_denied", 403);
2640
+ return fromOrganizationReadAuthorityError(value, status);
2641
+ }
2362
2642
  function fromInvitationAuthorityError(value, status) {
2363
2643
  const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
2364
2644
  if (status === 401 && code === "UNAUTHORIZED") return new AuthError("authentication_required", 401);
@@ -2445,6 +2725,46 @@ function normalizeProfileImage(value) {
2445
2725
  function isId(value) {
2446
2726
  return typeof value === "string" && id.test(value);
2447
2727
  }
2728
+ function exact(value, keys) {
2729
+ if (!isObject(value) || Object.keys(value).sort().join(",") !== [...keys].sort().join(",")) throw authorityUnavailable();
2730
+ }
2731
+ function boundedString(value, maximum) {
2732
+ return typeof value === "string" && value.length > 0 && new TextEncoder().encode(value).byteLength <= maximum;
2733
+ }
2734
+ function role(value) {
2735
+ return value === "owner" || value === "admin" || value === "member";
2736
+ }
2737
+ function nullableHttpsUrl(value) {
2738
+ if (value === null) return null;
2739
+ if (typeof value !== "string" || value.length > 2048) throw authorityUnavailable();
2740
+ let url;
2741
+ try {
2742
+ url = new URL(value);
2743
+ } catch {
2744
+ throw authorityUnavailable();
2745
+ }
2746
+ if (url.protocol !== "https:" || url.username || url.password || url.toString() !== value) throw authorityUnavailable();
2747
+ return value;
2748
+ }
2749
+ function responseDate(value) {
2750
+ if (typeof value !== "string") throw authorityUnavailable();
2751
+ const date = new Date(value);
2752
+ if (!Number.isFinite(date.getTime()) || date.toISOString() !== value) throw authorityUnavailable();
2753
+ return date;
2754
+ }
2755
+ function nullableCursor(value) {
2756
+ if (value === null) return null;
2757
+ if (typeof value !== "string" || value.length < 1 || value.length > 820 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value)) throw authorityUnavailable();
2758
+ return value;
2759
+ }
2760
+ function normalizeResponseId(value) {
2761
+ if (!isId(value)) throw authorityUnavailable();
2762
+ return value;
2763
+ }
2764
+ function unique(items, key) {
2765
+ if (new Set(items.map(key)).size !== items.length) throw authorityUnavailable();
2766
+ return items;
2767
+ }
2448
2768
  function isObject(value) {
2449
2769
  return typeof value === "object" && value !== null && !Array.isArray(value);
2450
2770
  }
@@ -2474,18 +2794,18 @@ async function requestJsonResponse(url, options) {
2474
2794
  }
2475
2795
  const contentType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
2476
2796
  if (response.status >= 300 || response.status < 200 || contentType !== "application/json") {
2477
- const body = contentType === "application/json" ? await readJson(response) : void 0;
2797
+ const body = contentType === "application/json" ? await readJson(response, options.maxResponseBytes) : void 0;
2478
2798
  await response.body?.cancel();
2479
2799
  throw (options.mapError ?? fromAuthorityError)(body, response.status, response.headers.get("retry-after"));
2480
2800
  }
2481
2801
  return {
2482
- value: await readJson(response),
2802
+ value: await readJson(response, options.maxResponseBytes),
2483
2803
  headers: response.headers
2484
2804
  };
2485
2805
  }
2486
- async function readJson(response) {
2806
+ async function readJson(response, maximum = MAX_RESPONSE_BYTES) {
2487
2807
  const length = response.headers.get("content-length");
2488
- if (length && (!/^\d+$/.test(length) || Number(length) > MAX_RESPONSE_BYTES)) {
2808
+ if (length && (!/^\d+$/.test(length) || Number(length) > maximum)) {
2489
2809
  await response.body?.cancel();
2490
2810
  throw authorityUnavailable();
2491
2811
  }
@@ -2498,7 +2818,7 @@ async function readJson(response) {
2498
2818
  const { done, value } = await reader.read();
2499
2819
  if (done) break;
2500
2820
  size += value.byteLength;
2501
- if (size > MAX_RESPONSE_BYTES) throw authorityUnavailable();
2821
+ if (size > maximum) throw authorityUnavailable();
2502
2822
  chunks.push(value);
2503
2823
  }
2504
2824
  } catch (error) {
@@ -3534,6 +3854,25 @@ function createAuthClient(options) {
3534
3854
  mapError
3535
3855
  })).value;
3536
3856
  }
3857
+ async function organizationRead(path, input, normalize) {
3858
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
3859
+ const generation = authorityGeneration;
3860
+ const query = normalizeOrganizationPageInput(input);
3861
+ const value = await requestJson(`${joinURL(authOrigin, "api/v1/auth/organizations", path)}${query.size ? `?${query}` : ""}`, {
3862
+ fetch: fetchImpl,
3863
+ timeoutMs,
3864
+ method: "GET",
3865
+ mapError: fromOrganizationReadAuthorityError,
3866
+ maxResponseBytes: 256 * 1024
3867
+ });
3868
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
3869
+ try {
3870
+ return normalize(value);
3871
+ } catch (error) {
3872
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
3873
+ throw error;
3874
+ }
3875
+ }
3537
3876
  return {
3538
3877
  _type: "browser",
3539
3878
  acceptInvitation(input) {
@@ -3544,7 +3883,7 @@ function createAuthClient(options) {
3544
3883
  return Promise.reject(error);
3545
3884
  }
3546
3885
  if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) return Promise.reject(new AuthError("state_conflict", 409));
3547
- const generation = authorityGeneration;
3886
+ const generation = ++authorityGeneration;
3548
3887
  const controller = new AbortController();
3549
3888
  clearCredential();
3550
3889
  const request = (async () => {
@@ -3575,22 +3914,102 @@ function createAuthClient(options) {
3575
3914
  return request;
3576
3915
  },
3577
3916
  getSession,
3578
- async listOrganizations() {
3579
- if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
3580
- const generation = authorityGeneration;
3917
+ async listOrganizations(input) {
3581
3918
  try {
3582
- const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organization/list"), {
3583
- fetch: fetchImpl,
3584
- timeoutMs,
3585
- method: "GET"
3586
- });
3587
- if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
3588
- return normalizeOrganizations(value);
3919
+ return await organizationRead("", input, normalizeOrganizations);
3589
3920
  } catch (error) {
3590
- if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
3591
3921
  throw fromOrganizationListError(error);
3592
3922
  }
3593
3923
  },
3924
+ async getOrganization(organizationId) {
3925
+ return organizationRead(normalizeIdInput(organizationId), void 0, normalizeOrganization);
3926
+ },
3927
+ async createOrganizationTeam(organizationId, name, idempotencyKey) {
3928
+ const id = normalizeIdInput(organizationId);
3929
+ const body = normalizeOrganizationTeamCreationInput(name, idempotencyKey);
3930
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
3931
+ const generation = authorityGeneration;
3932
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organizations", id, "teams"), {
3933
+ fetch: fetchImpl,
3934
+ timeoutMs,
3935
+ method: "POST",
3936
+ headers: { "content-type": "application/json" },
3937
+ body,
3938
+ mapError: fromOrganizationMutationAuthorityError
3939
+ });
3940
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
3941
+ return normalizeCreatedOrganizationTeam(value);
3942
+ },
3943
+ async createOrganizationMemberInvitation(organizationId, input) {
3944
+ const id = normalizeIdInput(organizationId);
3945
+ const body = normalizeOrganizationMemberInvitationCreationInput(input);
3946
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
3947
+ const generation = authorityGeneration;
3948
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organizations", id, "invitations"), {
3949
+ fetch: fetchImpl,
3950
+ timeoutMs,
3951
+ method: "POST",
3952
+ headers: { "content-type": "application/json" },
3953
+ body,
3954
+ mapError: fromOrganizationMutationAuthorityError
3955
+ });
3956
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
3957
+ return normalizeCreatedOrganizationMemberInvitation(value);
3958
+ },
3959
+ async updateOrganizationDisplay(organizationId, input) {
3960
+ const id = normalizeIdInput(organizationId);
3961
+ const desired = normalizeOrganizationDisplayInput(input);
3962
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
3963
+ const generation = authorityGeneration;
3964
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organizations", id, "display"), {
3965
+ fetch: fetchImpl,
3966
+ timeoutMs,
3967
+ method: "POST",
3968
+ headers: { "content-type": "application/json" },
3969
+ body: desired,
3970
+ mapError: fromOrganizationMutationAuthorityError
3971
+ });
3972
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
3973
+ return normalizeOrganizationDisplay(value);
3974
+ },
3975
+ async updateOrganizationTeamDisplay(organizationId, teamId, input) {
3976
+ const organization = normalizeIdInput(organizationId);
3977
+ const team = normalizeIdInput(teamId);
3978
+ const desired = normalizeOrganizationTeamDisplayInput(input);
3979
+ if (signOutRequest || activeAccountMutationGeneration !== void 0 || invitationRequest) throw new AuthError("state_conflict", 409);
3980
+ const generation = authorityGeneration;
3981
+ const value = await requestJson(joinURL(authOrigin, "api/v1/auth/organizations", organization, "teams", team, "display"), {
3982
+ fetch: fetchImpl,
3983
+ timeoutMs,
3984
+ method: "POST",
3985
+ headers: { "content-type": "application/json" },
3986
+ body: desired,
3987
+ mapError: fromOrganizationMutationAuthorityError
3988
+ });
3989
+ if (generation !== authorityGeneration) throw new AuthError("state_conflict", 409);
3990
+ return normalizeOrganizationTeamDisplay(value);
3991
+ },
3992
+ async listOrganizationMembers(organizationId, input) {
3993
+ return organizationRead(`${normalizeIdInput(organizationId)}/members`, input, normalizeOrganizationMembers);
3994
+ },
3995
+ async listOrganizationTeams(organizationId, input) {
3996
+ return organizationRead(`${normalizeIdInput(organizationId)}/teams`, input, normalizeOrganizationTeams);
3997
+ },
3998
+ async listOrganizationTeamMembers(organizationId, teamId, input) {
3999
+ return organizationRead(`${normalizeIdInput(organizationId)}/teams/${normalizeIdInput(teamId)}/members`, input, normalizeOrganizationTeamMembers);
4000
+ },
4001
+ async listOrganizationInvitations(organizationId, input) {
4002
+ return organizationRead(`${normalizeIdInput(organizationId)}/invitations`, input, normalizeOrganizationInvitations);
4003
+ },
4004
+ async getOrganizationInvitation(organizationId, invitationId) {
4005
+ return organizationRead(`${normalizeIdInput(organizationId)}/invitations/${normalizeIdInput(invitationId)}`, void 0, normalizeOrganizationInvitation);
4006
+ },
4007
+ async listReceivedInvitations(input) {
4008
+ return organizationRead("received-invitations", input, normalizeReceivedInvitations);
4009
+ },
4010
+ async getReceivedInvitation(invitationId) {
4011
+ return organizationRead(`received-invitations/${normalizeIdInput(invitationId)}`, void 0, normalizeReceivedInvitation);
4012
+ },
3594
4013
  async signIn(input) {
3595
4014
  const body = {
3596
4015
  email: normalizeEmail(input?.email),
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as AuthErrorStatus, S as AuthErrorCode, _ as SocialIdTokenInput, b as WorkspaceSelection, c as AuthUser, f as InvitationAcceptance, l as DriveCredential, m as PersonalWorkspaceSelection, o as AuthSession, p as OrganizationWorkspaceSelection, r as AuthOrganization, t as AcceptInvitationInput, u as DriveCredentialInput, v as SocialIdTokenProvider, x as AuthError } from "./types-DDopQNZR.js";
1
+ import { A as ReceivedOrganizationInvitationPage, B as AuthErrorCode, C as OrganizationTeam, D as OrganizationWorkspaceSelection, E as OrganizationTeamPage, F as UpdateOrganizationDisplayInput, I as UpdateOrganizationTeamDisplayInput, N as SocialIdTokenInput, O as PersonalWorkspaceSelection, P as SocialIdTokenProvider, R as WorkspaceSelection, S as OrganizationPageInput, T as OrganizationTeamMemberPage, V as AuthErrorStatus, _ as OrganizationInvitation, b as OrganizationMemberPage, c as AuthUser, d as CreatedOrganizationTeam, f as DriveCredential, g as OrganizationDisplay, h as InvitationAcceptance, k as ReceivedOrganizationInvitation, l as CreateOrganizationMemberInvitationInput, o as AuthSession, p as DriveCredentialInput, r as AuthOrganization, t as AcceptInvitationInput, u as CreatedOrganizationMemberInvitation, v as OrganizationInvitationPage, w as OrganizationTeamDisplay, x as OrganizationPage, y as OrganizationMember, z as AuthError } from "./types-Byw9JQwL.js";
2
2
  //#region src/server.d.ts
3
3
  interface ServerAuthOptions {
4
4
  authOrigin: string;
@@ -20,11 +20,23 @@ interface ServerSocialIdTokenSession extends AuthSession {
20
20
  interface FinuevaServerAuth {
21
21
  acceptInvitation(input: AcceptInvitationInput): Promise<ServerInvitationAcceptance>;
22
22
  getSession(): Promise<AuthSession | null>;
23
- listOrganizations(): Promise<AuthOrganization[]>;
23
+ listOrganizations(input?: OrganizationPageInput): Promise<OrganizationPage>;
24
+ getOrganization(organizationId: string): Promise<AuthOrganization>;
25
+ createOrganizationTeam(organizationId: string, name: string, idempotencyKey: string): Promise<CreatedOrganizationTeam>;
26
+ createOrganizationMemberInvitation(organizationId: string, input: CreateOrganizationMemberInvitationInput): Promise<CreatedOrganizationMemberInvitation>;
27
+ updateOrganizationDisplay(organizationId: string, input: UpdateOrganizationDisplayInput): Promise<OrganizationDisplay>;
28
+ updateOrganizationTeamDisplay(organizationId: string, teamId: string, input: UpdateOrganizationTeamDisplayInput): Promise<OrganizationTeamDisplay>;
29
+ listOrganizationMembers(organizationId: string, input?: OrganizationPageInput): Promise<OrganizationMemberPage>;
30
+ listOrganizationTeams(organizationId: string, input?: OrganizationPageInput): Promise<OrganizationTeamPage>;
31
+ listOrganizationTeamMembers(organizationId: string, teamId: string, input?: OrganizationPageInput): Promise<OrganizationTeamMemberPage>;
32
+ listOrganizationInvitations(organizationId: string, input?: OrganizationPageInput): Promise<OrganizationInvitationPage>;
33
+ getOrganizationInvitation(organizationId: string, invitationId: string): Promise<OrganizationInvitation>;
34
+ listReceivedInvitations(input?: OrganizationPageInput): Promise<ReceivedOrganizationInvitationPage>;
35
+ getReceivedInvitation(invitationId: string): Promise<ReceivedOrganizationInvitation>;
24
36
  signInWithSocialIdToken(input: SocialIdTokenInput): Promise<ServerSocialIdTokenSession>;
25
37
  getDriveCredential(input: DriveCredentialInput): Promise<DriveCredential>;
26
38
  signOut(): Promise<ServerSignOutResult>;
27
39
  }
28
40
  declare function createServerAuth(options: ServerAuthOptions): FinuevaServerAuth;
29
41
  //#endregion
30
- export { type AcceptInvitationInput, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type DriveCredential, type DriveCredentialInput, FinuevaServerAuth, type InvitationAcceptance, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type WorkspaceSelection, createServerAuth };
42
+ export { type AcceptInvitationInput, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CreateOrganizationMemberInvitationInput, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type DriveCredential, type DriveCredentialInput, FinuevaServerAuth, type InvitationAcceptance, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberPage, type OrganizationPage, type OrganizationPageInput, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type WorkspaceSelection, createServerAuth };