@carlonicora/nextjs-jsonapi 1.63.0 → 1.65.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.
Files changed (62) hide show
  1. package/dist/{BlockNoteEditor-TS62AHRY.mjs → BlockNoteEditor-SCQGD6F2.mjs} +4 -4
  2. package/dist/{BlockNoteEditor-QQ4XFT4G.js → BlockNoteEditor-Y5XAD6NR.js} +14 -14
  3. package/dist/{BlockNoteEditor-QQ4XFT4G.js.map → BlockNoteEditor-Y5XAD6NR.js.map} +1 -1
  4. package/dist/billing/index.js +346 -346
  5. package/dist/billing/index.mjs +3 -3
  6. package/dist/{chunk-HRG4EAOG.mjs → chunk-5KMKI23S.mjs} +2 -2
  7. package/dist/{chunk-ZRKQQLYI.js → chunk-5ODPC3YX.js} +769 -821
  8. package/dist/chunk-5ODPC3YX.js.map +1 -0
  9. package/dist/{chunk-YHNDD34Z.mjs → chunk-G7PGWMFO.mjs} +95 -3
  10. package/dist/chunk-G7PGWMFO.mjs.map +1 -0
  11. package/dist/{chunk-NAST4OSM.js → chunk-LRXJT656.js} +96 -4
  12. package/dist/chunk-LRXJT656.js.map +1 -0
  13. package/dist/{chunk-K3DKXOEU.mjs → chunk-OLNMWVOV.mjs} +1172 -1224
  14. package/dist/chunk-OLNMWVOV.mjs.map +1 -0
  15. package/dist/{chunk-BQSMP4NU.js → chunk-RA4RYKYB.js} +11 -11
  16. package/dist/{chunk-BQSMP4NU.js.map → chunk-RA4RYKYB.js.map} +1 -1
  17. package/dist/client/index.js +4 -4
  18. package/dist/client/index.mjs +3 -3
  19. package/dist/components/index.d.mts +11 -8
  20. package/dist/components/index.d.ts +11 -8
  21. package/dist/components/index.js +4 -6
  22. package/dist/components/index.js.map +1 -1
  23. package/dist/components/index.mjs +3 -5
  24. package/dist/contexts/index.d.mts +2 -1
  25. package/dist/contexts/index.d.ts +2 -1
  26. package/dist/contexts/index.js +4 -4
  27. package/dist/contexts/index.mjs +3 -3
  28. package/dist/core/index.d.mts +44 -1
  29. package/dist/core/index.d.ts +44 -1
  30. package/dist/core/index.js +8 -2
  31. package/dist/core/index.js.map +1 -1
  32. package/dist/core/index.mjs +7 -1
  33. package/dist/index.d.mts +1 -1
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +9 -3
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +8 -2
  38. package/dist/server/index.js +3 -3
  39. package/dist/server/index.mjs +1 -1
  40. package/package.json +1 -1
  41. package/src/core/index.ts +1 -0
  42. package/src/core/registry/ModuleRegistry.ts +2 -0
  43. package/src/features/audit-log/audit-log.module.ts +10 -0
  44. package/src/features/audit-log/data/audit-log.interface.ts +12 -0
  45. package/src/features/audit-log/data/audit-log.service.ts +24 -0
  46. package/src/features/audit-log/data/audit-log.ts +65 -0
  47. package/src/features/audit-log/data/index.ts +3 -0
  48. package/src/features/audit-log/index.ts +2 -0
  49. package/src/features/company/company.module.ts +3 -1
  50. package/src/features/company/components/containers/CompanyContainer.tsx +7 -2
  51. package/src/features/company/components/details/CompanyDetails.tsx +16 -1
  52. package/src/features/company/components/forms/CompanyConfigurationEditor.tsx +19 -51
  53. package/src/features/company/components/forms/index.ts +0 -1
  54. package/src/features/company/contexts/CompanyContext.tsx +5 -3
  55. package/src/features/user/user.module.ts +3 -1
  56. package/dist/chunk-K3DKXOEU.mjs.map +0 -1
  57. package/dist/chunk-NAST4OSM.js.map +0 -1
  58. package/dist/chunk-YHNDD34Z.mjs.map +0 -1
  59. package/dist/chunk-ZRKQQLYI.js.map +0 -1
  60. package/src/features/company/components/forms/CompanyConfigurationSecurityForm.tsx +0 -83
  61. /package/dist/{BlockNoteEditor-TS62AHRY.mjs.map → BlockNoteEditor-SCQGD6F2.mjs.map} +0 -0
  62. /package/dist/{chunk-HRG4EAOG.mjs.map → chunk-5KMKI23S.mjs.map} +0 -0
