@finueva/auth 0.12.0 → 0.14.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/README.md CHANGED
@@ -88,6 +88,7 @@ The browser owns the session cookie. The SDK does not expose or persist it.
88
88
  | Reset a password | `requestPasswordReset()`, `resetPassword()` | Not available | Not available |
89
89
  | Verify an email | `sendVerificationEmail()` | Not available | Not available |
90
90
  | List organizations | `listOrganizations()` | `listOrganizations()` | `listOrganizations()` |
91
+ | Read member authority | `getOrganizationMemberAuthority()` | `getOrganizationMemberAuthority()` | `getOrganizationMemberAuthority()` |
91
92
  | Create an ordinary team | `createOrganizationTeam()` | `createOrganizationTeam()` | `createOrganizationTeam()` |
92
93
  | Invite an ordinary member | `createOrganizationMemberInvitation()` | `createOrganizationMemberInvitation()` | `createOrganizationMemberInvitation()` |
93
94
  | Resend a member invitation | `resendOrganizationInvitation()` | `resendOrganizationInvitation()` (cookie) | Not available |
@@ -225,7 +226,7 @@ import { createServerAuth } from "@finueva/auth/server";
225
226
  export async function handleRequest(request: Request): Promise<Response> {
226
227
  const auth = createServerAuth({
227
228
  authOrigin: "https://auth.finueva.com",
228
- appOrigin: "https://files.finueva.com",
229
+ appOrigin: "https://app.heylomeet.com",
229
230
  request,
230
231
  });
231
232
 
package/dist/device.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as OrganizationPageInput, D as OrganizationTeamPage, E as OrganizationTeamMemberPage, G as UpdateOrganizationDisplayInput, K as UpdateOrganizationTeamDisplayInput, L as ReceivedOrganizationInvitation, R as ReceivedOrganizationInvitationPage, S as OrganizationPage, T as OrganizationTeamDisplay, U as SocialIdTokenInput, W as SocialIdTokenProvider, X as AuthErrorCode, Y as AuthError, Z as AuthErrorStatus, _ as OrganizationDisplay, b as OrganizationMember, d as CreatedOrganizationMemberInvitation, f as CreatedOrganizationTeam, m as DriveCredentialInput, o as AuthSession, p as DriveCredential, q as UpdateProfileInput, r as AuthOrganization, u as CreateOrganizationMemberInvitationInput, v as OrganizationInvitation, w as OrganizationTeam, x as OrganizationMemberPage, y as OrganizationInvitationPage } from "./types-Sh23XMKv.js";
1
+ import { C as OrganizationPage, D as OrganizationTeamMemberPage, E as OrganizationTeamDisplay, G as SocialIdTokenProvider, J as UpdateProfileInput, K as UpdateOrganizationDisplayInput, O as OrganizationTeamPage, Q as AuthErrorStatus, R as ReceivedOrganizationInvitation, S as OrganizationMemberPage, T as OrganizationTeam, W as SocialIdTokenInput, X as AuthError, Z as AuthErrorCode, _ as OrganizationDisplay, b as OrganizationMember, d as CreatedOrganizationMemberInvitation, f as CreatedOrganizationTeam, m as DriveCredentialInput, o as AuthSession, p as DriveCredential, q as UpdateOrganizationTeamDisplayInput, r as AuthOrganization, u as CreateOrganizationMemberInvitationInput, v as OrganizationInvitation, w as OrganizationPageInput, x as OrganizationMemberAuthority, y as OrganizationInvitationPage, z as ReceivedOrganizationInvitationPage } from "./types-Dsu3nEaN.js";
2
2
  //#region src/device.d.ts
3
3
  type DeviceAuthorizationErrorCode = "device_access_denied" | "device_authorization_cancelled" | "device_code_expired" | "invalid_device_authorization" | "identity_authority_unavailable";
