@motherbase/client 1.5.0 → 1.5.1

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 (93) hide show
  1. package/dist/admin.d.ts +131 -0
  2. package/dist/admin.d.ts.map +1 -0
  3. package/dist/admin.js +121 -0
  4. package/dist/admin.js.map +1 -0
  5. package/dist/auth.d.ts +459 -0
  6. package/dist/auth.d.ts.map +1 -0
  7. package/dist/auth.js +861 -0
  8. package/dist/auth.js.map +1 -0
  9. package/dist/channel.d.ts +129 -0
  10. package/dist/channel.d.ts.map +1 -0
  11. package/dist/channel.js +215 -0
  12. package/dist/channel.js.map +1 -0
  13. package/dist/compat.d.ts +40 -0
  14. package/dist/compat.d.ts.map +1 -0
  15. package/dist/compat.js +100 -0
  16. package/dist/compat.js.map +1 -0
  17. package/dist/cookie.d.ts +68 -0
  18. package/dist/cookie.d.ts.map +1 -0
  19. package/dist/cookie.js +152 -0
  20. package/dist/cookie.js.map +1 -0
  21. package/dist/database.d.ts +188 -0
  22. package/dist/database.d.ts.map +1 -0
  23. package/dist/database.js +2 -0
  24. package/dist/database.js.map +1 -0
  25. package/dist/functions.d.ts +60 -0
  26. package/dist/functions.d.ts.map +1 -0
  27. package/dist/functions.js +75 -0
  28. package/dist/functions.js.map +1 -0
  29. package/dist/http.d.ts +122 -0
  30. package/dist/http.d.ts.map +1 -0
  31. package/dist/http.js +206 -0
  32. package/dist/http.js.map +1 -0
  33. package/dist/index.d.ts +215 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +365 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/mfa.d.ts +126 -0
  38. package/dist/mfa.d.ts.map +1 -0
  39. package/dist/mfa.js +156 -0
  40. package/dist/mfa.js.map +1 -0
  41. package/dist/organization.d.ts +234 -0
  42. package/dist/organization.d.ts.map +1 -0
  43. package/dist/organization.js +157 -0
  44. package/dist/organization.js.map +1 -0
  45. package/dist/passkey.d.ts +59 -0
  46. package/dist/passkey.d.ts.map +1 -0
  47. package/dist/passkey.js +87 -0
  48. package/dist/passkey.js.map +1 -0
  49. package/dist/pkce.d.ts +13 -0
  50. package/dist/pkce.d.ts.map +1 -0
  51. package/dist/pkce.js +52 -0
  52. package/dist/pkce.js.map +1 -0
  53. package/dist/plugin-endpoint.d.ts +20 -0
  54. package/dist/plugin-endpoint.d.ts.map +1 -0
  55. package/dist/plugin-endpoint.js +24 -0
  56. package/dist/plugin-endpoint.js.map +1 -0
  57. package/dist/postgrest.d.ts +326 -0
  58. package/dist/postgrest.d.ts.map +1 -0
  59. package/dist/postgrest.js +625 -0
  60. package/dist/postgrest.js.map +1 -0
  61. package/dist/query.d.ts +97 -0
  62. package/dist/query.d.ts.map +1 -0
  63. package/dist/query.js +94 -0
  64. package/dist/query.js.map +1 -0
  65. package/dist/realtime.d.ts +114 -0
  66. package/dist/realtime.d.ts.map +1 -0
  67. package/dist/realtime.js +376 -0
  68. package/dist/realtime.js.map +1 -0
  69. package/dist/session.d.ts +47 -0
  70. package/dist/session.d.ts.map +1 -0
  71. package/dist/session.js +136 -0
  72. package/dist/session.js.map +1 -0
  73. package/dist/sso.d.ts +147 -0
  74. package/dist/sso.d.ts.map +1 -0
  75. package/dist/sso.js +35 -0
  76. package/dist/sso.js.map +1 -0
  77. package/dist/storage.d.ts +268 -0
  78. package/dist/storage.d.ts.map +1 -0
  79. package/dist/storage.js +441 -0
  80. package/dist/storage.js.map +1 -0
  81. package/dist/testing.d.ts +38 -0
  82. package/dist/testing.d.ts.map +1 -0
  83. package/dist/testing.js +50 -0
  84. package/dist/testing.js.map +1 -0
  85. package/dist/types.d.ts +348 -0
  86. package/dist/types.d.ts.map +1 -0
  87. package/dist/types.js +2 -0
  88. package/dist/types.js.map +1 -0
  89. package/dist/warn.d.ts +2 -0
  90. package/dist/warn.d.ts.map +1 -0
  91. package/dist/warn.js +23 -0
  92. package/dist/warn.js.map +1 -0
  93. package/package.json +4 -2
