@koolbase/core 12.44.0 → 12.45.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/cjs/app-admin.d.ts +55 -0
- package/dist/cjs/app-admin.js +107 -0
- package/dist/cjs/auth-errors.d.ts +32 -0
- package/dist/cjs/auth-errors.js +69 -0
- package/dist/cjs/auth.d.ts +8 -0
- package/dist/cjs/auth.js +61 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/types.d.ts +39 -0
- package/dist/esm/app-admin.d.ts +55 -0
- package/dist/esm/app-admin.js +103 -0
- package/dist/esm/auth-errors.d.ts +32 -0
- package/dist/esm/auth-errors.js +61 -0
- package/dist/esm/auth.d.ts +8 -0
- package/dist/esm/auth.js +62 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/types.d.ts +39 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { KoolbaseAssignableRole, KoolbaseMember, KoolbaseMemberPage, KoolbaseMemberRoles } from './types.js';
|
|
2
|
+
type AdminRequest = (path: string, options?: {
|
|
3
|
+
method?: string;
|
|
4
|
+
body?: unknown;
|
|
5
|
+
}) => Promise<any>;
|
|
6
|
+
/**
|
|
7
|
+
* Managing the app's people from inside the app, for its own admins.
|
|
8
|
+
*
|
|
9
|
+
* Only a signed-in person whose `app_admin` claim is true may use these; the
|
|
10
|
+
* project owner gives that claim in the dashboard. Everyone else gets
|
|
11
|
+
* `NotAppAdminError`. The server checks on every request, so taking the claim
|
|
12
|
+
* away takes effect at once.
|
|
13
|
+
*
|
|
14
|
+
* When the admin has two-step sign-in on, disabling, enabling and changing
|
|
15
|
+
* roles need it confirmed in the last ten minutes: catch
|
|
16
|
+
* `RecentMfaRequiredError`, call `stepUpMfa`, and try again.
|
|
17
|
+
*
|
|
18
|
+
* Reached through `Koolbase.auth.admin`; not built by apps.
|
|
19
|
+
*/
|
|
20
|
+
export declare class KoolbaseAppAdmin {
|
|
21
|
+
private readonly request;
|
|
22
|
+
constructor(request: AdminRequest);
|
|
23
|
+
/** The app's people, newest first. `query` matches email or name. */
|
|
24
|
+
members(options?: {
|
|
25
|
+
query?: string;
|
|
26
|
+
limit?: number;
|
|
27
|
+
offset?: number;
|
|
28
|
+
}): Promise<KoolbaseMemberPage>;
|
|
29
|
+
/** The roles admins may give, for a role picker. */
|
|
30
|
+
roles(): Promise<KoolbaseAssignableRole[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Invite someone by email. They get an email to set up their account, and
|
|
33
|
+
* `roles` are given at once. Throws `MemberExistsError` when the email
|
|
34
|
+
* already has an account.
|
|
35
|
+
*/
|
|
36
|
+
invite(params: {
|
|
37
|
+
email: string;
|
|
38
|
+
fullName?: string;
|
|
39
|
+
roles?: Record<string, unknown>;
|
|
40
|
+
}): Promise<KoolbaseMember>;
|
|
41
|
+
/** Stop someone signing in, and sign them out everywhere. */
|
|
42
|
+
disable(userId: string): Promise<void>;
|
|
43
|
+
/** Let a disabled person sign in again. */
|
|
44
|
+
enable(userId: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Change someone's roles. Only the keys given change; `null` removes a
|
|
47
|
+
* role. Pass the member's `version` as `expectedVersion`: when someone else
|
|
48
|
+
* changed them since, this throws `ClaimsVersionConflictError` carrying the
|
|
49
|
+
* new version, and nothing is changed.
|
|
50
|
+
*/
|
|
51
|
+
setRoles(userId: string, roles: Record<string, unknown>, options: {
|
|
52
|
+
expectedVersion: number;
|
|
53
|
+
}): Promise<KoolbaseMemberRoles>;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KoolbaseAppAdmin = void 0;
|
|
4
|
+
function mapMember(r) {
|
|
5
|
+
return {
|
|
6
|
+
id: String(r.id),
|
|
7
|
+
email: String(r.email ?? ''),
|
|
8
|
+
fullName: r.full_name ?? undefined,
|
|
9
|
+
avatarUrl: r.avatar_url ?? undefined,
|
|
10
|
+
status: r.status ?? 'active',
|
|
11
|
+
isAdmin: Boolean(r.is_admin),
|
|
12
|
+
roles: r.roles ?? {},
|
|
13
|
+
version: Number(r.version ?? 0),
|
|
14
|
+
joinedAt: String(r.joined_at),
|
|
15
|
+
lastSeenAt: r.last_seen_at ?? undefined,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Managing the app's people from inside the app, for its own admins.
|
|
20
|
+
*
|
|
21
|
+
* Only a signed-in person whose `app_admin` claim is true may use these; the
|
|
22
|
+
* project owner gives that claim in the dashboard. Everyone else gets
|
|
23
|
+
* `NotAppAdminError`. The server checks on every request, so taking the claim
|
|
24
|
+
* away takes effect at once.
|
|
25
|
+
*
|
|
26
|
+
* When the admin has two-step sign-in on, disabling, enabling and changing
|
|
27
|
+
* roles need it confirmed in the last ten minutes: catch
|
|
28
|
+
* `RecentMfaRequiredError`, call `stepUpMfa`, and try again.
|
|
29
|
+
*
|
|
30
|
+
* Reached through `Koolbase.auth.admin`; not built by apps.
|
|
31
|
+
*/
|
|
32
|
+
class KoolbaseAppAdmin {
|
|
33
|
+
constructor(request) {
|
|
34
|
+
this.request = request;
|
|
35
|
+
}
|
|
36
|
+
/** The app's people, newest first. `query` matches email or name. */
|
|
37
|
+
async members(options) {
|
|
38
|
+
const params = new URLSearchParams();
|
|
39
|
+
if (options?.query)
|
|
40
|
+
params.set('q', options.query);
|
|
41
|
+
if (options?.limit !== undefined)
|
|
42
|
+
params.set('limit', String(options.limit));
|
|
43
|
+
if (options?.offset !== undefined)
|
|
44
|
+
params.set('offset', String(options.offset));
|
|
45
|
+
const qs = params.toString();
|
|
46
|
+
const body = await this.request(`/v1/sdk/admin/members${qs ? `?${qs}` : ''}`);
|
|
47
|
+
return {
|
|
48
|
+
members: (body.members ?? []).map(mapMember),
|
|
49
|
+
total: Number(body.total ?? 0),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** The roles admins may give, for a role picker. */
|
|
53
|
+
async roles() {
|
|
54
|
+
const body = await this.request('/v1/sdk/admin/roles');
|
|
55
|
+
return (body.roles ?? []).map((r) => ({
|
|
56
|
+
key: String(r.key),
|
|
57
|
+
valueType: String(r.value_type ?? 'string'),
|
|
58
|
+
allowedValues: (r.allowed_values ?? []).map(String),
|
|
59
|
+
description: r.description ?? undefined,
|
|
60
|
+
holders: Number(r.holders ?? 0),
|
|
61
|
+
values: r.values ?? {},
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Invite someone by email. They get an email to set up their account, and
|
|
66
|
+
* `roles` are given at once. Throws `MemberExistsError` when the email
|
|
67
|
+
* already has an account.
|
|
68
|
+
*/
|
|
69
|
+
async invite(params) {
|
|
70
|
+
const body = await this.request('/v1/sdk/admin/members/invite', {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
body: {
|
|
73
|
+
email: params.email,
|
|
74
|
+
...(params.fullName !== undefined ? { full_name: params.fullName } : {}),
|
|
75
|
+
...(params.roles && Object.keys(params.roles).length ? { roles: params.roles } : {}),
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
return mapMember(body);
|
|
79
|
+
}
|
|
80
|
+
/** Stop someone signing in, and sign them out everywhere. */
|
|
81
|
+
async disable(userId) {
|
|
82
|
+
await this.request(`/v1/sdk/admin/members/${encodeURIComponent(userId)}/disable`, {
|
|
83
|
+
method: 'POST',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** Let a disabled person sign in again. */
|
|
87
|
+
async enable(userId) {
|
|
88
|
+
await this.request(`/v1/sdk/admin/members/${encodeURIComponent(userId)}/enable`, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Change someone's roles. Only the keys given change; `null` removes a
|
|
94
|
+
* role. Pass the member's `version` as `expectedVersion`: when someone else
|
|
95
|
+
* changed them since, this throws `ClaimsVersionConflictError` carrying the
|
|
96
|
+
* new version, and nothing is changed.
|
|
97
|
+
*/
|
|
98
|
+
async setRoles(userId, roles, options) {
|
|
99
|
+
const body = await this.request(`/v1/sdk/admin/members/${encodeURIComponent(userId)}/roles`, { method: 'PUT', body: { roles, expected_version: options.expectedVersion } });
|
|
100
|
+
return {
|
|
101
|
+
id: String(body.id),
|
|
102
|
+
roles: body.roles ?? {},
|
|
103
|
+
version: Number(body.version ?? 0),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.KoolbaseAppAdmin = KoolbaseAppAdmin;
|
|
@@ -299,3 +299,35 @@ export declare class MfaEnrollmentNotFoundError extends KoolbaseAuthError {
|
|
|
299
299
|
export declare class MfaNotEnabledError extends KoolbaseAuthError {
|
|
300
300
|
constructor();
|
|
301
301
|
}
|
|
302
|
+
/** The signed-in person is not an app admin. The project owner gives the `app_admin` claim in the dashboard. */
|
|
303
|
+
export declare class NotAppAdminError extends KoolbaseAuthError {
|
|
304
|
+
constructor();
|
|
305
|
+
}
|
|
306
|
+
/** An admin tried to disable themselves or change their own roles. */
|
|
307
|
+
export declare class AppAdminSelfError extends KoolbaseAuthError {
|
|
308
|
+
constructor();
|
|
309
|
+
}
|
|
310
|
+
/** The person is an app admin too; only the project owner can change them. */
|
|
311
|
+
export declare class AppAdminTargetIsAdminError extends KoolbaseAuthError {
|
|
312
|
+
constructor();
|
|
313
|
+
}
|
|
314
|
+
/** The project has not let app admins give this role. */
|
|
315
|
+
export declare class RoleNotAssignableError extends KoolbaseAuthError {
|
|
316
|
+
constructor(message?: string);
|
|
317
|
+
}
|
|
318
|
+
/** The role exists, but not with this value. */
|
|
319
|
+
export declare class RoleValueNotAllowedError extends KoolbaseAuthError {
|
|
320
|
+
constructor(message?: string);
|
|
321
|
+
}
|
|
322
|
+
/** The invited email already has an account in this app. */
|
|
323
|
+
export declare class MemberExistsError extends KoolbaseAuthError {
|
|
324
|
+
constructor();
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The person's roles changed since they were read; nothing was changed. Read
|
|
328
|
+
* them again, or retry with `currentVersion`.
|
|
329
|
+
*/
|
|
330
|
+
export declare class ClaimsVersionConflictError extends KoolbaseAuthError {
|
|
331
|
+
readonly currentVersion: number | null;
|
|
332
|
+
constructor(currentVersion: number | null);
|
|
333
|
+
}
|
package/dist/cjs/auth-errors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MfaNotEnabledError = exports.MfaEnrollmentNotFoundError = exports.MfaAlreadyEnabledError = exports.RecentMfaRequiredError = exports.RecentAuthRequiredError = exports.MfaRequiredError = exports.GoogleEmailRequiredError = exports.InvalidGoogleTokenError = exports.MalformedSessionResponseError = exports.ProviderIdentityAlreadyLinkedError = exports.IdentityNotFoundError = exports.InsufficientScopeError = exports.HideRequiresVerificationError = exports.LastCredentialError = exports.InsufficientAuthorityError = exports.SessionRequiredError = exports.UnsupportedOAuthProviderError = exports.OAuthOnlyAccountError = exports.AccountExistsError = exports.CurrentPasswordIncorrectError = exports.TokenAlreadyUsedError = exports.TokenExpiredError = exports.SignupsDisabledError = exports.ContactNotVerifiedError = exports.GoogleSignInNotConfiguredError = exports.OAuthEmailConflictError = exports.AppleEmailRequiredError = exports.InvalidAppleTokenError = exports.AppleSignInNotConfiguredError = exports.SmsConfigMissingError = exports.PhoneAlreadyLinkedError = exports.OtpRateLimitError = exports.OtpMaxAttemptsError = exports.OtpInvalidError = exports.OtpExpiredError = exports.EmailCodeDisabledError = exports.InvalidPhoneNumberError = exports.NetworkError = exports.VerificationResendDailyCapError = exports.VerificationResendCooldownError = exports.RateLimitError = exports.UnlockTokenInvalidError = exports.AccountLockedError = exports.TokenRevokedError = exports.SessionExpiredError = exports.WeakPasswordError = exports.UserDisabledError = exports.EmailAlreadyInUseError = exports.InvalidCredentialsError = exports.KoolbaseAuthError = void 0;
|
|
4
|
+
exports.ClaimsVersionConflictError = exports.MemberExistsError = exports.RoleValueNotAllowedError = exports.RoleNotAssignableError = exports.AppAdminTargetIsAdminError = exports.AppAdminSelfError = exports.NotAppAdminError = void 0;
|
|
4
5
|
exports.retryAfterOf = retryAfterOf;
|
|
5
6
|
const errors_js_1 = require("./errors.js");
|
|
6
7
|
/**
|
|
@@ -556,3 +557,71 @@ class MfaNotEnabledError extends KoolbaseAuthError {
|
|
|
556
557
|
}
|
|
557
558
|
}
|
|
558
559
|
exports.MfaNotEnabledError = MfaNotEnabledError;
|
|
560
|
+
// ─── In-app admin ──────────────────────────────────────────────────────────
|
|
561
|
+
/** The signed-in person is not an app admin. The project owner gives the `app_admin` claim in the dashboard. */
|
|
562
|
+
class NotAppAdminError extends KoolbaseAuthError {
|
|
563
|
+
constructor() {
|
|
564
|
+
super('Only app admins can do this', 'app_admin_required');
|
|
565
|
+
this.name = 'NotAppAdminError';
|
|
566
|
+
Object.setPrototypeOf(this, NotAppAdminError.prototype);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
exports.NotAppAdminError = NotAppAdminError;
|
|
570
|
+
/** An admin tried to disable themselves or change their own roles. */
|
|
571
|
+
class AppAdminSelfError extends KoolbaseAuthError {
|
|
572
|
+
constructor() {
|
|
573
|
+
super('You cannot change your own account here', 'app_admin_self');
|
|
574
|
+
this.name = 'AppAdminSelfError';
|
|
575
|
+
Object.setPrototypeOf(this, AppAdminSelfError.prototype);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
exports.AppAdminSelfError = AppAdminSelfError;
|
|
579
|
+
/** The person is an app admin too; only the project owner can change them. */
|
|
580
|
+
class AppAdminTargetIsAdminError extends KoolbaseAuthError {
|
|
581
|
+
constructor() {
|
|
582
|
+
super('Another app admin can only be changed by the project owner', 'app_admin_target_is_admin');
|
|
583
|
+
this.name = 'AppAdminTargetIsAdminError';
|
|
584
|
+
Object.setPrototypeOf(this, AppAdminTargetIsAdminError.prototype);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
exports.AppAdminTargetIsAdminError = AppAdminTargetIsAdminError;
|
|
588
|
+
/** The project has not let app admins give this role. */
|
|
589
|
+
class RoleNotAssignableError extends KoolbaseAuthError {
|
|
590
|
+
constructor(message) {
|
|
591
|
+
super(message ?? 'App admins cannot give this role', 'role_not_assignable');
|
|
592
|
+
this.name = 'RoleNotAssignableError';
|
|
593
|
+
Object.setPrototypeOf(this, RoleNotAssignableError.prototype);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
exports.RoleNotAssignableError = RoleNotAssignableError;
|
|
597
|
+
/** The role exists, but not with this value. */
|
|
598
|
+
class RoleValueNotAllowedError extends KoolbaseAuthError {
|
|
599
|
+
constructor(message) {
|
|
600
|
+
super(message ?? 'That value is not allowed for this role', 'role_value_not_allowed');
|
|
601
|
+
this.name = 'RoleValueNotAllowedError';
|
|
602
|
+
Object.setPrototypeOf(this, RoleValueNotAllowedError.prototype);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
exports.RoleValueNotAllowedError = RoleValueNotAllowedError;
|
|
606
|
+
/** The invited email already has an account in this app. */
|
|
607
|
+
class MemberExistsError extends KoolbaseAuthError {
|
|
608
|
+
constructor() {
|
|
609
|
+
super('Someone with this email is already in the app', 'member_exists');
|
|
610
|
+
this.name = 'MemberExistsError';
|
|
611
|
+
Object.setPrototypeOf(this, MemberExistsError.prototype);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
exports.MemberExistsError = MemberExistsError;
|
|
615
|
+
/**
|
|
616
|
+
* The person's roles changed since they were read; nothing was changed. Read
|
|
617
|
+
* them again, or retry with `currentVersion`.
|
|
618
|
+
*/
|
|
619
|
+
class ClaimsVersionConflictError extends KoolbaseAuthError {
|
|
620
|
+
constructor(currentVersion) {
|
|
621
|
+
super("This person's roles changed since you opened them", 'claims_version_conflict');
|
|
622
|
+
this.currentVersion = currentVersion;
|
|
623
|
+
this.name = 'ClaimsVersionConflictError';
|
|
624
|
+
Object.setPrototypeOf(this, ClaimsVersionConflictError.prototype);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
exports.ClaimsVersionConflictError = ClaimsVersionConflictError;
|
package/dist/cjs/auth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, KoolbaseAuditPage, KoolbaseSessionInfo, ResendVerificationResult, SendOtpParams, SignUpResult, SignInWithAppleParams, VerifyOtpParams } from './types.js';
|
|
2
|
+
import { KoolbaseAppAdmin } from './app-admin.js';
|
|
2
3
|
import type { KoolbaseAvatarFile, SignInWithGoogleParams, SignOutReason } from './types.js';
|
|
3
4
|
export declare class KoolbaseAuth {
|
|
4
5
|
private config;
|
|
@@ -340,6 +341,13 @@ export declare class KoolbaseAuth {
|
|
|
340
341
|
}): Promise<KoolbaseAuditPage>;
|
|
341
342
|
unlock(token: string): Promise<void>;
|
|
342
343
|
get currentUser(): KoolbaseUser | null;
|
|
344
|
+
private _admin?;
|
|
345
|
+
/**
|
|
346
|
+
* Managing the app's people, for the app's own admins (the `app_admin`
|
|
347
|
+
* claim). See {@link KoolbaseAppAdmin}.
|
|
348
|
+
*/
|
|
349
|
+
get admin(): KoolbaseAppAdmin;
|
|
350
|
+
private adminRequest;
|
|
343
351
|
get accessToken(): string | null;
|
|
344
352
|
/**
|
|
345
353
|
* Currently-valid access token for data-plane requests, refreshing
|
package/dist/cjs/auth.js
CHANGED
|
@@ -5,6 +5,7 @@ const errors_1 = require("./errors");
|
|
|
5
5
|
const network_js_1 = require("./network.js");
|
|
6
6
|
const types_js_1 = require("./types.js");
|
|
7
7
|
const auth_errors_js_1 = require("./auth-errors.js");
|
|
8
|
+
const app_admin_js_1 = require("./app-admin.js");
|
|
8
9
|
const errors_js_1 = require("./errors.js");
|
|
9
10
|
const platform_js_1 = require("./platform.js");
|
|
10
11
|
const device_metadata_js_1 = require("./device-metadata.js");
|
|
@@ -1002,6 +1003,66 @@ class KoolbaseAuth {
|
|
|
1002
1003
|
get currentUser() {
|
|
1003
1004
|
return this.session?.user ?? null;
|
|
1004
1005
|
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Managing the app's people, for the app's own admins (the `app_admin`
|
|
1008
|
+
* claim). See {@link KoolbaseAppAdmin}.
|
|
1009
|
+
*/
|
|
1010
|
+
get admin() {
|
|
1011
|
+
if (!this._admin) {
|
|
1012
|
+
this._admin = new app_admin_js_1.KoolbaseAppAdmin((path, options) => this.adminRequest(path, options));
|
|
1013
|
+
}
|
|
1014
|
+
return this._admin;
|
|
1015
|
+
}
|
|
1016
|
+
async adminRequest(path, options = {}) {
|
|
1017
|
+
const res = await this.authedRequest(path, options);
|
|
1018
|
+
if (res.ok)
|
|
1019
|
+
return res.json().catch(() => ({}));
|
|
1020
|
+
let body = {};
|
|
1021
|
+
try {
|
|
1022
|
+
body = await res.json();
|
|
1023
|
+
}
|
|
1024
|
+
catch {
|
|
1025
|
+
// ignore
|
|
1026
|
+
}
|
|
1027
|
+
const code = body.code ?? '';
|
|
1028
|
+
const msg = body.error ?? '';
|
|
1029
|
+
// The admin routes' own codes first. Their plain failures (a member not
|
|
1030
|
+
// found, a conflict, a refusal) keep the server's words: the general
|
|
1031
|
+
// status fallback would call a 409 an email in use and a 403 a disabled
|
|
1032
|
+
// account, neither of which an admin route means.
|
|
1033
|
+
switch (code) {
|
|
1034
|
+
// Never sent by these routes; mapped so every parser here handles the
|
|
1035
|
+
// challenge the same way (mfa.test checks each switch).
|
|
1036
|
+
case 'mfa_required':
|
|
1037
|
+
throw this.mfaRequired(body);
|
|
1038
|
+
case 'app_admin_required':
|
|
1039
|
+
throw new auth_errors_js_1.NotAppAdminError();
|
|
1040
|
+
case 'app_admin_self':
|
|
1041
|
+
throw new auth_errors_js_1.AppAdminSelfError();
|
|
1042
|
+
case 'app_admin_target_is_admin':
|
|
1043
|
+
throw new auth_errors_js_1.AppAdminTargetIsAdminError();
|
|
1044
|
+
case 'role_not_assignable':
|
|
1045
|
+
throw new auth_errors_js_1.RoleNotAssignableError(msg || undefined);
|
|
1046
|
+
case 'role_value_not_allowed':
|
|
1047
|
+
throw new auth_errors_js_1.RoleValueNotAllowedError(msg || undefined);
|
|
1048
|
+
case 'member_exists':
|
|
1049
|
+
throw new auth_errors_js_1.MemberExistsError();
|
|
1050
|
+
case 'claims_version_conflict':
|
|
1051
|
+
throw new auth_errors_js_1.ClaimsVersionConflictError(typeof body.version === 'number' ? body.version : null);
|
|
1052
|
+
case 'not_found':
|
|
1053
|
+
case 'conflict':
|
|
1054
|
+
case 'permission_denied':
|
|
1055
|
+
case 'validation_error':
|
|
1056
|
+
throw new auth_errors_js_1.KoolbaseAuthError(msg || 'The request was refused.', code);
|
|
1057
|
+
}
|
|
1058
|
+
// The body is read; hand the general parser what it read.
|
|
1059
|
+
return this.throwTypedError({
|
|
1060
|
+
ok: false,
|
|
1061
|
+
status: res.status,
|
|
1062
|
+
headers: res.headers,
|
|
1063
|
+
json: async () => body,
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1005
1066
|
get accessToken() {
|
|
1006
1067
|
return this.session?.accessToken ?? null;
|
|
1007
1068
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './auth-errors.js';
|
|
|
10
10
|
export * from './database-errors.js';
|
|
11
11
|
export * from './storage-errors.js';
|
|
12
12
|
export { KoolbaseAuth } from './auth.js';
|
|
13
|
+
export { KoolbaseAppAdmin } from './app-admin.js';
|
|
13
14
|
export { KoolbaseDatabase } from './database.js';
|
|
14
15
|
export { KoolbaseCollectionController, collectionQueryKey, initialCollectionState, } from './collection-controller.js';
|
|
15
16
|
export type { CollectionQuery, CollectionState, CollectionStatus } from './collection-controller.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.memoryPlatform = exports.getPlatform = exports.setPlatform = exports.RestoreResult = exports.koolbaseSdkVersion = exports.getOrCreateDeviceId = exports.KoolbaseMessaging = exports.isPending = exports.isFiscalized = exports.decodeFiscalResponse = exports.KoolbaseFiscalError = exports.KoolbaseFiscal = exports.disabledAnalytics = exports.KoolbaseAnalytics = exports.initialUploadQueueState = exports.KoolbaseUploadQueue = exports.initialFileState = exports.KoolbaseFileController = exports.filesQueryKey = exports.initialFilesState = exports.KoolbaseFilesController = exports.KoolbaseUploadTask = exports.KoolbaseStorage = exports.KoolbaseConnectivity = exports.KoolbaseRealtime = exports.KoolbaseFunctions = exports.KoolbaseFlags = exports.initialRecordState = exports.KoolbaseRecordController = exports.initialCollectionState = exports.collectionQueryKey = exports.KoolbaseCollectionController = exports.KoolbaseDatabase = exports.KoolbaseAuth = void 0;
|
|
22
|
+
exports.memoryPlatform = exports.getPlatform = exports.setPlatform = exports.RestoreResult = exports.koolbaseSdkVersion = exports.getOrCreateDeviceId = exports.KoolbaseMessaging = exports.isPending = exports.isFiscalized = exports.decodeFiscalResponse = exports.KoolbaseFiscalError = exports.KoolbaseFiscal = exports.disabledAnalytics = exports.KoolbaseAnalytics = exports.initialUploadQueueState = exports.KoolbaseUploadQueue = exports.initialFileState = exports.KoolbaseFileController = exports.filesQueryKey = exports.initialFilesState = exports.KoolbaseFilesController = exports.KoolbaseUploadTask = exports.KoolbaseStorage = exports.KoolbaseConnectivity = exports.KoolbaseRealtime = exports.KoolbaseFunctions = exports.KoolbaseFlags = exports.initialRecordState = exports.KoolbaseRecordController = exports.initialCollectionState = exports.collectionQueryKey = exports.KoolbaseCollectionController = exports.KoolbaseDatabase = exports.KoolbaseAppAdmin = exports.KoolbaseAuth = void 0;
|
|
23
23
|
__exportStar(require("./types.js"), exports);
|
|
24
24
|
__exportStar(require("./errors.js"), exports);
|
|
25
25
|
__exportStar(require("./network.js"), exports);
|
|
@@ -33,6 +33,8 @@ __exportStar(require("./database-errors.js"), exports);
|
|
|
33
33
|
__exportStar(require("./storage-errors.js"), exports);
|
|
34
34
|
var auth_js_1 = require("./auth.js");
|
|
35
35
|
Object.defineProperty(exports, "KoolbaseAuth", { enumerable: true, get: function () { return auth_js_1.KoolbaseAuth; } });
|
|
36
|
+
var app_admin_js_1 = require("./app-admin.js");
|
|
37
|
+
Object.defineProperty(exports, "KoolbaseAppAdmin", { enumerable: true, get: function () { return app_admin_js_1.KoolbaseAppAdmin; } });
|
|
36
38
|
var database_js_1 = require("./database.js");
|
|
37
39
|
Object.defineProperty(exports, "KoolbaseDatabase", { enumerable: true, get: function () { return database_js_1.KoolbaseDatabase; } });
|
|
38
40
|
var collection_controller_js_1 = require("./collection-controller.js");
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -170,6 +170,45 @@ export interface KoolbaseAuditPage {
|
|
|
170
170
|
limit: number;
|
|
171
171
|
offset: number;
|
|
172
172
|
}
|
|
173
|
+
/** One person in the app, as an app admin sees them. */
|
|
174
|
+
export interface KoolbaseMember {
|
|
175
|
+
id: string;
|
|
176
|
+
email: string;
|
|
177
|
+
fullName?: string;
|
|
178
|
+
avatarUrl?: string;
|
|
179
|
+
/** `invited` has not signed in yet. */
|
|
180
|
+
status: 'active' | 'invited' | 'disabled';
|
|
181
|
+
/** An app admin: only the project owner can disable them or change their roles. */
|
|
182
|
+
isAdmin: boolean;
|
|
183
|
+
/** The claims the project marked as ones app admins can give. Others are never sent. */
|
|
184
|
+
roles: Record<string, unknown>;
|
|
185
|
+
/** Pass back to `admin.setRoles` as `expectedVersion`. */
|
|
186
|
+
version: number;
|
|
187
|
+
joinedAt: string;
|
|
188
|
+
lastSeenAt?: string;
|
|
189
|
+
}
|
|
190
|
+
/** A page of members, with the total across all pages. */
|
|
191
|
+
export interface KoolbaseMemberPage {
|
|
192
|
+
members: KoolbaseMember[];
|
|
193
|
+
total: number;
|
|
194
|
+
}
|
|
195
|
+
/** A role an app admin may give, with how many people hold it. */
|
|
196
|
+
export interface KoolbaseAssignableRole {
|
|
197
|
+
key: string;
|
|
198
|
+
valueType: string;
|
|
199
|
+
/** The only values allowed, when the project limited them; empty otherwise. */
|
|
200
|
+
allowedValues: string[];
|
|
201
|
+
description?: string;
|
|
202
|
+
holders: number;
|
|
203
|
+
/** For each value, how many people hold it. */
|
|
204
|
+
values: Record<string, number>;
|
|
205
|
+
}
|
|
206
|
+
/** What `admin.setRoles` leaves: the roles now, and the version to pass next time. */
|
|
207
|
+
export interface KoolbaseMemberRoles {
|
|
208
|
+
id: string;
|
|
209
|
+
roles: Record<string, unknown>;
|
|
210
|
+
version: number;
|
|
211
|
+
}
|
|
173
212
|
export interface ResendVerificationResult {
|
|
174
213
|
alreadyVerified: boolean;
|
|
175
214
|
/** When the link in the email stops working. Null when nothing was sent. */
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { KoolbaseAssignableRole, KoolbaseMember, KoolbaseMemberPage, KoolbaseMemberRoles } from './types.js';
|
|
2
|
+
type AdminRequest = (path: string, options?: {
|
|
3
|
+
method?: string;
|
|
4
|
+
body?: unknown;
|
|
5
|
+
}) => Promise<any>;
|
|
6
|
+
/**
|
|
7
|
+
* Managing the app's people from inside the app, for its own admins.
|
|
8
|
+
*
|
|
9
|
+
* Only a signed-in person whose `app_admin` claim is true may use these; the
|
|
10
|
+
* project owner gives that claim in the dashboard. Everyone else gets
|
|
11
|
+
* `NotAppAdminError`. The server checks on every request, so taking the claim
|
|
12
|
+
* away takes effect at once.
|
|
13
|
+
*
|
|
14
|
+
* When the admin has two-step sign-in on, disabling, enabling and changing
|
|
15
|
+
* roles need it confirmed in the last ten minutes: catch
|
|
16
|
+
* `RecentMfaRequiredError`, call `stepUpMfa`, and try again.
|
|
17
|
+
*
|
|
18
|
+
* Reached through `Koolbase.auth.admin`; not built by apps.
|
|
19
|
+
*/
|
|
20
|
+
export declare class KoolbaseAppAdmin {
|
|
21
|
+
private readonly request;
|
|
22
|
+
constructor(request: AdminRequest);
|
|
23
|
+
/** The app's people, newest first. `query` matches email or name. */
|
|
24
|
+
members(options?: {
|
|
25
|
+
query?: string;
|
|
26
|
+
limit?: number;
|
|
27
|
+
offset?: number;
|
|
28
|
+
}): Promise<KoolbaseMemberPage>;
|
|
29
|
+
/** The roles admins may give, for a role picker. */
|
|
30
|
+
roles(): Promise<KoolbaseAssignableRole[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Invite someone by email. They get an email to set up their account, and
|
|
33
|
+
* `roles` are given at once. Throws `MemberExistsError` when the email
|
|
34
|
+
* already has an account.
|
|
35
|
+
*/
|
|
36
|
+
invite(params: {
|
|
37
|
+
email: string;
|
|
38
|
+
fullName?: string;
|
|
39
|
+
roles?: Record<string, unknown>;
|
|
40
|
+
}): Promise<KoolbaseMember>;
|
|
41
|
+
/** Stop someone signing in, and sign them out everywhere. */
|
|
42
|
+
disable(userId: string): Promise<void>;
|
|
43
|
+
/** Let a disabled person sign in again. */
|
|
44
|
+
enable(userId: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Change someone's roles. Only the keys given change; `null` removes a
|
|
47
|
+
* role. Pass the member's `version` as `expectedVersion`: when someone else
|
|
48
|
+
* changed them since, this throws `ClaimsVersionConflictError` carrying the
|
|
49
|
+
* new version, and nothing is changed.
|
|
50
|
+
*/
|
|
51
|
+
setRoles(userId: string, roles: Record<string, unknown>, options: {
|
|
52
|
+
expectedVersion: number;
|
|
53
|
+
}): Promise<KoolbaseMemberRoles>;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function mapMember(r) {
|
|
2
|
+
return {
|
|
3
|
+
id: String(r.id),
|
|
4
|
+
email: String(r.email ?? ''),
|
|
5
|
+
fullName: r.full_name ?? undefined,
|
|
6
|
+
avatarUrl: r.avatar_url ?? undefined,
|
|
7
|
+
status: r.status ?? 'active',
|
|
8
|
+
isAdmin: Boolean(r.is_admin),
|
|
9
|
+
roles: r.roles ?? {},
|
|
10
|
+
version: Number(r.version ?? 0),
|
|
11
|
+
joinedAt: String(r.joined_at),
|
|
12
|
+
lastSeenAt: r.last_seen_at ?? undefined,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Managing the app's people from inside the app, for its own admins.
|
|
17
|
+
*
|
|
18
|
+
* Only a signed-in person whose `app_admin` claim is true may use these; the
|
|
19
|
+
* project owner gives that claim in the dashboard. Everyone else gets
|
|
20
|
+
* `NotAppAdminError`. The server checks on every request, so taking the claim
|
|
21
|
+
* away takes effect at once.
|
|
22
|
+
*
|
|
23
|
+
* When the admin has two-step sign-in on, disabling, enabling and changing
|
|
24
|
+
* roles need it confirmed in the last ten minutes: catch
|
|
25
|
+
* `RecentMfaRequiredError`, call `stepUpMfa`, and try again.
|
|
26
|
+
*
|
|
27
|
+
* Reached through `Koolbase.auth.admin`; not built by apps.
|
|
28
|
+
*/
|
|
29
|
+
export class KoolbaseAppAdmin {
|
|
30
|
+
constructor(request) {
|
|
31
|
+
this.request = request;
|
|
32
|
+
}
|
|
33
|
+
/** The app's people, newest first. `query` matches email or name. */
|
|
34
|
+
async members(options) {
|
|
35
|
+
const params = new URLSearchParams();
|
|
36
|
+
if (options?.query)
|
|
37
|
+
params.set('q', options.query);
|
|
38
|
+
if (options?.limit !== undefined)
|
|
39
|
+
params.set('limit', String(options.limit));
|
|
40
|
+
if (options?.offset !== undefined)
|
|
41
|
+
params.set('offset', String(options.offset));
|
|
42
|
+
const qs = params.toString();
|
|
43
|
+
const body = await this.request(`/v1/sdk/admin/members${qs ? `?${qs}` : ''}`);
|
|
44
|
+
return {
|
|
45
|
+
members: (body.members ?? []).map(mapMember),
|
|
46
|
+
total: Number(body.total ?? 0),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** The roles admins may give, for a role picker. */
|
|
50
|
+
async roles() {
|
|
51
|
+
const body = await this.request('/v1/sdk/admin/roles');
|
|
52
|
+
return (body.roles ?? []).map((r) => ({
|
|
53
|
+
key: String(r.key),
|
|
54
|
+
valueType: String(r.value_type ?? 'string'),
|
|
55
|
+
allowedValues: (r.allowed_values ?? []).map(String),
|
|
56
|
+
description: r.description ?? undefined,
|
|
57
|
+
holders: Number(r.holders ?? 0),
|
|
58
|
+
values: r.values ?? {},
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Invite someone by email. They get an email to set up their account, and
|
|
63
|
+
* `roles` are given at once. Throws `MemberExistsError` when the email
|
|
64
|
+
* already has an account.
|
|
65
|
+
*/
|
|
66
|
+
async invite(params) {
|
|
67
|
+
const body = await this.request('/v1/sdk/admin/members/invite', {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
body: {
|
|
70
|
+
email: params.email,
|
|
71
|
+
...(params.fullName !== undefined ? { full_name: params.fullName } : {}),
|
|
72
|
+
...(params.roles && Object.keys(params.roles).length ? { roles: params.roles } : {}),
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
return mapMember(body);
|
|
76
|
+
}
|
|
77
|
+
/** Stop someone signing in, and sign them out everywhere. */
|
|
78
|
+
async disable(userId) {
|
|
79
|
+
await this.request(`/v1/sdk/admin/members/${encodeURIComponent(userId)}/disable`, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Let a disabled person sign in again. */
|
|
84
|
+
async enable(userId) {
|
|
85
|
+
await this.request(`/v1/sdk/admin/members/${encodeURIComponent(userId)}/enable`, {
|
|
86
|
+
method: 'POST',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Change someone's roles. Only the keys given change; `null` removes a
|
|
91
|
+
* role. Pass the member's `version` as `expectedVersion`: when someone else
|
|
92
|
+
* changed them since, this throws `ClaimsVersionConflictError` carrying the
|
|
93
|
+
* new version, and nothing is changed.
|
|
94
|
+
*/
|
|
95
|
+
async setRoles(userId, roles, options) {
|
|
96
|
+
const body = await this.request(`/v1/sdk/admin/members/${encodeURIComponent(userId)}/roles`, { method: 'PUT', body: { roles, expected_version: options.expectedVersion } });
|
|
97
|
+
return {
|
|
98
|
+
id: String(body.id),
|
|
99
|
+
roles: body.roles ?? {},
|
|
100
|
+
version: Number(body.version ?? 0),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -299,3 +299,35 @@ export declare class MfaEnrollmentNotFoundError extends KoolbaseAuthError {
|
|
|
299
299
|
export declare class MfaNotEnabledError extends KoolbaseAuthError {
|
|
300
300
|
constructor();
|
|
301
301
|
}
|
|
302
|
+
/** The signed-in person is not an app admin. The project owner gives the `app_admin` claim in the dashboard. */
|
|
303
|
+
export declare class NotAppAdminError extends KoolbaseAuthError {
|
|
304
|
+
constructor();
|
|
305
|
+
}
|
|
306
|
+
/** An admin tried to disable themselves or change their own roles. */
|
|
307
|
+
export declare class AppAdminSelfError extends KoolbaseAuthError {
|
|
308
|
+
constructor();
|
|
309
|
+
}
|
|
310
|
+
/** The person is an app admin too; only the project owner can change them. */
|
|
311
|
+
export declare class AppAdminTargetIsAdminError extends KoolbaseAuthError {
|
|
312
|
+
constructor();
|
|
313
|
+
}
|
|
314
|
+
/** The project has not let app admins give this role. */
|
|
315
|
+
export declare class RoleNotAssignableError extends KoolbaseAuthError {
|
|
316
|
+
constructor(message?: string);
|
|
317
|
+
}
|
|
318
|
+
/** The role exists, but not with this value. */
|
|
319
|
+
export declare class RoleValueNotAllowedError extends KoolbaseAuthError {
|
|
320
|
+
constructor(message?: string);
|
|
321
|
+
}
|
|
322
|
+
/** The invited email already has an account in this app. */
|
|
323
|
+
export declare class MemberExistsError extends KoolbaseAuthError {
|
|
324
|
+
constructor();
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The person's roles changed since they were read; nothing was changed. Read
|
|
328
|
+
* them again, or retry with `currentVersion`.
|
|
329
|
+
*/
|
|
330
|
+
export declare class ClaimsVersionConflictError extends KoolbaseAuthError {
|
|
331
|
+
readonly currentVersion: number | null;
|
|
332
|
+
constructor(currentVersion: number | null);
|
|
333
|
+
}
|
package/dist/esm/auth-errors.js
CHANGED
|
@@ -502,3 +502,64 @@ export class MfaNotEnabledError extends KoolbaseAuthError {
|
|
|
502
502
|
Object.setPrototypeOf(this, MfaNotEnabledError.prototype);
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
|
+
// ─── In-app admin ──────────────────────────────────────────────────────────
|
|
506
|
+
/** The signed-in person is not an app admin. The project owner gives the `app_admin` claim in the dashboard. */
|
|
507
|
+
export class NotAppAdminError extends KoolbaseAuthError {
|
|
508
|
+
constructor() {
|
|
509
|
+
super('Only app admins can do this', 'app_admin_required');
|
|
510
|
+
this.name = 'NotAppAdminError';
|
|
511
|
+
Object.setPrototypeOf(this, NotAppAdminError.prototype);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/** An admin tried to disable themselves or change their own roles. */
|
|
515
|
+
export class AppAdminSelfError extends KoolbaseAuthError {
|
|
516
|
+
constructor() {
|
|
517
|
+
super('You cannot change your own account here', 'app_admin_self');
|
|
518
|
+
this.name = 'AppAdminSelfError';
|
|
519
|
+
Object.setPrototypeOf(this, AppAdminSelfError.prototype);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
/** The person is an app admin too; only the project owner can change them. */
|
|
523
|
+
export class AppAdminTargetIsAdminError extends KoolbaseAuthError {
|
|
524
|
+
constructor() {
|
|
525
|
+
super('Another app admin can only be changed by the project owner', 'app_admin_target_is_admin');
|
|
526
|
+
this.name = 'AppAdminTargetIsAdminError';
|
|
527
|
+
Object.setPrototypeOf(this, AppAdminTargetIsAdminError.prototype);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
/** The project has not let app admins give this role. */
|
|
531
|
+
export class RoleNotAssignableError extends KoolbaseAuthError {
|
|
532
|
+
constructor(message) {
|
|
533
|
+
super(message ?? 'App admins cannot give this role', 'role_not_assignable');
|
|
534
|
+
this.name = 'RoleNotAssignableError';
|
|
535
|
+
Object.setPrototypeOf(this, RoleNotAssignableError.prototype);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
/** The role exists, but not with this value. */
|
|
539
|
+
export class RoleValueNotAllowedError extends KoolbaseAuthError {
|
|
540
|
+
constructor(message) {
|
|
541
|
+
super(message ?? 'That value is not allowed for this role', 'role_value_not_allowed');
|
|
542
|
+
this.name = 'RoleValueNotAllowedError';
|
|
543
|
+
Object.setPrototypeOf(this, RoleValueNotAllowedError.prototype);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/** The invited email already has an account in this app. */
|
|
547
|
+
export class MemberExistsError extends KoolbaseAuthError {
|
|
548
|
+
constructor() {
|
|
549
|
+
super('Someone with this email is already in the app', 'member_exists');
|
|
550
|
+
this.name = 'MemberExistsError';
|
|
551
|
+
Object.setPrototypeOf(this, MemberExistsError.prototype);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* The person's roles changed since they were read; nothing was changed. Read
|
|
556
|
+
* them again, or retry with `currentVersion`.
|
|
557
|
+
*/
|
|
558
|
+
export class ClaimsVersionConflictError extends KoolbaseAuthError {
|
|
559
|
+
constructor(currentVersion) {
|
|
560
|
+
super("This person's roles changed since you opened them", 'claims_version_conflict');
|
|
561
|
+
this.currentVersion = currentVersion;
|
|
562
|
+
this.name = 'ClaimsVersionConflictError';
|
|
563
|
+
Object.setPrototypeOf(this, ClaimsVersionConflictError.prototype);
|
|
564
|
+
}
|
|
565
|
+
}
|
package/dist/esm/auth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, KoolbaseAuditPage, KoolbaseSessionInfo, ResendVerificationResult, SendOtpParams, SignUpResult, SignInWithAppleParams, VerifyOtpParams } from './types.js';
|
|
2
|
+
import { KoolbaseAppAdmin } from './app-admin.js';
|
|
2
3
|
import type { KoolbaseAvatarFile, SignInWithGoogleParams, SignOutReason } from './types.js';
|
|
3
4
|
export declare class KoolbaseAuth {
|
|
4
5
|
private config;
|
|
@@ -340,6 +341,13 @@ export declare class KoolbaseAuth {
|
|
|
340
341
|
}): Promise<KoolbaseAuditPage>;
|
|
341
342
|
unlock(token: string): Promise<void>;
|
|
342
343
|
get currentUser(): KoolbaseUser | null;
|
|
344
|
+
private _admin?;
|
|
345
|
+
/**
|
|
346
|
+
* Managing the app's people, for the app's own admins (the `app_admin`
|
|
347
|
+
* claim). See {@link KoolbaseAppAdmin}.
|
|
348
|
+
*/
|
|
349
|
+
get admin(): KoolbaseAppAdmin;
|
|
350
|
+
private adminRequest;
|
|
343
351
|
get accessToken(): string | null;
|
|
344
352
|
/**
|
|
345
353
|
* Currently-valid access token for data-plane requests, refreshing
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { KoolbaseInvalidPublicKeyError, previewErrorFor } from './errors';
|
|
2
2
|
import { koolbaseFetch } from './network.js';
|
|
3
3
|
import { RestoreResult, } from './types.js';
|
|
4
|
-
import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, IdentityNotFoundError, InsufficientScopeError, MalformedSessionResponseError, ProviderIdentityAlreadyLinkedError, AccountExistsError, ContactNotVerifiedError, CurrentPasswordIncorrectError, HideRequiresVerificationError, InsufficientAuthorityError, LastCredentialError, OAuthOnlyAccountError, SessionRequiredError, SignupsDisabledError, TokenAlreadyUsedError, TokenExpiredError, UnsupportedOAuthProviderError, RateLimitError, retryAfterOf, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, TokenRevokedError, UnlockTokenInvalidError, UserDisabledError, WeakPasswordError, AppleEmailRequiredError, AppleSignInNotConfiguredError, InvalidAppleTokenError, OAuthEmailConflictError, GoogleEmailRequiredError, GoogleSignInNotConfiguredError, InvalidGoogleTokenError, EmailCodeDisabledError, MfaRequiredError, RecentAuthRequiredError, RecentMfaRequiredError, MfaAlreadyEnabledError, MfaEnrollmentNotFoundError, MfaNotEnabledError, } from './auth-errors.js';
|
|
4
|
+
import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, IdentityNotFoundError, InsufficientScopeError, MalformedSessionResponseError, ProviderIdentityAlreadyLinkedError, AccountExistsError, ContactNotVerifiedError, CurrentPasswordIncorrectError, HideRequiresVerificationError, InsufficientAuthorityError, LastCredentialError, OAuthOnlyAccountError, SessionRequiredError, SignupsDisabledError, TokenAlreadyUsedError, TokenExpiredError, UnsupportedOAuthProviderError, RateLimitError, retryAfterOf, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, TokenRevokedError, UnlockTokenInvalidError, UserDisabledError, WeakPasswordError, AppleEmailRequiredError, AppleSignInNotConfiguredError, InvalidAppleTokenError, OAuthEmailConflictError, GoogleEmailRequiredError, GoogleSignInNotConfiguredError, InvalidGoogleTokenError, EmailCodeDisabledError, MfaRequiredError, RecentAuthRequiredError, RecentMfaRequiredError, MfaAlreadyEnabledError, MfaEnrollmentNotFoundError, MfaNotEnabledError, NotAppAdminError, AppAdminSelfError, AppAdminTargetIsAdminError, RoleNotAssignableError, RoleValueNotAllowedError, MemberExistsError, ClaimsVersionConflictError, } from './auth-errors.js';
|
|
5
|
+
import { KoolbaseAppAdmin } from './app-admin.js';
|
|
5
6
|
import { KoolbaseServiceUnavailableError } from './errors.js';
|
|
6
7
|
import { getPlatform } from './platform.js';
|
|
7
8
|
import { DeviceMetadata } from './device-metadata.js';
|
|
@@ -999,6 +1000,66 @@ export class KoolbaseAuth {
|
|
|
999
1000
|
get currentUser() {
|
|
1000
1001
|
return this.session?.user ?? null;
|
|
1001
1002
|
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Managing the app's people, for the app's own admins (the `app_admin`
|
|
1005
|
+
* claim). See {@link KoolbaseAppAdmin}.
|
|
1006
|
+
*/
|
|
1007
|
+
get admin() {
|
|
1008
|
+
if (!this._admin) {
|
|
1009
|
+
this._admin = new KoolbaseAppAdmin((path, options) => this.adminRequest(path, options));
|
|
1010
|
+
}
|
|
1011
|
+
return this._admin;
|
|
1012
|
+
}
|
|
1013
|
+
async adminRequest(path, options = {}) {
|
|
1014
|
+
const res = await this.authedRequest(path, options);
|
|
1015
|
+
if (res.ok)
|
|
1016
|
+
return res.json().catch(() => ({}));
|
|
1017
|
+
let body = {};
|
|
1018
|
+
try {
|
|
1019
|
+
body = await res.json();
|
|
1020
|
+
}
|
|
1021
|
+
catch {
|
|
1022
|
+
// ignore
|
|
1023
|
+
}
|
|
1024
|
+
const code = body.code ?? '';
|
|
1025
|
+
const msg = body.error ?? '';
|
|
1026
|
+
// The admin routes' own codes first. Their plain failures (a member not
|
|
1027
|
+
// found, a conflict, a refusal) keep the server's words: the general
|
|
1028
|
+
// status fallback would call a 409 an email in use and a 403 a disabled
|
|
1029
|
+
// account, neither of which an admin route means.
|
|
1030
|
+
switch (code) {
|
|
1031
|
+
// Never sent by these routes; mapped so every parser here handles the
|
|
1032
|
+
// challenge the same way (mfa.test checks each switch).
|
|
1033
|
+
case 'mfa_required':
|
|
1034
|
+
throw this.mfaRequired(body);
|
|
1035
|
+
case 'app_admin_required':
|
|
1036
|
+
throw new NotAppAdminError();
|
|
1037
|
+
case 'app_admin_self':
|
|
1038
|
+
throw new AppAdminSelfError();
|
|
1039
|
+
case 'app_admin_target_is_admin':
|
|
1040
|
+
throw new AppAdminTargetIsAdminError();
|
|
1041
|
+
case 'role_not_assignable':
|
|
1042
|
+
throw new RoleNotAssignableError(msg || undefined);
|
|
1043
|
+
case 'role_value_not_allowed':
|
|
1044
|
+
throw new RoleValueNotAllowedError(msg || undefined);
|
|
1045
|
+
case 'member_exists':
|
|
1046
|
+
throw new MemberExistsError();
|
|
1047
|
+
case 'claims_version_conflict':
|
|
1048
|
+
throw new ClaimsVersionConflictError(typeof body.version === 'number' ? body.version : null);
|
|
1049
|
+
case 'not_found':
|
|
1050
|
+
case 'conflict':
|
|
1051
|
+
case 'permission_denied':
|
|
1052
|
+
case 'validation_error':
|
|
1053
|
+
throw new KoolbaseAuthError(msg || 'The request was refused.', code);
|
|
1054
|
+
}
|
|
1055
|
+
// The body is read; hand the general parser what it read.
|
|
1056
|
+
return this.throwTypedError({
|
|
1057
|
+
ok: false,
|
|
1058
|
+
status: res.status,
|
|
1059
|
+
headers: res.headers,
|
|
1060
|
+
json: async () => body,
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1002
1063
|
get accessToken() {
|
|
1003
1064
|
return this.session?.accessToken ?? null;
|
|
1004
1065
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './auth-errors.js';
|
|
|
10
10
|
export * from './database-errors.js';
|
|
11
11
|
export * from './storage-errors.js';
|
|
12
12
|
export { KoolbaseAuth } from './auth.js';
|
|
13
|
+
export { KoolbaseAppAdmin } from './app-admin.js';
|
|
13
14
|
export { KoolbaseDatabase } from './database.js';
|
|
14
15
|
export { KoolbaseCollectionController, collectionQueryKey, initialCollectionState, } from './collection-controller.js';
|
|
15
16
|
export type { CollectionQuery, CollectionState, CollectionStatus } from './collection-controller.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from './auth-errors.js';
|
|
|
15
15
|
export * from './database-errors.js';
|
|
16
16
|
export * from './storage-errors.js';
|
|
17
17
|
export { KoolbaseAuth } from './auth.js';
|
|
18
|
+
export { KoolbaseAppAdmin } from './app-admin.js';
|
|
18
19
|
export { KoolbaseDatabase } from './database.js';
|
|
19
20
|
export { KoolbaseCollectionController, collectionQueryKey, initialCollectionState, } from './collection-controller.js';
|
|
20
21
|
export { KoolbaseRecordController, initialRecordState } from './record-controller.js';
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -170,6 +170,45 @@ export interface KoolbaseAuditPage {
|
|
|
170
170
|
limit: number;
|
|
171
171
|
offset: number;
|
|
172
172
|
}
|
|
173
|
+
/** One person in the app, as an app admin sees them. */
|
|
174
|
+
export interface KoolbaseMember {
|
|
175
|
+
id: string;
|
|
176
|
+
email: string;
|
|
177
|
+
fullName?: string;
|
|
178
|
+
avatarUrl?: string;
|
|
179
|
+
/** `invited` has not signed in yet. */
|
|
180
|
+
status: 'active' | 'invited' | 'disabled';
|
|
181
|
+
/** An app admin: only the project owner can disable them or change their roles. */
|
|
182
|
+
isAdmin: boolean;
|
|
183
|
+
/** The claims the project marked as ones app admins can give. Others are never sent. */
|
|
184
|
+
roles: Record<string, unknown>;
|
|
185
|
+
/** Pass back to `admin.setRoles` as `expectedVersion`. */
|
|
186
|
+
version: number;
|
|
187
|
+
joinedAt: string;
|
|
188
|
+
lastSeenAt?: string;
|
|
189
|
+
}
|
|
190
|
+
/** A page of members, with the total across all pages. */
|
|
191
|
+
export interface KoolbaseMemberPage {
|
|
192
|
+
members: KoolbaseMember[];
|
|
193
|
+
total: number;
|
|
194
|
+
}
|
|
195
|
+
/** A role an app admin may give, with how many people hold it. */
|
|
196
|
+
export interface KoolbaseAssignableRole {
|
|
197
|
+
key: string;
|
|
198
|
+
valueType: string;
|
|
199
|
+
/** The only values allowed, when the project limited them; empty otherwise. */
|
|
200
|
+
allowedValues: string[];
|
|
201
|
+
description?: string;
|
|
202
|
+
holders: number;
|
|
203
|
+
/** For each value, how many people hold it. */
|
|
204
|
+
values: Record<string, number>;
|
|
205
|
+
}
|
|
206
|
+
/** What `admin.setRoles` leaves: the roles now, and the version to pass next time. */
|
|
207
|
+
export interface KoolbaseMemberRoles {
|
|
208
|
+
id: string;
|
|
209
|
+
roles: Record<string, unknown>;
|
|
210
|
+
version: number;
|
|
211
|
+
}
|
|
173
212
|
export interface ResendVerificationResult {
|
|
174
213
|
alreadyVerified: boolean;
|
|
175
214
|
/** When the link in the email stops working. Null when nothing was sent. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.45.0",
|
|
4
4
|
"description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|