@finueva/auth 0.18.1 → 0.20.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/server.d.ts CHANGED
@@ -1,4 +1,19 @@
1
- import { $ as AuthError, A as OrganizationTeamPage, B as ReceivedOrganizationInvitation, C as OrganizationMemberAuthority, D as OrganizationTeam, E as OrganizationPageInput, J as SocialIdTokenProvider, M as PersonalWorkspaceSelection, O as OrganizationTeamDisplay, Q as WorkspaceSelection, S as OrganizationMember, T as OrganizationPage, U as RemovedOrganizationMember, V as ReceivedOrganizationInvitationPage, W as ResentOrganizationInvitation, X as UpdateOrganizationTeamDisplayInput, Y as UpdateOrganizationDisplayInput, _ as InvitationAcceptance, b as OrganizationInvitation, c as AuthUser, d as CreatedOrganization, et as AuthErrorCode, f as CreatedOrganizationMemberInvitation, h as DriveCredentialInput, j as OrganizationWorkspaceSelection, k as OrganizationTeamMemberPage, l as CanceledOrganizationInvitation, m as DriveCredential, nt as UserApiCredential, o as AuthSession, p as CreatedOrganizationTeam, q as SocialIdTokenInput, r as AuthOrganization, rt as UserApiCredentialInput, t as AcceptInvitationInput, tt as AuthErrorStatus, u as CreateOrganizationMemberInvitationInput, v as OrganizationDeparture, w as OrganizationMemberPage, x as OrganizationInvitationPage, y as OrganizationDisplay } from "./types-CrdIcEJ3.js";
1
+ import { At as AuthError, B as OrganizationMember, C as DeclineInvitationInput, D as DriveCredential, Dt as UpdateOrganizationTeamDisplayInput, Et as UpdateOrganizationDisplayInput, G as OrganizationTeam, H as OrganizationMemberPage, I as OrganizationDeparture, J as OrganizationTeamPage, K as OrganizationTeamDisplay, L as OrganizationDisplay, M as InvitationDecline, Mt as AuthErrorStatus, Nt as UserApiCredential, O as DriveCredentialInput, Pt as UserApiCredentialInput, Q as PersonalWorkspaceSelection, R as OrganizationInvitation, S as CreatedOrganizationTeam, U as OrganizationPage, V as OrganizationMemberAuthority, W as OrganizationPageInput, Y as OrganizationWorkspaceSelection, b as CreatedOrganization, d as AuthUser, dt as ResentOrganizationInvitation, f as CanceledOrganizationInvitation, i as AuthOrganization, j as InvitationAcceptance, jt as AuthErrorCode, kt as WorkspaceSelection, lt as RemovedOrganizationMember, n as AddedOrganizationTeamMember, ot as ReceivedOrganizationInvitation, q as OrganizationTeamMemberPage, s as AuthSession, st as ReceivedOrganizationInvitationPage, t as AcceptInvitationInput, ut as RemovedOrganizationTeamMember, vt as SocialIdTokenInput, w as DeletedOrganizationTeam, x as CreatedOrganizationMemberInvitation, y as CreateOrganizationMemberInvitationInput, yt as SocialIdTokenProvider, z as OrganizationInvitationPage } from "./types-Cv_qxcBP.js";
2
+ //#region src/google-recovery.d.ts
3
+ interface GoogleAccountRecoveryInput {
4
+ idToken: {
5
+ token: string;
6
+ nonce?: string;
7
+ };
8
+ }
9
+ interface CompleteGoogleAccountRecoveryInput extends GoogleAccountRecoveryInput {
10
+ recoveryToken: string;
11
+ }
12
+ interface GoogleAccountRecovery {
13
+ recoveryToken: string;
14
+ expiresAt: string;
15
+ }
16
+ //#endregion
2
17
  //#region src/user-api/verifier.d.ts
