@maravilla-labs/platform 0.5.1 → 0.6.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/config.d.ts +116 -8
- package/dist/config.js +159 -2
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +6 -568
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
- package/src/config.ts +313 -8
- package/src/remote-client.ts +81 -5
- package/src/types.ts +64 -654
- package/tests/policy-builder.test.ts +186 -0
- package/tests/types.test-d.ts +94 -0
- package/tsconfig.test.json +8 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DbDocument, AuthService, AuthUser } from '@maravilla-labs/types';
|
|
2
|
+
export { ActAsContext, AddCircleMemberOptions, AddRelationOptions, AuthCaller, AuthCircle, AuthConfig, AuthField, AuthGroup, AuthService, AuthSession, AuthStewardshipApi, AuthUser, CanCheck, CircleMembership, CreateCircleOptions, CreateGroupOptions, CreateManagedUserOptions, CreateRelationTypeOptions, CreateResourceOptions, CreateStewardshipOverrideOptions, DbDocument, DelegationMode, GroupPermission, ListRelationsOptions, LoginOptions, PolicyExplain, RegisterOptions, Relation, RelationListDirection, RelationType, Resource, ResourceServiceType, ScopedPermission, StewardshipAuditEntry, StewardshipOverride, StewardshipResolution, StewardshipStatus, UpdateCircleOptions, UpdateGroupOptions, UpdateRelationTypeOptions, UpdateResourceOptions, UpdateUserOptions, UserListFilter, UserListResponse } from '@maravilla-labs/types';
|
|
1
3
|
export { R as RenClient, a as RenClientOptions, b as RenEvent, g as getOrCreateClientId, r as renFetch, s as storageDelete, c as storageUpload } from './ren-DrYefHO5.js';
|
|
2
4
|
import { LocalParticipant } from 'livekit-client';
|
|
3
5
|
export { RegisterPushOptions, RegisterPushResult, offsetBefore, registerPush, unregisterPush } from './push.js';
|
|
@@ -214,7 +216,7 @@ interface Database {
|
|
|
214
216
|
* );
|
|
215
217
|
* ```
|
|
216
218
|
*/
|
|
217
|
-
find(collection: string, filter?: any, options?: DbFindOptions): Promise<
|
|
219
|
+
find<T = Record<string, unknown>>(collection: string, filter?: any, options?: DbFindOptions): Promise<DbDocument<T>[]>;
|
|
218
220
|
/**
|
|
219
221
|
* Find a single document in a collection.
|
|
220
222
|
*
|
|
@@ -230,7 +232,7 @@ interface Database {
|
|
|
230
232
|
* }
|
|
231
233
|
* ```
|
|
232
234
|
*/
|
|
233
|
-
findOne(collection: string, filter: any): Promise<
|
|
235
|
+
findOne<T = Record<string, unknown>>(collection: string, filter: any): Promise<DbDocument<T> | null>;
|
|
234
236
|
/**
|
|
235
237
|
* Insert a single document into a collection.
|
|
236
238
|
*
|
|
@@ -816,571 +818,7 @@ interface PresenceService {
|
|
|
816
818
|
lastSeen?: number;
|
|
817
819
|
}>>;
|
|
818
820
|
}
|
|
819
|
-
|
|
820
|
-
* Authenticated user record from the platform auth service.
|
|
821
|
-
*/
|
|
822
|
-
interface AuthUser {
|
|
823
|
-
/** Unique user ID (prefixed with "usr_") */
|
|
824
|
-
id: string;
|
|
825
|
-
/** User's email address */
|
|
826
|
-
email: string;
|
|
827
|
-
/** Whether the email has been verified */
|
|
828
|
-
email_verified: boolean;
|
|
829
|
-
/** Account status */
|
|
830
|
-
status: 'active' | 'suspended' | 'deactivated';
|
|
831
|
-
/** Authentication provider ("email", "google", "github", etc.) */
|
|
832
|
-
provider: string;
|
|
833
|
-
/** Group IDs the user belongs to */
|
|
834
|
-
groups: string[];
|
|
835
|
-
/** Unix timestamp when the user was created */
|
|
836
|
-
created_at: number;
|
|
837
|
-
/** Unix timestamp when the user was last updated */
|
|
838
|
-
updated_at: number;
|
|
839
|
-
/** Unix timestamp of last login (if any) */
|
|
840
|
-
last_login_at?: number;
|
|
841
|
-
}
|
|
842
|
-
/**
|
|
843
|
-
* Snapshot of whoever is currently bound to the request as the caller.
|
|
844
|
-
*
|
|
845
|
-
* Populated by {@link AuthService.login} (implicit), {@link AuthService.setCurrentUser}
|
|
846
|
-
* (explicit), or left anonymous if neither has run for this request.
|
|
847
|
-
* This is exactly what per-resource policies see as `auth.*` when they run.
|
|
848
|
-
*/
|
|
849
|
-
interface AuthCaller {
|
|
850
|
-
/** Caller's user id, or `""` if anonymous */
|
|
851
|
-
user_id: string;
|
|
852
|
-
/** Caller's email, or `""` if anonymous */
|
|
853
|
-
email: string;
|
|
854
|
-
/** Admin flag from the session */
|
|
855
|
-
is_admin: boolean;
|
|
856
|
-
/** Role names (project-scoped) */
|
|
857
|
-
roles: string[];
|
|
858
|
-
/** `true` when no identity is bound to this request */
|
|
859
|
-
is_anonymous: boolean;
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* Session returned after successful login or token refresh.
|
|
863
|
-
*/
|
|
864
|
-
interface AuthSession {
|
|
865
|
-
/** Short-lived JWT access token (default 15 min) */
|
|
866
|
-
access_token: string;
|
|
867
|
-
/** Single-use opaque refresh token (default 30 days) */
|
|
868
|
-
refresh_token: string;
|
|
869
|
-
/** Access token lifetime in seconds */
|
|
870
|
-
expires_in: number;
|
|
871
|
-
/** The authenticated user */
|
|
872
|
-
user: AuthUser;
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* Custom registration field defined in project auth settings.
|
|
876
|
-
*/
|
|
877
|
-
interface AuthField {
|
|
878
|
-
/** Field key (used as form field name) */
|
|
879
|
-
key: string;
|
|
880
|
-
/** Display label */
|
|
881
|
-
label: string;
|
|
882
|
-
/** Field type: text, email, phone, date, number, select, boolean, url, textarea */
|
|
883
|
-
field_type: string;
|
|
884
|
-
/** Whether the field is required */
|
|
885
|
-
required: boolean;
|
|
886
|
-
/** Whether the field appears on the registration form */
|
|
887
|
-
show_on_register: boolean;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Options for registering a new user.
|
|
891
|
-
*/
|
|
892
|
-
interface RegisterOptions {
|
|
893
|
-
/** User's email address */
|
|
894
|
-
email: string;
|
|
895
|
-
/** Password (minimum 8 characters) */
|
|
896
|
-
password: string;
|
|
897
|
-
/** Optional profile data (custom fields) */
|
|
898
|
-
profile?: Record<string, any>;
|
|
899
|
-
}
|
|
900
|
-
/**
|
|
901
|
-
* Options for logging in.
|
|
902
|
-
*/
|
|
903
|
-
interface LoginOptions {
|
|
904
|
-
/** User's email address */
|
|
905
|
-
email: string;
|
|
906
|
-
/** User's password */
|
|
907
|
-
password: string;
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* Filter options for listing users.
|
|
911
|
-
*/
|
|
912
|
-
interface UserListFilter {
|
|
913
|
-
/** Max results per page (default 50) */
|
|
914
|
-
limit?: number;
|
|
915
|
-
/** Number of results to skip */
|
|
916
|
-
offset?: number;
|
|
917
|
-
/** Filter by account status */
|
|
918
|
-
status?: 'active' | 'suspended' | 'deactivated';
|
|
919
|
-
/** Filter by email (partial match) */
|
|
920
|
-
email_contains?: string;
|
|
921
|
-
/** Filter by group ID */
|
|
922
|
-
group_id?: string;
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* Paginated user list response.
|
|
926
|
-
*/
|
|
927
|
-
interface UserListResponse {
|
|
928
|
-
/** Users in this page */
|
|
929
|
-
users: AuthUser[];
|
|
930
|
-
/** Total number of matching users */
|
|
931
|
-
total: number;
|
|
932
|
-
/** Page size */
|
|
933
|
-
limit: number;
|
|
934
|
-
/** Offset */
|
|
935
|
-
offset: number;
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* Options for updating a user.
|
|
939
|
-
*/
|
|
940
|
-
interface UpdateUserOptions {
|
|
941
|
-
/** New email address */
|
|
942
|
-
email?: string;
|
|
943
|
-
/** New status */
|
|
944
|
-
status?: 'active' | 'suspended' | 'deactivated';
|
|
945
|
-
/** Profile data to merge */
|
|
946
|
-
profile?: Record<string, any>;
|
|
947
|
-
}
|
|
948
|
-
interface AuthGroup {
|
|
949
|
-
id: string;
|
|
950
|
-
name: string;
|
|
951
|
-
description: string | null;
|
|
952
|
-
permissions: string[];
|
|
953
|
-
member_count: number;
|
|
954
|
-
created_at: number;
|
|
955
|
-
updated_at: number;
|
|
956
|
-
}
|
|
957
|
-
interface CreateGroupOptions {
|
|
958
|
-
name: string;
|
|
959
|
-
description?: string;
|
|
960
|
-
permissions?: string[];
|
|
961
|
-
}
|
|
962
|
-
interface UpdateGroupOptions {
|
|
963
|
-
name?: string;
|
|
964
|
-
description?: string;
|
|
965
|
-
permissions?: string[];
|
|
966
|
-
}
|
|
967
|
-
interface GroupPermission {
|
|
968
|
-
resource_name: string;
|
|
969
|
-
actions: string[];
|
|
970
|
-
}
|
|
971
|
-
interface AuthCircle {
|
|
972
|
-
id: string;
|
|
973
|
-
name: string;
|
|
974
|
-
metadata: Record<string, any> | null;
|
|
975
|
-
member_count: number;
|
|
976
|
-
created_at: number;
|
|
977
|
-
updated_at: number;
|
|
978
|
-
}
|
|
979
|
-
interface CreateCircleOptions {
|
|
980
|
-
name: string;
|
|
981
|
-
metadata?: Record<string, any>;
|
|
982
|
-
}
|
|
983
|
-
interface UpdateCircleOptions {
|
|
984
|
-
name?: string;
|
|
985
|
-
metadata?: Record<string, any>;
|
|
986
|
-
}
|
|
987
|
-
interface AddCircleMemberOptions {
|
|
988
|
-
user_id: string;
|
|
989
|
-
relationship: string;
|
|
990
|
-
is_primary_contact?: boolean;
|
|
991
|
-
}
|
|
992
|
-
interface CircleMembership {
|
|
993
|
-
user_id: string;
|
|
994
|
-
email: string;
|
|
995
|
-
relationship: string;
|
|
996
|
-
is_primary_contact: boolean;
|
|
997
|
-
joined_at: number;
|
|
998
|
-
}
|
|
999
|
-
type ResourceServiceType = 'kv' | 'database' | 'realtime' | 'media' | 'vector' | 'storage' | 'queue' | 'push' | 'workflow' | 'transforms';
|
|
1000
|
-
interface Resource {
|
|
1001
|
-
id: string;
|
|
1002
|
-
resource_name: string;
|
|
1003
|
-
title: string;
|
|
1004
|
-
description: string | null;
|
|
1005
|
-
actions: string[];
|
|
1006
|
-
policy: string | null;
|
|
1007
|
-
service_type: ResourceServiceType | null;
|
|
1008
|
-
read_filter: string | null;
|
|
1009
|
-
created_at: number;
|
|
1010
|
-
updated_at: number;
|
|
1011
|
-
}
|
|
1012
|
-
interface CreateResourceOptions {
|
|
1013
|
-
resource_name: string;
|
|
1014
|
-
title: string;
|
|
1015
|
-
description?: string;
|
|
1016
|
-
actions?: string[];
|
|
1017
|
-
policy?: string;
|
|
1018
|
-
service_type?: ResourceServiceType;
|
|
1019
|
-
read_filter?: string;
|
|
1020
|
-
}
|
|
1021
|
-
interface UpdateResourceOptions {
|
|
1022
|
-
title?: string;
|
|
1023
|
-
description?: string;
|
|
1024
|
-
actions?: string[];
|
|
1025
|
-
policy?: string;
|
|
1026
|
-
service_type?: ResourceServiceType;
|
|
1027
|
-
read_filter?: string;
|
|
1028
|
-
}
|
|
1029
|
-
interface RelationType {
|
|
1030
|
-
id: string;
|
|
1031
|
-
relation_name: string;
|
|
1032
|
-
title: string;
|
|
1033
|
-
description: string | null;
|
|
1034
|
-
category: string;
|
|
1035
|
-
icon: string | null;
|
|
1036
|
-
color: string | null;
|
|
1037
|
-
inverse_relation_id: string | null;
|
|
1038
|
-
implies_stewardship: boolean;
|
|
1039
|
-
requires_minor: boolean;
|
|
1040
|
-
bidirectional: boolean;
|
|
1041
|
-
is_system: boolean;
|
|
1042
|
-
created_at: number;
|
|
1043
|
-
updated_at: number;
|
|
1044
|
-
}
|
|
1045
|
-
interface CreateRelationTypeOptions {
|
|
1046
|
-
relation_name: string;
|
|
1047
|
-
title: string;
|
|
1048
|
-
description?: string;
|
|
1049
|
-
category?: string;
|
|
1050
|
-
icon?: string;
|
|
1051
|
-
color?: string;
|
|
1052
|
-
inverse_relation_id?: string;
|
|
1053
|
-
implies_stewardship?: boolean;
|
|
1054
|
-
requires_minor?: boolean;
|
|
1055
|
-
bidirectional?: boolean;
|
|
1056
|
-
is_system?: boolean;
|
|
1057
|
-
}
|
|
1058
|
-
interface UpdateRelationTypeOptions {
|
|
1059
|
-
title?: string;
|
|
1060
|
-
description?: string;
|
|
1061
|
-
category?: string;
|
|
1062
|
-
icon?: string;
|
|
1063
|
-
color?: string;
|
|
1064
|
-
inverse_relation_id?: string;
|
|
1065
|
-
implies_stewardship?: boolean;
|
|
1066
|
-
requires_minor?: boolean;
|
|
1067
|
-
bidirectional?: boolean;
|
|
1068
|
-
}
|
|
1069
|
-
interface AuthConfig {
|
|
1070
|
-
fields: AuthField[];
|
|
1071
|
-
oauth_providers: any[];
|
|
1072
|
-
branding: Record<string, any>;
|
|
1073
|
-
password_policy: Record<string, any>;
|
|
1074
|
-
session_config: Record<string, any>;
|
|
1075
|
-
}
|
|
1076
|
-
type DelegationMode = 'full' | 'scoped';
|
|
1077
|
-
type StewardshipStatus = 'active' | 'suspended' | 'revoked' | 'expired';
|
|
1078
|
-
interface ScopedPermission {
|
|
1079
|
-
resource: string;
|
|
1080
|
-
actions: string[];
|
|
1081
|
-
}
|
|
1082
|
-
interface StewardshipOverride {
|
|
1083
|
-
id: string;
|
|
1084
|
-
steward_id: string;
|
|
1085
|
-
ward_id: string;
|
|
1086
|
-
delegation_mode: DelegationMode;
|
|
1087
|
-
scoped_permissions: ScopedPermission[];
|
|
1088
|
-
valid_from: number | null;
|
|
1089
|
-
valid_until: number | null;
|
|
1090
|
-
status: StewardshipStatus;
|
|
1091
|
-
reason: string | null;
|
|
1092
|
-
source: string;
|
|
1093
|
-
source_circle_id: string | null;
|
|
1094
|
-
source_relation_type_id: string | null;
|
|
1095
|
-
created_at: number;
|
|
1096
|
-
updated_at: number;
|
|
1097
|
-
}
|
|
1098
|
-
interface CreateStewardshipOverrideOptions {
|
|
1099
|
-
steward_id: string;
|
|
1100
|
-
ward_id: string;
|
|
1101
|
-
delegation_mode?: DelegationMode;
|
|
1102
|
-
scoped_permissions?: ScopedPermission[];
|
|
1103
|
-
valid_from?: number;
|
|
1104
|
-
valid_until?: number;
|
|
1105
|
-
reason?: string;
|
|
1106
|
-
}
|
|
1107
|
-
interface StewardshipResolution {
|
|
1108
|
-
stewards: StewardshipOverride[];
|
|
1109
|
-
wards: StewardshipOverride[];
|
|
1110
|
-
}
|
|
1111
|
-
interface ActAsContext {
|
|
1112
|
-
steward_id: string;
|
|
1113
|
-
ward_id: string;
|
|
1114
|
-
delegation_mode: DelegationMode;
|
|
1115
|
-
scoped_permissions: ScopedPermission[];
|
|
1116
|
-
session_token: string;
|
|
1117
|
-
expires_at: number;
|
|
1118
|
-
}
|
|
1119
|
-
interface StewardshipAuditEntry {
|
|
1120
|
-
id: string;
|
|
1121
|
-
performed_by: string;
|
|
1122
|
-
on_behalf_of: string;
|
|
1123
|
-
action: string;
|
|
1124
|
-
resource: string | null;
|
|
1125
|
-
details: Record<string, any> | null;
|
|
1126
|
-
created_at: number;
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Sub-namespace exposed at `platform.auth.stewardship` mirroring the
|
|
1130
|
-
* runtime's `globalThis.platform.auth.stewardship.*` surface.
|
|
1131
|
-
*/
|
|
1132
|
-
interface AuthStewardshipApi {
|
|
1133
|
-
resolve(userId: string): Promise<StewardshipResolution>;
|
|
1134
|
-
createOverride(opts: CreateStewardshipOverrideOptions): Promise<StewardshipOverride>;
|
|
1135
|
-
revoke(id: string): Promise<void>;
|
|
1136
|
-
checkPermission(stewardId: string, wardId: string, resource: string, action: string): Promise<boolean>;
|
|
1137
|
-
createActAs(stewardId: string, wardId: string): Promise<ActAsContext>;
|
|
1138
|
-
listAudit(userId: string, options?: {
|
|
1139
|
-
limit?: number;
|
|
1140
|
-
offset?: number;
|
|
1141
|
-
}): Promise<StewardshipAuditEntry[]>;
|
|
1142
|
-
}
|
|
1143
|
-
/**
|
|
1144
|
-
* Auth service for end-user authentication and user management.
|
|
1145
|
-
*
|
|
1146
|
-
* @example
|
|
1147
|
-
* ```typescript
|
|
1148
|
-
* const platform = getPlatform();
|
|
1149
|
-
*
|
|
1150
|
-
* // Register a new user
|
|
1151
|
-
* const user = await platform.auth.register({
|
|
1152
|
-
* email: 'user@example.com',
|
|
1153
|
-
* password: 'securePassword123'
|
|
1154
|
-
* });
|
|
1155
|
-
*
|
|
1156
|
-
* // Login
|
|
1157
|
-
* const session = await platform.auth.login({
|
|
1158
|
-
* email: 'user@example.com',
|
|
1159
|
-
* password: 'securePassword123'
|
|
1160
|
-
* });
|
|
1161
|
-
* // session.access_token — short-lived JWT
|
|
1162
|
-
* // session.refresh_token — single-use refresh token
|
|
1163
|
-
*
|
|
1164
|
-
* // Validate a token (e.g. from Authorization header or cookie)
|
|
1165
|
-
* const user = await platform.auth.validate(session.access_token);
|
|
1166
|
-
*
|
|
1167
|
-
* // Protect a route with withAuth middleware
|
|
1168
|
-
* export default {
|
|
1169
|
-
* fetch: platform.auth.withAuth(async (request) => {
|
|
1170
|
-
* // request.user is guaranteed to be set
|
|
1171
|
-
* return new Response(`Hello ${request.user.email}`);
|
|
1172
|
-
* })
|
|
1173
|
-
* };
|
|
1174
|
-
* ```
|
|
1175
|
-
*/
|
|
1176
|
-
interface AuthService {
|
|
1177
|
-
/**
|
|
1178
|
-
* Register a new user with email and password.
|
|
1179
|
-
* @returns The created user (not yet email-verified)
|
|
1180
|
-
*/
|
|
1181
|
-
register(options: RegisterOptions): Promise<AuthUser>;
|
|
1182
|
-
/**
|
|
1183
|
-
* Authenticate a user and create a session.
|
|
1184
|
-
* @returns Session with access token, refresh token, and user info
|
|
1185
|
-
*/
|
|
1186
|
-
login(options: LoginOptions): Promise<AuthSession>;
|
|
1187
|
-
/**
|
|
1188
|
-
* Validate an access token and return the authenticated user.
|
|
1189
|
-
* @param accessToken - JWT access token from login or refresh
|
|
1190
|
-
* @throws If the token is invalid or expired
|
|
1191
|
-
*/
|
|
1192
|
-
validate(accessToken: string): Promise<AuthUser>;
|
|
1193
|
-
/**
|
|
1194
|
-
* Refresh a session using a refresh token (single-use).
|
|
1195
|
-
* @param refreshToken - The refresh token from a previous login/refresh
|
|
1196
|
-
* @returns New session with fresh access and refresh tokens
|
|
1197
|
-
*/
|
|
1198
|
-
refresh(refreshToken: string): Promise<AuthSession>;
|
|
1199
|
-
/**
|
|
1200
|
-
* Revoke a specific session.
|
|
1201
|
-
*/
|
|
1202
|
-
logout(sessionId: string): Promise<void>;
|
|
1203
|
-
/**
|
|
1204
|
-
* Get a user by ID.
|
|
1205
|
-
* @returns The user, or null if not found
|
|
1206
|
-
*/
|
|
1207
|
-
getUser(userId: string): Promise<AuthUser | null>;
|
|
1208
|
-
/**
|
|
1209
|
-
* List users with optional filtering and pagination.
|
|
1210
|
-
*/
|
|
1211
|
-
listUsers(filter?: UserListFilter): Promise<UserListResponse>;
|
|
1212
|
-
/**
|
|
1213
|
-
* Update a user's email, status, or profile data.
|
|
1214
|
-
*/
|
|
1215
|
-
updateUser(userId: string, update: UpdateUserOptions): Promise<AuthUser>;
|
|
1216
|
-
/**
|
|
1217
|
-
* Delete a user and all their sessions.
|
|
1218
|
-
*/
|
|
1219
|
-
deleteUser(userId: string): Promise<void>;
|
|
1220
|
-
/**
|
|
1221
|
-
* Create an email verification token.
|
|
1222
|
-
* @returns The verification token (caller decides how to deliver it)
|
|
1223
|
-
*/
|
|
1224
|
-
sendVerification(userId: string): Promise<{
|
|
1225
|
-
token: string;
|
|
1226
|
-
}>;
|
|
1227
|
-
/**
|
|
1228
|
-
* Verify an email address using a verification token.
|
|
1229
|
-
*/
|
|
1230
|
-
verifyEmail(token: string): Promise<void>;
|
|
1231
|
-
/**
|
|
1232
|
-
* Create a password reset token for an email address.
|
|
1233
|
-
* @returns The reset token (caller decides how to deliver it)
|
|
1234
|
-
*/
|
|
1235
|
-
sendPasswordReset(email: string): Promise<{
|
|
1236
|
-
token: string;
|
|
1237
|
-
}>;
|
|
1238
|
-
/**
|
|
1239
|
-
* Reset a password using a reset token.
|
|
1240
|
-
*/
|
|
1241
|
-
resetPassword(token: string, newPassword: string): Promise<void>;
|
|
1242
|
-
/**
|
|
1243
|
-
* Change a user's password (requires old password).
|
|
1244
|
-
*/
|
|
1245
|
-
changePassword(userId: string, oldPassword: string, newPassword: string): Promise<void>;
|
|
1246
|
-
/**
|
|
1247
|
-
* Get the configured registration fields for this project.
|
|
1248
|
-
*/
|
|
1249
|
-
getFieldConfig(): Promise<{
|
|
1250
|
-
fields: AuthField[];
|
|
1251
|
-
}>;
|
|
1252
|
-
/**
|
|
1253
|
-
* Start an OAuth flow by generating an authorization URL.
|
|
1254
|
-
* Redirect the user to the returned URL to begin authentication.
|
|
1255
|
-
*
|
|
1256
|
-
* @param provider - Provider name: "google", "github", "okta", or "custom_oidc"
|
|
1257
|
-
* @param options - Optional configuration
|
|
1258
|
-
* @returns Object with `auth_url` (redirect target) and `state` (for CSRF verification)
|
|
1259
|
-
*/
|
|
1260
|
-
getOAuthUrl(provider: string, options?: {
|
|
1261
|
-
redirectUri?: string;
|
|
1262
|
-
}): Promise<{
|
|
1263
|
-
auth_url: string;
|
|
1264
|
-
state: string;
|
|
1265
|
-
}>;
|
|
1266
|
-
/**
|
|
1267
|
-
* Complete an OAuth flow by exchanging the authorization code.
|
|
1268
|
-
* Call this after the provider redirects back with a code and state.
|
|
1269
|
-
*
|
|
1270
|
-
* @param provider - Provider name
|
|
1271
|
-
* @param params - The code and state from the OAuth callback
|
|
1272
|
-
* @returns Either a session (user authenticated) or a link_required result
|
|
1273
|
-
*/
|
|
1274
|
-
handleOAuthCallback(provider: string, params: {
|
|
1275
|
-
code: string;
|
|
1276
|
-
state: string;
|
|
1277
|
-
}): Promise<AuthSession | {
|
|
1278
|
-
type: 'LinkRequired';
|
|
1279
|
-
email: string;
|
|
1280
|
-
provider: string;
|
|
1281
|
-
provider_id: string;
|
|
1282
|
-
existing_user_id: string;
|
|
1283
|
-
}>;
|
|
1284
|
-
/**
|
|
1285
|
-
* Middleware helper that validates auth and injects `request.user`.
|
|
1286
|
-
* Returns 401 JSON response if no valid token is found.
|
|
1287
|
-
*
|
|
1288
|
-
* Extracts token from `Authorization: Bearer <token>` header
|
|
1289
|
-
* or `__session` cookie.
|
|
1290
|
-
*
|
|
1291
|
-
* @example
|
|
1292
|
-
* ```typescript
|
|
1293
|
-
* export default {
|
|
1294
|
-
* fetch: platform.auth.withAuth(async (request) => {
|
|
1295
|
-
* const data = await platform.db.items.find({ owner: request.user.id });
|
|
1296
|
-
* return Response.json(data);
|
|
1297
|
-
* })
|
|
1298
|
-
* };
|
|
1299
|
-
* ```
|
|
1300
|
-
*/
|
|
1301
|
-
withAuth<T extends (request: Request & {
|
|
1302
|
-
user: AuthUser;
|
|
1303
|
-
}) => Promise<Response>>(handler: T): (request: Request) => Promise<Response>;
|
|
1304
|
-
createGroup(options: CreateGroupOptions): Promise<AuthGroup>;
|
|
1305
|
-
listGroups(): Promise<AuthGroup[]>;
|
|
1306
|
-
getGroup(groupId: string): Promise<AuthGroup | null>;
|
|
1307
|
-
/**
|
|
1308
|
-
* Look up a group by its declarative name (the same name used in
|
|
1309
|
-
* `maravilla.config.ts`'s `groups: [...]` block). Returns null if the
|
|
1310
|
-
* auth-settings reconciler hasn't created it yet. Apps that want to
|
|
1311
|
-
* add a user to a group typically only know the name, so use this
|
|
1312
|
-
* first to resolve the id, then call `addUserToGroup`.
|
|
1313
|
-
*/
|
|
1314
|
-
getGroupByName(name: string): Promise<AuthGroup | null>;
|
|
1315
|
-
updateGroup(groupId: string, options: UpdateGroupOptions): Promise<AuthGroup>;
|
|
1316
|
-
deleteGroup(groupId: string): Promise<void>;
|
|
1317
|
-
addUserToGroup(userId: string, groupId: string): Promise<void>;
|
|
1318
|
-
removeUserFromGroup(userId: string, groupId: string): Promise<void>;
|
|
1319
|
-
getUserGroups(userId: string): Promise<AuthGroup[]>;
|
|
1320
|
-
getGroupMembers(groupId: string): Promise<AuthUser[]>;
|
|
1321
|
-
getGroupPermissions(groupId: string): Promise<GroupPermission[]>;
|
|
1322
|
-
setGroupPermissions(groupId: string, permissions: GroupPermission[]): Promise<void>;
|
|
1323
|
-
createCircle(options: CreateCircleOptions): Promise<AuthCircle>;
|
|
1324
|
-
listCircles(): Promise<AuthCircle[]>;
|
|
1325
|
-
getCircle(circleId: string): Promise<AuthCircle | null>;
|
|
1326
|
-
updateCircle(circleId: string, options: UpdateCircleOptions): Promise<AuthCircle>;
|
|
1327
|
-
deleteCircle(circleId: string): Promise<void>;
|
|
1328
|
-
addCircleMember(circleId: string, options: AddCircleMemberOptions): Promise<void>;
|
|
1329
|
-
removeCircleMember(circleId: string, userId: string): Promise<void>;
|
|
1330
|
-
getCircleMembers(circleId: string): Promise<CircleMembership[]>;
|
|
1331
|
-
getUserCircles(userId: string): Promise<AuthCircle[]>;
|
|
1332
|
-
createResource(options: CreateResourceOptions): Promise<Resource>;
|
|
1333
|
-
listResources(): Promise<Resource[]>;
|
|
1334
|
-
updateResource(resourceId: string, options: UpdateResourceOptions): Promise<Resource>;
|
|
1335
|
-
deleteResource(resourceId: string): Promise<void>;
|
|
1336
|
-
createRelationType(options: CreateRelationTypeOptions): Promise<RelationType>;
|
|
1337
|
-
listRelationTypes(): Promise<RelationType[]>;
|
|
1338
|
-
updateRelationType(id: string, options: UpdateRelationTypeOptions): Promise<RelationType>;
|
|
1339
|
-
deleteRelationType(id: string): Promise<void>;
|
|
1340
|
-
getProfile(userId: string): Promise<Record<string, any>>;
|
|
1341
|
-
setProfile(userId: string, data: Record<string, any>): Promise<void>;
|
|
1342
|
-
getAuthConfig(): Promise<AuthConfig>;
|
|
1343
|
-
setAuthConfig(config: AuthConfig): Promise<void>;
|
|
1344
|
-
readonly stewardship: AuthStewardshipApi;
|
|
1345
|
-
/**
|
|
1346
|
-
* Explicitly bind the caller for the remainder of this request.
|
|
1347
|
-
* Pass a JWT to validate + bind, or `null` / `""` to clear.
|
|
1348
|
-
*
|
|
1349
|
-
* `login()` already binds implicitly on success; reach for `setCurrentUser`
|
|
1350
|
-
* when you receive a JWT from an inbound `Authorization` header or cookie
|
|
1351
|
-
* and want subsequent KV/DB/realtime/media ops to run as that user.
|
|
1352
|
-
*
|
|
1353
|
-
* Not available on remote clients — throws.
|
|
1354
|
-
*/
|
|
1355
|
-
setCurrentUser(token: string | null): Promise<void>;
|
|
1356
|
-
/**
|
|
1357
|
-
* Snapshot of the currently bound caller. Returns an anonymous caller
|
|
1358
|
-
* (`is_anonymous: true`) when no identity has been bound.
|
|
1359
|
-
*
|
|
1360
|
-
* Not available on remote clients — throws.
|
|
1361
|
-
*/
|
|
1362
|
-
getCurrentUser(): AuthCaller;
|
|
1363
|
-
/**
|
|
1364
|
-
* Ask the policy engine whether the bound caller would be allowed to
|
|
1365
|
-
* perform `action` on `resourceId`, given the supplied `node` payload.
|
|
1366
|
-
* Returns a boolean — never throws on denial.
|
|
1367
|
-
*
|
|
1368
|
-
* The check runs the exact same evaluator that gates direct KV/DB/
|
|
1369
|
-
* realtime/media ops, so `can(...)` is authoritative.
|
|
1370
|
-
*
|
|
1371
|
-
* @example
|
|
1372
|
-
* ```typescript
|
|
1373
|
-
* const ok = await platform.auth.can("delete", "documents", {
|
|
1374
|
-
* owner: doc.owner,
|
|
1375
|
-
* status: doc.status,
|
|
1376
|
-
* });
|
|
1377
|
-
* if (!ok) return new Response("Forbidden", { status: 403 });
|
|
1378
|
-
* ```
|
|
1379
|
-
*
|
|
1380
|
-
* Not available on remote clients — throws.
|
|
1381
|
-
*/
|
|
1382
|
-
can(action: string, resourceId: string, node?: Record<string, unknown> | null): Promise<boolean>;
|
|
1383
|
-
}
|
|
821
|
+
|
|
1384
822
|
/**
|
|
1385
823
|
* Per-request opt-out toggle for the Layer 2 policy evaluator.
|
|
1386
824
|
*
|
|
@@ -2066,4 +1504,4 @@ declare function getPlatform(options?: {
|
|
|
2066
1504
|
*/
|
|
2067
1505
|
declare function clearPlatformCache(): void;
|
|
2068
1506
|
|
|
2069
|
-
export { type
|
|
1507
|
+
export { type Database, type DbFindOptions, type IndexDescriptor, type IndexDirection, type IndexKind, type IndexSpec, type KvListResult, type KvNamespace, type ListScheduledFilter, MediaLocalParticipant, type MediaParticipant, type MediaParticipantInfo, MediaRoom, MediaRoomEvent, type MediaRoomInfo, type MediaRoomInfoSettings, type MediaRoomOptions, type MediaService, type MediaTokenResult, type MediaTrackPublication, type NotificationPayload, type Platform, type PlatformEnv, type PolicyService, type PresenceMember, type PresenceService, type PublicPushConfig, type PushService, type PushTarget, type QueueStats, RealtimeClient, type RealtimeClientOptions, type RealtimeEvent, type RealtimeService, RemoteMediaService, type RequestStore, type ScheduleOptions, type ScheduledJob, type SendReport, type Storage, type StoragePutStreamSource, type StoredPushSubscription, type SubscriptionCounts, type TrackKind, type TrackSource, type VectorAggregation, type VectorIndexDescriptor, type VectorIndexSpec, type VectorMetric, type VectorQuery, type VectorQueryMode, type VectorQueryWithFilter, type VectorSearchHit, type VectorStorage, type VideoResolution, type WorkflowHandle, type WorkflowRun, type WorkflowRunStatus, type WorkflowStepKind, type WorkflowStepRecord, type Workflows, attachTrack, clearPlatformCache, detachTrack, getCurrentRequestStore, getPlatform, runWithRequest };
|
package/dist/index.js
CHANGED
|
@@ -568,6 +568,9 @@ var RemoteAuthService = class _RemoteAuthService {
|
|
|
568
568
|
async deleteUser(userId) {
|
|
569
569
|
await this.post("/delete-user", { user_id: userId });
|
|
570
570
|
}
|
|
571
|
+
async createManagedUser(options) {
|
|
572
|
+
return this.post("/create-managed-user", options);
|
|
573
|
+
}
|
|
571
574
|
async sendVerification(userId) {
|
|
572
575
|
return this.post("/send-verification", { user_id: userId });
|
|
573
576
|
}
|
|
@@ -684,6 +687,28 @@ var RemoteAuthService = class _RemoteAuthService {
|
|
|
684
687
|
async deleteRelationType(id) {
|
|
685
688
|
await this.post("/relation-types/delete", { id });
|
|
686
689
|
}
|
|
690
|
+
// ── Relations (typed edges, FR-1) ──
|
|
691
|
+
async addRelation(options) {
|
|
692
|
+
return this.post("/relations/add", {
|
|
693
|
+
from_user_id: options.from_user_id,
|
|
694
|
+
to_user_id: options.to_user_id,
|
|
695
|
+
relation_type: options.relation_type,
|
|
696
|
+
metadata: options.metadata ?? null
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
async removeRelation(fromUserId, toUserId, relationTypeId) {
|
|
700
|
+
await this.post("/relations/remove", {
|
|
701
|
+
from_user_id: fromUserId,
|
|
702
|
+
to_user_id: toUserId,
|
|
703
|
+
relation_type_id: relationTypeId
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
async listRelations(options) {
|
|
707
|
+
return this.post("/relations/list", {
|
|
708
|
+
user_id: options.user_id,
|
|
709
|
+
direction: options.direction ?? "both"
|
|
710
|
+
});
|
|
711
|
+
}
|
|
687
712
|
// ── Profile ──
|
|
688
713
|
async getProfile(userId) {
|
|
689
714
|
return this.post("/profile/get", { user_id: userId });
|
|
@@ -808,6 +833,43 @@ var RemoteAuthService = class _RemoteAuthService {
|
|
|
808
833
|
});
|
|
809
834
|
return Boolean(r?.allowed);
|
|
810
835
|
}
|
|
836
|
+
async explain(action, resourceId, node) {
|
|
837
|
+
const { getCurrentRequestStore: getCurrentRequestStore2 } = await Promise.resolve().then(() => (init_request_scope(), request_scope_exports));
|
|
838
|
+
const store = getCurrentRequestStore2();
|
|
839
|
+
const token = store?.token;
|
|
840
|
+
if (!token) {
|
|
841
|
+
return { allowed: false, reason: "no bound user" };
|
|
842
|
+
}
|
|
843
|
+
const r = await this.post("/can-explain", {
|
|
844
|
+
token,
|
|
845
|
+
action,
|
|
846
|
+
resource_id: resourceId,
|
|
847
|
+
node: node ?? null
|
|
848
|
+
});
|
|
849
|
+
return {
|
|
850
|
+
allowed: Boolean(r?.allowed),
|
|
851
|
+
reason: r?.reason,
|
|
852
|
+
failedClause: r?.failedClause
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
async canMany(checks) {
|
|
856
|
+
const { getCurrentRequestStore: getCurrentRequestStore2 } = await Promise.resolve().then(() => (init_request_scope(), request_scope_exports));
|
|
857
|
+
const store = getCurrentRequestStore2();
|
|
858
|
+
const token = store?.token;
|
|
859
|
+
if (!token) {
|
|
860
|
+
return checks.map(() => ({ allowed: false }));
|
|
861
|
+
}
|
|
862
|
+
const r = await this.post("/can-many", {
|
|
863
|
+
token,
|
|
864
|
+
checks: checks.map((c) => ({
|
|
865
|
+
action: c.action,
|
|
866
|
+
resource_id: c.resourceId,
|
|
867
|
+
node: c.node ?? null
|
|
868
|
+
}))
|
|
869
|
+
});
|
|
870
|
+
const results = Array.isArray(r) ? r : r?.results ?? [];
|
|
871
|
+
return checks.map((_, i) => ({ allowed: Boolean(results[i]?.allowed) }));
|
|
872
|
+
}
|
|
811
873
|
};
|
|
812
874
|
Promise.resolve().then(() => (init_request_scope(), request_scope_exports)).then((mod) => {
|
|
813
875
|
RemoteAuthService._requestScope = mod;
|