@krak-stack/auth 0.1.17 → 0.1.18

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.
@@ -209,6 +209,17 @@ const isOrganizationSlugConflict = (error) => {
209
209
  });
210
210
  };
211
211
  const nullableString = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
212
+ const assetPath = (value) => {
213
+ if (!value?.trim())
214
+ return null;
215
+ try {
216
+ const url = new URL(value);
217
+ return url.pathname.startsWith("/api/assets/") ? url.pathname : value;
218
+ }
219
+ catch {
220
+ return value;
221
+ }
222
+ };
212
223
  const parsePresignedUpload = (value, m) => {
213
224
  if (!isRecord(value) ||
214
225
  typeof value.uploadUrl !== "string" ||
@@ -236,12 +247,13 @@ const uploadOrganizationLogo = async (authClient, file, m) => {
236
247
  if (!uploadResponse.ok) {
237
248
  throw new Error(m.organization_logo_upload_error());
238
249
  }
239
- return presigned.url;
250
+ return assetPath(presigned.url);
240
251
  };
241
252
  const currentOrganizationLocale = () => getLocale() === "fr" ? "fr" : "en";
242
253
  const parseOrganizationMetadata = (metadata) => {
243
254
  try {
244
- return Schema.decodeUnknownSync(OrganizationMetadata)(metadata);
255
+ const value = typeof metadata === "string" ? JSON.parse(metadata) : metadata;
256
+ return Schema.decodeUnknownSync(OrganizationMetadata)(value);
245
257
  }
246
258
  catch {
247
259
  return { translations: [] };
@@ -262,7 +274,7 @@ const organizationDisplay = (organization, m) => {
262
274
  organization?.name ||
263
275
  m.organization_switcher_label(),
264
276
  subtitle: organization?.slug ?? m.organization_switcher_label(),
265
- logo: translation?.logo || undefined,
277
+ image: translation?.icon || translation?.logo || undefined,
266
278
  };
267
279
  };
268
280
  const organizationFormDefaults = (organization) => {
@@ -273,24 +285,24 @@ const organizationFormDefaults = (organization) => {
273
285
  name: organization?.name ?? "",
274
286
  slug: organization?.slug ?? "",
275
287
  enName: en?.name || organization?.name || "",
276
- enLogo: null,
277
- enLogoUrl: en?.logo ?? "",
278
- enIcon: null,
279
- enIconUrl: en?.icon ?? "",
288
+ enLogo: en?.logo ?? null,
289
+ enIcon: en?.icon ?? null,
280
290
  enContactEmail: en?.contactEmail ?? "",
281
291
  enLocation: en?.location ?? "",
282
292
  frName: fr?.name ?? "",
283
- frLogo: null,
284
- frLogoUrl: fr?.logo ?? "",
285
- frIcon: null,
286
- frIconUrl: fr?.icon ?? "",
293
+ frLogo: fr?.logo ?? null,
294
+ frIcon: fr?.icon ?? null,
287
295
  frContactEmail: fr?.contactEmail ?? "",
288
296
  frLocation: fr?.location ?? "",
289
297
  };
290
298
  };
291
- const organizationLogoFromForm = async (authClient, file, fallback, m) => file
292
- ? await uploadOrganizationLogo(authClient, file, m)
293
- : nullableString(fallback);
299
+ const organizationLogoFromForm = async (authClient, value, m) => {
300
+ if (value instanceof File)
301
+ return await uploadOrganizationLogo(authClient, value, m);
302
+ if (typeof value === "string")
303
+ return assetPath(value);
304
+ return null;
305
+ };
294
306
  const organizationRoles = ["owner", "admin", "member"];
295
307
  const normalizeOrganizationRole = (role) => role === "owner" || role === "admin" || role === "member" ? role : "member";
296
308
  const organizationRoleLabel = (role, m) => {
@@ -315,10 +327,10 @@ const organizationMetadataFromForm = async (authClient, value, m) => {
315
327
  const translations = [];
316
328
  const enName = value.enName.trim() || value.name.trim();
317
329
  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);
330
+ const enLogo = await organizationLogoFromForm(authClient, value.enLogo, m);
331
+ const enIcon = await organizationLogoFromForm(authClient, value.enIcon, m);
332
+ const frLogo = await organizationLogoFromForm(authClient, value.frLogo, m);
333
+ const frIcon = await organizationLogoFromForm(authClient, value.frIcon, m);
322
334
  if (enName) {
323
335
  translations.push({
324
336
  locale: "en",
@@ -401,10 +413,10 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
401
413
  const activeDisplay = organizationDisplay(active ?? null, m);
402
414
  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
415
  ? 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 }
416
+ : 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
417
+ ? { imageSrc: activeDisplay.image }
418
+ : {}) }), _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
419
+ ? { imageSrc: activeDisplay.image }
408
420
  : {}) }) }), 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
421
  const display = organizationDisplay(organization, m);
410
422
  return (_jsx(DropdownMenuItem, { onClick: async () => {
@@ -415,7 +427,7 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
415
427
  await refresh();
416
428
  onChange?.(organization);
417
429
  }
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));
430
+ }, 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
431
  })) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
420
432
  ? m.organization_switcher_no_other_organizations()
421
433
  : 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 +571,22 @@ function EditOrganizationSection({ authClient, organization, onUpdated, }) {
559
571
  event.preventDefault();
560
572
  event.stopPropagation();
561
573
  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: {
574
+ }, 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
575
  width: 175,
564
576
  height: 50,
565
577
  suggestedWidth: 350,
566
578
  suggestedHeight: 100,
567
- } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.enIconUrl, size: {
579
+ } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
568
580
  width: 96,
569
581
  height: 96,
570
582
  suggestedWidth: 512,
571
583
  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: {
584
+ } })) }), _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
585
  width: 175,
574
586
  height: 50,
575
587
  suggestedWidth: 350,
576
588
  suggestedHeight: 100,
577
- } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.frIconUrl, size: {
589
+ } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
578
590
  width: 96,
579
591
  height: 96,
580
592
  suggestedWidth: 512,
@@ -650,22 +662,22 @@ function CreateOrganizationSection({ authClient, onCreated, }) {
650
662
  event.preventDefault();
651
663
  event.stopPropagation();
652
664
  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: {
665
+ }, 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
666
  width: 175,
655
667
  height: 50,
656
668
  suggestedWidth: 350,
657
669
  suggestedHeight: 100,
658
- } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.enIconUrl, size: {
670
+ } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
659
671
  width: 96,
660
672
  height: 96,
661
673
  suggestedWidth: 512,
662
674
  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: {
675
+ } })) }), _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
676
  width: 175,
665
677
  height: 50,
666
678
  suggestedWidth: 350,
667
679
  suggestedHeight: 100,
668
- } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.frIconUrl, size: {
680
+ } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), size: {
669
681
  width: 96,
670
682
  height: 96,
671
683
  suggestedWidth: 512,
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.18",
4
4
  "description": "Effect HttpApi clients and schemas for KrakStack Auth.",
5
5
  "license": "MIT",
6
6
  "files": [