3
18
  interface UserApiIdentity {
4
19
  userId: string;
@@ -125,6 +140,7 @@ interface ServerSocialIdTokenSession extends AuthSession {
125
140
  }
126
141
  interface FinuevaServerAuth {
127
142
  acceptInvitation(input: AcceptInvitationInput): Promise<ServerInvitationAcceptance>;
143
+ declineInvitation(input: DeclineInvitationInput): Promise<InvitationDecline>;
128
144
  getSession(): Promise<AuthSession | null>;
129
145
  listOrganizations(input?: OrganizationPageInput): Promise<OrganizationPage>;
130
146
  getOrganization(organizationId: string): Promise<AuthOrganization>;
@@ -136,6 +152,9 @@ interface FinuevaServerAuth {
136
152
  cancelOrganizationInvitation(organizationId: string, invitationId: string, idempotencyKey: string): Promise<CanceledOrganizationInvitation>;
137
153
  removeOrganizationMember(organizationId: string, memberId: string, idempotencyKey: string): Promise<RemovedOrganizationMember>;
138
154
  leaveOrganization(organizationId: string, idempotencyKey: string): Promise<OrganizationDeparture>;
155
+ addOrganizationTeamMember(organizationId: string, teamId: string, memberId: string, idempotencyKey: string): Promise<AddedOrganizationTeamMember>;
156
+ removeOrganizationTeamMember(organizationId: string, teamId: string, memberId: string, idempotencyKey: string): Promise<RemovedOrganizationTeamMember>;
157
+ deleteOrganizationTeam(organizationId: string, teamId: string, idempotencyKey: string): Promise<DeletedOrganizationTeam>;
139
158
  updateOrganizationDisplay(organizationId: string, input: UpdateOrganizationDisplayInput): Promise<OrganizationDisplay>;
140
159
  updateOrganizationTeamDisplay(organizationId: string, teamId: string, input: UpdateOrganizationTeamDisplayInput): Promise<OrganizationTeamDisplay>;
141
160
  listOrganizationMembers(organizationId: string, input?: OrganizationPageInput): Promise<OrganizationMemberPage>;
@@ -146,10 +165,14 @@ interface FinuevaServerAuth {
146
165
  listReceivedInvitations(input?: OrganizationPageInput): Promise<ReceivedOrganizationInvitationPage>;
147
166
  getReceivedInvitation(invitationId: string): Promise<ReceivedOrganizationInvitation>;
148
167
  signInWithSocialIdToken(input: SocialIdTokenInput): Promise<ServerSocialIdTokenSession>;
168
+ startGoogleAccountRecovery(input: GoogleAccountRecoveryInput): Promise<GoogleAccountRecovery>;
169
+ completeGoogleAccountRecovery(input: CompleteGoogleAccountRecoveryInput): Promise<{
170
+ linked: true;
171
+ }>;
149
172
  getDriveCredential(input: DriveCredentialInput): Promise<DriveCredential>;
150
173
  getUserApiCredential(input: UserApiCredentialInput): Promise<UserApiCredential>;
151
174
  signOut(): Promise<ServerSignOutResult>;
152
175
  }
153
176
  declare function createServerAuth(options: ServerAuthOptions): FinuevaServerAuth;
154
177
  //#endregion
155
- export { type AcceptInvitationInput, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CanceledOrganizationInvitation, type CreateOrganizationMemberInvitationInput, type CreatedOrganization, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type DriveProvisioningAuthOptions, type DriveProvisioningCredential, type DriveRecipient, type DriveRecipientAuthOptions, type FinuevaDriveProvisioningAuth, type FinuevaDriveRecipientAuth, type FinuevaIdentityResolverAuth, type FinuevaMembershipResolverAuth, FinuevaServerAuth, type IdentityResolverAuthOptions, type InvitationAcceptance, type MembershipResolverAuthOptions, type OrganizationDeparture, 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 RemovedOrganizationMember, type ResentOrganizationInvitation, type ResolveDriveRecipientInput, type ResolveIdentityInput, type ResolveMembershipInput, type ResolvedIdentity, type ResolvedMembership, type ResolvedMembershipRole, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type UserApiCredential, type UserApiCredentialInput, type UserApiIdentity, type UserApiVerifierOptions, type WorkspaceSelection, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createServerAuth, createUserApiVerifier };
178
+ export { type AcceptInvitationInput, type AddedOrganizationTeamMember, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CanceledOrganizationInvitation, type CompleteGoogleAccountRecoveryInput, type CreateOrganizationMemberInvitationInput, type CreatedOrganization, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type DeclineInvitationInput, type DeletedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type DriveProvisioningAuthOptions, type DriveProvisioningCredential, type DriveRecipient, type DriveRecipientAuthOptions, type FinuevaDriveProvisioningAuth, type FinuevaDriveRecipientAuth, type FinuevaIdentityResolverAuth, type FinuevaMembershipResolverAuth, FinuevaServerAuth, type GoogleAccountRecovery, type GoogleAccountRecoveryInput, type IdentityResolverAuthOptions, type InvitationAcceptance, type InvitationDecline, type MembershipResolverAuthOptions, type OrganizationDeparture, 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 RemovedOrganizationMember, type RemovedOrganizationTeamMember, type ResentOrganizationInvitation, type ResolveDriveRecipientInput, type ResolveIdentityInput, type ResolveMembershipInput, type ResolvedIdentity, type ResolvedMembership, type ResolvedMembershipRole, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type UserApiCredential, type UserApiCredentialInput, type UserApiIdentity, type UserApiVerifierOptions, type WorkspaceSelection, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createServerAuth, createUserApiVerifier };
package/dist/server.js CHANGED
@@ -1,183 +1,13 @@
1
- String.fromCharCode;
2
- const HASH_RE = /#/g;
3
- const AMPERSAND_RE = /&/g;
4
- const SLASH_RE = /\//g;
5
- const EQUAL_RE = /=/g;
6
- const PLUS_RE = /\+/g;
7
- const ENC_CARET_RE = /%5e/gi;
8
- const ENC_BACKTICK_RE = /%60/gi;
9
- const ENC_PIPE_RE = /%7c/gi;
10
- const ENC_SPACE_RE = /%20/gi;
11
- function encode$2(text) {
12
- return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
13
- }
14
- function encodeQueryValue(input) {
15
- return encode$2(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
16
- }
17
- function encodeQueryKey(text) {
18
- return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
19
- }
20
- function decode$1(text = "") {
21
- try {
22
- return decodeURIComponent("" + text);
23
- } catch {
24
- return "" + text;
25
- }
26
- }
27
- function decodeQueryKey(text) {
28
- return decode$1(text.replace(PLUS_RE, " "));
29
- }
30
- function decodeQueryValue(text) {
31
- return decode$1(text.replace(PLUS_RE, " "));
32
- }
33
- function parseQuery(parametersString = "") {
34
- const object = Object.create(null);
35
- if (parametersString[0] === "?") parametersString = parametersString.slice(1);
36
- for (const parameter of parametersString.split("&")) {
37
- const s = parameter.match(/([^=]+)=?(.*)/) || [];
38
- if (s.length < 2) continue;
39
- const key = decodeQueryKey(s[1]);
40
- if (key === "__proto__" || key === "constructor") continue;
41
- const value = decodeQueryValue(s[2] || "");
42
- if (object[key] === void 0) object[key] = value;
43
- else if (Array.isArray(object[key])) object[key].push(value);
44
- else object[key] = [object[key], value];
45
- }
46
- return object;
47
- }
48
- function encodeQueryItem(key, value) {
49
- if (typeof value === "number" || typeof value === "boolean") value = String(value);
50
- if (!value) return encodeQueryKey(key);
51
- if (Array.isArray(value)) return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
52
- return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
53
- }
54
- function stringifyQuery(query) {
55
- return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
56
- }
57
- const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
58
- const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
59
- const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
60
- const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
61
- const JOIN_LEADING_SLASH_RE = /^\.?\//;
62
- function hasProtocol(inputString, opts = {}) {
63
- if (typeof opts === "boolean") opts = { acceptRelative: opts };
64
- if (opts.strict) return PROTOCOL_STRICT_REGEX.test(inputString);
65
- return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
66
- }
67
- function hasTrailingSlash(input = "", respectQueryAndFragment) {
68
- if (!respectQueryAndFragment) return input.endsWith("/");
69
- return TRAILING_SLASH_RE.test(input);
70
- }
71
- function withoutTrailingSlash(input = "", respectQueryAndFragment) {
72
- if (!respectQueryAndFragment) return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
73
- if (!hasTrailingSlash(input, true)) return input || "/";
74
- let path = input;
75
- let fragment = "";
76
- const fragmentIndex = input.indexOf("#");
77
- if (fragmentIndex !== -1) {
78
- path = input.slice(0, fragmentIndex);
79
- fragment = input.slice(fragmentIndex);
80
- }
81
- const [s0, ...s] = path.split("?");
82
- return ((s0.endsWith("/") ? s0.slice(0, -1) : s0) || "/") + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
83
- }
84
- function withTrailingSlash(input = "", respectQueryAndFragment) {
85
- if (!respectQueryAndFragment) return input.endsWith("/") ? input : input + "/";
86
- if (hasTrailingSlash(input, true)) return input || "/";
87
- let path = input;
88
- let fragment = "";
89
- const fragmentIndex = input.indexOf("#");
90
- if (fragmentIndex !== -1) {
91
- path = input.slice(0, fragmentIndex);
92
- fragment = input.slice(fragmentIndex);
93
- if (!path) return fragment;
94
- }
95
- const [s0, ...s] = path.split("?");
96
- return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
97
- }
98
- function withBase(input, base) {
99
- if (isEmptyURL(base) || hasProtocol(input)) return input;
100
- const _base = withoutTrailingSlash(base);
101
- if (input.startsWith(_base)) {
102
- const nextChar = input[_base.length];
103
- if (!nextChar || nextChar === "/" || nextChar === "?") return input;
104
- }
105
- return joinURL(_base, input);
106
- }
107
- function withQuery(input, query) {
108
- const parsed = parseURL(input);
109
- parsed.search = stringifyQuery({
110
- ...parseQuery(parsed.search),
111
- ...query
112
- });
113
- return stringifyParsedURL(parsed);
114
- }
115
- function isEmptyURL(url) {
116
- return !url || url === "/";
117
- }
118
- function isNonEmptyURL(url) {
119
- return url && url !== "/";
120
- }
121
- function joinURL(base, ...input) {
122
- let url = base || "";
123
- for (const segment of input.filter((url2) => isNonEmptyURL(url2))) if (url) {
124
- const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
125
- url = withTrailingSlash(url) + _segment;
126
- } else url = segment;
127
- return url;
128
- }
129
- const protocolRelative = Symbol.for("ufo:protocolRelative");
130
- function parseURL(input = "", defaultProto) {
131
- const _specialProtoMatch = input.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);
132
- if (_specialProtoMatch) {
133
- const [, _proto, _pathname = ""] = _specialProtoMatch;
134
- return {
135
- protocol: _proto.toLowerCase(),
136
- pathname: _pathname,
137
- href: _proto + _pathname,
138
- auth: "",
139
- host: "",
140
- search: "",
141
- hash: ""
142
- };
143
- }
144
- if (!hasProtocol(input, { acceptRelative: true })) return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
145
- const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
146
- let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
147
- if (protocol === "file:") path = path.replace(/\/(?=[A-Za-z]:)/, "");
148
- const { pathname, search, hash } = parsePath(path);
149
- return {
150
- protocol: protocol.toLowerCase(),
151
- auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
152
- host,
153
- pathname,
154
- search,
155
- hash,
156
- [protocolRelative]: !protocol
157
- };
158
- }
159
- function parsePath(input = "") {
160
- const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
161
- return {
162
- pathname,
163
- search,
164
- hash
165
- };
166
- }
167
- function stringifyParsedURL(parsed) {
168
- const pathname = parsed.pathname || "";
169
- const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
170
- const hash = parsed.hash || "";
171
- const auth = parsed.auth ? parsed.auth + "@" : "";
172
- const host = parsed.host || "";
173
- return (parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "") + auth + host + pathname + search + hash;
174
- }
175
- //#endregion
176
1
  //#region src/errors.ts
177
2
  const messages = {
178
3
  invalid_credentials: "The credentials are invalid.",
179
4
  invalid_auth_input: "The authentication input is invalid.",
180
5
  account_conflict: "The account is not available.",
6
+ google_recovery_in_progress: "A Google connection is already being completed. Return to that sign-in, or wait up to ten minutes and restart.",
7
+ google_recovery_not_required: "Google account recovery is not required.",
8
+ google_recovery_invalid: "The Google account recovery request is invalid.",
9
+ google_recovery_expired: "Google account recovery has expired. Start Google sign-in again.",
10
+ google_recovery_account_mismatch: "Sign in to the existing account associated with this Google identity.",
181
11
  password_reset_invalid: "The password reset request is invalid.",
182
12
  authentication_required: "Authentication is required.",
183
13
  request_origin_denied: "The request origin is not allowed.",
@@ -198,7 +28,18 @@ const messages = {
198
28
  platform_target_unavailable: "The platform administration target is unavailable.",
199
29
  platform_quorum_unavailable: "Platform administration quorum is unavailable.",
200
30
  platform_recovery_required: "Platform administration requires separate recovery.",
201
- identity_authority_unavailable: "Authentication is temporarily unavailable."
31
+ identity_authority_unavailable: "Authentication is temporarily unavailable.",
32
+ two_factor_required: "A second authentication factor is required.",
33
+ two_factor_code_invalid: "The verification code is invalid.",
34
+ two_factor_challenge_expired: "The second-factor challenge has ended. Sign in again.",
35
+ two_factor_locked: "Second-factor verification is temporarily locked.",
36
+ recent_sign_in_required: "A recent sign-in is required.",
37
+ enterprise_recovery_required: "Enterprise administration evidence requires operator recovery.",
38
+ recent_authentication_required: "A ready recent-authentication action is required.",
39
+ organization_closure_confirmation_mismatch: "The confirmation does not match the organization.",
40
+ organization_closure_cancellation_ended: "The closure cancellation period has ended.",
41
+ ceremony_return_refused: "The return address is not registered for this application.",
42
+ password_sign_in_required: "A password sign-in method is required for this passkey change."
202
43
  };
203
44
  var AuthError = class extends Error {
204
45
  code;
@@ -462,6 +303,25 @@ function normalizeOrganizationDeparture(value) {
462
303
  if (value.status !== "left") throw authorityUnavailable();
463
304
  return { status: "left" };
464
305
  }
306
+ function normalizeOrganizationTeamMembershipInput(idempotencyKey) {
307
+ if (!boundedString(idempotencyKey, 255)) throw new AuthError("invalid_request", 400);
308
+ return { idempotencyKey };
309
+ }
310
+ function normalizeAddedOrganizationTeamMember(value) {
311
+ exact$3(value, ["status"]);
312
+ if (value.status !== "added") throw authorityUnavailable();
313
+ return { status: "added" };
314
+ }
315
+ function normalizeRemovedOrganizationTeamMember(value) {
316
+ exact$3(value, ["status"]);
317
+ if (value.status !== "removed") throw authorityUnavailable();
318
+ return { status: "removed" };
319
+ }
320
+ function normalizeDeletedOrganizationTeam(value) {
321
+ exact$3(value, ["status"]);
322
+ if (value.status !== "deleted") throw authorityUnavailable();
323
+ return { status: "deleted" };
324
+ }
465
325
  function normalizeOrganizations(value) {
466
326
  exact$3(value, ["nextCursor", "organizations"]);
467
327
  if (!Array.isArray(value.organizations) || value.organizations.length > 100) throw authorityUnavailable();
@@ -623,6 +483,10 @@ function normalizeInvitationAcceptance(value, invitationId) {
623
483
  if (!isObject$1(value) || !isObject$1(value.invitation) || !isObject$1(value.member) || value.invitation.id !== invitationId || value.invitation.status !== "accepted" || !isId(value.invitation.organizationId) || value.member.organizationId !== value.invitation.organizationId) throw authorityUnavailable();
624
484
  return { organizationId: value.invitation.organizationId };
625
485
  }
486
+ function normalizeInvitationDecline(value, invitationId) {
487
+ if (!isObject$1(value) || !isObject$1(value.invitation) || value.invitation.id !== invitationId || value.invitation.status !== "rejected" || value.member !== null) throw authorityUnavailable();
488
+ return { status: "declined" };
489
+ }
626
490
  function normalizeWorkspaceSelection(value) {
627
491
  if (!isObject$1(value)) throw new AuthError("invalid_workspace_selection", 422);
628
492
  const keys = Object.keys(value);
@@ -843,6 +707,229 @@ function isObject$1(value) {
843
707
  return typeof value === "object" && value !== null && !Array.isArray(value);
844
708
  }
845
709
  //#endregion
710
+ //#region src/google-recovery.ts
711
+ function object(value) {
712
+ return value !== null && typeof value === "object" && !Array.isArray(value);
713
+ }
714
+ function validTicket(value) {
715
+ return typeof value === "string" && /^[A-Za-z0-9_-]{43}$/.test(value);
716
+ }
717
+ function googleRecoveryInput(value, complete) {
718
+ if (!object(value) || Object.keys(value).sort().join(",") !== (complete ? "idToken,recoveryToken" : "idToken") || !object(value.idToken) || Object.keys(value.idToken).some((key) => key !== "token" && key !== "nonce") || complete && !validTicket(value.recoveryToken)) throw new AuthError("invalid_request", 400);
719
+ const social = normalizeSocialIdTokenInput({
720
+ provider: "google",
721
+ idToken: value.idToken.token,
722
+ signUp: false,
723
+ ...value.idToken.nonce === void 0 ? {} : { nonce: value.idToken.nonce }
724
+ });
725
+ return {
726
+ idToken: {
727
+ token: social.idToken,
728
+ ...social.nonce === void 0 ? {} : { nonce: social.nonce }
729
+ },
730
+ ...complete ? { recoveryToken: value.recoveryToken } : {}
731
+ };
732
+ }
733
+ function normalizeGoogleRecovery(value, now) {
734
+ if (!object(value) || Object.keys(value).sort().join(",") !== "expiresAt,recoveryToken" || !validTicket(value.recoveryToken) || typeof value.expiresAt !== "string") throw authorityUnavailable();
735
+ const expiresAt = Date.parse(value.expiresAt);
736
+ if (!Number.isFinite(expiresAt) || expiresAt <= now || expiresAt > now + 10 * 6e4) throw authorityUnavailable();
737
+ return {
738
+ recoveryToken: value.recoveryToken,
739
+ expiresAt: value.expiresAt
740
+ };
741
+ }
742
+ function normalizeGoogleRecoveryCompletion(value) {
743
+ if (!object(value) || Object.keys(value).join(",") !== "linked" || value.linked !== true) throw authorityUnavailable();
744
+ return { linked: true };
745
+ }
746
+ function fromGoogleRecoveryError(value, status, retryAfter) {
747
+ const code = object(value) ? value.code : void 0;
748
+ if (status === 409 && code === "GOOGLE_RECOVERY_IN_PROGRESS") return new AuthError("google_recovery_in_progress", 409);
749
+ if (status === 409 && code === "GOOGLE_RECOVERY_NOT_REQUIRED") return new AuthError("google_recovery_not_required", 409);
750
+ if (status === 403 && code === "GOOGLE_RECOVERY_EMAIL_VERIFICATION_REQUIRED") return new AuthError("email_verification_required", 403);
751
+ if (status === 400 && code === "GOOGLE_RECOVERY_INVALID") return new AuthError("google_recovery_invalid", 400);
752
+ if (status === 410 && code === "GOOGLE_RECOVERY_EXPIRED") return new AuthError("google_recovery_expired", 410);
753
+ if (status === 403 && code === "GOOGLE_RECOVERY_ACCOUNT_MISMATCH") return new AuthError("google_recovery_account_mismatch", 403);
754
+ if (status === 401 && code === "GOOGLE_RECOVERY_FRESH_SIGN_IN_REQUIRED") return new AuthError("recent_sign_in_required", 401);
755
+ if (code === "GOOGLE_RECOVERY_UNAVAILABLE") return authorityUnavailable();
756
+ return fromAccountAuthorityError(value, status, retryAfter);
757
+ }
758
+ String.fromCharCode;
759
+ const HASH_RE = /#/g;
760
+ const AMPERSAND_RE = /&/g;
761
+ const SLASH_RE = /\//g;
762
+ const EQUAL_RE = /=/g;
763
+ const PLUS_RE = /\+/g;
764
+ const ENC_CARET_RE = /%5e/gi;
765
+ const ENC_BACKTICK_RE = /%60/gi;
766
+ const ENC_PIPE_RE = /%7c/gi;
767
+ const ENC_SPACE_RE = /%20/gi;
768
+ function encode$2(text) {
769
+ return encodeURI("" + text).replace(ENC_PIPE_RE, "|");
770
+ }
771
+ function encodeQueryValue(input) {
772
+ return encode$2(typeof input === "string" ? input : JSON.stringify(input)).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CARET_RE, "^").replace(SLASH_RE, "%2F");
773
+ }
774
+ function encodeQueryKey(text) {
775
+ return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
776
+ }
777
+ function decode$1(text = "") {
778
+ try {
779
+ return decodeURIComponent("" + text);
780
+ } catch {
781
+ return "" + text;
782
+ }
783
+ }
784
+ function decodeQueryKey(text) {
785
+ return decode$1(text.replace(PLUS_RE, " "));
786
+ }
787
+ function decodeQueryValue(text) {
788
+ return decode$1(text.replace(PLUS_RE, " "));
789
+ }
790
+ function parseQuery(parametersString = "") {
791
+ const object = Object.create(null);
792
+ if (parametersString[0] === "?") parametersString = parametersString.slice(1);
793
+ for (const parameter of parametersString.split("&")) {
794
+ const s = parameter.match(/([^=]+)=?(.*)/) || [];
795
+ if (s.length < 2) continue;
796
+ const key = decodeQueryKey(s[1]);
797
+ if (key === "__proto__" || key === "constructor") continue;
798
+ const value = decodeQueryValue(s[2] || "");
799
+ if (object[key] === void 0) object[key] = value;
800
+ else if (Array.isArray(object[key])) object[key].push(value);
801
+ else object[key] = [object[key], value];
802
+ }
803
+ return object;
804
+ }
805
+ function encodeQueryItem(key, value) {
806
+ if (typeof value === "number" || typeof value === "boolean") value = String(value);
807
+ if (!value) return encodeQueryKey(key);
808
+ if (Array.isArray(value)) return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
809
+ return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
810
+ }
811
+ function stringifyQuery(query) {
812
+ return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).filter(Boolean).join("&");
813
+ }
814
+ const PROTOCOL_STRICT_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
815
+ const PROTOCOL_REGEX = /^[\s\w\0+.-]{2,}:([/\\]{2})?/;
816
+ const PROTOCOL_RELATIVE_REGEX = /^([/\\]\s*){2,}[^/\\]/;
817
+ const TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
818
+ const JOIN_LEADING_SLASH_RE = /^\.?\//;
819
+ function hasProtocol(inputString, opts = {}) {
820
+ if (typeof opts === "boolean") opts = { acceptRelative: opts };
821
+ if (opts.strict) return PROTOCOL_STRICT_REGEX.test(inputString);
822
+ return PROTOCOL_REGEX.test(inputString) || (opts.acceptRelative ? PROTOCOL_RELATIVE_REGEX.test(inputString) : false);
823
+ }
824
+ function hasTrailingSlash(input = "", respectQueryAndFragment) {
825
+ if (!respectQueryAndFragment) return input.endsWith("/");
826
+ return TRAILING_SLASH_RE.test(input);
827
+ }
828
+ function withoutTrailingSlash(input = "", respectQueryAndFragment) {
829
+ if (!respectQueryAndFragment) return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
830
+ if (!hasTrailingSlash(input, true)) return input || "/";
831
+ let path = input;
832
+ let fragment = "";
833
+ const fragmentIndex = input.indexOf("#");
834
+ if (fragmentIndex !== -1) {
835
+ path = input.slice(0, fragmentIndex);
836
+ fragment = input.slice(fragmentIndex);
837
+ }
838
+ const [s0, ...s] = path.split("?");
839
+ return ((s0.endsWith("/") ? s0.slice(0, -1) : s0) || "/") + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
840
+ }
841
+ function withTrailingSlash(input = "", respectQueryAndFragment) {
842
+ if (!respectQueryAndFragment) return input.endsWith("/") ? input : input + "/";
843
+ if (hasTrailingSlash(input, true)) return input || "/";
844
+ let path = input;
845
+ let fragment = "";
846
+ const fragmentIndex = input.indexOf("#");
847
+ if (fragmentIndex !== -1) {
848
+ path = input.slice(0, fragmentIndex);
849
+ fragment = input.slice(fragmentIndex);
850
+ if (!path) return fragment;
851
+ }
852
+ const [s0, ...s] = path.split("?");
853
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
854
+ }
855
+ function withBase(input, base) {
856
+ if (isEmptyURL(base) || hasProtocol(input)) return input;
857
+ const _base = withoutTrailingSlash(base);
858
+ if (input.startsWith(_base)) {
859
+ const nextChar = input[_base.length];
860
+ if (!nextChar || nextChar === "/" || nextChar === "?") return input;
861
+ }
862
+ return joinURL(_base, input);
863
+ }
864
+ function withQuery(input, query) {
865
+ const parsed = parseURL(input);
866
+ parsed.search = stringifyQuery({
867
+ ...parseQuery(parsed.search),
868
+ ...query
869
+ });
870
+ return stringifyParsedURL(parsed);
871
+ }
872
+ function isEmptyURL(url) {
873
+ return !url || url === "/";
874
+ }
875
+ function isNonEmptyURL(url) {
876
+ return url && url !== "/";
877
+ }
878
+ function joinURL(base, ...input) {
879
+ let url = base || "";
880
+ for (const segment of input.filter((url2) => isNonEmptyURL(url2))) if (url) {
881
+ const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
882
+ url = withTrailingSlash(url) + _segment;
883
+ } else url = segment;
884
+ return url;
885
+ }
886
+ const protocolRelative = Symbol.for("ufo:protocolRelative");
887
+ function parseURL(input = "", defaultProto) {
888
+ const _specialProtoMatch = input.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);
889
+ if (_specialProtoMatch) {
890
+ const [, _proto, _pathname = ""] = _specialProtoMatch;
891
+ return {
892
+ protocol: _proto.toLowerCase(),
893
+ pathname: _pathname,
894
+ href: _proto + _pathname,
895
+ auth: "",
896
+ host: "",
897
+ search: "",
898
+ hash: ""
899
+ };
900
+ }
901
+ if (!hasProtocol(input, { acceptRelative: true })) return defaultProto ? parseURL(defaultProto + input) : parsePath(input);
902
+ const [, protocol = "", auth, hostAndPath = ""] = input.replace(/\\/g, "/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/) || [];
903
+ let [, host = "", path = ""] = hostAndPath.match(/([^#/?]*)(.*)?/) || [];
904
+ if (protocol === "file:") path = path.replace(/\/(?=[A-Za-z]:)/, "");
905
+ const { pathname, search, hash } = parsePath(path);
906
+ return {
907
+ protocol: protocol.toLowerCase(),
908
+ auth: auth ? auth.slice(0, Math.max(0, auth.length - 1)) : "",
909
+ host,
910
+ pathname,
911
+ search,
912
+ hash,
913
+ [protocolRelative]: !protocol
914
+ };
915
+ }
916
+ function parsePath(input = "") {
917
+ const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
918
+ return {
919
+ pathname,
920
+ search,
921
+ hash
922
+ };
923
+ }
924
+ function stringifyParsedURL(parsed) {
925
+ const pathname = parsed.pathname || "";
926
+ const search = parsed.search ? (parsed.search.startsWith("?") ? "" : "?") + parsed.search : "";
927
+ const hash = parsed.hash || "";
928
+ const auth = parsed.auth ? parsed.auth + "@" : "";
929
+ const host = parsed.host || "";
930
+ return (parsed.protocol || parsed[protocolRelative] ? (parsed.protocol || "") + "//" : "") + auth + host + pathname + search + hash;
931
+ }
932
+ //#endregion
846
933
  //#region src/user-api/credential.ts
847
934
  function userApiApplication(input) {
848
935
  if (!input || typeof input.applicationId !== "string" || !/^[A-Za-z0-9_-]{1,128}$(?![\s\S])/.test(input.applicationId) || input.forceRefresh !== void 0 && typeof input.forceRefresh !== "boolean") throw new TypeError("User API credential input is invalid");
@@ -2907,6 +2994,23 @@ function createServerAuth(options) {
2907
2994
  ...authorization ? { authorization } : { cookie },
2908
2995
  ...includeOrigin ? { origin: appOrigin } : {}
2909
2996
  });
2997
+ async function teamMembershipMutation(ids, idempotencyKey, action) {
2998
+ if (authorization) throw new AuthError("authentication_required", 401);
2999
+ const [organization, team, member] = ids.map(normalizeIdInput);
3000
+ const body = normalizeOrganizationTeamMembershipInput(idempotencyKey);
3001
+ return requestJson(action === "delete" ? joinURL(authOrigin, "api/v1/auth/organizations", organization, "teams", team, "delete") : joinURL(authOrigin, "api/v1/auth/organizations", organization, "teams", team, "members", member, action), {
3002
+ fetch: fetchImpl,
3003
+ timeoutMs,
3004
+ method: "POST",
3005
+ credentials,
3006
+ headers: {
3007
+ ...authHeaders(),
3008
+ "content-type": "application/json"
3009
+ },
3010
+ body,
3011
+ mapError: fromOrganizationMutationAuthorityError
3012
+ });
3013
+ }
2910
3014
  async function organizationRead(path, input, normalize) {
2911
3015
  const query = normalizeOrganizationPageInput(input);
2912
3016
  return normalize(await requestJson(`${joinURL(authOrigin, "api/v1/auth/organizations", path)}${query.size ? `?${query}` : ""}`, {
@@ -2947,6 +3051,25 @@ function createServerAuth(options) {
2947
3051
  throw fromInvitationError(error);
2948
3052
  }
2949
3053
  },
3054
+ async declineInvitation(input) {
3055
+ const invitation = normalizeInvitationInput(input);
3056
+ try {
3057
+ return normalizeInvitationDecline(await requestJson(joinURL(authOrigin, "api/v1/auth/organization/reject-invitation"), {
3058
+ fetch: fetchImpl,
3059
+ timeoutMs,
3060
+ method: "POST",
3061
+ credentials,
3062
+ headers: {
3063
+ ...authHeaders(),
3064
+ "content-type": "application/json; charset=utf-8"
3065
+ },
3066
+ body: invitation,
3067
+ mapError: fromInvitationAuthorityError
3068
+ }), invitation.invitationId);
3069
+ } catch (error) {
3070
+ throw fromInvitationError(error);
3071
+ }
3072
+ },
2950
3073
  async getSession() {
2951
3074
  return normalizeSession(await requestJson(joinURL(authOrigin, "api/v1/auth/get-session"), {
2952
3075
  fetch: fetchImpl,
@@ -3089,6 +3212,23 @@ function createServerAuth(options) {
3089
3212
  mapError: fromOrganizationMembershipRemovalError
3090
3213
  }));
3091
3214
  },
3215
+ async addOrganizationTeamMember(organizationId, teamId, memberId, idempotencyKey) {
3216
+ return normalizeAddedOrganizationTeamMember(await teamMembershipMutation([
3217
+ organizationId,
3218
+ teamId,
3219
+ memberId
3220
+ ], idempotencyKey, "add"));
3221
+ },
3222
+ async removeOrganizationTeamMember(organizationId, teamId, memberId, idempotencyKey) {
3223
+ return normalizeRemovedOrganizationTeamMember(await teamMembershipMutation([
3224
+ organizationId,
3225
+ teamId,
3226
+ memberId
3227
+ ], idempotencyKey, "remove"));
3228
+ },
3229
+ async deleteOrganizationTeam(organizationId, teamId, idempotencyKey) {
3230
+ return normalizeDeletedOrganizationTeam(await teamMembershipMutation([organizationId, teamId], idempotencyKey, "delete"));
3231
+ },
3092
3232
  async updateOrganizationDisplay(organizationId, input) {
3093
3233
  const id = normalizeIdInput(organizationId);
3094
3234
  const desired = normalizeOrganizationDisplayInput(input);
@@ -3143,6 +3283,39 @@ function createServerAuth(options) {
3143
3283
  getReceivedInvitation(invitationId) {
3144
3284
  return organizationRead(`received-invitations/${normalizeIdInput(invitationId)}`, void 0, normalizeReceivedInvitation);
3145
3285
  },
3286
+ async startGoogleAccountRecovery(input) {
3287
+ if (authorization) throw new AuthError("state_conflict", 409);
3288
+ const body = googleRecoveryInput(input, false);
3289
+ return normalizeGoogleRecovery(await requestJson(joinURL(authOrigin, "api/v1/auth/google-account-recovery/start"), {
3290
+ fetch: fetchImpl,
3291
+ timeoutMs,
3292
+ method: "POST",
3293
+ credentials: "include",
3294
+ headers: {
3295
+ ...authHeaders(),
3296
+ "content-type": "application/json; charset=utf-8"
3297
+ },
3298
+ body,
3299
+ mapError: fromGoogleRecoveryError
3300
+ }), now());
3301
+ },
3302
+ async completeGoogleAccountRecovery(input) {
3303
+ if (authorization) throw new AuthError("state_conflict", 409);
3304
+ if (!cookie) throw new AuthError("authentication_required", 401);
3305
+ const body = googleRecoveryInput(input, true);
3306
+ return normalizeGoogleRecoveryCompletion(await requestJson(joinURL(authOrigin, "api/v1/auth/google-account-recovery/complete"), {
3307
+ fetch: fetchImpl,
3308
+ timeoutMs,
3309
+ method: "POST",
3310
+ credentials: "include",
3311
+ headers: {
3312
+ ...authHeaders(),
3313
+ "content-type": "application/json; charset=utf-8"
3314
+ },
3315
+ body,
3316
+ mapError: fromGoogleRecoveryError
3317
+ }));
3318
+ },
3146
3319
  async signInWithSocialIdToken(input) {
3147
3320
  if (authorization) throw new AuthError("state_conflict", 409);
3148
3321
  const body = socialIdTokenRequest(normalizeSocialIdTokenInput(input));