4
4
  declare class DeviceAuthorizationError extends Error {
@@ -45,6 +45,7 @@ interface DeviceAuthClient {
45
45
  getSession(): Promise<AuthSession | null>;
46
46
  listOrganizations(input?: OrganizationPageInput): Promise<OrganizationPage>;
47
47
  getOrganization(organizationId: string): Promise<AuthOrganization>;
48
+ getOrganizationMemberAuthority(organizationId: string, memberId: string): Promise<OrganizationMemberAuthority>;
48
49
  createOrganizationTeam(organizationId: string, name: string, idempotencyKey: string): Promise<CreatedOrganizationTeam>;
49
50
  createOrganizationMemberInvitation(organizationId: string, input: CreateOrganizationMemberInvitationInput): Promise<CreatedOrganizationMemberInvitation>;
50
51
  updateOrganizationDisplay(organizationId: string, input: UpdateOrganizationDisplayInput): Promise<OrganizationDisplay>;
@@ -68,4 +69,4 @@ interface DeviceAuthClient {
68
69
  }
69
70
  declare function createDeviceAuth(options: DeviceAuthOptions): DeviceAuthClient;
70
71
  //#endregion
71
- export { AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type CreateOrganizationMemberInvitationInput, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, DeviceAuthClient, DeviceAuthOptions, DeviceAuthorization, DeviceAuthorizationError, DeviceAuthorizationErrorCode, DeviceToken, DeviceTokenPersistence, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberPage, type OrganizationPage, type OrganizationPageInput, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, PollDeviceOptions, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, createDeviceAuth };
72
+ export { AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type CreateOrganizationMemberInvitationInput, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, DeviceAuthClient, DeviceAuthOptions, DeviceAuthorization, DeviceAuthorizationError, DeviceAuthorizationErrorCode, DeviceToken, DeviceTokenPersistence, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberAuthority, type OrganizationMemberPage, type OrganizationPage, type OrganizationPageInput, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, PollDeviceOptions, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, createDeviceAuth };
package/dist/device.js CHANGED
@@ -897,6 +897,44 @@ function fromOrganizationMutationAuthorityError(value, status, retryAfter) {
897
897
  if (status === 403 && code === "REQUEST_ORIGIN_DENIED") return new AuthError("request_origin_denied", 403);
898
898
  return fromOrganizationReadAuthorityError(value, status);
899
899
  }
900
+ function normalizeOrganizationMemberAuthority(value, organizationId, memberId) {
901
+ exact(value, [
902
+ "organizationId",
903
+ "actor",
904
+ "target"
905
+ ]);
906
+ if (!isId(value.organizationId) || value.organizationId !== organizationId) throw authorityUnavailable();
907
+ const actor = normalizeOrganizationAuthorityMemberOutcome(value.actor);
908
+ const target = normalizeOrganizationAuthorityMemberOutcome(value.target);
909
+ if (target.memberId !== memberId || actor.manualRole !== "owner" && actor.manualRole !== "admin") throw authorityUnavailable();
910
+ for (const member of [actor, target]) if (member.manualRole === "member" ? member.role === "owner" : member.role !== member.manualRole) throw authorityUnavailable();
911
+ if (actor.memberId === target.memberId && (actor.manualRole !== target.manualRole || actor.role !== target.role || actor.authorityRevision !== target.authorityRevision)) throw authorityUnavailable();
912
+ return {
913
+ organizationId: value.organizationId,
914
+ actor,
915
+ target
916
+ };
917
+ }
918
+ function normalizeOrganizationAuthorityMemberOutcome(value, includesStatus = false) {
919
+ exact(value, [
920
+ "memberId",
921
+ "manualRole",
922
+ "role",
923
+ "authorityRevision",
924
+ ...includesStatus ? ["status"] : []
925
+ ]);
926
+ if (!isId(value.memberId) || value.manualRole !== "owner" && value.manualRole !== "admin" && value.manualRole !== "member" || value.role !== "owner" && value.role !== "admin" && value.role !== "member") throw authorityUnavailable();
927
+ return {
928
+ memberId: value.memberId,
929
+ manualRole: value.manualRole,
930
+ role: value.role,
931
+ authorityRevision: normalizeAuthorityResultRevision(value.authorityRevision)
932
+ };
933
+ }
934
+ function normalizeAuthorityResultRevision(value) {
935
+ if (!Number.isSafeInteger(value) || value < 0 || value >= Number.MAX_SAFE_INTEGER) throw authorityUnavailable();
936
+ return value;
937
+ }
900
938
  function mapError(code, status) {
901
939
  if (code === "authentication_required") return {
902
940
  code,
@@ -1476,6 +1514,11 @@ function createDeviceAuth(options) {
1476
1514
  return Promise.reject(error);
1477
1515
  }
1478
1516
  },
1517
+ async getOrganizationMemberAuthority(organizationId, memberId) {
1518
+ const organization = normalizeIdInput(organizationId);
1519
+ const member = normalizeIdInput(memberId);
1520
+ return serializeAuthority(() => organizationRead(`${organization}/members/${member}/authority`, void 0, (value) => normalizeOrganizationMemberAuthority(value, organization, member)));
1521
+ },
1479
1522
  createOrganizationTeam(organizationId, name, idempotencyKey) {
1480
1523
  let id;
1481
1524
  let body;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as PlatformBootstrapRoleChangeInput, B as ResentOrganizationInvitation, C as OrganizationPageInput, D as OrganizationTeamPage, E as OrganizationTeamMemberPage, F as PlatformRoleFirstApproval, G as UpdateOrganizationDisplayInput, H as SignInInput, I as PlatformStatus, J as WorkspaceSelection, K as UpdateOrganizationTeamDisplayInput, L as ReceivedOrganizationInvitation, M as PlatformRoleApplied, N as PlatformRoleApproval, O as OrganizationWorkspaceSelection, P as PlatformRoleChangeRecentAuthenticationInput, R as ReceivedOrganizationInvitationPage, S as OrganizationPage, T as OrganizationTeamDisplay, U as SocialIdTokenInput, V as SendVerificationEmailInput, W as SocialIdTokenProvider, X as AuthErrorCode, Y as AuthError, Z as AuthErrorStatus, _ as OrganizationDisplay, a as AuthPersistenceDriver, b as OrganizationMember, c as AuthUser, d as CreatedOrganizationMemberInvitation, f as CreatedOrganizationTeam, g as InvitationAcceptance, h as FinuevaAuthClient, i as AuthPersistence, j as PlatformRole, k as PersonalWorkspaceSelection, l as CanceledOrganizationInvitation, m as DriveCredentialInput, n as AuthClientOptions, o as AuthSession, p as DriveCredential, q as UpdateProfileInput, r as AuthOrganization, s as AuthState, t as AcceptInvitationInput, u as CreateOrganizationMemberInvitationInput, v as OrganizationInvitation, w as OrganizationTeam, x as OrganizationMemberPage, y as OrganizationInvitationPage, z as RecentAuthenticationStatus } from "./types-Sh23XMKv.js";
1
+ import { A as PersonalWorkspaceSelection, B as RecentAuthenticationStatus, C as OrganizationPage, D as OrganizationTeamMemberPage, E as OrganizationTeamDisplay, F as PlatformRoleChangeRecentAuthenticationInput, G as SocialIdTokenProvider, H as SendVerificationEmailInput, I as PlatformRoleFirstApproval, J as UpdateProfileInput, K as UpdateOrganizationDisplayInput, L as PlatformStatus, M as PlatformRole, N as PlatformRoleApplied, O as OrganizationTeamPage, P as PlatformRoleApproval, Q as AuthErrorStatus, R as ReceivedOrganizationInvitation, S as OrganizationMemberPage, T as OrganizationTeam, U as SignInInput, V as ResentOrganizationInvitation, W as SocialIdTokenInput, X as AuthError, Y as WorkspaceSelection, Z as AuthErrorCode, _ as OrganizationDisplay, a as AuthPersistenceDriver, b as OrganizationMember, c as AuthUser, d as CreatedOrganizationMemberInvitation, f as CreatedOrganizationTeam, g as InvitationAcceptance, h as FinuevaAuthClient, i as AuthPersistence, j as PlatformBootstrapRoleChangeInput, k as OrganizationWorkspaceSelection, l as CanceledOrganizationInvitation, m as DriveCredentialInput, n as AuthClientOptions, o as AuthSession, p as DriveCredential, q as UpdateOrganizationTeamDisplayInput, r as AuthOrganization, s as AuthState, t as AcceptInvitationInput, u as CreateOrganizationMemberInvitationInput, v as OrganizationInvitation, w as OrganizationPageInput, x as OrganizationMemberAuthority, y as OrganizationInvitationPage, z as ReceivedOrganizationInvitationPage } from "./types-Dsu3nEaN.js";
2
2
  //#region src/client.d.ts
3
3
  declare function createAuthClient(options: AuthClientOptions): FinuevaAuthClient;
4
4
  //#endregion
5
- export { type AcceptInvitationInput, type AuthClientOptions, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthPersistence, type AuthPersistenceDriver, type AuthSession, type AuthState, type AuthUser, type CanceledOrganizationInvitation, type CreateOrganizationMemberInvitationInput, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type FinuevaAuthClient, 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 PlatformBootstrapRoleChangeInput, type PlatformRole, type PlatformRoleApplied, type PlatformRoleApproval, type PlatformRoleChangeRecentAuthenticationInput, type PlatformRoleFirstApproval, type PlatformStatus, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type RecentAuthenticationStatus, type ResentOrganizationInvitation, type SendVerificationEmailInput, type SignInInput, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type UpdateProfileInput, type WorkspaceSelection, createAuthClient };
5
+ export { type AcceptInvitationInput, type AuthClientOptions, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthPersistence, type AuthPersistenceDriver, type AuthSession, type AuthState, type AuthUser, type CanceledOrganizationInvitation, type CreateOrganizationMemberInvitationInput, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type FinuevaAuthClient, type InvitationAcceptance, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberAuthority, type OrganizationMemberPage, type OrganizationPage, type OrganizationPageInput, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type PlatformBootstrapRoleChangeInput, type PlatformRole, type PlatformRoleApplied, type PlatformRoleApproval, type PlatformRoleChangeRecentAuthenticationInput, type PlatformRoleFirstApproval, type PlatformStatus, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type RecentAuthenticationStatus, type ResentOrganizationInvitation, type SendVerificationEmailInput, type SignInInput, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type UpdateProfileInput, type WorkspaceSelection, createAuthClient };
package/dist/index.js CHANGED
@@ -3382,6 +3382,24 @@ function normalizeOrganizationManualRoleChangeResult(value) {
3382
3382
  ...normalizeOrganizationAuthorityMemberOutcome(value, true)
3383
3383
  };
3384
3384
  }
3385
+ function normalizeOrganizationMemberAuthority(value, organizationId, memberId) {
3386
+ exact(value, [
3387
+ "organizationId",
3388
+ "actor",
3389
+ "target"
3390
+ ]);
3391
+ if (!isId(value.organizationId) || value.organizationId !== organizationId) throw authorityUnavailable();
3392
+ const actor = normalizeOrganizationAuthorityMemberOutcome(value.actor);
3393
+ const target = normalizeOrganizationAuthorityMemberOutcome(value.target);
3394
+ if (target.memberId !== memberId || actor.manualRole !== "owner" && actor.manualRole !== "admin") throw authorityUnavailable();
3395
+ for (const member of [actor, target]) if (member.manualRole === "member" ? member.role === "owner" : member.role !== member.manualRole) throw authorityUnavailable();
3396
+ if (actor.memberId === target.memberId && (actor.manualRole !== target.manualRole || actor.role !== target.role || actor.authorityRevision !== target.authorityRevision)) throw authorityUnavailable();
3397
+ return {
3398
+ organizationId: value.organizationId,
3399
+ actor,
3400
+ target
3401
+ };
3402
+ }
3385
3403
  function normalizeOrganizationOwnershipTransferResult(value) {
3386
3404
  exact(value, [
3387
3405
  "status",
@@ -4930,6 +4948,11 @@ function createAuthClient(options) {
4930
4948
  async getOrganization(organizationId) {
4931
4949
  return organizationRead(normalizeIdInput(organizationId), void 0, normalizeOrganization);
4932
4950
  },
4951
+ async getOrganizationMemberAuthority(organizationId, memberId) {
4952
+ const organization = normalizeIdInput(organizationId);
4953
+ const member = normalizeIdInput(memberId);
4954
+ return organizationRead(`${organization}/members/${member}/authority`, void 0, (value) => normalizeOrganizationMemberAuthority(value, organization, member));
4955
+ },
4933
4956
  async createOrganizationTeam(organizationId, name, idempotencyKey) {
4934
4957
  const id = normalizeIdInput(organizationId);
4935
4958
  const body = normalizeOrganizationTeamCreationInput(name, idempotencyKey);
package/dist/server.d.ts CHANGED
@@ -1,4 +1,22 @@
1
- import { B as ResentOrganizationInvitation, C as OrganizationPageInput, D as OrganizationTeamPage, E as OrganizationTeamMemberPage, G as UpdateOrganizationDisplayInput, J as WorkspaceSelection, K as UpdateOrganizationTeamDisplayInput, L as ReceivedOrganizationInvitation, O as OrganizationWorkspaceSelection, R as ReceivedOrganizationInvitationPage, S as OrganizationPage, T as OrganizationTeamDisplay, U as SocialIdTokenInput, W as SocialIdTokenProvider, X as AuthErrorCode, Y as AuthError, Z as AuthErrorStatus, _ as OrganizationDisplay, b as OrganizationMember, c as AuthUser, d as CreatedOrganizationMemberInvitation, f as CreatedOrganizationTeam, g as InvitationAcceptance, k as PersonalWorkspaceSelection, l as CanceledOrganizationInvitation, m as DriveCredentialInput, o as AuthSession, p as DriveCredential, r as AuthOrganization, t as AcceptInvitationInput, u as CreateOrganizationMemberInvitationInput, v as OrganizationInvitation, w as OrganizationTeam, x as OrganizationMemberPage, y as OrganizationInvitationPage } from "./types-Sh23XMKv.js";
1
+ import { A as PersonalWorkspaceSelection, C as OrganizationPage, D as OrganizationTeamMemberPage, E as OrganizationTeamDisplay, G as SocialIdTokenProvider, K as UpdateOrganizationDisplayInput, O as OrganizationTeamPage, Q as AuthErrorStatus, R as ReceivedOrganizationInvitation, S as OrganizationMemberPage, T as OrganizationTeam, V as ResentOrganizationInvitation, W as SocialIdTokenInput, X as AuthError, Y as WorkspaceSelection, Z as AuthErrorCode, _ as OrganizationDisplay, b as OrganizationMember, c as AuthUser, d as CreatedOrganizationMemberInvitation, f as CreatedOrganizationTeam, g as InvitationAcceptance, k as OrganizationWorkspaceSelection, l as CanceledOrganizationInvitation, m as DriveCredentialInput, o as AuthSession, p as DriveCredential, q as UpdateOrganizationTeamDisplayInput, r as AuthOrganization, t as AcceptInvitationInput, u as CreateOrganizationMemberInvitationInput, v as OrganizationInvitation, w as OrganizationPageInput, x as OrganizationMemberAuthority, y as OrganizationInvitationPage, z as ReceivedOrganizationInvitationPage } from "./types-Dsu3nEaN.js";
2
+ //#region src/provisioning.d.ts
3
+ interface DriveProvisioningAuthOptions {
4
+ authOrigin: string;
5
+ fetch?: typeof globalThis.fetch;
6
+ now?: () => number;
7
+ timeoutMs?: number;
8
+ }
9
+ interface DriveProvisioningCredential {
10
+ tokenType: "Bearer";
11
+ token: string;
12
+ expiresAt: Date;
13
+ }
14
+ interface FinuevaDriveProvisioningAuth {
15
+ getDriveProvisioningCredential(clientAssertion: string): Promise<DriveProvisioningCredential>;
16
+ }
17
+ /** Service authority only. Never pass an incoming User request or session to this client. */
18
+ declare function createDriveProvisioningAuth(options: DriveProvisioningAuthOptions): FinuevaDriveProvisioningAuth;
19
+ //#endregion
2
20
  //#region src/server.d.ts
3
21
  interface ServerAuthOptions {
4
22
  authOrigin: string;
@@ -22,6 +40,7 @@ interface FinuevaServerAuth {
22
40
  getSession(): Promise<AuthSession | null>;
23
41
  listOrganizations(input?: OrganizationPageInput): Promise<OrganizationPage>;
24
42
  getOrganization(organizationId: string): Promise<AuthOrganization>;
43
+ getOrganizationMemberAuthority(organizationId: string, memberId: string): Promise<OrganizationMemberAuthority>;
25
44
  createOrganizationTeam(organizationId: string, name: string, idempotencyKey: string): Promise<CreatedOrganizationTeam>;
26
45
  createOrganizationMemberInvitation(organizationId: string, input: CreateOrganizationMemberInvitationInput): Promise<CreatedOrganizationMemberInvitation>;
27
46
  resendOrganizationInvitation(organizationId: string, invitationId: string, idempotencyKey: string): Promise<ResentOrganizationInvitation>;
@@ -41,4 +60,4 @@ interface FinuevaServerAuth {
41
60
  }
42
61
  declare function createServerAuth(options: ServerAuthOptions): FinuevaServerAuth;
43
62
  //#endregion
44
- export { type AcceptInvitationInput, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CanceledOrganizationInvitation, 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, type ResentOrganizationInvitation, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type WorkspaceSelection, createServerAuth };
63
+ export { type AcceptInvitationInput, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CanceledOrganizationInvitation, type CreateOrganizationMemberInvitationInput, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type DriveProvisioningAuthOptions, type DriveProvisioningCredential, type FinuevaDriveProvisioningAuth, FinuevaServerAuth, type InvitationAcceptance, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberAuthority, type OrganizationMemberPage, type OrganizationPage, type OrganizationPageInput, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type ResentOrganizationInvitation, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type WorkspaceSelection, createDriveProvisioningAuth, createServerAuth };
package/dist/server.js CHANGED
@@ -211,269 +211,6 @@ var AuthError = class extends Error {
211
211
  }
212
212
  };
213
213
  //#endregion
214
- //#region ../../node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs
215
- 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*:/;
216
- 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*:/;
217
- const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
218
- function jsonParseTransform(key, value) {
219
- if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
220
- warnKeyDropped(key);
221
- return;
222
- }
223
- return value;
224
- }
225
- function warnKeyDropped(key) {
226
- console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
227
- }
228
- function destr(value, options = {}) {
229
- if (typeof value !== "string") return value;
230
- if (value[0] === "\"" && value[value.length - 1] === "\"" && value.indexOf("\\") === -1) return value.slice(1, -1);
231
- const _value = value.trim();
232
- if (_value.length <= 9) switch (_value.toLowerCase()) {
233
- case "true": return true;
234
- case "false": return false;
235
- case "undefined": return;
236
- case "null": return null;
237
- case "nan": return NaN;
238
- case "infinity": return Number.POSITIVE_INFINITY;
239
- case "-infinity": return Number.NEGATIVE_INFINITY;
240
- }
241
- if (!JsonSigRx.test(value)) {
242
- if (options.strict) throw new SyntaxError("[destr] Invalid JSON");
243
- return value;
244
- }
245
- try {
246
- if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
247
- if (options.strict) throw new Error("[destr] Possible prototype pollution");
248
- return JSON.parse(value, jsonParseTransform);
249
- }
250
- return JSON.parse(value);
251
- } catch (error) {
252
- if (options.strict) throw error;
253
- return value;
254
- }
255
- }
256
- //#endregion
257
- //#region ../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs
258
- var FetchError = class extends Error {
259
- constructor(message, opts) {
260
- super(message, opts);
261
- this.name = "FetchError";
262
- if (opts?.cause && !this.cause) this.cause = opts.cause;
263
- }
264
- };
265
- function createFetchError(ctx) {
266
- const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
267
- const method = ctx.request?.method || ctx.options?.method || "GET";
268
- const url = ctx.request?.url || String(ctx.request) || "/";
269
- 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);
270
- for (const key of [
271
- "request",
272
- "options",
273
- "response"
274
- ]) Object.defineProperty(fetchError, key, { get() {
275
- return ctx[key];
276
- } });
277
- for (const [key, refKey] of [
278
- ["data", "_data"],
279
- ["status", "status"],
280
- ["statusCode", "status"],
281
- ["statusText", "statusText"],
282
- ["statusMessage", "statusText"]
283
- ]) Object.defineProperty(fetchError, key, { get() {
284
- return ctx.response && ctx.response[refKey];
285
- } });
286
- return fetchError;
287
- }
288
- const payloadMethods = new Set(Object.freeze([
289
- "PATCH",
290
- "POST",
291
- "PUT",
292
- "DELETE"
293
- ]));
294
- function isPayloadMethod(method = "GET") {
295
- return payloadMethods.has(method.toUpperCase());
296
- }
297
- function isJSONSerializable(value) {
298
- if (value === void 0) return false;
299
- const t = typeof value;
300
- if (t === "string" || t === "number" || t === "boolean" || t === null) return true;
301
- if (t !== "object") return false;
302
- if (Array.isArray(value)) return true;
303
- if (value.buffer) return false;
304
- if (value instanceof FormData || value instanceof URLSearchParams) return false;
305
- return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
306
- }
307
- const textTypes = new Set([
308
- "image/svg",
309
- "application/xml",
310
- "application/xhtml",
311
- "application/html"
312
- ]);
313
- const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
314
- function detectResponseType(_contentType = "") {
315
- if (!_contentType) return "json";
316
- const contentType = _contentType.split(";").shift() || "";
317
- if (JSON_RE.test(contentType)) return "json";
318
- if (contentType === "text/event-stream") return "stream";
319
- if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
320
- return "blob";
321
- }
322
- function resolveFetchOptions(request, input, defaults, Headers) {
323
- const headers = mergeHeaders(input?.headers ?? request?.headers, defaults?.headers, Headers);
324
- let query;
325
- if (defaults?.query || defaults?.params || input?.params || input?.query) query = {
326
- ...defaults?.params,
327
- ...defaults?.query,
328
- ...input?.params,
329
- ...input?.query
330
- };
331
- return {
332
- ...defaults,
333
- ...input,
334
- query,
335
- params: query,
336
- headers
337
- };
338
- }
339
- function mergeHeaders(input, defaults, Headers) {
340
- if (!defaults) return new Headers(input);
341
- const headers = new Headers(defaults);
342
- if (input) for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) headers.set(key, value);
343
- return headers;
344
- }
345
- async function callHooks(context, hooks) {
346
- if (hooks) if (Array.isArray(hooks)) for (const hook of hooks) await hook(context);
347
- else await hooks(context);
348
- }
349
- const retryStatusCodes = new Set([
350
- 408,
351
- 409,
352
- 425,
353
- 429,
354
- 500,
355
- 502,
356
- 503,
357
- 504
358
- ]);
359
- const nullBodyResponses = new Set([
360
- 101,
361
- 204,
362
- 205,
363
- 304
364
- ]);
365
- function createFetch(globalOptions = {}) {
366
- const { fetch = globalThis.fetch, Headers = globalThis.Headers, AbortController = globalThis.AbortController } = globalOptions;
367
- async function onError(context) {
368
- const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
369
- if (context.options.retry !== false && !isAbort) {
370
- let retries;
371
- if (typeof context.options.retry === "number") retries = context.options.retry;
372
- else retries = isPayloadMethod(context.options.method) ? 0 : 1;
373
- const responseCode = context.response && context.response.status || 500;
374
- if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
375
- const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
376
- if (retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
377
- return $fetchRaw(context.request, {
378
- ...context.options,
379
- retry: retries - 1
380
- });
381
- }
382
- }
383
- const error = createFetchError(context);
384
- if (Error.captureStackTrace) Error.captureStackTrace(error, $fetchRaw);
385
- throw error;
386
- }
387
- const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
388
- const context = {
389
- request: _request,
390
- options: resolveFetchOptions(_request, _options, globalOptions.defaults, Headers),
391
- response: void 0,
392
- error: void 0
393
- };
394
- if (context.options.method) context.options.method = context.options.method.toUpperCase();
395
- if (context.options.onRequest) {
396
- await callHooks(context, context.options.onRequest);
397
- if (!(context.options.headers instanceof Headers)) context.options.headers = new Headers(context.options.headers || {});
398
- }
399
- if (typeof context.request === "string") {
400
- if (context.options.baseURL) context.request = withBase(context.request, context.options.baseURL);
401
- if (context.options.query) {
402
- context.request = withQuery(context.request, context.options.query);
403
- delete context.options.query;
404
- }
405
- if ("query" in context.options) delete context.options.query;
406
- if ("params" in context.options) delete context.options.params;
407
- }
408
- if (context.options.body && isPayloadMethod(context.options.method)) {
409
- if (isJSONSerializable(context.options.body)) {
410
- const contentType = context.options.headers.get("content-type");
411
- 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);
412
- if (!contentType) context.options.headers.set("content-type", "application/json");
413
- if (!context.options.headers.has("accept")) context.options.headers.set("accept", "application/json");
414
- } else if ("pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || typeof context.options.body.pipe === "function") {
415
- if (!("duplex" in context.options)) context.options.duplex = "half";
416
- }
417
- }
418
- let abortTimeout;
419
- if (!context.options.signal && context.options.timeout) {
420
- const controller = new AbortController();
421
- abortTimeout = setTimeout(() => {
422
- const error = new Error("[TimeoutError]: The operation was aborted due to timeout");
423
- error.name = "TimeoutError";
424
- error.code = 23;
425
- controller.abort(error);
426
- }, context.options.timeout);
427
- context.options.signal = controller.signal;
428
- }
429
- try {
430
- context.response = await fetch(context.request, context.options);
431
- } catch (error) {
432
- context.error = error;
433
- if (context.options.onRequestError) await callHooks(context, context.options.onRequestError);
434
- return await onError(context);
435
- } finally {
436
- if (abortTimeout) clearTimeout(abortTimeout);
437
- }
438
- if ((context.response.body || context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD") {
439
- const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
440
- switch (responseType) {
441
- case "json": {
442
- const data = await context.response.text();
443
- const parseFunction = context.options.parseResponse || destr;
444
- context.response._data = parseFunction(data);
445
- break;
446
- }
447
- case "stream":
448
- context.response._data = context.response.body || context.response._bodyInit;
449
- break;
450
- default: context.response._data = await context.response[responseType]();
451
- }
452
- }
453
- if (context.options.onResponse) await callHooks(context, context.options.onResponse);
454
- if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
455
- if (context.options.onResponseError) await callHooks(context, context.options.onResponseError);
456
- return await onError(context);
457
- }
458
- return context.response;
459
- };
460
- const $fetch = async function $fetch2(request, options) {
461
- return (await $fetchRaw(request, options))._data;
462
- };
463
- $fetch.raw = $fetchRaw;
464
- $fetch.native = (...args) => fetch(...args);
465
- $fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
466
- ...globalOptions,
467
- ...customGlobalOptions,
468
- defaults: {
469
- ...globalOptions.defaults,
470
- ...customGlobalOptions.defaults,
471
- ...defaultOptions
472
- }
473
- });
474
- return $fetch;
475
- }
476
- //#endregion
477
214
  //#region src/shared.ts
