@krak-stack/auth 0.2.11 → 0.2.12

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.
@@ -117,7 +117,7 @@ export declare const AuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpApiEndp
117
117
  readonly createdAt: Schema.DateFromString;
118
118
  readonly updatedAt: Schema.DateFromString;
119
119
  }>;
120
- }>>, Schema.toCodecJson<typeof AuthBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"adminStopImpersonating", "POST", "/admin/stop-impersonating", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
120
+ }>>, Schema.toCodecJson<typeof AuthBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"adminStopImpersonating", "POST", "/admin/stop-impersonating", never, never, Schema.toCodecJson<Schema.Struct<{}>>, never, Schema.toCodecJson<Schema.Struct<{
121
121
  readonly session: Schema.Struct<{
122
122
  readonly id: Schema.String;
123
123
  readonly expiresAt: Schema.DateFromString;
@@ -1,6 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { HttpApiEndpoint, HttpApiGroup, OpenApi, } from "effect/unstable/httpapi";
3
- import { AdminBanUserPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
3
+ import { AdminBanUserPayload, AdminStopImpersonatingPayload, AdminUserIdPayload, AdminUserResponse, AuthBadRequest, AuthConflict, AuthExpectationFailed, AuthForbidden, AuthInternalServerError, AuthInvitation, AuthNotFound, AuthOrganization, AuthSessionResponse, AuthStatusResponse, AuthSuccessResponse, AuthTooManyRequests, AuthUnauthorized, ChangePasswordPayload, ChangePasswordResponse, CreateOrganizationPayload, DeleteApiKeyPayload, FullAuthOrganization, GetFullOrganizationQuery, GetInvitationQuery, GetInvitationResponse, GetSessionQuery, GetSessionResponse, InvitationActionResponse, InvitationIdPayload, InviteMemberPayload, LeaveOrganizationPayload, LinkedAccount, LinkSocialPayload, ListApiKeysQuery, ListApiKeysResponse, MemberResponse, OAuthConsentPayload, OAuthPublicClient, OAuthPublicClientQuery, OAuthRedirectResponse, OrganizationImpersonateUserPayload, OrganizationImpersonateUserResponse, OrganizationInvitationsQuery, OrganizationListMembersQuery, OrganizationListMembersResponse, RemoveMemberPayload, RequestPasswordResetPayload, RequestPasswordResetResponse, ResetPasswordPayload, SendVerificationOtpPayload, SetActiveOrganizationPayload, SignInEmailOtpPayload, SignInEmailPayload, SignInEmailResponse, SignInResponse, SignInSocialPayload, SignOutPayload, SocialRedirectResponse, TwoFactorBackupVerifyPayload, TwoFactorDisablePayload, TwoFactorEnablePayload, TwoFactorEnableResponse, TwoFactorSendPayload, TwoFactorVerifyPayload, UnlinkAccountPayload, UpdateMemberRolePayload, UpdateOrganizationPayload, UpdateUserPayload, UserInvitationsQuery, VerifyEmailOtpPayload, VerifyEmailOtpResponse, } from "./schema.js";
4
4
  export * from "./schema.js";
5
5
  const errors = [
6
6
  AuthBadRequest,
@@ -218,6 +218,7 @@ export const AuthApiGroup = HttpApiGroup.make("auth")
218
218
  error: errors,
219
219
  }).annotateMerge(docs("Impersonate user", "Starts a user impersonation session.")))
220
220
  .add(HttpApiEndpoint.post("adminStopImpersonating", "/admin/stop-impersonating", {
221
+ payload: AdminStopImpersonatingPayload,
221
222
  success: AuthSessionResponse,
222
223
  error: errors,
223
224
  }).annotateMerge(docs("Stop impersonating", "Restores the administrator session.")))
@@ -1176,6 +1176,7 @@ export declare const DeleteApiKeyPayload: Schema.Struct<{
1176
1176
  export declare const AdminUserIdPayload: Schema.Struct<{
1177
1177
  readonly userId: Schema.String;
1178
1178
  }>;
1179
+ export declare const AdminStopImpersonatingPayload: Schema.Struct<{}>;
1179
1180
  export declare const AdminBanUserPayload: Schema.Struct<{
1180
1181
  readonly userId: Schema.String;
1181
1182
  readonly banReason: Schema.optional<Schema.String>;
@@ -602,6 +602,10 @@ export const AdminUserIdPayload = Schema.Struct({
602
602
  identifier: "AdminUserIdPayload",
603
603
  title: "Admin user ID payload",
604
604
  });
605
+ export const AdminStopImpersonatingPayload = Schema.Struct({}).annotate({
606
+ identifier: "AdminStopImpersonatingPayload",
607
+ title: "Stop impersonating payload",
608
+ });
605
609
  export const AdminBanUserPayload = Schema.Struct({
606
610
  userId: Schema.String,
607
611
  banReason: Schema.optional(Schema.String),
@@ -1,18 +1,21 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useAtomSet, useAtomSubscribe, useAtomValue } from "@effect/atom-react";
3
+ import { useNavigate, useRouter } from "@tanstack/react-router";
3
4
  import { Cause, Effect, Schema } from "effect";
4
5
  import { Atom, AsyncResult } from "effect/unstable/reactivity";
5
- import { Building2, Pencil, Trash2 } from "lucide-react";
6
+ import { Building2, Pencil, Trash2, UserCog } from "lucide-react";
6
7
  import { useState } from "react";
7
8
  import { DataTable, DataTableListSummary, } from "@krak-stack/registry/data-table";
8
9
  import { SortParamsFromString, } from "@krak-stack/registry/query";
9
10
  import { ErrorMessage } from "@krak-stack/registry/effect-form";
10
11
  import { AppBrand } from "@krak-stack/registry/app-brand";
12
+ import * as messages from "@/paraglide/messages";
11
13
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
12
14
  import { AdminOrganizationForm } from "./admin-organization-form.js";
13
15
  import { authClientApi, authHttpClient } from "./auth-client-api.js";
14
16
  import { useKrakstackAuth } from "./auth-provider.js";
15
17
  import { assetUrl, organizationBranding } from "./utils.js";
18
+ import { notifyAuthChange } from "./auth-atoms.js";
16
19
  const defaultMessages = {
17
20
  en: {
18
21
  admin_column_created: "Created",
@@ -103,6 +106,24 @@ export function AdminOrganizationsTable({ onSearchChange, reloadKey = 0, search,
103
106
  const m = labels(locale);
104
107
  const baseUrl = auth?.baseUrl;
105
108
  const projectId = auth?.projectId;
109
+ const navigate = useNavigate();
110
+ const router = useRouter();
111
+ const [impersonateAtom] = useState(() => authClientApi(baseUrl).runtime.fn(({ userId, organizationId, }) => Effect.gen(function* () {
112
+ const client = yield* authHttpClient(baseUrl);
113
+ yield* client.auth.adminImpersonateUser({ payload: { userId } });
114
+ yield* client.auth
115
+ .organizationSetActive({ payload: { organizationId } })
116
+ .pipe(Effect.tapError(() => client.auth.adminStopImpersonating({ payload: {} })), Effect.ensuring(Effect.sync(notifyAuthChange)));
117
+ yield* Effect.tryPromise({
118
+ try: async () => {
119
+ await navigate({ to: "/" });
120
+ await router.invalidate();
121
+ },
122
+ catch: (cause) => cause instanceof Error ? cause : new Error(String(cause)),
123
+ });
124
+ })));
125
+ const impersonate = useAtomSet(impersonateAtom);
126
+ const impersonateResult = useAtomValue(impersonateAtom);
106
127
  const [refreshKey, setRefreshKey] = useState(0);
107
128
  const [editingOrganization, setEditingOrganization] = useState(null);
108
129
  const [deletingOrganization, setDeletingOrganization] = useState(null);
@@ -132,7 +153,7 @@ export function AdminOrganizationsTable({ onSearchChange, reloadKey = 0, search,
132
153
  onFailure: () => false,
133
154
  onSuccess: () => false,
134
155
  });
135
- return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columnDefs: organizationColumns(m, locale, baseUrl), rowData: organizations, features: {
156
+ return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, AsyncResult.isFailure(impersonateResult) ? (_jsx(ErrorMessage, { text: messages.organization_impersonate_member_error({}, { locale }) })) : null, _jsx(DataTable, { columnDefs: organizationColumns(m, locale, baseUrl, impersonate, impersonateResult.waiting), rowData: organizations, features: {
136
157
  columnVisibility: true,
137
158
  export: { baseName: "organizations" },
138
159
  gallery: false,
@@ -167,7 +188,7 @@ export function AdminOrganizationsTable({ onSearchChange, reloadKey = 0, search,
167
188
  setRefreshKey((current) => current + 1);
168
189
  } })) : null] }));
169
190
  }
170
- const organizationColumns = (m, locale, baseUrl) => [
191
+ const organizationColumns = (m, locale, baseUrl, impersonate, isImpersonating) => [
171
192
  {
172
193
  field: "name",
173
194
  headerName: m.admin_column_organization,
@@ -179,7 +200,29 @@ const organizationColumns = (m, locale, baseUrl) => [
179
200
  {
180
201
  field: "memberCount",
181
202
  headerName: m.admin_column_members,
182
- cellRenderer: ({ data }) => (_jsx(OrganizationMembers, { baseUrl: baseUrl, members: data.memberPreviews ?? [], total: data.memberCount ?? 0 })),
203
+ type: "list",
204
+ typeOptions: {
205
+ emptyLabel: "0",
206
+ display: "icon",
207
+ getItems: (row) => (row.memberPreviews ?? []).map((member) => ({
208
+ value: member.id,
209
+ label: member.name,
210
+ imageSrc: assetUrl(member.image, baseUrl),
211
+ })),
212
+ getTotalCount: (row) => row.memberCount ?? 0,
213
+ actionsLabel: m.admin_column_members,
214
+ itemActions: [
215
+ {
216
+ name: messages.organization_impersonate_member({}, { locale }),
217
+ icon: _jsx(UserCog, { className: "size-4" }),
218
+ disabled: () => isImpersonating,
219
+ onClick: ({ item, row }) => {
220
+ if (item.value)
221
+ impersonate({ userId: item.value, organizationId: row.id });
222
+ },
223
+ },
224
+ ],
225
+ },
183
226
  },
184
227
  {
185
228
  field: "projects",
@@ -191,7 +234,7 @@ const organizationColumns = (m, locale, baseUrl) => [
191
234
  value: project.id,
192
235
  icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(project.name)),
193
236
  };
194
- }), variant: "icon" })),
237
+ }), display: "icon" })),
195
238
  },
