@krak-stack/auth 0.1.17 → 0.1.19

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.
@@ -16,6 +16,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "
16
16
  import { Separator } from "@/components/ui/separator";
17
17
  import { cn } from "@/lib/utils";
18
18
  import { OrganizationMetadata, } from "@krak-stack/auth/schema";
19
+ import { assetPath, isRecord } from "./utils";
19
20
  const messages = {
20
21
  en: {
21
22
  api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
@@ -217,7 +218,6 @@ const parsePresignedUpload = (value, m) => {
217
218
  }
218
219
  return { uploadUrl: value.uploadUrl, url: value.url };
219
220
  };
220
- const isRecord = (value) => typeof value === "object" && value !== null;
221
221
  const uploadOrganizationLogo = async (authClient, file, m) => {
222
222
  const contentType = file.type || "image/png";
223
223
  const presignResult = await authClient.$fetch("../organizations/logo/presign", {
@@ -236,12 +236,13 @@ const uploadOrganizationLogo = async (authClient, file, m) => {
236
236
  if (!uploadResponse.ok) {
237
237
  throw new Error(m.organization_logo_upload_error());
238
238
  }
239
- return presigned.url;
239
+ return assetPath(presigned.url);
240
240
  };
241
241
  const currentOrganizationLocale = () => getLocale() === "fr" ? "fr" : "en";
242
242
  const parseOrganizationMetadata = (metadata) => {
243
243
  try {
244
- return Schema.decodeUnknownSync(OrganizationMetadata)(metadata);
244
+ const value = typeof metadata === "string" ? JSON.parse(metadata) : metadata;
245
+ return Schema.decodeUnknownSync(OrganizationMetadata)(value);
245
246
  }
246
247
  catch {
247
248
  return { translations: [] };
@@ -262,7 +263,7 @@ const organizationDisplay = (organization, m) => {
262
263
  organization?.name ||
263
264
  m.organization_switcher_label(),
264
265
  subtitle: organization?.slug ?? m.organization_switcher_label(),
265
- logo: translation?.logo || undefined,
266
+ image: translation?.icon || translation?.logo || undefined,
266
267
  };
267
268
  };
268
269
  const organizationFormDefaults = (organization) => {
@@ -273,24 +274,24 @@ const organizationFormDefaults = (organization) => {
273
274
  name: organization?.name ?? "",
274
275
  slug: organization?.slug ?? "",
275
276
  enName: en?.name || organization?.name || "",
276
- enLogo: null,
277
- enLogoUrl: en?.logo ?? "",
278
- enIcon: null,
279
- enIconUrl: en?.icon ?? "",
277
+ enLogo: en?.logo ?? null,
278
+ enIcon: en?.icon ?? null,
280
279
  enContactEmail: en?.contactEmail ?? "",
281
280
  enLocation: en?.location ?? "",
282
281
  frName: fr?.name ?? "",
283
- frLogo: null,
284
- frLogoUrl: fr?.logo ?? "",
285
- frIcon: null,
286
- frIconUrl: fr?.icon ?? "",
282
+ frLogo: fr?.logo ?? null,
283
+ frIcon: fr?.icon ?? null,
287
284
  frContactEmail: fr?.contactEmail ?? "",
288
285
  frLocation: fr?.location ?? "",
289
286
  };
290
287
  };
291
- const organizationLogoFromForm = async (authClient, file, fallback, m) => file
292
- ? await uploadOrganizationLogo(authClient, file, m)
293
- : nullableString(fallback);
288
+ const organizationLogoFromForm = async (authClient, value, m) => {
289
+ if (value instanceof File)
290
+ return await uploadOrganizationLogo(authClient, value, m);
291
+ if (typeof value === "string")
292
+ return assetPath(value);
293
+ return null;
294
+ };
294
295
  const organizationRoles = ["owner", "admin", "member"];
295
296
  const normalizeOrganizationRole = (role) => role === "owner" || role === "admin" || role === "member" ? role : "member";
296
297
  const organizationRoleLabel = (role, m) => {
@@ -315,10 +316,10 @@ const organizationMetadataFromForm = async (authClient, value, m) => {
315
316
  const translations = [];
316
317
  const enName = value.enName.trim() || value.name.trim();
317
318
  const frName = value.frName.trim();
318
- const enLogo = await organizationLogoFromForm(authClient, value.enLogo, value.enLogoUrl, m);
319
- const enIcon = await organizationLogoFromForm(authClient, value.enIcon, value.enIconUrl, m);
320
- const frLogo = await organizationLogoFromForm(authClient, value.frLogo, value.frLogoUrl, m);
321
- const frIcon = await organizationLogoFromForm(authClient, value.frIcon, value.frIconUrl, m);
319
+ const enLogo = await organizationLogoFromForm(authClient, value.enLogo, m);
320
+ const enIcon = await organizationLogoFromForm(authClient, value.enIcon, m);
321
+ const frLogo = await organizationLogoFromForm(authClient, value.frLogo, m);
322
+ const frIcon = await organizationLogoFromForm(authClient, value.frIcon, m);
322
323
  if (enName) {
323
324
  translations.push({
324
325
  locale: "en",
@@ -401,10 +402,10 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
401
402
  const activeDisplay = organizationDisplay(active ?? null, m);
402
403
  return (_jsxs(OrganizationMessagesContext.Provider, { value: m, children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "ghost", className: cn("h-11 w-full justify-between gap-2 !px-1 !py-0 group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-start group-data-[collapsible=icon]:!p-0", className), children: [_jsx(AppBrand, { to: null, label: activeName
403
404
  ? activeDisplay.name
404
- : m.organization_switcher_label(), subtitle: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "min-w-0 flex-1 !p-0 text-left group-data-[collapsible=icon]:flex-none group-data-[collapsible=icon]:justify-start", ...(activeDisplay.logo
405
- ? { imageSrc: activeDisplay.logo }
406
- : {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.logo
407
- ? { imageSrc: activeDisplay.logo }
405
+ : m.organization_switcher_label(), subtitle: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "min-w-0 flex-1 !p-0 text-left group-data-[collapsible=icon]:flex-none group-data-[collapsible=icon]:justify-start", ...(activeDisplay.image
406
+ ? { imageSrc: activeDisplay.image }
407
+ : {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
408
+ ? { imageSrc: activeDisplay.image }
408
409
  : {}) }) }), hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, !locked && selectableOrganizations.length ? (selectableOrganizations.map((organization) => {
409
410
  const display = organizationDisplay(organization, m);
410
411
  return (_jsx(DropdownMenuItem, { onClick: async () => {
@@ -415,7 +416,7 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
415
416
  await refresh();
416
417
  onChange?.(organization);
417
418
  }
418
- }, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: display.subtitle, icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.logo ? { imageSrc: display.logo } : {}) }) }, organization.id));
419
+ }, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: display.subtitle, icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.image ? { imageSrc: display.image } : {}) }) }, organization.id));
419
420
  })) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
420
421
  ? m.organization_switcher_no_other_organizations()
421
422
  : m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}), !locked ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("create"), children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => {
@@ -559,22 +560,22 @@ function EditOrganizationSection({ authClient, organization, onUpdated, }) {
559
560
  event.preventDefault();
560
561
  event.stopPropagation();
561
562
  form.handleSubmit();
562
- }, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), required: true })) }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.enLogoUrl, size: {
563
+ }, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), required: true })) }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
563
564
  width: 175,