478
215
  const DRIVE_CREDENTIAL_LIFETIME_SECONDS = 840;
479
216
  const id = /^[A-Za-z0-9_-]{1,128}$/;
@@ -909,6 +646,44 @@ function fromOrganizationInvitationAdministrationError(value, status, retryAfter
909
646
  if (status === 422 && isObject(value) && value.code === "RECOVERY_REQUIRED") return new AuthError("invitation_recovery_required", 422);
910
647
  return fromOrganizationMutationAuthorityError(value, status, retryAfter);
911
648
  }
649
+ function normalizeOrganizationMemberAuthority(value, organizationId, memberId) {
650
+ exact(value, [
651
+ "organizationId",
652
+ "actor",
653
+ "target"
654
+ ]);
655
+ if (!isId(value.organizationId) || value.organizationId !== organizationId) throw authorityUnavailable();
656
+ const actor = normalizeOrganizationAuthorityMemberOutcome(value.actor);
657
+ const target = normalizeOrganizationAuthorityMemberOutcome(value.target);
658
+ if (target.memberId !== memberId || actor.manualRole !== "owner" && actor.manualRole !== "admin") throw authorityUnavailable();
659
+ for (const member of [actor, target]) if (member.manualRole === "member" ? member.role === "owner" : member.role !== member.manualRole) throw authorityUnavailable();
660
+ if (actor.memberId === target.memberId && (actor.manualRole !== target.manualRole || actor.role !== target.role || actor.authorityRevision !== target.authorityRevision)) throw authorityUnavailable();
661
+ return {
662
+ organizationId: value.organizationId,
663
+ actor,
664
+ target
665
+ };
666
+ }
667
+ function normalizeOrganizationAuthorityMemberOutcome(value, includesStatus = false) {
668
+ exact(value, [
669
+ "memberId",
670
+ "manualRole",
671
+ "role",
672
+ "authorityRevision",
673
+ ...includesStatus ? ["status"] : []
674
+ ]);
675
+ if (!isId(value.memberId) || value.manualRole !== "owner" && value.manualRole !== "admin" && value.manualRole !== "member" || value.role !== "owner" && value.role !== "admin" && value.role !== "member") throw authorityUnavailable();
676
+ return {
677
+ memberId: value.memberId,
678
+ manualRole: value.manualRole,
679
+ role: value.role,
680
+ authorityRevision: normalizeAuthorityResultRevision(value.authorityRevision)
681
+ };
682
+ }
683
+ function normalizeAuthorityResultRevision(value) {
684
+ if (!Number.isSafeInteger(value) || value < 0 || value >= Number.MAX_SAFE_INTEGER) throw authorityUnavailable();
685
+ return value;
686
+ }
912
687
  function fromInvitationAuthorityError(value, status) {
913
688
  const code = isObject(value) && typeof value.code === "string" ? value.code : void 0;
914
689
  if (status === 401 && code === "UNAUTHORIZED") return new AuthError("authentication_required", 401);
@@ -986,45 +761,412 @@ function isId(value) {
986
761
  function exact(value, keys) {
987
762
  if (!isObject(value) || Object.keys(value).sort().join(",") !== [...keys].sort().join(",")) throw authorityUnavailable();
988
763
  }
989
- function boundedString(value, maximum) {
990
- return typeof value === "string" && value.length > 0 && new TextEncoder().encode(value).byteLength <= maximum;
764
+ function boundedString(value, maximum) {
765
+ return typeof value === "string" && value.length > 0 && new TextEncoder().encode(value).byteLength <= maximum;
766
+ }
767
+ function role(value) {
768
+ return value === "owner" || value === "admin" || value === "member";
769
+ }
770
+ function nullableHttpsUrl(value) {
771
+ if (value === null) return null;
772
+ if (typeof value !== "string" || value.length > 2048) throw authorityUnavailable();
773
+ let url;
774
+ try {
775
+ url = new URL(value);
776
+ } catch {
777
+ throw authorityUnavailable();
778
+ }
779
+ if (url.protocol !== "https:" || url.username || url.password || url.toString() !== value) throw authorityUnavailable();
780
+ return value;
781
+ }
782
+ function responseDate(value) {
783
+ if (typeof value !== "string") throw authorityUnavailable();
784
+ const date = new Date(value);
785
+ if (!Number.isFinite(date.getTime()) || date.toISOString() !== value) throw authorityUnavailable();
786
+ return date;
787
+ }
788
+ function nullableCursor(value) {
789
+ if (value === null) return null;
790
+ if (typeof value !== "string" || value.length < 1 || value.length > 820 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value)) throw authorityUnavailable();
791
+ return value;
792
+ }
793
+ function normalizeResponseId(value) {
794
+ if (!isId(value)) throw authorityUnavailable();
795
+ return value;
796
+ }
797
+ function unique(items, key) {
798
+ if (new Set(items.map(key)).size !== items.length) throw authorityUnavailable();
799
+ return items;
800
+ }
801
+ function isObject(value) {
802
+ return typeof value === "object" && value !== null && !Array.isArray(value);
803
+ }
804
+ //#endregion
805
+ //#region src/provisioning.ts
806
+ const MAX_BYTES = 16 * 1024;
807
+ const compactJwt = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
808
+ function isCompactCredential(value) {
809
+ return typeof value === "string" && value.length + 7 <= MAX_BYTES && compactJwt.test(value);
810
+ }
811
+ function createDriveProvisioningAuth(options) {
812
+ const url = joinURL(normalizeOrigin(options.authOrigin, "authOrigin"), "api/v1/auth/drive-provisioning-credential");
813
+ const fetchImpl = options.fetch ?? globalThis.fetch?.bind(globalThis);
814
+ if (typeof fetchImpl !== "function") throw new TypeError("fetch is required");
815
+ const timeoutMs = normalizeTimeout(options.timeoutMs);
816
+ const now = options.now ?? Date.now;
817
+ let inFlight = false;
818
+ return { async getDriveProvisioningCredential(clientAssertion) {
819
+ if (!isCompactCredential(clientAssertion)) throw new AuthError("invalid_request", 400);
820
+ if (inFlight) throw new AuthError("state_conflict", 409);
821
+ inFlight = true;
822
+ const controller = new AbortController();
823
+ let reader;
824
+ let timer;
825
+ let exchangeStarted = false;
826
+ let authorityError;
827
+ try {
828
+ const startedAt = now();
829
+ if (!Number.isSafeInteger(startedAt) || startedAt < 0 || startedAt > 86399999997e5) throw authorityUnavailable();
830
+ const deadline = new Promise((_, reject) => {
831
+ timer = setTimeout(() => {
832
+ reject(authorityUnavailable());
833
+ controller.abort();
834
+ reader?.cancel().catch(() => {});
835
+ }, timeoutMs);
836
+ });
837
+ const exchange = async () => {
838
+ const response = await fetchImpl(url, {
839
+ method: "POST",
840
+ headers: {
841
+ authorization: `Bearer ${clientAssertion}`,
842
+ accept: "application/json"
843
+ },
844
+ credentials: "omit",
845
+ cache: "no-store",
846
+ redirect: "manual",
847
+ signal: controller.signal
848
+ });
849
+ if (controller.signal.aborted) {
850
+ response.body?.cancel().catch(() => {});
851
+ throw authorityUnavailable();
852
+ }
853
+ if (!response.body) throw authorityUnavailable();
854
+ reader = response.body.getReader();
855
+ const contentType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
856
+ const length = response.headers.get("content-length");
857
+ if (contentType !== "application/json" || length !== null && (!/^\d+$/.test(length) || Number(length) > MAX_BYTES)) throw authorityUnavailable();
858
+ const bytes = new Uint8Array(MAX_BYTES);
859
+ let size = 0;
860
+ while (true) {
861
+ const chunk = await reader.read();
862
+ if (chunk.done) break;
863
+ if (controller.signal.aborted || size + chunk.value.byteLength > MAX_BYTES) throw authorityUnavailable();
864
+ bytes.set(chunk.value, size);
865
+ size += chunk.value.byteLength;
866
+ }
867
+ const value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(0, size)));
868
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw authorityUnavailable();
869
+ const record = value;
870
+ if (response.status !== 200) {
871
+ if (Object.keys(record).length !== 2 || !("code" in record) || !("message" in record)) throw authorityUnavailable();
872
+ if (response.status === 401 && record.code === "UNAUTHORIZED" && record.message === "The ecosystem client assertion is invalid.") {
873
+ authorityError = new AuthError("authentication_required", 401);
874
+ throw authorityError;
875
+ }
876
+ const retryAfter = response.headers.get("retry-after");
877
+ if (response.status === 429 && record.code === "TOO_MANY_REQUESTS" && record.message === "Ecosystem credential exchanges are temporarily limited." && retryAfter !== null && /^(?:[1-9]|[1-5][0-9]|60)$/.test(retryAfter)) {
878
+ authorityError = new AuthError("auth_request_rate_limited", 429, Number(retryAfter));
879
+ throw authorityError;
880
+ }
881
+ throw authorityUnavailable();
882
+ }
883
+ if (Object.keys(record).length !== 3 || record.tokenType !== "Bearer" || record.expiresIn !== 300 || !isCompactCredential(record.token)) throw authorityUnavailable();
884
+ const expiresAt = new Date(Math.floor(startedAt / 1e3) * 1e3 + 3e5);
885
+ const completedAt = now();
886
+ if (!Number.isSafeInteger(completedAt) || completedAt < 0 || completedAt >= expiresAt.getTime()) throw authorityUnavailable();
887
+ return {
888
+ tokenType: "Bearer",
889
+ token: record.token,
890
+ expiresAt
891
+ };
892
+ };
893
+ exchangeStarted = true;
894
+ return await Promise.race([exchange().finally(() => {
895
+ inFlight = false;
896
+ }), deadline]);
897
+ } catch (error) {
898
+ if (authorityError && error === authorityError) throw authorityError;
899
+ throw authorityUnavailable();
900
+ } finally {
901
+ clearTimeout(timer);
902
+ controller.abort();
903
+ reader?.cancel().catch(() => {});
904
+ if (!exchangeStarted) inFlight = false;
905
+ }
906
+ } };
907
+ }
908
+ //#endregion
909
+ //#region ../../node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs
910
+ 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*:/;
911
+ 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*:/;
912
+ const JsonSigRx = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
913
+ function jsonParseTransform(key, value) {
914
+ if (key === "__proto__" || key === "constructor" && value && typeof value === "object" && "prototype" in value) {
915
+ warnKeyDropped(key);
916
+ return;
917
+ }
918
+ return value;
919
+ }
920
+ function warnKeyDropped(key) {
921
+ console.warn(`[destr] Dropping "${key}" key to prevent prototype pollution.`);
922
+ }
923
+ function destr(value, options = {}) {
924
+ if (typeof value !== "string") return value;
925
+ if (value[0] === "\"" && value[value.length - 1] === "\"" && value.indexOf("\\") === -1) return value.slice(1, -1);
926
+ const _value = value.trim();
927
+ if (_value.length <= 9) switch (_value.toLowerCase()) {
928
+ case "true": return true;
929
+ case "false": return false;
930
+ case "undefined": return;
931
+ case "null": return null;
932
+ case "nan": return NaN;
933
+ case "infinity": return Number.POSITIVE_INFINITY;
934
+ case "-infinity": return Number.NEGATIVE_INFINITY;
935
+ }
936
+ if (!JsonSigRx.test(value)) {
937
+ if (options.strict) throw new SyntaxError("[destr] Invalid JSON");
938
+ return value;
939
+ }
940
+ try {
941
+ if (suspectProtoRx.test(value) || suspectConstructorRx.test(value)) {
942
+ if (options.strict) throw new Error("[destr] Possible prototype pollution");
943
+ return JSON.parse(value, jsonParseTransform);
944
+ }
945
+ return JSON.parse(value);
946
+ } catch (error) {
947
+ if (options.strict) throw error;
948
+ return value;
949
+ }
950
+ }
951
+ //#endregion
952
+ //#region ../../node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs
953
+ var FetchError = class extends Error {
954
+ constructor(message, opts) {
955
+ super(message, opts);
956
+ this.name = "FetchError";
957
+ if (opts?.cause && !this.cause) this.cause = opts.cause;
958
+ }
959
+ };
960
+ function createFetchError(ctx) {
961
+ const errorMessage = ctx.error?.message || ctx.error?.toString() || "";
962
+ const method = ctx.request?.method || ctx.options?.method || "GET";
963
+ const url = ctx.request?.url || String(ctx.request) || "/";
964
+ 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);
965
+ for (const key of [
966
+ "request",
967
+ "options",
968
+ "response"
969
+ ]) Object.defineProperty(fetchError, key, { get() {
970
+ return ctx[key];
971
+ } });
972
+ for (const [key, refKey] of [
973
+ ["data", "_data"],
974
+ ["status", "status"],
975
+ ["statusCode", "status"],
976
+ ["statusText", "statusText"],
977
+ ["statusMessage", "statusText"]
978
+ ]) Object.defineProperty(fetchError, key, { get() {
979
+ return ctx.response && ctx.response[refKey];
980
+ } });
981
+ return fetchError;
991
982
  }