package/dist/mfa.js ADDED
@@ -0,0 +1,156 @@
1
+ import { toError } from './http.js';
2
+ const R = {
3
+ enable: '/api/auth/two-factor/enable',
4
+ disable: '/api/auth/two-factor/disable',
5
+ totpUri: '/api/auth/two-factor/get-totp-uri',
6
+ verifyTotp: '/api/auth/two-factor/verify-totp',
7
+ sendOtp: '/api/auth/two-factor/send-otp',
8
+ verifyOtp: '/api/auth/two-factor/verify-otp',
9
+ verifyBackupCode: '/api/auth/two-factor/verify-backup-code',
10
+ generateBackupCodes: '/api/auth/two-factor/generate-backup-codes',
11
+ };
12
+ export class MfaClient {
13
+ constructor(http,
14
+ /** Re-reads the session after a verify, so a stepped-up token is persisted. */
15
+ onVerified) {
16
+ this.http = http;
17
+ this.onVerified = onVerified;
18
+ }
19
+ /**
20
+ * Start TOTP enrolment. Returns the otpauth URI, the secret and the backup
21
+ * codes. The factor is not usable until `verify()` accepts a code from it.
22
+ */
23
+ async enroll(params) {
24
+ try {
25
+ const payload = await this.http.request(R.enable, {
26
+ method: 'POST',
27
+ body: { password: params.password, ...(params.issuer ? { issuer: params.issuer } : {}) },
28
+ raw: true,
29
+ });
30
+ const uri = payload.totpURI ?? payload.totpUri ?? '';
31
+ return {
32
+ data: {
33
+ // Better Auth has no per-factor id: the user is the factor. `totp` is
34
+ // used as a stable handle so unenroll/challenge/verify have something
35
+ // to take, matching the supabase-js shape.
36
+ id: 'totp',
37
+ type: 'totp',
38
+ totp: { uri, secret: secretFromUri(uri) },
39
+ backupCodes: payload.backupCodes ?? [],
40
+ },
41
+ error: null,
42
+ };
43
+ }
44
+ catch (err) {
45
+ return { data: null, error: toError(err) };
46
+ }
47
+ }
48
+ /**
49
+ * For TOTP this resolves immediately and sends nothing: the code already lives
50
+ * on the user's device. Pass `channel` to send a second-factor code by email
51
+ * or SMS instead, when the project has that enabled.
52
+ */
53
+ async challenge(params = {}) {
54
+ if (!params.channel) {
55
+ return { data: { id: params.factorId ?? 'totp', expires_at: null }, error: null };
56
+ }
57
+ try {
58
+ await this.http.request(R.sendOtp, { method: 'POST', body: {}, raw: true });
59
+ return { data: { id: params.factorId ?? 'otp', expires_at: null }, error: null };
60
+ }
61
+ catch (err) {
62
+ return { data: null, error: toError(err) };
63
+ }
64
+ }
65
+ /**
66
+ * Verify a code. `code` is a TOTP code by default; set `type` to `otp` for an
67
+ * emailed or texted second factor, or `backup` to spend a recovery code.
68
+ */
69
+ async verify(params) {
70
+ // All three routes take the code under the same key.
71
+ const route = params.type === 'backup' ? R.verifyBackupCode : params.type === 'otp' ? R.verifyOtp : R.verifyTotp;
72
+ try {
73
+ await this.http.request(route, {
74
+ method: 'POST',
75
+ body: { code: params.code, ...(params.trustDevice ? { trustDevice: true } : {}) },
76
+ raw: true,
77
+ });
78
+ // Verification can hand back a stepped-up session; adopt it before the
79
+ // caller makes its next request with the old one.
80
+ await this.onVerified();
81
+ return { data: { verified: true }, error: null };
82
+ }
83
+ catch (err) {
84
+ return { data: null, error: toError(err) };
85
+ }
86
+ }
87
+ /** Turn two-factor off. Requires the password, as enabling did. */
88
+ async unenroll(params) {
89
+ try {
90
+ await this.http.request(R.disable, { method: 'POST', body: { password: params.password }, raw: true });
91
+ return { data: { id: params.factorId ?? 'totp' }, error: null };
92
+ }
93
+ catch (err) {
94
+ return { data: null, error: toError(err) };
95
+ }
96
+ }
97
+ /** Issue a fresh set of backup codes, invalidating the previous set. */
98
+ async regenerateBackupCodes(params) {
99
+ try {
100
+ const payload = await this.http.request(R.generateBackupCodes, {
101
+ method: 'POST',
102
+ body: { password: params.password },
103
+ raw: true,
104
+ });
105
+ return { data: { backupCodes: payload.backupCodes ?? [] }, error: null };
106
+ }
107
+ catch (err) {
108
+ return { data: null, error: toError(err) };
109
+ }
110
+ }
111
+ /**
112
+ * Where this session stands, supabase-js style. `currentLevel` is `aal2`
113
+ * once the session passed a second factor (the server marks it then);
114
+ * `nextLevel` is `aal2` when the user has one to pass. `currentLevel` below
115
+ * `nextLevel` means: ask for the code before anything sensitive.
116
+ * `currentAuthenticationMethods` is always empty: sessions do not record
117
+ * which methods produced them.
118
+ */
119
+ async getAuthenticatorAssuranceLevel() {
120
+ try {
121
+ const payload = await this.http.request('/api/auth/get-session', { raw: true });
122
+ if (!payload?.session) {
123
+ return { data: { currentLevel: null, nextLevel: null, currentAuthenticationMethods: [] }, error: null };
124
+ }
125
+ const currentLevel = payload.session.aal === 'aal2' ? 'aal2' : 'aal1';
126
+ const nextLevel = payload.user?.twoFactorEnabled ? 'aal2' : currentLevel;
127
+ return { data: { currentLevel, nextLevel, currentAuthenticationMethods: [] }, error: null };
128
+ }
129
+ catch (err) {
130
+ return { data: null, error: toError(err) };
131
+ }
132
+ }
133
+ /**
134
+ * The user's factors. Reads the TOTP URI: getting one back means TOTP is
135
+ * enrolled, a failure means it is not. There is no list endpoint to call
136
+ * because there is no list, and inventing one client-side would be a lie about
137
+ * what the server models.
138
+ */
139
+ async listFactors() {
140
+ try {
141
+ await this.http.request(R.totpUri, { method: 'POST', body: {}, raw: true });
142
+ const factor = { id: 'totp', factor_type: 'totp', status: 'verified', friendly_name: 'TOTP' };
143
+ return { data: { totp: [factor], all: [factor] }, error: null };
144
+ }
145
+ catch {
146
+ // Not enrolled is a normal state, not an error the caller should branch on.
147
+ return { data: { totp: [], all: [] }, error: null };
148
+ }
149
+ }
150
+ }
151
+ /** Pull the `secret` query parameter out of an otpauth:// URI. */
152
+ function secretFromUri(uri) {
153
+ const match = /[?&]secret=([^&]+)/i.exec(uri);
154
+ return match ? decodeURIComponent(match[1]) : '';
155
+ }
156
+ //# sourceMappingURL=mfa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mfa.js","sourceRoot":"","sources":["../src/mfa.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsDpC,MAAM,CAAC,GAAG;IACR,MAAM,EAAE,6BAA6B;IACrC,OAAO,EAAE,8BAA8B;IACvC,OAAO,EAAE,mCAAmC;IAC5C,UAAU,EAAE,kCAAkC;IAC9C,OAAO,EA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C,WAAW;QACf,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5E,MAAM,MAAM,GAAc,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;YACzG,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAClE,CAAC;QAAC,MAAM,CAAC;YACP,4EAA4E;YAC5E,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAED,kEAAkE;AAClE,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9C,OAAO,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,234 @@
1
+ import type { HttpClient } from './http.js';
2
+ import type { MotherbaseResponse } from './types.js';
3
+ /**
4
+ * `client.auth.organization`: end-user organizations, their members,
5
+ * invitations and teams (Better Auth's organization plugin).
6
+ *
7
+ * Method names and parameters are the ones Better Auth's own client uses, so
8
+ * code written against `authClient.organization.*` ports by changing the
9
+ * receiver. Calls that take an optional `organizationId` default to the
10
+ * session's active organization (`setActive`).
11
+ *
12
+ * What the project's settings decide, and what happens otherwise:
13
+ *
14
+ * * Auth · Organizations off: every call fails with a 404.
15
+ * * Teams inside organizations off: the team methods fail with a 404.
16
+ * * Dynamic roles (`createRole` and friends) are not exposed: the server does
17
+ * not enable them, so roles are the built-in `owner`, `admin` and `member`.
18
+ */
19
+ /** A role, or several. Better Auth stores several as one comma-separated string. */
20
+ export type OrganizationRole = 'owner' | 'admin' | 'member' | (string & {});
21
+ export interface Organization {
22
+ id: string;
23
+ name: string;
24
+ slug: string;
25
+ logo?: string | null;
26
+ metadata?: Record<string, unknown> | null;
27
+ createdAt: string;
28
+ }
29
+ export interface OrganizationMember {
30
+ id: string;
31
+ organizationId: string;
32
+ userId: string;
33
+ role: OrganizationRole;
34
+ createdAt: string;
35
+ user: {
36
+ id: string;
37
+ name: string;
38
+ email: string;
39
+ image?: string | null;
40
+ };
41
+ }
42
+ export type InvitationStatus = 'pending' | 'accepted' | 'rejected' | 'canceled';
43
+ export interface OrganizationInvitation {
44
+ id: string;
45
+ organizationId: string;
46
+ email: string;
47
+ role: OrganizationRole;
48
+ status: InvitationStatus;
49
+ teamId?: string | null;
50
+ inviterId: string;
51
+ expiresAt: string;
52
+ createdAt: string;
53
+ }
54
+ export interface Team {
55
+ id: string;
56
+ name: string;
57
+ organizationId: string;
58
+ createdAt: string;
59
+ updatedAt?: string;
60
+ }
61
+ export interface TeamMember {
62
+ id: string;
63
+ teamId: string;
64
+ userId: string;
65
+ createdAt: string;
66
+ }
67
+ export interface FullOrganization extends Organization {
68
+ members: OrganizationMember[];
69
+ invitations: OrganizationInvitation[];
70
+ /** Present when teams are enabled. */
71
+ teams?: Team[];
72
+ }
73
+ /** Target an organization other than the active one. */
74
+ interface OrganizationTarget {
75
+ organizationId?: string;
76
+ }
77
+ /** `{ resource: [actions] }`, e.g. `{ member: ['create'], invitation: ['cancel'] }`. */
78
+ export type OrganizationPermissions = Record<string, string[]>;
79
+ export declare class OrganizationClient {
80
+ private readonly http;
81
+ constructor(http: HttpClient);
82
+ /** Create an organization. The caller becomes its owner, and it becomes active unless told otherwise. */
83
+ create(params: {
84
+ name: string;
85
+ slug: string;
86
+ logo?: string;
87
+ metadata?: Record<string, unknown>;
88
+ keepCurrentActiveOrganization?: boolean;
89
+ }): Promise<MotherbaseResponse<Organization & {
90
+ members: OrganizationMember[];
91
+ }>>;
92
+ update(params: {
93
+ data: Partial<Pick<Organization, 'name' | 'slug' | 'logo' | 'metadata'>>;
94
+ } & OrganizationTarget): Promise<MotherbaseResponse<Organization>>;
95
+ delete(params: {
96
+ organizationId: string;
97
+ }): Promise<MotherbaseResponse<Organization>>;
98
+ /** Organizations the signed-in user belongs to. */
99
+ list(): Promise<MotherbaseResponse<Organization[]>>;
100
+ /**
101
+ * One organization with its members, invitations and teams. With no
102
+ * parameters, the active organization; `null` when there is none.
103
+ */
104
+ getFullOrganization(params?: {
105
+ organizationSlug?: string;
106
+ membersLimit?: number;
107
+ } & OrganizationTarget): Promise<MotherbaseResponse<FullOrganization | null>>;
108
+ /**
109
+ * Make an organization the session's active one, which every call taking an
110
+ * optional `organizationId` then defaults to. `organizationId: null` clears it.
111
+ */
112
+ setActive(params: {
113
+ organizationId?: string | null;
114
+ organizationSlug?: string;
115
+ }): Promise<MotherbaseResponse<FullOrganization | null>>;
116
+ /** Whether a slug is free. A taken slug is an error, as the server reports it. */
117
+ checkSlug(params: {
118
+ slug: string;
119
+ }): Promise<MotherbaseResponse<{
120
+ status: boolean;
121
+ }>>;
122
+ leave(params: {
123
+ organizationId: string;
124
+ }): Promise<MotherbaseResponse<OrganizationMember>>;
125
+ listMembers(params?: {
126
+ organizationSlug?: string;
127
+ limit?: number;
128
+ offset?: number;
129
+ sortBy?: string;
130
+ sortDirection?: 'asc' | 'desc';
131
+ filterField?: string;
132
+ filterValue?: string | number | boolean;
133
+ filterOperator?: 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte' | 'in' | 'not_in' | 'contains' | 'starts_with' | 'ends_with';
134
+ } & OrganizationTarget): Promise<MotherbaseResponse<{
135
+ members: OrganizationMember[];
136
+ total: number;
137
+ }>>;
138
+ /** The signed-in user's membership in the active organization. */
139
+ getActiveMember(): Promise<MotherbaseResponse<OrganizationMember>>;
140
+ /** A member's role. Without `userId`, the signed-in user's. */
141
+ getActiveMemberRole(params?: {
142
+ userId?: string;
143
+ organizationSlug?: string;
144
+ } & OrganizationTarget): Promise<MotherbaseResponse<{
145
+ role: OrganizationRole;
146
+ }>>;
147
+ removeMember(params: {
148
+ memberIdOrEmail: string;
149
+ } & OrganizationTarget): Promise<MotherbaseResponse<{
150
+ member: OrganizationMember;
151
+ }>>;
152
+ updateMemberRole(params: {
153
+ memberId: string;
154
+ role: OrganizationRole | OrganizationRole[];
155
+ } & OrganizationTarget): Promise<MotherbaseResponse<OrganizationMember>>;
156
+ /** Whether the signed-in user's role grants every listed action. */
157
+ hasPermission(params: {
158
+ permissions: OrganizationPermissions;
159
+ } & OrganizationTarget): Promise<MotherbaseResponse<{
160
+ success: boolean;
161
+ }>>;
162
+ /** Invite by email. The project's invitation email carries the invitation id for `acceptInvitation`. */
163
+ inviteMember(params: {
164
+ email: string;
165
+ role: OrganizationRole | OrganizationRole[];
166
+ resend?: boolean;
167
+ teamId?: string | string[];
168
+ } & OrganizationTarget): Promise<MotherbaseResponse<OrganizationInvitation>>;
169
+ acceptInvitation(params: {
170
+ invitationId: string;
171
+ }): Promise<MotherbaseResponse<{
172
+ invitation: OrganizationInvitation;
173
+ member: OrganizationMember;
174
+ }>>;
175
+ rejectInvitation(params: {
176
+ invitationId: string;
177
+ }): Promise<MotherbaseResponse<{
178
+ invitation: OrganizationInvitation;
179
+ member: null;
180
+ }>>;
181
+ /** Withdraw an invitation that was sent. Rejecting one you received is `rejectInvitation`. */
182
+ cancelInvitation(params: {
183
+ invitationId: string;
184
+ }): Promise<MotherbaseResponse<OrganizationInvitation>>;
185
+ /** An invitation addressed to the signed-in user, with what an accept screen needs to show. */
186
+ getInvitation(params: {
187
+ id: string;
188
+ }): Promise<MotherbaseResponse<OrganizationInvitation & {
189
+ organizationName: string;
190
+ organizationSlug: string;
191
+ inviterEmail: string;
192
+ }>>;
193
+ /** Invitations an organization has sent. */
194
+ listInvitations(params?: OrganizationTarget): Promise<MotherbaseResponse<OrganizationInvitation[]>>;
195
+ /** Pending invitations addressed to the signed-in user, across organizations. */
196
+ listUserInvitations(): Promise<MotherbaseResponse<OrganizationInvitation[]>>;
197
+ createTeam(params: {
198
+ name: string;
199
+ } & OrganizationTarget): Promise<MotherbaseResponse<Team>>;
200
+ updateTeam(params: {
201
+ teamId: string;
202
+ data: Partial<Pick<Team, 'name'>>;
203
+ }): Promise<MotherbaseResponse<Team>>;
204
+ removeTeam(params: {
205
+ teamId: string;
206
+ } & OrganizationTarget): Promise<MotherbaseResponse<{
207
+ message: string;
208
+ }>>;
209
+ /** Teams of an organization. */
210
+ listTeams(params?: OrganizationTarget): Promise<MotherbaseResponse<Team[]>>;
211
+ /** `teamId: null` clears the active team. */
212
+ setActiveTeam(params: {
213
+ teamId: string | null;
214
+ }): Promise<MotherbaseResponse<Team | null>>;
215
+ /** Teams the signed-in user is in. */
216
+ listUserTeams(): Promise<MotherbaseResponse<Team[]>>;
217
+ /** Members of a team. Without `teamId`, the active team. */
218
+ listTeamMembers(params?: {
219
+ teamId?: string;
220
+ }): Promise<MotherbaseResponse<TeamMember[]>>;
221
+ /** Add an organization member to a team. */
222
+ addTeamMember(params: {
223
+ teamId: string;
224
+ userId: string;
225
+ } & OrganizationTarget): Promise<MotherbaseResponse<TeamMember>>;
226
+ removeTeamMember(params: {
227
+ teamId: string;
228
+ userId: string;
229
+ } & OrganizationTarget): Promise<MotherbaseResponse<{
230
+ message: string;
231
+ }>>;
232
+ }
233
+ export {};
234
+ //# sourceMappingURL=organization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organization.d.ts","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,Y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kB,GAC9D,OAAO,CAAC,kBAAkB,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAGpD"}
@@ -0,0 +1,157 @@
1
+ import { pluginGet, pluginPost } from './plugin-endpoint.js';
2
+ const R = {
3
+ create: '/api/auth/organization/create',
4
+ update: '/api/auth/organization/update',
5
+ delete: '/api/auth/organization/delete',
6
+ list: '/api/auth/organization/list',
7
+ getFull: '/api/auth/organization/get-full-organization',
8
+ setActive: '/api/auth/organization/set-active',
9
+ checkSlug: '/api/auth/organization/check-slug',
10
+ leave: '/api/auth/organization/leave',
11
+ listMembers: '/api/auth/organization/list-members',
12
+ getActiveMember: '/api/auth/organization/get-active-member',
13
+ getActiveMemberRole: '/api/auth/organization/get-active-member-role',
14
+ removeMember: '/api/auth/organization/remove-member',
15
+ updateMemberRole: '/api/auth/organization/update-member-role',
16
+ hasPermission: '/api/auth/organization/has-permission',
17
+ inviteMember: '/api/auth/organization/invite-member',
18
+ acceptInvitation: '/api/auth/organization/accept-invitation',
19
+ rejectInvitation: '/api/auth/organization/reject-invitation',
20
+ cancelInvitation: '/api/auth/organization/cancel-invitation',
21
+ getInvitation: '/api/auth/organization/get-invitation',
22
+ listInvitations: '/api/auth/organization/list-invitations',
23
+ listUserInvitations: '/api/auth/organization/list-user-invitations',
24
+ createTeam: '/api/auth/organization/create-team',
25
+ updateTeam: '/api/auth/organization/update-team',
26
+ removeTeam: '/api/auth/organization/remove-team',
27
+ listTeams: '/api/auth/organization/list-teams',
28
+ setActiveTeam: '/api/auth/organization/set-active-team',
29
+ listUserTeams: '/api/auth/organization/list-user-teams',
30
+ listTeamMembers: '/api/auth/organization/list-team-members',
31
+ addTeamMember: '/api/auth/organization/add-team-member',
32
+ removeTeamMember: '/api/auth/organization/remove-team-member',
33
+ };
34
+ export class OrganizationClient {
35
+ constructor(http) {
36
+ this.http = http;
37
+ }
38
+ // Organizations
39
+ /** Create an organization. The caller becomes its owner, and it becomes active unless told otherwise. */
40
+ create(params) {
41
+ return pluginPost(this.http, R.create, params);
42
+ }
43
+ update(params) {
44
+ return pluginPost(this.http, R.update, params);
45
+ }
46
+ delete(params) {
47
+ return pluginPost(this.http, R.delete, params);
48
+ }
49
+ /** Organizations the signed-in user belongs to. */
50
+ list() {
51
+ return pluginGet(this.http, R.list);
52
+ }
53
+ /**
54
+ * One organization with its members, invitations and teams. With no
55
+ * parameters, the active organization; `null` when there is none.
56
+ */
57
+ getFullOrganization(params = {}) {
58
+ return pluginGet(this.http, R.getFull, params);
59
+ }
60
+ /**
61
+ * Make an organization the session's active one, which every call taking an
62
+ * optional `organizationId` then defaults to. `organizationId: null` clears it.
63
+ */
64
+ setActive(params) {
65
+ return pluginPost(this.http, R.setActive, params);
66
+ }
67
+ /** Whether a slug is free. A taken slug is an error, as the server reports it. */
68
+ checkSlug(params) {
69
+ return pluginPost(this.http, R.checkSlug, params);
70
+ }
71
+ leave(params) {
72
+ return pluginPost(this.http, R.leave, params);
73
+ }
74
+ // Members
75
+ listMembers(params = {}) {
76
+ return pluginGet(this.http, R.listMembers, params);
77
+ }
78
+ /** The signed-in user's membership in the active organization. */
79
+ getActiveMember() {
80
+ return pluginGet(this.http, R.getActiveMember);
81
+ }
82
+ /** A member's role. Without `userId`, the signed-in user's. */
83
+ getActiveMemberRole(params = {}) {
84
+ return pluginGet(this.http, R.getActiveMemberRole, params);
85
+ }
86
+ removeMember(params) {
87
+ return pluginPost(this.http, R.removeMember, params);
88
+ }
89
+ updateMemberRole(params) {
90
+ return pluginPost(this.http, R.updateMemberRole, params);
91
+ }
92
+ /** Whether the signed-in user's role grants every listed action. */
93
+ hasPermission(params) {
94
+ return pluginPost(this.http, R.hasPermission, params);
95
+ }
96
+ // Invitations
97
+ /** Invite by email. The project's invitation email carries the invitation id for `acceptInvitation`. */
98
+ inviteMember(params) {
99
+ return pluginPost(this.http, R.inviteMember, params);
100
+ }
101
+ acceptInvitation(params) {
102
+ return pluginPost(this.http, R.acceptInvitation, params);
103
+ }
104
+ rejectInvitation(params) {
105
+ return pluginPost(this.http, R.rejectInvitation, params);
106
+ }
107
+ /** Withdraw an invitation that was sent. Rejecting one you received is `rejectInvitation`. */
108
+ cancelInvitation(params) {
109
+ return pluginPost(this.http, R.cancelInvitation, params);
110
+ }
111
+ /** An invitation addressed to the signed-in user, with what an accept screen needs to show. */
112
+ getInvitation(params) {
113
+ return pluginGet(this.http, R.getInvitation, params);
114
+ }
115
+ /** Invitations an organization has sent. */
116
+ listInvitations(params = {}) {
117
+ return pluginGet(this.http, R.listInvitations, params);
118
+ }
119
+ /** Pending invitations addressed to the signed-in user, across organizations. */
120
+ listUserInvitations() {
121
+ return pluginGet(this.http, R.listUserInvitations);
122
+ }
123
+ // Teams (require "Teams inside organizations")
124
+ createTeam(params) {
125
+ return pluginPost(this.http, R.createTeam, params);
126
+ }
127
+ updateTeam(params) {
128
+ return pluginPost(this.http, R.updateTeam, params);
129
+ }
130
+ removeTeam(params) {
131
+ return pluginPost(this.http, R.removeTeam, params);
132
+ }
133
+ /** Teams of an organization. */
134
+ listTeams(params = {}) {
135
+ return pluginGet(this.http, R.listTeams, params);
136
+ }
137
+ /** `teamId: null` clears the active team. */
138
+ setActiveTeam(params) {
139
+ return pluginPost(this.http, R.setActiveTeam, params);
140
+ }
141
+ /** Teams the signed-in user is in. */
142
+ listUserTeams() {
143
+ return pluginGet(this.http, R.listUserTeams);
144
+ }
145
+ /** Members of a team. Without `teamId`, the active team. */
146
+ listTeamMembers(params = {}) {
147
+ return pluginGet(this.http, R.listTeamMembers, params);
148
+ }
149
+ /** Add an organization member to a team. */
150
+ addTeamMember(params) {
151
+ return pluginPost(this.http, R.addTeamMember, params);
152
+ }
153
+ removeTeamMember(params) {
154
+ return pluginPost(this.http, R.removeTeamMember, params);
155
+ }
156
+ }
157
+ //# sourceMappingURL=organization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organization.js","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,gBAAgB,CACd,MAA+D;QAE/D,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;CACF"}
@@ -0,0 +1,59 @@
1
+ import type { HttpClient } from './http.js';
2
+ import type { MotherbaseResponse, User } from './types.js';
3
+ /**
4
+ * `client.auth.passkey`: the signed-in user's passkeys (Better Auth's passkey
5
+ * plugin). Signing in with one is `client.auth.signInWithPasskey()`.
6
+ *
7
+ * A passkey here is a first factor: it signs the user in on its own. supabase-js
8
+ * only knows WebAuthn as a second factor (`mfa.enroll({ factorType: 'webauthn' })`),
9
+ * so this is a separate namespace rather than a `mfa` factor that would sign in
10
+ * where supabase-js code expects a step-up.
11
+ *
12
+ * The browser ceremony uses WebAuthn's JSON methods
13
+ * (`PublicKeyCredential.parseCreationOptionsFromJSON` and `toJSON()`), so there
14
+ * is no encoding dependency. A runtime without them (React Native, Node, an old
15
+ * browser) gets an error result, not a crash.
16
+ */
17
+ export interface Passkey {
18
+ id: string;
19
+ name?: string | null;
20
+ userId: string;
21
+ credentialID: string;
22
+ deviceType: 'singleDevice' | 'multiDevice';
23
+ /** Synced by the platform (iCloud Keychain, Google Password Manager). */
24
+ backedUp: boolean;
25
+ transports?: string;
26
+ aaguid?: string | null;
27
+ createdAt: string;
28
+ }
29
+ export declare class PasskeyClient {
30
+ private readonly http;
31
+ constructor(http: HttpClient);
32
+ /** Create a passkey on this device for the signed-in user. Prompts the browser's passkey UI. */
33
+ register(params?: {
34
+ name?: string;
35
+ authenticatorAttachment?: 'platform' | 'cross-platform';
36
+ }): Promise<MotherbaseResponse<Passkey>>;
37
+ list(): Promise<MotherbaseResponse<Passkey[]>>;
38
+ /** Rename a passkey. */
39
+ update(params: {
40
+ id: string;
41
+ name: string;
42
+ }): Promise<MotherbaseResponse<{
43
+ passkey: Passkey;
44
+ }>>;
45
+ delete(params: {
46
+ id: string;
47
+ }): Promise<MotherbaseResponse<{
48
+ status: boolean;
49
+ }>>;
50
+ }
51
+ /**
52
+ * The sign-in half of the ceremony, for `AuthClient.signInWithPasskey`, which
53
+ * owns persisting the session. Resolves with the Better Auth session token.
54
+ */
55
+ export declare function authenticateWithPasskey(http: HttpClient): Promise<MotherbaseResponse<{
56
+ token: string;
57
+ user: User;
58
+ }>>;
59
+ //# sourceMappingURL=passkey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passkey.d.ts","sourceRoot":"","sources":["../src/passkey.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,cAAc,GAAG,aAAa,CAAC;IAC3C,yEAAyE;IACzE,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAiBD,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C,gGAAgG;IAC1F,QAAQ,CACZ,MAAM,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,uBAAuB,CAAC,EAAE,UAAU,GAAG,gBAAgB,CAAA;KAAO,GACtF,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAyBvC,IAAI,IAAI,OAAO,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC,CAA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