196
239
  {
197
240
  field: "createdAt",
@@ -205,16 +248,6 @@ const initials = (name) => name
205
248
  .map((part) => part[0])
206
249
  .join("")
207
250
  .toUpperCase();
208
- function OrganizationMembers({ baseUrl, members, total, }) {
209
- return (_jsx(DataTableListSummary, { emptyLabel: "0", items: members.map((member) => {
210
- const image = assetUrl(member.image, baseUrl);
211
- return {
212
- label: member.name,
213
- value: member.id,
214
- icon: image ? (_jsx("img", { alt: "", className: "size-full object-cover", src: image })) : (initials(member.name)),
215
- };
216
- }), totalCount: total, variant: "icon" }));
217
- }
218
251
  function DeleteOrganizationDialog({ baseUrl, labels: m, organization, onClose, onDeleted, }) {
219
252
  const [deleteOrganizationAtom] = useState(() => authClientApi(baseUrl).runtime.fn((id) => Effect.flatMap(authHttpClient(baseUrl), (http) => http.admin.deleteOrganization({ params: { id } }))));
220
253
  const deleteOrganization = useAtomSet(deleteOrganizationAtom);
@@ -305,7 +305,7 @@ const userColumns = (m, baseUrl) => [
305
305
  value: organization.id,
306
306
  icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(organization.name)),
307
307
  };
308
- }), variant: "icon" })),
308
+ }), display: "icon" })),
309
309
  },