992
- function role(value) {
993
- return value === "owner" || value === "admin" || value === "member";
983
+ const payloadMethods = new Set(Object.freeze([
984
+ "PATCH",
985
+ "POST",
986
+ "PUT",
987
+ "DELETE"
988
+ ]));
989
+ function isPayloadMethod(method = "GET") {
990
+ return payloadMethods.has(method.toUpperCase());
994
991
  }
995
- function nullableHttpsUrl(value) {
996
- if (value === null) return null;
997
- if (typeof value !== "string" || value.length > 2048) throw authorityUnavailable();
998
- let url;
999
- try {
1000
- url = new URL(value);
1001
- } catch {
1002
- throw authorityUnavailable();
1003
- }
1004
- if (url.protocol !== "https:" || url.username || url.password || url.toString() !== value) throw authorityUnavailable();
1005
- return value;
992
+ function isJSONSerializable(value) {
993
+ if (value === void 0) return false;
994
+ const t = typeof value;
995
+ if (t === "string" || t === "number" || t === "boolean" || t === null) return true;
996
+ if (t !== "object") return false;
997
+ if (Array.isArray(value)) return true;
998
+ if (value.buffer) return false;
999
+ if (value instanceof FormData || value instanceof URLSearchParams) return false;
1000
+ return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
1006
1001
  }
1007
- function responseDate(value) {
1008
- if (typeof value !== "string") throw authorityUnavailable();
1009
- const date = new Date(value);
1010
- if (!Number.isFinite(date.getTime()) || date.toISOString() !== value) throw authorityUnavailable();
1011
- return date;
1002
+ const textTypes = new Set([
1003
+ "image/svg",
1004
+ "application/xml",
1005
+ "application/xhtml",
1006
+ "application/html"
1007
+ ]);
1008
+ const JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
1009
+ function detectResponseType(_contentType = "") {
1010
+ if (!_contentType) return "json";
1011
+ const contentType = _contentType.split(";").shift() || "";
1012
+ if (JSON_RE.test(contentType)) return "json";
1013
+ if (contentType === "text/event-stream") return "stream";
1014
+ if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
1015
+ return "blob";
1012
1016
  }
1013
- function nullableCursor(value) {
1014
- if (value === null) return null;
1015
- if (typeof value !== "string" || value.length < 1 || value.length > 820 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value)) throw authorityUnavailable();
1016
- return value;
1017
+ function resolveFetchOptions(request, input, defaults, Headers) {
1018
+ const headers = mergeHeaders(input?.headers ?? request?.headers, defaults?.headers, Headers);
1019
+ let query;
1020
+ if (defaults?.query || defaults?.params || input?.params || input?.query) query = {
1021
+ ...defaults?.params,
1022
+ ...defaults?.query,
1023
+ ...input?.params,
1024
+ ...input?.query
1025
+ };
1026
+ return {
1027
+ ...defaults,
1028
+ ...input,
1029
+ query,
1030
+ params: query,
1031
+ headers
1032
+ };
1017
1033
  }
1018
- function normalizeResponseId(value) {
1019
- if (!isId(value)) throw authorityUnavailable();
1020
- return value;
1034
+ function mergeHeaders(input, defaults, Headers) {
1035
+ if (!defaults) return new Headers(input);
1036
+ const headers = new Headers(defaults);
1037
+ if (input) for (const [key, value] of Symbol.iterator in input || Array.isArray(input) ? input : new Headers(input)) headers.set(key, value);
1038
+ return headers;
1021
1039
  }
1022
- function unique(items, key) {
1023
- if (new Set(items.map(key)).size !== items.length) throw authorityUnavailable();
1024
- return items;
1040
+ async function callHooks(context, hooks) {
1041
+ if (hooks) if (Array.isArray(hooks)) for (const hook of hooks) await hook(context);
1042
+ else await hooks(context);
1025
1043
  }
1026
- function isObject(value) {
1027
- return typeof value === "object" && value !== null && !Array.isArray(value);
1044
+ const retryStatusCodes = new Set([
1045
+ 408,
1046
+ 409,
1047
+ 425,
1048
+ 429,
1049
+ 500,
1050
+ 502,
1051
+ 503,
1052
+ 504
1053
+ ]);
1054
+ const nullBodyResponses = new Set([
1055
+ 101,
1056
+ 204,
1057
+ 205,
1058
+ 304
1059
+ ]);
1060
+ function createFetch(globalOptions = {}) {
1061
+ const { fetch = globalThis.fetch, Headers = globalThis.Headers, AbortController = globalThis.AbortController } = globalOptions;
1062
+ async function onError(context) {
1063
+ const isAbort = context.error && context.error.name === "AbortError" && !context.options.timeout || false;
1064
+ if (context.options.retry !== false && !isAbort) {
1065
+ let retries;
1066
+ if (typeof context.options.retry === "number") retries = context.options.retry;
1067
+ else retries = isPayloadMethod(context.options.method) ? 0 : 1;
1068
+ const responseCode = context.response && context.response.status || 500;
1069
+ if (retries > 0 && (Array.isArray(context.options.retryStatusCodes) ? context.options.retryStatusCodes.includes(responseCode) : retryStatusCodes.has(responseCode))) {
1070
+ const retryDelay = typeof context.options.retryDelay === "function" ? context.options.retryDelay(context) : context.options.retryDelay || 0;
1071
+ if (retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
1072
+ return $fetchRaw(context.request, {
1073
+ ...context.options,
1074
+ retry: retries - 1
1075
+ });
1076
+ }
1077
+ }
1078
+ const error = createFetchError(context);
1079
+ if (Error.captureStackTrace) Error.captureStackTrace(error, $fetchRaw);
1080
+ throw error;
1081
+ }
1082
+ const $fetchRaw = async function $fetchRaw2(_request, _options = {}) {
1083
+ const context = {
1084
+ request: _request,
1085
+ options: resolveFetchOptions(_request, _options, globalOptions.defaults, Headers),
1086
+ response: void 0,
1087
+ error: void 0
1088
+ };
1089
+ if (context.options.method) context.options.method = context.options.method.toUpperCase();
1090
+ if (context.options.onRequest) {
1091
+ await callHooks(context, context.options.onRequest);
1092
+ if (!(context.options.headers instanceof Headers)) context.options.headers = new Headers(context.options.headers || {});
1093
+ }
1094
+ if (typeof context.request === "string") {
1095
+ if (context.options.baseURL) context.request = withBase(context.request, context.options.baseURL);
1096
+ if (context.options.query) {
1097
+ context.request = withQuery(context.request, context.options.query);
1098
+ delete context.options.query;
1099
+ }
1100
+ if ("query" in context.options) delete context.options.query;
1101
+ if ("params" in context.options) delete context.options.params;
1102
+ }
1103
+ if (context.options.body && isPayloadMethod(context.options.method)) {
1104
+ if (isJSONSerializable(context.options.body)) {
1105
+ const contentType = context.options.headers.get("content-type");
1106
+ 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);
1107
+ if (!contentType) context.options.headers.set("content-type", "application/json");
1108
+ if (!context.options.headers.has("accept")) context.options.headers.set("accept", "application/json");
1109
+ } else if ("pipeTo" in context.options.body && typeof context.options.body.pipeTo === "function" || typeof context.options.body.pipe === "function") {
1110
+ if (!("duplex" in context.options)) context.options.duplex = "half";
1111
+ }
1112
+ }
1113
+ let abortTimeout;
1114
+ if (!context.options.signal && context.options.timeout) {
1115
+ const controller = new AbortController();
1116
+ abortTimeout = setTimeout(() => {
1117
+ const error = new Error("[TimeoutError]: The operation was aborted due to timeout");
1118
+ error.name = "TimeoutError";
1119
+ error.code = 23;
1120
+ controller.abort(error);
1121
+ }, context.options.timeout);
1122
+ context.options.signal = controller.signal;
1123
+ }
1124
+ try {
1125
+ context.response = await fetch(context.request, context.options);
1126
+ } catch (error) {
1127
+ context.error = error;
1128
+ if (context.options.onRequestError) await callHooks(context, context.options.onRequestError);
1129
+ return await onError(context);
1130
+ } finally {
1131
+ if (abortTimeout) clearTimeout(abortTimeout);
1132
+ }
1133
+ if ((context.response.body || context.response._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD") {
1134
+ const responseType = (context.options.parseResponse ? "json" : context.options.responseType) || detectResponseType(context.response.headers.get("content-type") || "");
1135
+ switch (responseType) {
1136
+ case "json": {
1137
+ const data = await context.response.text();
1138
+ const parseFunction = context.options.parseResponse || destr;
1139
+ context.response._data = parseFunction(data);
1140
+ break;
1141
+ }
1142
+ case "stream":
1143
+ context.response._data = context.response.body || context.response._bodyInit;
1144
+ break;
1145
+ default: context.response._data = await context.response[responseType]();
1146
+ }
1147
+ }
1148
+ if (context.options.onResponse) await callHooks(context, context.options.onResponse);
1149
+ if (!context.options.ignoreResponseError && context.response.status >= 400 && context.response.status < 600) {
1150
+ if (context.options.onResponseError) await callHooks(context, context.options.onResponseError);
1151
+ return await onError(context);
1152
+ }
1153
+ return context.response;
1154
+ };
1155
+ const $fetch = async function $fetch2(request, options) {
1156
+ return (await $fetchRaw(request, options))._data;
1157
+ };
1158
+ $fetch.raw = $fetchRaw;
1159
+ $fetch.native = (...args) => fetch(...args);
1160
+ $fetch.create = (defaultOptions = {}, customGlobalOptions = {}) => createFetch({
1161
+ ...globalOptions,
1162
+ ...customGlobalOptions,
1163
+ defaults: {
1164
+ ...globalOptions.defaults,
1165
+ ...customGlobalOptions.defaults,
1166
+ ...defaultOptions
1167
+ }
1168
+ });
1169
+ return $fetch;
1028
1170
  }
1029
1171
  //#endregion
1030
1172
  //#region src/http.ts
@@ -1173,6 +1315,11 @@ function createServerAuth(options) {
1173
1315
  getOrganization(organizationId) {
1174
1316
  return organizationRead(normalizeIdInput(organizationId), void 0, normalizeOrganization);
1175
1317
  },
1318
+ async getOrganizationMemberAuthority(organizationId, memberId) {
1319
+ const organization = normalizeIdInput(organizationId);
1320
+ const member = normalizeIdInput(memberId);
1321
+ return organizationRead(`${organization}/members/${member}/authority`, void 0, (value) => normalizeOrganizationMemberAuthority(value, organization, member));
1322
+ },
1176
1323
  async createOrganizationTeam(organizationId, name, idempotencyKey) {
1177
1324
  const id = normalizeIdInput(organizationId);
1178
1325
  const body = normalizeOrganizationTeamCreationInput(name, idempotencyKey);
@@ -1388,4 +1535,4 @@ function authAuthorizationHeader(value) {
1388
1535
  return value;
1389
1536
  }
1390
1537
  //#endregion
1391
- export { AuthError, createServerAuth };
1538
+ export { AuthError, createDriveProvisioningAuth, createServerAuth };
@@ -251,6 +251,11 @@ interface OrganizationManualRoleChangeResult {
251
251
  role: OrganizationManualRole;
252
252
  authorityRevision: number;
253
253
  }
254
+ interface OrganizationMemberAuthority {
255
+ organizationId: string;
256
+ actor: Omit<OrganizationManualRoleChangeResult, "status">;
257
+ target: Omit<OrganizationManualRoleChangeResult, "status">;
258
+ }
254
259
  interface OrganizationOwnershipTransferInput {
255
260
  outgoingOwnerMembershipId: string;
256
261
  successorMembershipId: string;
@@ -287,6 +292,7 @@ interface FinuevaAuthClient {
287
292
  getSession(): Promise<AuthSession | null>;
288
293
  listOrganizations(input?: OrganizationPageInput): Promise<OrganizationPage>;
289
294
  getOrganization(organizationId: string): Promise<AuthOrganization>;
295
+ getOrganizationMemberAuthority(organizationId: string, memberId: string): Promise<OrganizationMemberAuthority>;
290
296
  createOrganizationTeam(organizationId: string, name: string, idempotencyKey: string): Promise<CreatedOrganizationTeam>;
291
297
  createOrganizationMemberInvitation(organizationId: string, input: CreateOrganizationMemberInvitationInput): Promise<CreatedOrganizationMemberInvitation>;
292
298
  resendOrganizationInvitation(organizationId: string, invitationId: string, idempotencyKey: string): Promise<ResentOrganizationInvitation>;
@@ -316,4 +322,4 @@ interface FinuevaAuthClient {
316
322
  onSessionChange(listener: (session: AuthSession | null) => void): () => void;
317
323
  }
318
324
  //#endregion
319
- export { PlatformBootstrapRoleChangeInput as A, ResentOrganizationInvitation as B, OrganizationPageInput as C, OrganizationTeamPage as D, OrganizationTeamMemberPage as E, PlatformRoleFirstApproval as F, UpdateOrganizationDisplayInput as G, SignInInput as H, PlatformStatus as I, WorkspaceSelection as J, UpdateOrganizationTeamDisplayInput as K, ReceivedOrganizationInvitation as L, PlatformRoleApplied as M, PlatformRoleApproval as N, OrganizationWorkspaceSelection as O, PlatformRoleChangeRecentAuthenticationInput as P, ReceivedOrganizationInvitationPage as R, OrganizationPage as S, OrganizationTeamDisplay as T, SocialIdTokenInput as U, SendVerificationEmailInput as V, SocialIdTokenProvider as W, AuthErrorCode as X, AuthError as Y, AuthErrorStatus as Z, OrganizationDisplay as _, AuthPersistenceDriver as a, OrganizationMember as b, AuthUser as c, CreatedOrganizationMemberInvitation as d, CreatedOrganizationTeam as f, InvitationAcceptance as g, FinuevaAuthClient as h, AuthPersistence as i, PlatformRole as j, PersonalWorkspaceSelection as k, CanceledOrganizationInvitation as l, DriveCredentialInput as m, AuthClientOptions as n, AuthSession as o, DriveCredential as p, UpdateProfileInput as q, AuthOrganization as r, AuthState as s, AcceptInvitationInput as t, CreateOrganizationMemberInvitationInput as u, OrganizationInvitation as v, OrganizationTeam as w, OrganizationMemberPage as x, OrganizationInvitationPage as y, RecentAuthenticationStatus as z };
325
+ export { PersonalWorkspaceSelection as A, RecentAuthenticationStatus as B, OrganizationPage as C, OrganizationTeamMemberPage as D, OrganizationTeamDisplay as E, PlatformRoleChangeRecentAuthenticationInput as F, SocialIdTokenProvider as G, SendVerificationEmailInput as H, PlatformRoleFirstApproval as I, UpdateProfileInput as J, UpdateOrganizationDisplayInput as K, PlatformStatus as L, PlatformRole as M, PlatformRoleApplied as N, OrganizationTeamPage as O, PlatformRoleApproval as P, AuthErrorStatus as Q, ReceivedOrganizationInvitation as R, OrganizationMemberPage as S, OrganizationTeam as T, SignInInput as U, ResentOrganizationInvitation as V, SocialIdTokenInput as W, AuthError as X, WorkspaceSelection as Y, AuthErrorCode as Z, OrganizationDisplay as _, AuthPersistenceDriver as a, OrganizationMember as b, AuthUser as c, CreatedOrganizationMemberInvitation as d, CreatedOrganizationTeam as f, InvitationAcceptance as g, FinuevaAuthClient as h, AuthPersistence as i, PlatformBootstrapRoleChangeInput as j, OrganizationWorkspaceSelection as k, CanceledOrganizationInvitation as l, DriveCredentialInput as m, AuthClientOptions as n, AuthSession as o, DriveCredential as p, UpdateOrganizationTeamDisplayInput as q, AuthOrganization as r, AuthState as s, AcceptInvitationInput as t, CreateOrganizationMemberInvitationInput as u, OrganizationInvitation as v, OrganizationPageInput as w, OrganizationMemberAuthority as x, OrganizationInvitationPage as y, ReceivedOrganizationInvitationPage as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finueva/auth",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Public browser and server SDK for Finueva Auth",
5
5
  "type": "module",
6
6
  "sideEffects": false,