@@ -0,0 +1,65 @@
1
+ import { AbstractApiData, JsonApiHydratedDataInterface, Modules, UserInterface } from "../../../core";
2
+ import { AuditLogInterface } from "./audit-log.interface";
3
+
4
+ export class AuditLog extends AbstractApiData implements AuditLogInterface {
5
+ private _kind: "audit" | "comment" = "audit";
6
+ private _action?: string;
7
+ private _fieldName?: string;
8
+ private _oldValue?: string;
9
+ private _newValue?: string;
10
+ private _content?: string;
11
+ private _annotationId?: string;
12
+ private _user?: UserInterface;
13
+
14
+ get kind(): "audit" | "comment" {
15
+ return this._kind;
16
+ }
17
+
18
+ get action(): string | undefined {
19
+ return this._action;
20
+ }
21
+
22
+ get fieldName(): string | undefined {
23
+ return this._fieldName;
24
+ }
25
+
26
+ get oldValue(): string | undefined {
27
+ return this._oldValue;
28
+ }
29
+
30
+ get newValue(): string | undefined {
31
+ return this._newValue;
32
+ }
33
+
34
+ get content(): string | undefined {
35
+ return this._content;
36
+ }
37
+
38
+ get annotationId(): string | undefined {
39
+ return this._annotationId;
40
+ }
41
+
42
+ get user(): UserInterface | undefined {
43
+ return this._user;
44
+ }
45
+
46
+ rehydrate(data: JsonApiHydratedDataInterface): this {
47
+ super.rehydrate(data);
48
+
49
+ this._kind = data.jsonApi.attributes.kind ?? "audit";
50
+ this._action = data.jsonApi.attributes.action ?? undefined;
51
+ this._fieldName = data.jsonApi.attributes.fieldName ?? undefined;
52
+ this._oldValue = data.jsonApi.attributes.oldValue ?? undefined;
53
+ this._newValue = data.jsonApi.attributes.newValue ?? undefined;
54
+ this._content = data.jsonApi.attributes.content ?? undefined;
55
+ this._annotationId = data.jsonApi.attributes.annotationId ?? undefined;
56
+
57
+ this._user = this._readIncluded(data, "user", Modules.User) as UserInterface | undefined;
58
+
59
+ return this;
60
+ }
61
+
62
+ createJsonApi(): any {
63
+ throw new Error("AuditLog is read-only");
64
+ }
65
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./audit-log";
2
+ export * from "./audit-log.interface";
3
+ export * from "./audit-log.service";
@@ -0,0 +1,2 @@
1
+ export * from "./data";
2
+ export * from "./audit-log.module";
@@ -1,5 +1,6 @@
1
- import { ModuleFactory } from "../../permissions";
1
+ import { Building2Icon } from "lucide-react";
2
2
  import { Company } from ".";
3
+ import { ModuleFactory } from "../../permissions";
3
4
 
4
5
  export const CompanyModule = (factory: ModuleFactory) =>
5
6
  factory({
@@ -7,4 +8,5 @@ export const CompanyModule = (factory: ModuleFactory) =>
7
8
  name: "companies",
8
9
  model: Company,
9
10
  moduleId: "f9e77c8f-bfd1-4fd4-80b0-e1d891ab7113",
11
+ icon: Building2Icon,
10
12
  });
@@ -1,16 +1,21 @@
1
1
  "use client";
2
2
 
3
+ import { ReactNode } from "react";
3
4
  import { UserInterface } from "../../../user";
4
5
  import { useCurrentUserContext } from "../../../user/contexts";
5
6
  import { CompanyProvider } from "../../contexts/CompanyContext";
6
7
  import { CompanyDetails } from "../details/CompanyDetails";
7
8
 
8
- export function CompanyContainer() {
9
+ type CompanyContainerProps = {
10
+ configurationEditorSlot?: ReactNode;
11
+ };
12
+
13
+ export function CompanyContainer({ configurationEditorSlot }: CompanyContainerProps) {
9
14
  const { currentUser } = useCurrentUserContext<UserInterface>();
10
15
  if (!currentUser) return null;
11
16
 
12
17
  return (
13
- <CompanyProvider dehydratedCompany={currentUser.company}>
18
+ <CompanyProvider dehydratedCompany={currentUser.company} configurationEditorSlot={configurationEditorSlot}>
14
19
  <CompanyDetails />
15
20
  </CompanyProvider>
16
21
  );
@@ -7,9 +7,10 @@ import { ContentTitle } from "../../../../components";
7
7
  import { useSharedContext } from "../../../../contexts";
8
8
  import { usePageUrlGenerator } from "../../../../hooks";
9
9
  import { useCompanyContext } from "../../contexts/CompanyContext";
10
+ import { TokenStatusIndicator } from "./TokenStatusIndicator";
10
11
 
11
12
  export function CompanyDetails() {
12
- const _t = useTranslations();
13
+ const t = useTranslations();
13
14
  const { title } = useSharedContext();
14
15
  const _generateUrl = usePageUrlGenerator();
15
16
 
@@ -22,6 +23,20 @@ export function CompanyDetails() {
22
23
  {company.logo && (
23
24
  <Image src={company.logo} alt={company.name} width={150} height={150} className="mb-4 rounded-md" />
24
25
  )}
26
+ <TokenStatusIndicator size="md" />
27
+ <div className="flex flex-col gap-y-1">
28
+ {company.configurations?.country && (
29
+ <div className="text-muted-foreground text-sm">
30
+ <span className="font-medium">{t("features.configuration.country")}:</span> {company.configurations.country}
31
+ </div>
32
+ )}
33
+ {company.configurations?.currency && (
34
+ <div className="text-muted-foreground text-sm">
35
+ <span className="font-medium">{t("features.configuration.currency")}:</span>{" "}
36
+ {company.configurations.currency}
37
+ </div>
38
+ )}
39
+ </div>
25
40
  </div>
26
41
  );
27
42
  }
@@ -3,8 +3,8 @@
3
3
  import { zodResolver } from "@hookform/resolvers/zod";
4
4
  import { Settings2Icon } from "lucide-react";
5
5
  import { useTranslations } from "next-intl";
6
- import { useEffect, useMemo, useState } from "react";
7
- import { SubmitHandler, useForm } from "react-hook-form";
6
+ import { ReactNode, useEffect, useState } from "react";
7
+ import { SubmitHandler, UseFormReturn, useForm } from "react-hook-form";
8
8
  import { showToast } from "../../../../utils/toast";
9
9
  import z from "zod";
10
10
  import { CommonEditorButtons, errorToast } from "../../../../components";
@@ -18,44 +18,37 @@ import {
18
18
  DialogTitle,
19
19
  DialogTrigger,
20
20
  Form,
21
- Tabs,
22
- TabsContent,
23
- TabsList,
24
- TabsTrigger,
25
21
  } from "../../../../shadcnui";
26
22
  import { UserInterface } from "../../../user";
27
23
  import { useCurrentUserContext } from "../../../user/contexts";
28
24
  import { UserService } from "../../../user/data/user.service";
29
25
  import { CompanyInput, CompanyInterface } from "../../data";
30
26
  import { CompanyService } from "../../data/company.service";
31
- import { CompanyConfigurationSecurityForm } from "./CompanyConfigurationSecurityForm";
32
27
 
33
28
  type CompanyConfigurationEditorProps = {
34
29
  company: CompanyInterface;
30
+ formSchema: z.ZodObject<any>;
31
+ defaultValues: Record<string, any>;
32
+ buildPayload: (values: Record<string, any>) => Partial<CompanyInput["configurations"]>;
33
+ children: (form: UseFormReturn<any>) => ReactNode;
35
34
  };
36
35
 
37
- function CompanyConfigurationEditorInternal({ company }: CompanyConfigurationEditorProps) {
36
+ function CompanyConfigurationEditorInternal({
37
+ company,
38
+ formSchema,
39
+ defaultValues,
40
+ buildPayload,
41
+ children,
42
+ }: CompanyConfigurationEditorProps) {
38
43
  const [open, setOpen] = useState<boolean>(false);
39
44
  const t = useTranslations();
40
45
  const { setUser } = useCurrentUserContext<UserInterface>();
41
46
 
42
- const defaultValues = useMemo(() => {
43
- return {
44
- isManagedKnowledge: company.configurations?.isManagedKnowledge ?? false,
45
- allowPublicBot: company.configurations?.allowPublicBot ?? false,
46
- };
47
- }, [company.configurations]);
48
-
49
47
  const close = () => {
50
48
  setOpen(false);
51
49
  form.reset();
52
50
  };
53
51
 
54
- const formSchema = z.object({
55
- isManagedKnowledge: z.boolean().optional(),
56
- allowPublicBot: z.boolean().optional(),
57
- });
58
-
59
52
  const form = useForm<z.infer<typeof formSchema>>({
60
53
  resolver: zodResolver(formSchema),
61
54
  defaultValues: defaultValues,
@@ -64,33 +57,26 @@ function CompanyConfigurationEditorInternal({ company }: CompanyConfigurationEdi
64
57
 
65
58
  useEffect(() => {
66
59
  if (open) {
67
- form.reset({
68
- isManagedKnowledge: company.configurations?.isManagedKnowledge ?? false,
69
- allowPublicBot: company.configurations?.allowPublicBot ?? false,
70
- });
60
+ form.reset(defaultValues);
71
61
  }
72
62
  }, [company, open]);
73
63
 
74
64
  const onSubmit: SubmitHandler<z.infer<typeof formSchema>> = async (values) => {
75
65
  const payload: CompanyInput = {
76
66
  id: company.id,
77
- configurations: {
78
- isManagedKnowledge: values.isManagedKnowledge ?? false,
79
- allowPublicBot: values.allowPublicBot ?? false,
80
- },
67
+ configurations: buildPayload(values),
81
68
  };
82
69
 
83
70
  try {
84
71
  await CompanyService.updateConfigurations(payload);
85
72
 
86
- // Refresh user data to update localStorage with new company configurations
87
73
  const fullUser = await UserService.findFullUser();
88
74
  if (fullUser) {
89
75
  setUser(fullUser);
90
76
  }
91
77
 
92
- showToast("Configurations Updated", {
93
- description: `The system configurations have been updated successfully.`,
78
+ showToast(t("features.configuration.updated_title"), {
79
+ description: t("features.configuration.updated_description"),
94
80
  });
95
81
  close();
96
82
  } catch (error) {
@@ -104,7 +90,7 @@ function CompanyConfigurationEditorInternal({ company }: CompanyConfigurationEdi
104
90
  return (
105
91
  <Dialog open={open} onOpenChange={setOpen}>
106
92
  <DialogTrigger>
107
- <Button size="sm" variant={`ghost`} className="cursor-pointer">
93
+ <Button render={<div />} nativeButton={false} size="sm" variant={`ghost`} className="cursor-pointer">
108
94
  <Settings2Icon className="h-3.5 w-3.5" />
109
95
  </Button>
110
96
  </DialogTrigger>
@@ -117,25 +103,7 @@ function CompanyConfigurationEditorInternal({ company }: CompanyConfigurationEdi
117
103
  </DialogHeader>
118
104
  <Form {...form}>
119
105
  <form onSubmit={form.handleSubmit(onSubmit)} className={`flex w-full flex-col gap-y-4`}>
120
- <div className={`flex flex-row gap-x-4`}>
121
- <div className={`flex w-full flex-col justify-start gap-y-4`}>
122
- <Tabs defaultValue={process.env.NEXT_PUBLIC_PRIVATE_INSTALLATION ? "security" : "ai"}>
123
- <TabsList>
124
- <TabsTrigger value="security">Privacy & Security</TabsTrigger>
125
- </TabsList>
126
- <TabsContent value="features">
127
- <div className="space-y-4">
128
- <p className="text-muted-foreground text-sm">
129
- Feature configuration will be implemented in future updates.
130
- </p>
131
- </div>
132
- </TabsContent>
133
- <TabsContent value="security">
134
- <CompanyConfigurationSecurityForm form={form} />
135
- </TabsContent>
136
- </Tabs>
137
- </div>
138
- </div>
106
+ {children(form)}
139
107
  <CommonEditorButtons form={form} setOpen={setOpen} isEdit={true} />
140
108
  </form>
141
109
  </Form>
@@ -1,4 +1,3 @@
1
1
  export * from "./CompanyConfigurationEditor";
2
- export * from "./CompanyConfigurationSecurityForm";
3
2
  export * from "./CompanyDeleter";
4
3
  export * from "./CompanyEditor";
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { useTranslations } from "next-intl";
4
- import { createContext, ReactNode, useContext, useState } from "react";
4
+ import { Fragment, createContext, ReactNode, useContext, useState } from "react";
5
5
  import { SharedProvider } from "../../../contexts";
6
6
  import { JsonApiHydratedDataInterface, Modules, rehydrate } from "../../../core";
7
7
  import { usePageUrlGenerator } from "../../../hooks";
@@ -23,6 +23,7 @@ const CompanyContext = createContext<CompanyContextType | undefined>(undefined);
23
23
  type CompanyProviderProps = {
24
24
  children: ReactNode;
25
25
  dehydratedCompany?: JsonApiHydratedDataInterface;
26
+ configurationEditorSlot?: ReactNode;
26
27
  };
27
28
 
28
29
  const defaultContextValue: CompanyContextType = {
@@ -30,7 +31,7 @@ const defaultContextValue: CompanyContextType = {
30
31
  setCompany: () => {},
31
32
  };
32
33
 
33
- export const CompanyProvider = ({ children, dehydratedCompany }: CompanyProviderProps) => {
34
+ export const CompanyProvider = ({ children, dehydratedCompany, configurationEditorSlot }: CompanyProviderProps) => {
34
35
  const generateUrl = usePageUrlGenerator();
35
36
  const t = useTranslations();
36
37
  const { hasPermissionToModule, hasRole } = useCurrentUserContext<UserInterface>();
@@ -71,7 +72,8 @@ export const CompanyProvider = ({ children, dehydratedCompany }: CompanyProvider
71
72
  hasRole(getRoleId().Administrator) ||
72
73
  hasPermissionToModule({ module: Modules.Company, action: Action.Update })
73
74
  ) {
74
- // if (company) functions.push(<CompanyConfigurationEditor key="companyConfigurationEditor" company={company} />);
75
+ if (company && configurationEditorSlot)
76
+ functions.push(<Fragment key="configurationEditorSlot">{configurationEditorSlot}</Fragment>);
75
77
  functions.push(<CompanyEditor key="companyEditor" company={company} propagateChanges={setCompany} />);
76
78
  }
77
79
 
@@ -1,6 +1,7 @@
1
- import { User } from "./data/user";
1
+ import { UsersIcon } from "lucide-react";
2
2
  import { createJsonApiInclusion } from "../../core";
3
3
  import { ModuleFactory } from "../../permissions";
4
+ import { User } from "./data/user";
4
5
 
5
6
  export const UserModule = (factory: ModuleFactory) =>
6
7
  factory({
@@ -8,6 +9,7 @@ export const UserModule = (factory: ModuleFactory) =>
8
9
  name: "users",
9
10
  model: User,
10
11
  moduleId: "04cfc677-0fd2-4f5e-adf4-2483a00c0277",
12
+ icon: UsersIcon,
11
13
  inclusions: {
12
14
  lists: {
13
15
  fields: [