310
310
  {
311
311
  field: "projects",
@@ -317,7 +317,7 @@ const userColumns = (m, baseUrl) => [
317
317
  value: project.id,
318
318
  icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(project.name)),
319
319
  };
320
- }), variant: "icon" })),
320
+ }), display: "icon" })),
321
321
  },
322
322
  {
323
323
  field: "emailVerified",
@@ -529,7 +529,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
529
529
  readonly updatedAt: import("effect/Schema").DateFromString;
530
530
  }>;
531
531
  }>>, import("effect/Schema").toCodecJson<typeof import("../auth/schema.js").AuthBadRequest>, never, never>, never, never>;
532
- readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
532
+ readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
533
533
  readonly session: import("effect/Schema").Struct<{
534
534
  readonly id: import("effect/Schema").String;
535
535
  readonly expiresAt: import("effect/Schema").DateFromString;
@@ -5,7 +5,7 @@ import { Effect, Option, Predicate, Schema } from "effect";
5
5
  import { AsyncResult, Atom } from "effect/unstable/reactivity";
6
6
  import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
7
7
  import { createContext, useContext, useEffect, useRef, useState, } from "react";
8
- import { DataTable, DataTableListSummary, DataTableRelationshipCell, } from "@krak-stack/registry/data-table";
8
+ import { DataTable, DataTableListSummary, DataTableListCell, } from "@krak-stack/registry/data-table";
9
9
  import { CheckboxField, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
10
10
  import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
11
11
  import { AppBrand } from "@krak-stack/registry/app-brand";
@@ -1367,10 +1367,10 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
1367
1367
  if (!canChangeRoles) {
1368
1368
  return (_jsx("div", { className: "flex flex-wrap gap-1", children: roleOptions.map((role) => (_jsx(Badge, { variant: "secondary", children: role.label }, role.value))) }));
1369
1369
  }
1370
- return (_jsx(DataTableRelationshipCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
1370
+ return (_jsx(DataTableListCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
1371
1371
  label: organizationRoleLabel(role, m),
1372
1372
  value: role,
1373
- })), value: roleOptions, onAdd: (value) => {
1373
+ })), items: roleOptions, onAdd: (value) => {
1374
1374
  if (!isOrganizationRole(value))
1375
1375
  return;
1376
1376
  onRoleChange(member, Array.from(new Set([...roles, value])));
@@ -500,7 +500,7 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
500
500
  const signOutResult = useAtomValue(signOutAction);
501
501
  const [stopImpersonatingAction] = useState(() => authClientApi(resolvedBaseUrl).runtime.fn((input) => Effect.gen(function* () {
502
502
  setIsStoppingImpersonation(true);
503
- yield* authHttpClient(input.baseUrl).pipe(Effect.flatMap((client) => client.auth.adminStopImpersonating()), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.tap(() => Effect.sync(input.refreshSession)), Effect.flatMap(() => Effect.tryPromise(() => navigate({ href: input.currentSiteHref }))), Effect.ensuring(Effect.sync(() => setIsStoppingImpersonation(false))));
503
+ yield* authHttpClient(input.baseUrl).pipe(Effect.flatMap((client) => client.auth.adminStopImpersonating({ payload: {} })), Effect.tap(() => Effect.sync(notifyAuthChange)), Effect.tap(() => Effect.sync(input.refreshSession)), Effect.flatMap(() => Effect.tryPromise(() => navigate({ href: input.currentSiteHref }))), Effect.ensuring(Effect.sync(() => setIsStoppingImpersonation(false))));
504
504
  })));
505
505
  const stopImpersonating = useAtomSet(stopImpersonatingAction);
506
506
  const stopImpersonatingResult = useAtomValue(stopImpersonatingAction);
package/dist/service.d.ts CHANGED
@@ -158,7 +158,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
158
158
  readonly updatedAt: import("effect/Schema").DateFromString;
159
159
  }>;
160
160
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest>, never, never>, never, never>;
161
- readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
161
+ readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
162
162
  readonly session: import("effect/Schema").Struct<{
163
163
  readonly id: import("effect/Schema").String;
164
164
  readonly expiresAt: import("effect/Schema").DateFromString;
@@ -2181,7 +2181,7 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
2181
2181
  readonly updatedAt: import("effect/Schema").DateFromString;
2182
2182
  }>;
2183
2183
  }>>, import("effect/Schema").toCodecJson<typeof import("./auth/schema.js").AuthBadRequest>, never, never>, never, never>;
2184
- readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2184
+ readonly adminStopImpersonating: HttpApiClient.Client.Method<import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"adminStopImpersonating", "POST", "/api/auth/admin/stop-impersonating", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{}>>, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
2185
2185
  readonly session: import("effect/Schema").Struct<{
2186
2186
  readonly id: import("effect/Schema").String;
2187
2187
  readonly expiresAt: import("effect/Schema").DateFromString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -76,7 +76,7 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "@effect/atom-react": "4.0.0-rc.112",
79
- "@krak-stack/registry": "^0.1.25",
79
+ "@krak-stack/registry": "^0.1.31",
80
80
  "@lucas-barake/effect-form-react": "^0.26.0-beta.5",
81
81
  "react-qr-code": "^2.2.0"
82
82
  },