@geekapps/auth-nextjs 0.24.0 → 0.26.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/client.d.ts CHANGED
@@ -11,6 +11,11 @@ declare class GeekappsSessionExpiredError extends Error {
11
11
  type UserStatus = "active" | "inactive" | "suspended";
12
12
  type OrganizationStatus = "active" | "inactive" | "suspended";
13
13
  type OAuthClientType = "public" | "confidential";
14
+ /**
15
+ * Códigos de erro conhecidos devolvidos pelo auth-server. A lista é aberta
16
+ * (`string & {}`): códigos novos continuam tipados como string.
17
+ */
18
+ type AuthErrorCode = "waitlist_required" | "waitlist_disabled" | "password_reset_required" | "account_locked" | "invalid_credentials" | "not_found" | "invalid_request" | "interaction_required" | (string & {});
14
19
  type AuthResult<T = unknown> = {
15
20
  success: true;
16
21
  data: T;
@@ -18,8 +23,10 @@ type AuthResult<T = unknown> = {
18
23
  success: false;
19
24
  error: string;
20
25
  status?: number;
21
- /** Código de erro da API (ex.: "legal_fields_required", "invalid_tax_id"). */
22
- code?: string;
26
+ /** Código de erro da API (ex.: "waitlist_required", "account_locked", "legal_fields_required"). */
27
+ code?: AuthErrorCode;
28
+ /** Segundos até poder tentar de novo (`account_locked`). */
29
+ retryAfter?: number;
23
30
  /** Campos obrigatórios que faltaram (ex.: "legalName", "legalAddress.city"). */
24
31
  missingFields?: string[];
25
32
  };
@@ -28,7 +35,8 @@ declare class GeekappsApiError extends Error {
28
35
  readonly status: number;
29
36
  readonly code?: string | undefined;
30
37
  readonly missingFields?: string[] | undefined;
31
- constructor(message: string, status: number, code?: string | undefined, missingFields?: string[] | undefined);
38
+ readonly retryAfter?: number | undefined;
39
+ constructor(message: string, status: number, code?: string | undefined, missingFields?: string[] | undefined, retryAfter?: number | undefined);
32
40
  }
33
41
  /** standard: organização comum. legal: pessoa jurídica associada a um Tax ID (CNPJ ou genérico). */
34
42
  type OrganizationType = "standard" | "legal";
@@ -296,7 +304,52 @@ type OrganizationJoinRequest = {
296
304
  createdAt: string | Date;
297
305
  updatedAt: string | Date;
298
306
  };
307
+ type WaitlistEntry = {
308
+ id: string;
309
+ email: string;
310
+ name: string | null;
311
+ status: WaitlistStatus;
312
+ position: number | null;
313
+ createdAt: string;
314
+ approvedAt: string | null;
315
+ };
316
+ type WaitlistList = {
317
+ waiting: number;
318
+ entries: WaitlistEntry[];
319
+ };
320
+ type ForcePasswordResetInput = {
321
+ organizationId: string;
322
+ applicationId: string;
323
+ userIds?: string[];
324
+ all?: boolean;
325
+ };
326
+ type ForcePasswordResetResult = {
327
+ ok: boolean;
328
+ scheduled: number;
329
+ alreadyPending: number;
330
+ skipped: number;
331
+ estimatedMinutes: number;
332
+ batchSize: number;
333
+ intervalSeconds: number;
334
+ };
335
+ type ForcePasswordResetProgress = {
336
+ pending: number;
337
+ done: number;
338
+ failed: number;
339
+ batchSize: number;
340
+ intervalSeconds: number;
341
+ };
342
+ /** Campos graváveis de uma Application via PATCH /applications/:id. */
343
+ type ApplicationUpdateInput = {
344
+ name?: string;
345
+ description?: string | null;
346
+ imageUrl?: string | null;
347
+ /** Só e-mails aprovados na lista de espera podem se cadastrar. */
348
+ waitlistEnabled?: boolean;
349
+ [key: string]: unknown;
350
+ };
299
351
  type OrganizationOwnedApplication = {
352
+ waitlistEnabled?: boolean;
300
353
  id: string;
301
354
  name: string;
302
355
  description: string | null;
@@ -506,6 +559,7 @@ declare function registerWithPassword(params: {
506
559
  imageUrl?: string;
507
560
  address?: Record<string, unknown>;
508
561
  password: string;
562
+ authorizationFlowId?: string;
509
563
  redirectTo?: string;
510
564
  }, options?: ClientActionOptions): Promise<AuthResult<RegisterResponse>>;
511
565
  declare function startGoogleLogin(params?: CallbackUrlOptions, options?: ClientActionOptions): void;
@@ -515,6 +569,22 @@ declare function requestPasswordlessLink(params: {
515
569
  redirectTo?: string;
516
570
  callbackUrl?: string;
517
571
  }, options?: ClientActionOptions): Promise<AuthResult>;
572
+ type WaitlistStatus = "waiting" | "approved" | "joined";
573
+ type JoinWaitlistParams = {
574
+ clientId: string;
575
+ email: string;
576
+ name?: string;
577
+ };
578
+ type JoinWaitlistResponse = {
579
+ ok: true;
580
+ status: WaitlistStatus;
581
+ position: number | null;
582
+ };
583
+ /**
584
+ * Entra na lista de espera de uma app com `waitlistEnabled`.
585
+ * Erros: code "not_found" (404) ou "waitlist_disabled" (409).
586
+ */
587
+ declare function joinWaitlist(params: JoinWaitlistParams, options?: ClientActionOptions): Promise<AuthResult<JoinWaitlistResponse>>;
518
588
  type GeekappsAuthContextValue = {
519
589
  basePath: string;
520
590
  user: User | null;
@@ -553,6 +623,7 @@ type GeekappsAuthContextValue = {
553
623
  redirectTo?: string;
554
624
  }) => Promise<AuthResult<RegisterResponse>>;
555
625
  startGoogleLogin: (params?: CallbackUrlOptions) => void;
626
+ joinWaitlist: (params: JoinWaitlistParams) => Promise<AuthResult<JoinWaitlistResponse>>;
556
627
  requestPasswordlessLink: (params: {
557
628
  email: string;
558
629
  authorizationFlowId?: string;
@@ -736,4 +807,4 @@ type UseServiceAccountResult = {
736
807
  };
737
808
  declare function useServiceAccount(): UseServiceAccountResult;
738
809
 
739
- export { type AcceptInviteResult, type AddMemberInput, type AuthResult, type CallbackUrlOptions, type ConnectedAccount, type CreateServiceAccountInput, GeekappsApiError, type GeekappsAuthContextValue, GeekappsAuthProvider, type GeekappsAuthProviderProps, GeekappsSessionExpiredError, type JoinRequestStatus, type LoginResponse, type MemberInviteInput, type MemberRole, type MyOrganizationInvite, type OAuthClientType, type OidcPrompt, type Organization, type OrganizationInput, type OrganizationInvite, type OrganizationInvitePreview, type OrganizationJoinRequest, type OrganizationLegalAddress, type OrganizationLegalData, type OrganizationMember, type OrganizationMembership, type OrganizationOwnedApplication, type OrganizationStatus, type OrganizationType, type OrganizationUpdateInput, type Permission, type PermissionCheckOptions, type PermissionInput, type PermissionUpdateInput, type PublicOrganization, type RegisterResponse, type Role, type RoleAssignment, type RoleInput, type RolePermission, type RoleUpdateInput, type ServiceAccount, type ServiceAccountWithSecret, type SessionApplication, type SignInInput, type SignInOptions, type TaxIdLookupResult, type TaxIdType, type UpdateMemberInput, type UpdateMemberRoleInput, type UseAccountsResult, type UseInvitesResult, type UseJoinRequestsResult, type UseMembersResult, type UseOrgResult, type UsePermissionsResult, type UsePublicOrganizationsResult, type UseRolesResult, type UseServiceAccountResult, type UseSessionsResult, type UseUsersResult, type User, type UserInput, type UserSession, type UserStatus, loginWithPassword, registerWithPassword, requestPasswordlessLink, startGoogleLogin, useAccounts, useAuth, useInvites, useJoinRequests, useMembers, useOrg, usePermissions, usePublicOrganizations, useRoles, useServiceAccount, useSessions, useUsers };
810
+ export { type AcceptInviteResult, type AddMemberInput, type ApplicationUpdateInput, type AuthErrorCode, type AuthResult, type CallbackUrlOptions, type ConnectedAccount, type CreateServiceAccountInput, type ForcePasswordResetInput, type ForcePasswordResetProgress, type ForcePasswordResetResult, GeekappsApiError, type GeekappsAuthContextValue, GeekappsAuthProvider, type GeekappsAuthProviderProps, GeekappsSessionExpiredError, type JoinRequestStatus, type JoinWaitlistParams, type JoinWaitlistResponse, type LoginResponse, type MemberInviteInput, type MemberRole, type MyOrganizationInvite, type OAuthClientType, type OidcPrompt, type Organization, type OrganizationInput, type OrganizationInvite, type OrganizationInvitePreview, type OrganizationJoinRequest, type OrganizationLegalAddress, type OrganizationLegalData, type OrganizationMember, type OrganizationMembership, type OrganizationOwnedApplication, type OrganizationStatus, type OrganizationType, type OrganizationUpdateInput, type Permission, type PermissionCheckOptions, type PermissionInput, type PermissionUpdateInput, type PublicOrganization, type RegisterResponse, type Role, type RoleAssignment, type RoleInput, type RolePermission, type RoleUpdateInput, type ServiceAccount, type ServiceAccountWithSecret, type SessionApplication, type SignInInput, type SignInOptions, type TaxIdLookupResult, type TaxIdType, type UpdateMemberInput, type UpdateMemberRoleInput, type UseAccountsResult, type UseInvitesResult, type UseJoinRequestsResult, type UseMembersResult, type UseOrgResult, type UsePermissionsResult, type UsePublicOrganizationsResult, type UseRolesResult, type UseServiceAccountResult, type UseSessionsResult, type UseUsersResult, type User, type UserInput, type UserSession, type UserStatus, type WaitlistEntry, type WaitlistList, type WaitlistStatus, joinWaitlist, loginWithPassword, registerWithPassword, requestPasswordlessLink, startGoogleLogin, useAccounts, useAuth, useInvites, useJoinRequests, useMembers, useOrg, usePermissions, usePublicOrganizations, useRoles, useServiceAccount, useSessions, useUsers };
package/dist/client.js CHANGED
@@ -19,16 +19,18 @@ var GeekappsSessionExpiredError = class extends Error {
19
19
  }
20
20
  };
21
21
  var GeekappsApiError = class extends Error {
22
- constructor(message, status, code, missingFields) {
22
+ constructor(message, status, code, missingFields, retryAfter) {
23
23
  super(message);
24
24
  this.status = status;
25
25
  this.code = code;
26
26
  this.missingFields = missingFields;
27
+ this.retryAfter = retryAfter;
27
28
  this.name = "GeekappsApiError";
28
29
  }
29
30
  status;
30
31
  code;
31
32
  missingFields;
33
+ retryAfter;
32
34
  };
33
35
  function normalizeBasePath(basePath) {
34
36
  return basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
@@ -41,6 +43,18 @@ async function parseError(response) {
41
43
  const data = await response.json().catch(() => null);
42
44
  return data?.error_description ?? data?.error ?? data?.message ?? `Request failed with status ${response.status}`;
43
45
  }
46
+ async function apiErrorFromResponse(response) {
47
+ const data = await response.clone().json().catch(() => null);
48
+ const code = typeof data?.code === "string" ? data.code : typeof data?.error === "string" ? data.error : void 0;
49
+ const retry = Number(data?.retry_after ?? data?.retryAfter);
50
+ return new GeekappsApiError(
51
+ await parseError(response),
52
+ response.status,
53
+ code,
54
+ Array.isArray(data?.missingFields) ? data.missingFields : void 0,
55
+ Number.isFinite(retry) ? retry : void 0
56
+ );
57
+ }
44
58
  function redirectTo(path) {
45
59
  window.location.assign(path);
46
60
  }
@@ -65,7 +79,7 @@ async function clientRequest(path, options = {}, basePath = "/api/auth") {
65
79
  method: options.method ?? "GET"
66
80
  });
67
81
  if (!response.ok) {
68
- throw new Error(await parseError(response));
82
+ throw await apiErrorFromResponse(response);
69
83
  }
70
84
  if (response.status === 204) {
71
85
  return null;
@@ -79,6 +93,16 @@ async function toStandaloneAuthResult(fn) {
79
93
  data: await fn()
80
94
  };
81
95
  } catch (error) {
96
+ if (error instanceof GeekappsApiError) {
97
+ return {
98
+ success: false,
99
+ error: error.message,
100
+ status: error.status,
101
+ code: error.code,
102
+ missingFields: error.missingFields,
103
+ retryAfter: error.retryAfter
104
+ };
105
+ }
82
106
  return {
83
107
  success: false,
84
108
  error: error instanceof Error ? error.message : "Auth request failed"
@@ -143,6 +167,18 @@ async function requestPasswordlessLink(params, options) {
143
167
  )
144
168
  );
145
169
  }
170
+ async function joinWaitlist(params, options) {
171
+ return toStandaloneAuthResult(
172
+ () => clientRequest(
173
+ "/waitlist/join",
174
+ {
175
+ body: { client_id: params.clientId, email: params.email, name: params.name },
176
+ method: "POST"
177
+ },
178
+ options?.basePath
179
+ )
180
+ );
181
+ }
146
182
  var GeekappsAuthContext = createContext(null);
147
183
  function GeekappsAuthProvider({
148
184
  children,
@@ -176,13 +212,7 @@ function GeekappsAuthProvider({
176
212
  throw new GeekappsSessionExpiredError();
177
213
  }
178
214
  if (!response.ok) {
179
- const data = await response.clone().json().catch(() => null);
180
- throw new GeekappsApiError(
181
- await parseError(response),
182
- response.status,
183
- typeof data?.code === "string" ? data.code : void 0,
184
- Array.isArray(data?.missingFields) ? data.missingFields : void 0
185
- );
215
+ throw await apiErrorFromResponse(response);
186
216
  }
187
217
  if (response.status === 204) {
188
218
  return null;
@@ -346,7 +376,8 @@ function GeekappsAuthProvider({
346
376
  error: error.message,
347
377
  status: error.status,
348
378
  code: error.code,
349
- missingFields: error.missingFields
379
+ missingFields: error.missingFields,
380
+ retryAfter: error.retryAfter
350
381
  };
351
382
  }
352
383
  return { success: false, error: error instanceof Error ? error.message : "Unexpected error" };
@@ -462,6 +493,12 @@ function GeekappsAuthProvider({
462
493
  if (params?.authorizationFlowId) url.searchParams.set("flow_id", params.authorizationFlowId);
463
494
  redirectTo(url.toString());
464
495
  },
496
+ joinWaitlist: (params) => toAuthResult(
497
+ () => request("/waitlist/join", {
498
+ method: "POST",
499
+ body: { client_id: params.clientId, email: params.email, name: params.name }
500
+ })
501
+ ),
465
502
  requestPasswordlessLink: (params) => toAuthResult(() => request("/passwordless/link", { method: "POST", body: params })),
466
503
  refreshOrganizations,
467
504
  setCurrentOrg,
@@ -858,6 +895,7 @@ export {
858
895
  GeekappsApiError,
859
896
  GeekappsAuthProvider,
860
897
  GeekappsSessionExpiredError,
898
+ joinWaitlist,
861
899
  loginWithPassword,
862
900
  registerWithPassword,
863
901
  requestPasswordlessLink,