564
565
  height: 50,
565
566
  suggestedWidth: 350,
566
567
  suggestedHeight: 100,
567
- } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.enIconUrl, size: {
568
+ } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
568
569
  width: 96,
569
570
  height: 96,
570
571
  suggestedWidth: 512,
571
572
  suggestedHeight: 512,
572
- } })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.frLogoUrl, size: {
573
+ } })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
573
574
  width: 175,
574
575
  height: 50,
575
576
  suggestedWidth: 350,
576
577
  suggestedHeight: 100,
577
- } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.frIconUrl, size: {
578
+ } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
578
579
  width: 96,
579
580
  height: 96,
580
581
  suggestedWidth: 512,
@@ -650,22 +651,22 @@ function CreateOrganizationSection({ authClient, onCreated, }) {
650
651
  event.preventDefault();
651
652
  event.stopPropagation();
652
653
  form.handleSubmit();
653
- }, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(CreateOrganizationSlugAutoFill, { form: form }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.enLogoUrl, size: {
654
+ }, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(CreateOrganizationSlugAutoFill, { form: form }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
654
655
  width: 175,
655
656
  height: 50,
656
657
  suggestedWidth: 350,
657
658
  suggestedHeight: 100,
658
- } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.enIconUrl, size: {
659
+ } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
659
660
  width: 96,
660
661
  height: 96,
661
662
  suggestedWidth: 512,
662
663
  suggestedHeight: 512,
663
- } })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.frLogoUrl, size: {
664
+ } })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
664
665
  width: 175,
665
666
  height: 50,
666
667
  suggestedWidth: 350,
667
668
  suggestedHeight: 100,
668
- } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.frIconUrl, size: {
669
+ } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
669
670
  width: 96,
670
671
  height: 96,
671
672
  suggestedWidth: 512,
@@ -14,6 +14,7 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, }
14
14
  import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, } from "@/components/ui/field";
15
15
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
16
16
  import { Separator } from "@/components/ui/separator";
17
+ import { assetPath, isRecord } from "./utils";
17
18
  const messages = {
18
19
  en: {
19
20
  api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
@@ -201,7 +202,6 @@ const userButtonMessageFns = (labels) => {
201
202
  const UserButtonMessagesContext = createContext(userButtonMessageFns(userButtonMessages()));
202
203
  const useUserButtonMessages = () => useContext(UserButtonMessagesContext);
203
204
  const isFile = (value) => value instanceof File;
204
- const isRecord = (value) => typeof value === "object" && value !== null;
205
205
  const presignUserImageUpload = async (authClient, file, m) => {
206
206
  const contentType = file.type || "image/png";
207
207
  const result = await authClient.$fetch("/image/presign", {
@@ -255,10 +255,10 @@ export const UserButton = ({ authClient, signOutRedirect = "/", side = "bottom",
255
255
  if (!uploadResponse.ok) {
256
256
  throw new Error(m.user_profile_image_upload_error());
257
257
  }
258
- return presigned.url;
258
+ return assetPath(presigned.url);
259
259
  })()
260
260
  : typeof values.image === "string"
261
- ? values.image
261
+ ? assetPath(values.image)
262
262
  : null;
263
263
  const result = await authClient.updateUser({
264
264
  name: values.name.trim(),
@@ -0,0 +1,2 @@
1
+ export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
2
+ export declare const assetPath: (value: string | null | undefined) => string | null;
@@ -0,0 +1,12 @@
1
+ export const isRecord = (value) => typeof value === "object" && value !== null;
2
+ export const assetPath = (value) => {
3
+ if (!value?.trim())
4
+ return null;
5
+ try {
6
+ const url = new URL(value);
7
+ return url.pathname.startsWith("/api/assets/") ? url.pathname : value;
8
+ }
9
+ catch {
10
+ return value;
11
+ }
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/auth",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [