@atlasauth/js 0.15.0 → 0.16.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/account-hints.d.ts +53 -0
  3. package/dist/account-hints.js +114 -0
  4. package/dist/account-hints.js.map +1 -0
  5. package/dist/attempt.d.ts +3 -1
  6. package/dist/attempt.js.map +1 -1
  7. package/dist/captcha-controller.d.ts +21 -0
  8. package/dist/captcha-controller.js +35 -0
  9. package/dist/captcha-controller.js.map +1 -1
  10. package/dist/environment.d.ts +48 -0
  11. package/dist/environment.js +54 -1
  12. package/dist/environment.js.map +1 -1
  13. package/dist/fapi.d.ts +29 -0
  14. package/dist/fapi.js +90 -7
  15. package/dist/fapi.js.map +1 -1
  16. package/dist/impersonation.d.ts +44 -0
  17. package/dist/impersonation.js +47 -0
  18. package/dist/impersonation.js.map +1 -0
  19. package/dist/index.d.ts +9 -0
  20. package/dist/index.js +16 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/instance-settings.d.ts +7 -1
  23. package/dist/instance-settings.js +15 -1
  24. package/dist/instance-settings.js.map +1 -1
  25. package/dist/mfa-enrollment.d.ts +154 -0
  26. package/dist/mfa-enrollment.js +288 -0
  27. package/dist/mfa-enrollment.js.map +1 -0
  28. package/dist/organization-audit-log.d.ts +63 -0
  29. package/dist/organization-audit-log.js +96 -0
  30. package/dist/organization-audit-log.js.map +1 -0
  31. package/dist/organizations.d.ts +330 -0
  32. package/dist/organizations.js +375 -0
  33. package/dist/organizations.js.map +1 -0
  34. package/dist/passkey-sign-in.d.ts +40 -0
  35. package/dist/passkey-sign-in.js +41 -0
  36. package/dist/passkey-sign-in.js.map +1 -0
  37. package/dist/passkey-sign-up.d.ts +46 -0
  38. package/dist/passkey-sign-up.js +98 -0
  39. package/dist/passkey-sign-up.js.map +1 -0
  40. package/dist/password-reset.d.ts +12 -0
  41. package/dist/password-reset.js +15 -0
  42. package/dist/password-reset.js.map +1 -1
  43. package/dist/phone-numbers.d.ts +43 -0
  44. package/dist/phone-numbers.js +65 -0
  45. package/dist/phone-numbers.js.map +1 -0
  46. package/dist/profile.d.ts +24 -0
  47. package/dist/profile.js +24 -0
  48. package/dist/profile.js.map +1 -0
  49. package/dist/referral-detect.js +1 -1
  50. package/dist/referral.d.ts +1 -1
  51. package/dist/referral.js +3 -2
  52. package/dist/referral.js.map +1 -1
  53. package/dist/sign-out-guard.d.ts +8 -0
  54. package/dist/sign-out-guard.js +15 -0
  55. package/dist/sign-out-guard.js.map +1 -1
  56. package/dist/version.d.ts +1 -1
  57. package/dist/version.js +1 -1
  58. package/package.json +2 -2
@@ -0,0 +1,330 @@
1
+ import type { FapiClient } from './fapi';
2
+ /**
3
+ * Organization self-management from the browser, over the Frontend API: the
4
+ * signed-in user's organizations, members, invitations, roles, teams, settings,
5
+ * membership requests, leaving and deleting. Cookie-authenticated through the
6
+ * {@link FapiClient}. Admin actions are gated by the user's role in the ACTIVE
7
+ * organization, exactly as the server enforces them.
8
+ *
9
+ * {@link OrganizationProfileController} is the headless state behind every SDK's
10
+ * `<OrganizationProfile>`: members, invitations and roles, with the actions an
11
+ * admin needs, as a subscribable store a framework renders.
12
+ */
13
+ export interface ClientOrganization {
14
+ object: 'organization';
15
+ id: string;
16
+ name: string;
17
+ slug: string | null;
18
+ image_url?: string | null;
19
+ public_metadata?: Record<string, unknown>;
20
+ max_allowed_memberships?: number | null;
21
+ members_count?: number;
22
+ created_at?: number;
23
+ updated_at?: number;
24
+ /** On by-slug reads: the caller's own role. */
25
+ membership?: {
26
+ role: string;
27
+ };
28
+ }
29
+ export interface OrganizationMember {
30
+ object: 'organization_membership';
31
+ id: string;
32
+ role: string;
33
+ user: {
34
+ id: string;
35
+ first_name: string | null;
36
+ last_name: string | null;
37
+ image_url: string | null;
38
+ } | null;
39
+ }
40
+ export interface OrganizationInvitation {
41
+ object: 'organization_invitation';
42
+ id: string;
43
+ organization_id: string;
44
+ email_address: string;
45
+ role: string | null;
46
+ status: 'pending' | 'accepted' | 'revoked' | 'expired' | string;
47
+ inviter_user_id: string | null;
48
+ expires_at: number;
49
+ created_at: number;
50
+ }
51
+ /** What an accept page shows before the invitee signs in. */
52
+ export interface PublicOrganizationInvitation {
53
+ object: 'organization_invitation';
54
+ id: string;
55
+ email_address: string;
56
+ role: string | null;
57
+ status: string;
58
+ expires_at: number;
59
+ organization: {
60
+ id: string;
61
+ name: string;
62
+ slug: string | null;
63
+ image_url: string | null;
64
+ };
65
+ inviter: {
66
+ first_name: string | null;
67
+ last_name: string | null;
68
+ image_url: string | null;
69
+ } | null;
70
+ }
71
+ export interface OrganizationRole {
72
+ object: 'role';
73
+ /** Present from servers that support per-organization custom roles. */
74
+ id?: string;
75
+ key: string;
76
+ name: string;
77
+ description: string | null;
78
+ is_system?: boolean;
79
+ /** Set on the organization's own custom roles; null for an instance-wide role. */
80
+ organization_id?: string | null;
81
+ /** Included only for a caller who manages members. */
82
+ permissions?: string[];
83
+ member_count?: number;
84
+ }
85
+ /** A permission an organization admin may put on a custom role. */
86
+ export interface OrganizationPermission {
87
+ object: 'permission';
88
+ key: string;
89
+ name: string;
90
+ description: string | null;
91
+ }
92
+ /** What a custom role is made of. */
93
+ export interface OrganizationRoleInput {
94
+ name?: string;
95
+ description?: string | null;
96
+ /** Permission keys; each must be one the caller holds. */
97
+ permissions?: string[];
98
+ }
99
+ export interface OrganizationTeam {
100
+ object: 'team';
101
+ id: string;
102
+ organization_id: string;
103
+ name: string;
104
+ description: string | null;
105
+ members_count?: number;
106
+ created_at: number;
107
+ updated_at: number;
108
+ }
109
+ export interface OrganizationTeamMember {
110
+ object: 'team_membership';
111
+ team_id: string;
112
+ user_id: string;
113
+ user: {
114
+ id: string;
115
+ first_name: string | null;
116
+ last_name: string | null;
117
+ image_url: string | null;
118
+ } | null;
119
+ }
120
+ export interface OrganizationSlugCheck {
121
+ object: 'organization_slug_check';
122
+ slug: string;
123
+ valid: boolean;
124
+ available: boolean;
125
+ }
126
+ export interface OrganizationPage<T> {
127
+ data: T[];
128
+ totalCount?: number;
129
+ hasMore: boolean;
130
+ }
131
+ /** A refused request. `code` is the server's stable error code. */
132
+ export declare class OrganizationRequestError extends Error {
133
+ readonly code: string;
134
+ readonly status: number;
135
+ readonly param?: string;
136
+ readonly reason?: string;
137
+ readonly meta?: Record<string, unknown>;
138
+ constructor(status: number, code: string, message: string, param?: string, reason?: string, meta?: Record<string, unknown>);
139
+ /** True when the action needs a fresh re-authentication first (deleting an organization). */
140
+ get needsReverification(): boolean;
141
+ }
142
+ /** The organizations the signed-in user belongs to. */
143
+ export declare function listMyOrganizations(client: FapiClient): Promise<OrganizationPage<Record<string, unknown>>>;
144
+ export declare function createOrganization(client: FapiClient, input: {
145
+ name: string;
146
+ slug?: string;
147
+ }): Promise<ClientOrganization>;
148
+ /** The ACTIVE organization. */
149
+ export declare function getOrganization(client: FapiClient, organizationId: string): Promise<ClientOrganization>;
150
+ export declare function updateOrganization(client: FapiClient, organizationId: string, input: {
151
+ name?: string;
152
+ slug?: string;
153
+ image_url?: string | null;
154
+ }): Promise<ClientOrganization>;
155
+ /**
156
+ * Delete the active organization (admin only, when the application allows it).
157
+ * Needs a recent re-authentication: a stale session gets an error whose
158
+ * `needsReverification` is true.
159
+ */
160
+ export declare function deleteOrganization(client: FapiClient, organizationId: string): Promise<{
161
+ object: 'organization';
162
+ id: string;
163
+ deleted: true;
164
+ }>;
165
+ /** Leave an organization (any member; the only admin must promote someone first). */
166
+ export declare function leaveOrganization(client: FapiClient, organizationId: string): Promise<{
167
+ object: 'organization_membership';
168
+ organization_id: string;
169
+ user_id: string;
170
+ deleted: true;
171
+ }>;
172
+ export declare function checkOrganizationSlug(client: FapiClient, slug: string): Promise<OrganizationSlugCheck>;
173
+ /** An organization the user belongs to, by slug (404 otherwise). */
174
+ export declare function getOrganizationBySlug(client: FapiClient, slug: string): Promise<ClientOrganization>;
175
+ /** The roles a member can hold (for a role picker). */
176
+ export declare function listOrganizationRoles(client: FapiClient, organizationId: string): Promise<OrganizationRole[]>;
177
+ /**
178
+ * The permissions the caller may put on a custom role: the instance's
179
+ * permissions that the caller holds (needs member management).
180
+ */
181
+ export declare function listAssignablePermissions(client: FapiClient, organizationId: string): Promise<OrganizationPermission[]>;
182
+ /** Create a custom role for the active organization (never past the caller's own permissions). */
183
+ export declare function createOrganizationRole(client: FapiClient, organizationId: string, input: OrganizationRoleInput & {
184
+ key: string;
185
+ name: string;
186
+ }): Promise<OrganizationRole>;
187
+ /** Rename one of the organization's own roles or replace its permissions (the key is fixed). */
188
+ export declare function updateOrganizationRole(client: FapiClient, organizationId: string, roleId: string, input: OrganizationRoleInput): Promise<OrganizationRole>;
189
+ /**
190
+ * Delete one of the organization's own roles. A role still in use needs
191
+ * `reassignTo` (a role key) — its members and pending invitations move first.
192
+ */
193
+ export declare function deleteOrganizationRole(client: FapiClient, organizationId: string, roleId: string, options?: {
194
+ reassignTo?: string;
195
+ }): Promise<{
196
+ object: 'role';
197
+ id: string;
198
+ key: string;
199
+ deleted: true;
200
+ members_reassigned: number;
201
+ }>;
202
+ export declare function listOrganizationMembers(client: FapiClient, organizationId: string, options?: {
203
+ limit?: number;
204
+ offset?: number;
205
+ }): Promise<OrganizationPage<OrganizationMember>>;
206
+ export declare function updateMemberRole(client: FapiClient, organizationId: string, userId: string, role: string): Promise<{
207
+ object: 'organization_membership';
208
+ organization_id: string;
209
+ user_id: string;
210
+ role: string;
211
+ }>;
212
+ export declare function removeMember(client: FapiClient, organizationId: string, userId: string): Promise<unknown>;
213
+ export declare function listOrganizationInvitations(client: FapiClient, organizationId: string, options?: {
214
+ status?: string;
215
+ }): Promise<OrganizationPage<OrganizationInvitation>>;
216
+ export declare function inviteMember(client: FapiClient, organizationId: string, input: {
217
+ emailAddress: string;
218
+ role: string;
219
+ }): Promise<OrganizationInvitation>;
220
+ export declare function revokeInvitation(client: FapiClient, organizationId: string, invitationId: string): Promise<OrganizationInvitation>;
221
+ export declare function resendInvitation(client: FapiClient, organizationId: string, invitationId: string): Promise<OrganizationInvitation>;
222
+ /** The public view of an invitation, for an accept page (no sign-in needed). */
223
+ export declare function getOrganizationInvitation(client: FapiClient, invitationId: string): Promise<PublicOrganizationInvitation>;
224
+ /** Accept an invitation by id as the signed-in user. */
225
+ export declare function acceptOrganizationInvitation(client: FapiClient, invitationId: string): Promise<unknown>;
226
+ /** Invitations addressed to the signed-in user. */
227
+ export declare function listMyOrganizationInvitations(client: FapiClient): Promise<OrganizationPage<Record<string, unknown>>>;
228
+ export declare function acceptMyOrganizationInvitation(client: FapiClient, invitationId: string): Promise<unknown>;
229
+ export declare function declineMyOrganizationInvitation(client: FapiClient, invitationId: string): Promise<unknown>;
230
+ /** Organizations the user could join (verified email domain matches). */
231
+ export declare function listMyOrganizationSuggestions(client: FapiClient): Promise<OrganizationPage<Record<string, unknown>>>;
232
+ export declare function acceptOrganizationSuggestion(client: FapiClient, organizationId: string): Promise<unknown>;
233
+ export declare function listMembershipRequests(client: FapiClient, organizationId: string): Promise<OrganizationPage<Record<string, unknown>>>;
234
+ export declare function acceptMembershipRequest(client: FapiClient, organizationId: string, requestId: string): Promise<unknown>;
235
+ export declare function rejectMembershipRequest(client: FapiClient, organizationId: string, requestId: string): Promise<unknown>;
236
+ export declare function getOrganizationSettings(client: FapiClient, organizationId: string): Promise<{
237
+ schema: Record<string, unknown> | null;
238
+ values: Record<string, unknown>;
239
+ version: number;
240
+ }>;
241
+ /** Write the organization's settings (admin; needs a recent re-authentication). */
242
+ export declare function updateOrganizationSettings(client: FapiClient, organizationId: string, values: Record<string, unknown>): Promise<{
243
+ values: Record<string, unknown>;
244
+ version: number;
245
+ }>;
246
+ export declare function listTeams(client: FapiClient, organizationId: string): Promise<OrganizationTeam[]>;
247
+ /** The caller's own teams, and the session's active team. */
248
+ export declare function listMyTeams(client: FapiClient, organizationId: string): Promise<{
249
+ data: OrganizationTeam[];
250
+ activeTeamId: string | null;
251
+ }>;
252
+ export declare function createTeam(client: FapiClient, organizationId: string, input: {
253
+ name: string;
254
+ description?: string | null;
255
+ }): Promise<OrganizationTeam>;
256
+ export declare function updateTeam(client: FapiClient, organizationId: string, teamId: string, input: {
257
+ name?: string;
258
+ description?: string | null;
259
+ }): Promise<OrganizationTeam>;
260
+ export declare function deleteTeam(client: FapiClient, organizationId: string, teamId: string): Promise<unknown>;
261
+ export declare function listTeamMembers(client: FapiClient, organizationId: string, teamId: string): Promise<OrganizationTeamMember[]>;
262
+ export declare function addTeamMember(client: FapiClient, organizationId: string, teamId: string, userId: string): Promise<unknown>;
263
+ export declare function removeTeamMember(client: FapiClient, organizationId: string, teamId: string, userId: string): Promise<unknown>;
264
+ export interface OrganizationProfileState {
265
+ status: 'idle' | 'loading' | 'ready' | 'error';
266
+ members: OrganizationMember[];
267
+ membersTotal: number;
268
+ /** Pending invitations (admins only; empty for others). */
269
+ invitations: OrganizationInvitation[];
270
+ roles: OrganizationRole[];
271
+ /** Permissions an admin may put on a custom role (admins only; empty for others). */
272
+ permissions: OrganizationPermission[];
273
+ /** The last failure, for display. */
274
+ error: OrganizationRequestError | Error | null;
275
+ /** The action in flight (e.g. `invite`, `remove:<userId>`), or null. */
276
+ busy: string | null;
277
+ }
278
+ /**
279
+ * The state and actions behind `<OrganizationProfile>`, framework-free. Each
280
+ * SDK wraps it in its own reactivity (`subscribe` + `getState`). Admin-only
281
+ * reads (invitations) are skipped when `canManage` is false; a refused admin
282
+ * call surfaces as `error` rather than throwing out of an event handler.
283
+ */
284
+ export declare class OrganizationProfileController {
285
+ private readonly client;
286
+ readonly organizationId: string;
287
+ private readonly options;
288
+ private state;
289
+ private readonly listeners;
290
+ constructor(client: FapiClient, organizationId: string, options?: {
291
+ canManage?: boolean;
292
+ onChange?: () => void | Promise<void>;
293
+ });
294
+ getState(): OrganizationProfileState;
295
+ subscribe(listener: (state: OrganizationProfileState) => void): () => void;
296
+ private set;
297
+ /** Load members, roles and (for admins) pending invitations. */
298
+ load(): Promise<void>;
299
+ private run;
300
+ changeRole(userId: string, role: string): Promise<{
301
+ object: "organization_membership";
302
+ organization_id: string;
303
+ user_id: string;
304
+ role: string;
305
+ } | undefined>;
306
+ removeMember(userId: string): Promise<unknown>;
307
+ invite(emailAddress: string, role: string): Promise<OrganizationInvitation | undefined>;
308
+ revokeInvitation(invitationId: string): Promise<OrganizationInvitation | undefined>;
309
+ resendInvitation(invitationId: string): Promise<OrganizationInvitation | undefined>;
310
+ /** The organization's own custom roles (a subset of `roles`). */
311
+ customRoles(): OrganizationRole[];
312
+ createRole(input: OrganizationRoleInput & {
313
+ key: string;
314
+ name: string;
315
+ }): Promise<OrganizationRole | undefined>;
316
+ updateRole(roleId: string, input: OrganizationRoleInput): Promise<OrganizationRole | undefined>;
317
+ deleteRole(roleId: string, options?: {
318
+ reassignTo?: string;
319
+ }): Promise<{
320
+ object: "role";
321
+ id: string;
322
+ key: string;
323
+ deleted: true;
324
+ members_reassigned: number;
325
+ } | undefined>;
326
+ /** Leave; `onChange` (e.g. a session reload) runs after. */
327
+ leave(): Promise<boolean>;
328
+ /** Delete (admin; may need re-authentication: check `error.needsReverification`). */
329
+ deleteOrganization(): Promise<boolean>;
330
+ }