@appconda/nextjs 1.0.94 → 1.0.96

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.
@@ -1,10 +1,8 @@
1
- export declare const actionClient: import("next-safe-action").SafeActionClient<string, undefined, undefined, unknown, {}, undefined, undefined, undefined, readonly [], {
1
+ export declare const actionClient: () => import("next-safe-action").SafeActionClient<unknown, import("next-safe-action").DVES, import("zod").ZodType<any, import("zod").ZodTypeDef, any>, any, {}, undefined, undefined, undefined, readonly [], {
2
2
  formErrors: string[];
3
3
  fieldErrors: {};
4
4
  }, readonly []>;
5
- export declare const authenticatedActionClient: import("next-safe-action").SafeActionClient<string, undefined, undefined, unknown, {
6
- user: any;
7
- }, undefined, undefined, undefined, readonly [], {
5
+ export declare const authenticatedActionClient: () => import("next-safe-action").SafeActionClient<unknown, import("next-safe-action").DVES, import("zod").ZodType<any, import("zod").ZodTypeDef, any>, any, {}, undefined, undefined, undefined, readonly [], {
8
6
  formErrors: string[];
9
7
  fieldErrors: {};
10
8
  }, readonly []>;
@@ -2,36 +2,52 @@ import { getServerSession } from "next-auth";
2
2
  import { DEFAULT_SERVER_ERROR_MESSAGE, createSafeActionClient } from "next-safe-action";
3
3
  import { authOptions } from "./authOptions";
4
4
  import { AuthenticationError, AuthorizationError } from "../lib/errors";
5
- export const actionClient = createSafeActionClient({
6
- handleServerError(e) {
7
- /* if (
8
- e instanceof ResourceNotFoundError ||
9
- e instanceof AuthorizationError ||
10
- e instanceof InvalidInputError ||
11
- e instanceof UnknownError ||
12
- e instanceof AuthenticationError ||
13
- e instanceof OperationNotAllowedError ||
14
- e instanceof AppcondaException
15
- ) {
16
- return e.message;
17
- } */
18
- // eslint-disable-next-line no-console -- This error needs to be logged for debugging server-side errors
19
- console.error("SERVER ERROR: ", e);
20
- return DEFAULT_SERVER_ERROR_MESSAGE;
21
- },
22
- });
23
- export const authenticatedActionClient = actionClient.use(async ({ next }) => {
24
- const session = await getServerSession(authOptions());
25
- //@ts-ignore
26
- if (!session?.user) {
27
- throw new AuthenticationError("Not authenticated");
28
- }
29
- //@ts-ignore
30
- const userId = session.user.id;
31
- //@ts-ignore
32
- const user = await getUser(userId);
33
- if (!user) {
34
- throw new AuthorizationError("User not found");
35
- }
36
- return next({ ctx: { user } });
37
- });
5
+ export const actionClient = (() => {
6
+ let internalActionClient = null;
7
+ return () => {
8
+ if (internalActionClient == null) {
9
+ internalActionClient = createSafeActionClient({
10
+ handleServerError(e) {
11
+ /* if (
12
+ e instanceof ResourceNotFoundError ||
13
+ e instanceof AuthorizationError ||
14
+ e instanceof InvalidInputError ||
15
+ e instanceof UnknownError ||
16
+ e instanceof AuthenticationError ||
17
+ e instanceof OperationNotAllowedError ||
18
+ e instanceof AppcondaException
19
+ ) {
20
+ return e.message;
21
+ } */
22
+ // eslint-disable-next-line no-console -- This error needs to be logged for debugging server-side errors
23
+ console.error("SERVER ERROR: ", e);
24
+ return DEFAULT_SERVER_ERROR_MESSAGE;
25
+ },
26
+ });
27
+ }
28
+ return internalActionClient;
29
+ };
30
+ })();
31
+ export const authenticatedActionClient = (() => {
32
+ let internalActionClient = null;
33
+ return () => {
34
+ if (internalActionClient == null) {
35
+ internalActionClient = actionClient().use(async ({ next }) => {
36
+ const session = await getServerSession(authOptions());
37
+ //@ts-ignore
38
+ if (!session?.user) {
39
+ throw new AuthenticationError("Not authenticated");
40
+ }
41
+ //@ts-ignore
42
+ const userId = session.user.id;
43
+ //@ts-ignore
44
+ const user = await getUser(userId);
45
+ if (!user) {
46
+ throw new AuthorizationError("User not found");
47
+ }
48
+ return next({ ctx: { user } });
49
+ });
50
+ }
51
+ return internalActionClient;
52
+ };
53
+ })();
@@ -1,25 +1 @@
1
- import { User } from "./types";
2
- export declare const CreateUser: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
3
- userId: import("zod").ZodOptional<import("zod").ZodString>;
4
- email: import("zod").ZodString;
5
- password: import("zod").ZodString;
6
- name: import("zod").ZodOptional<import("zod").ZodString>;
7
- }, "strip", import("zod").ZodTypeAny, {
8
- name?: string;
9
- password?: string;
10
- email?: string;
11
- userId?: string;
12
- }, {
13
- name?: string;
14
- password?: string;
15
- email?: string;
16
- userId?: string;
17
- }>, readonly [], {
18
- formErrors: string[];
19
- fieldErrors: {
20
- name?: string[];
21
- password?: string[];
22
- email?: string[];
23
- userId?: string[];
24
- };
25
- }, readonly [], User>;
1
+ export declare const CreateUser: any;
@@ -1,9 +1,9 @@
1
1
  import { Agent, AIModel } from './types';
2
- export declare const ListAgents: import("next-safe-action").SafeActionFn<string, undefined, readonly [], {
2
+ export declare const ListAgents: import("next-safe-action").SafeActionFn<unknown, undefined, readonly [], {
3
3
  formErrors: string[];
4
4
  fieldErrors: {};
5
5
  }, readonly [], Agent[]>;
6
- export declare const CreateAgent: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
6
+ export declare const CreateAgent: import("next-safe-action").SafeActionFn<unknown, import("zod").ZodObject<{
7
7
  id: import("zod").ZodOptional<import("zod").ZodString>;
8
8
  name: import("zod").ZodString;
9
9
  modelId: import("zod").ZodString;
@@ -16,6 +16,17 @@ export declare const CreateAgent: import("next-safe-action").SafeActionFn<string
16
16
  id?: string;
17
17
  modelId?: string;
18
18
  }>, readonly [], {
19
+ _errors?: string[];
20
+ name?: {
21
+ _errors?: string[];
22
+ };
23
+ id?: {
24
+ _errors?: string[];
25
+ };
26
+ modelId?: {
27
+ _errors?: string[];
28
+ };
29
+ } | {
19
30
  formErrors: string[];
20
31
  fieldErrors: {
21
32
  name?: string[];
@@ -23,29 +34,39 @@ export declare const CreateAgent: import("next-safe-action").SafeActionFn<string
23
34
  modelId?: string[];
24
35
  };
25
36
  }, readonly [], Agent>;
26
- export declare const GetAgent: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
37
+ export declare const GetAgent: import("next-safe-action").SafeActionFn<unknown, import("zod").ZodObject<{
27
38
  id: import("zod").ZodString;
28
39
  }, "strip", import("zod").ZodTypeAny, {
29
40
  id?: string;
30
41
  }, {
31
42
  id?: string;
32
43
  }>, readonly [], {
44
+ _errors?: string[];
45
+ id?: {
46
+ _errors?: string[];
47
+ };
48
+ } | {
33
49
  formErrors: string[];
34
50
  fieldErrors: {
35
51
  id?: string[];
36
52
  };
37
53
  }, readonly [], Agent>;
38
- export declare const ListModelProviders: import("next-safe-action").SafeActionFn<string, undefined, readonly [], {
54
+ export declare const ListModelProviders: import("next-safe-action").SafeActionFn<unknown, undefined, readonly [], {
39
55
  formErrors: string[];
40
56
  fieldErrors: {};
41
57
  }, readonly [], Agent[]>;
42
- export declare const ListModels: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
58
+ export declare const ListModels: import("next-safe-action").SafeActionFn<unknown, import("zod").ZodObject<{
43
59
  modelProviderId: import("zod").ZodString;
44
60
  }, "strip", import("zod").ZodTypeAny, {
45
61
  modelProviderId?: string;
46
62
  }, {
47
63
  modelProviderId?: string;
48
64
  }>, readonly [], {
65
+ _errors?: string[];
66
+ modelProviderId?: {
67
+ _errors?: string[];
68
+ };
69
+ } | {
49
70
  formErrors: string[];
50
71
  fieldErrors: {
51
72
  modelProviderId?: string[];
@@ -2,7 +2,7 @@
2
2
  import { actionClient } from '../../actions/actionClient';
3
3
  import { getSDKForCurrentUser } from '../../getSDKForCurrentUser';
4
4
  import { CreateAgentSchema, GetAgentSchema, ListModelsSchema } from './schema';
5
- export const ListAgents = actionClient
5
+ export const ListAgents = actionClient()
6
6
  //.schema(ListWaitlistSignupsSchema)
7
7
  .action(async ({ parsedInput }) => {
8
8
  try {
@@ -14,7 +14,7 @@ export const ListAgents = actionClient
14
14
  throw new Error('Failed to fetch ListWaitlistSignups');
15
15
  }
16
16
  });
17
- export const CreateAgent = actionClient
17
+ export const CreateAgent = actionClient()
18
18
  .schema(CreateAgentSchema)
19
19
  .action(async ({ parsedInput }) => {
20
20
  try {
@@ -26,7 +26,7 @@ export const CreateAgent = actionClient
26
26
  throw new Error('Failed to fetch ListWaitlists');
27
27
  }
28
28
  });
29
- export const GetAgent = actionClient
29
+ export const GetAgent = actionClient()
30
30
  .schema(GetAgentSchema)
31
31
  .action(async ({ parsedInput }) => {
32
32
  try {
@@ -38,7 +38,7 @@ export const GetAgent = actionClient
38
38
  throw new Error('Failed to fetch ListWaitlists');
39
39
  }
40
40
  });
41
- export const ListModelProviders = actionClient
41
+ export const ListModelProviders = actionClient()
42
42
  .action(async ({ parsedInput }) => {
43
43
  try {
44
44
  const { agent } = await getSDKForCurrentUser();
@@ -49,7 +49,7 @@ export const ListModelProviders = actionClient
49
49
  throw new Error('Failed to fetch ListModelProviders');
50
50
  }
51
51
  });
52
- export const ListModels = actionClient
52
+ export const ListModels = actionClient()
53
53
  .schema(ListModelsSchema)
54
54
  .action(async ({ parsedInput }) => {
55
55
  try {
@@ -1,4 +1,4 @@
1
- export declare const getAllNodesAction: import("next-safe-action").SafeActionFn<string, undefined, readonly [], {
1
+ export declare const getAllNodesAction: import("next-safe-action").SafeActionFn<unknown, undefined, readonly [], {
2
2
  formErrors: string[];
3
3
  fieldErrors: {};
4
4
  }, readonly [], any[]>;
@@ -1,7 +1,7 @@
1
1
  'use server';
2
2
  import { actionClient } from "../../../actions/actionClient";
3
3
  import { getSDKForCurrentUser } from "../../../getSDKForCurrentUser";
4
- export const getAllNodesAction = actionClient
4
+ export const getAllNodesAction = actionClient()
5
5
  // .schema(listModelsSchema)
6
6
  .action(async ({ parsedInput }) => {
7
7
  try {
@@ -1,29 +1,39 @@
1
1
  import { z } from "zod";
2
- export declare const getTenantAction: import("next-safe-action").SafeActionFn<string, z.ZodObject<{
2
+ export declare const getTenantAction: import("next-safe-action").SafeActionFn<unknown, z.ZodObject<{
3
3
  tenantId: z.ZodString;
4
4
  }, "strip", z.ZodTypeAny, {
5
5
  tenantId?: string;
6
6
  }, {
7
7
  tenantId?: string;
8
8
  }>, readonly [], {
9
+ _errors?: string[];
10
+ tenantId?: {
11
+ _errors?: string[];
12
+ };
13
+ } | {
9
14
  formErrors: string[];
10
15
  fieldErrors: {
11
16
  tenantId?: string[];
12
17
  };
13
18
  }, readonly [], import("@appconda/nextjs").Models.Tenant>;
14
- export declare const listUserTenantsAction: import("next-safe-action").SafeActionFn<string, z.ZodObject<{
19
+ export declare const listUserTenantsAction: import("next-safe-action").SafeActionFn<unknown, z.ZodObject<{
15
20
  userId: z.ZodString;
16
21
  }, "strip", z.ZodTypeAny, {
17
22
  userId?: string;
18
23
  }, {
19
24
  userId?: string;
20
25
  }>, readonly [], {
26
+ _errors?: string[];
27
+ userId?: {
28
+ _errors?: string[];
29
+ };
30
+ } | {
21
31
  formErrors: string[];
22
32
  fieldErrors: {
23
33
  userId?: string[];
24
34
  };
25
35
  }, readonly [], import("@appconda/nextjs").Models.TenantUserList>;
26
- export declare const createTenantAction: import("next-safe-action").SafeActionFn<string, z.ZodObject<{
36
+ export declare const createTenantAction: import("next-safe-action").SafeActionFn<unknown, z.ZodObject<{
27
37
  id: z.ZodString;
28
38
  name: z.ZodString;
29
39
  slug: z.ZodString;
@@ -36,6 +46,17 @@ export declare const createTenantAction: import("next-safe-action").SafeActionFn
36
46
  id?: string;
37
47
  slug?: string;
38
48
  }>, readonly [], {
49
+ _errors?: string[];
50
+ name?: {
51
+ _errors?: string[];
52
+ };
53
+ id?: {
54
+ _errors?: string[];
55
+ };
56
+ slug?: {
57
+ _errors?: string[];
58
+ };
59
+ } | {
39
60
  formErrors: string[];
40
61
  fieldErrors: {
41
62
  name?: string[];
@@ -5,7 +5,7 @@ import { actionClient } from "../../actions/actionClient";
5
5
  const getTenantActionSchema = z.object({
6
6
  tenantId: z.string()
7
7
  });
8
- export const getTenantAction = actionClient
8
+ export const getTenantAction = actionClient()
9
9
  .schema(getTenantActionSchema)
10
10
  .action(async ({ parsedInput }) => {
11
11
  const { tenantId } = parsedInput;
@@ -15,7 +15,7 @@ export const getTenantAction = actionClient
15
15
  const listUserTenantsScheema = z.object({
16
16
  userId: z.string()
17
17
  });
18
- export const listUserTenantsAction = actionClient
18
+ export const listUserTenantsAction = actionClient()
19
19
  .schema(listUserTenantsScheema)
20
20
  .action(async ({ parsedInput }) => {
21
21
  const { userId } = parsedInput;
@@ -27,7 +27,7 @@ const createTenantScheema = z.object({
27
27
  name: z.string(),
28
28
  slug: z.string()
29
29
  });
30
- export const createTenantAction = actionClient
30
+ export const createTenantAction = actionClient()
31
31
  .schema(createTenantScheema)
32
32
  .action(async ({ parsedInput }) => {
33
33
  const { id, name, slug } = parsedInput;
@@ -1,33 +1,43 @@
1
1
  import { Waitlist, WaitlistSignup } from './types';
2
- export declare const ListWaitlistSignups: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
2
+ export declare const ListWaitlistSignups: import("next-safe-action").SafeActionFn<unknown, import("zod").ZodObject<{
3
3
  waitlistId: import("zod").ZodString;
4
4
  }, "strip", import("zod").ZodTypeAny, {
5
5
  waitlistId?: string;
6
6
  }, {
7
7
  waitlistId?: string;
8
8
  }>, readonly [], {
9
+ _errors?: string[];
10
+ waitlistId?: {
11
+ _errors?: string[];
12
+ };
13
+ } | {
9
14
  formErrors: string[];
10
15
  fieldErrors: {
11
16
  waitlistId?: string[];
12
17
  };
13
18
  }, readonly [], WaitlistSignup[]>;
14
- export declare const ListWaitlists: import("next-safe-action").SafeActionFn<string, undefined, readonly [], {
19
+ export declare const ListWaitlists: import("next-safe-action").SafeActionFn<unknown, undefined, readonly [], {
15
20
  formErrors: string[];
16
21
  fieldErrors: {};
17
22
  }, readonly [], Waitlist[]>;
18
- export declare const CreateWaitlist: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
23
+ export declare const CreateWaitlist: import("next-safe-action").SafeActionFn<unknown, import("zod").ZodObject<{
19
24
  name: import("zod").ZodString;
20
25
  }, "strip", import("zod").ZodTypeAny, {
21
26
  name?: string;
22
27
  }, {
23
28
  name?: string;
24
29
  }>, readonly [], {
30
+ _errors?: string[];
31
+ name?: {
32
+ _errors?: string[];
33
+ };
34
+ } | {
25
35
  formErrors: string[];
26
36
  fieldErrors: {
27
37
  name?: string[];
28
38
  };
29
39
  }, readonly [], Waitlist>;
30
- export declare const CreateWaitlistSignup: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
40
+ export declare const CreateWaitlistSignup: import("next-safe-action").SafeActionFn<unknown, import("zod").ZodObject<{
31
41
  waitlistId: import("zod").ZodString;
32
42
  email: import("zod").ZodString;
33
43
  }, "strip", import("zod").ZodTypeAny, {
@@ -37,31 +47,49 @@ export declare const CreateWaitlistSignup: import("next-safe-action").SafeAction
37
47
  email?: string;
38
48
  waitlistId?: string;
39
49
  }>, readonly [], {
50
+ _errors?: string[];
51
+ email?: {
52
+ _errors?: string[];
53
+ };
54
+ waitlistId?: {
55
+ _errors?: string[];
56
+ };
57
+ } | {
40
58
  formErrors: string[];
41
59
  fieldErrors: {
42
60
  email?: string[];
43
61
  waitlistId?: string[];
44
62
  };
45
63
  }, readonly [], WaitlistSignup>;
46
- export declare const CreateWaitlistOffboardedSignup: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
64
+ export declare const CreateWaitlistOffboardedSignup: import("next-safe-action").SafeActionFn<unknown, import("zod").ZodObject<{
47
65
  waitlistSignupId: import("zod").ZodString;
48
66
  }, "strip", import("zod").ZodTypeAny, {
49
67
  waitlistSignupId?: string;
50
68
  }, {
51
69
  waitlistSignupId?: string;
52
70
  }>, readonly [], {
71
+ _errors?: string[];
72
+ waitlistSignupId?: {
73
+ _errors?: string[];
74
+ };
75
+ } | {
53
76
  formErrors: string[];
54
77
  fieldErrors: {
55
78
  waitlistSignupId?: string[];
56
79
  };
57
80
  }, readonly [], WaitlistSignup>;
58
- export declare const ListWaitlistOffboardedSignups: import("next-safe-action").SafeActionFn<string, import("zod").ZodObject<{
81
+ export declare const ListWaitlistOffboardedSignups: import("next-safe-action").SafeActionFn<unknown, import("zod").ZodObject<{
59
82
  waitlistId: import("zod").ZodString;
60
83
  }, "strip", import("zod").ZodTypeAny, {
61
84
  waitlistId?: string;
62
85
  }, {
63
86
  waitlistId?: string;
64
87
  }>, readonly [], {
88
+ _errors?: string[];
89
+ waitlistId?: {
90
+ _errors?: string[];
91
+ };
92
+ } | {
65
93
  formErrors: string[];
66
94
  fieldErrors: {
67
95
  waitlistId?: string[];
@@ -3,7 +3,7 @@ import { actionClient } from '../../actions/actionClient';
3
3
  import { getSDKForCurrentUser } from '../../getSDKForCurrentUser';
4
4
  import { getSDKForService } from '../../getSDKForService';
5
5
  import { CreateWaitlistOffboardedSignupSchema, CreateWaitlistSchema, CreateWaitlistSignupSchema, ListWaitlistOffboardedSignupsSchema, ListWaitlistSignupsSchema } from "./schema";
6
- export const ListWaitlistSignups = actionClient
6
+ export const ListWaitlistSignups = actionClient()
7
7
  .schema(ListWaitlistSignupsSchema)
8
8
  .action(async ({ parsedInput }) => {
9
9
  try {
@@ -16,7 +16,7 @@ export const ListWaitlistSignups = actionClient
16
16
  throw new Error('Failed to fetch ListWaitlistSignups');
17
17
  }
18
18
  });
19
- export const ListWaitlists = actionClient
19
+ export const ListWaitlists = actionClient()
20
20
  .action(async () => {
21
21
  try {
22
22
  const { waitlist } = await getSDKForService();
@@ -27,7 +27,7 @@ export const ListWaitlists = actionClient
27
27
  throw new Error('Failed to fetch ListWaitlists');
28
28
  }
29
29
  });
30
- export const CreateWaitlist = actionClient
30
+ export const CreateWaitlist = actionClient()
31
31
  .schema(CreateWaitlistSchema)
32
32
  .action(async ({ parsedInput }) => {
33
33
  try {
@@ -39,7 +39,7 @@ export const CreateWaitlist = actionClient
39
39
  throw new Error('Failed to fetch ListWaitlists');
40
40
  }
41
41
  });
42
- export const CreateWaitlistSignup = actionClient
42
+ export const CreateWaitlistSignup = actionClient()
43
43
  .schema(CreateWaitlistSignupSchema)
44
44
  .action(async ({ parsedInput }) => {
45
45
  try {
@@ -51,7 +51,7 @@ export const CreateWaitlistSignup = actionClient
51
51
  throw new Error('Failed to fetch ListWaitlists');
52
52
  }
53
53
  });
54
- export const CreateWaitlistOffboardedSignup = actionClient
54
+ export const CreateWaitlistOffboardedSignup = actionClient()
55
55
  .schema(CreateWaitlistOffboardedSignupSchema)
56
56
  .action(async ({ parsedInput }) => {
57
57
  try {
@@ -63,7 +63,7 @@ export const CreateWaitlistOffboardedSignup = actionClient
63
63
  throw new Error('Failed to fetch ListWaitlists');
64
64
  }
65
65
  });
66
- export const ListWaitlistOffboardedSignups = actionClient
66
+ export const ListWaitlistOffboardedSignups = actionClient()
67
67
  .schema(ListWaitlistOffboardedSignupsSchema)
68
68
  .action(async ({ parsedInput }) => {
69
69
  try {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@appconda/nextjs",
3
3
  "homepage": "https://appconda.io/support",
4
4
  "description": "Appconda is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5
- "version": "1.0.94",
5
+ "version": "1.0.96",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
@@ -5,42 +5,57 @@ import { authOptions } from "./authOptions";
5
5
  import { AuthenticationError, AuthorizationError } from "../lib/errors";
6
6
 
7
7
 
8
-
9
- export const actionClient = createSafeActionClient({
10
- handleServerError(e: Error) {
11
- /* if (
12
- e instanceof ResourceNotFoundError ||
13
- e instanceof AuthorizationError ||
14
- e instanceof InvalidInputError ||
15
- e instanceof UnknownError ||
16
- e instanceof AuthenticationError ||
17
- e instanceof OperationNotAllowedError ||
18
- e instanceof AppcondaException
19
- ) {
20
- return e.message;
21
- } */
22
-
23
- // eslint-disable-next-line no-console -- This error needs to be logged for debugging server-side errors
24
- console.error("SERVER ERROR: ", e);
25
- return DEFAULT_SERVER_ERROR_MESSAGE;
26
- },
27
- });
28
-
29
- export const authenticatedActionClient = actionClient.use(async ({ next }) => {
30
- const session = await getServerSession(authOptions());
31
- //@ts-ignore
32
- if (!session?.user) {
33
- throw new AuthenticationError("Not authenticated");
8
+ export const actionClient = (() => {
9
+ let internalActionClient: ReturnType<typeof createSafeActionClient> = null;
10
+ return () => {
11
+ if (internalActionClient == null) {
12
+ internalActionClient = createSafeActionClient({
13
+ handleServerError(e: Error) {
14
+ /* if (
15
+ e instanceof ResourceNotFoundError ||
16
+ e instanceof AuthorizationError ||
17
+ e instanceof InvalidInputError ||
18
+ e instanceof UnknownError ||
19
+ e instanceof AuthenticationError ||
20
+ e instanceof OperationNotAllowedError ||
21
+ e instanceof AppcondaException
22
+ ) {
23
+ return e.message;
24
+ } */
25
+
26
+ // eslint-disable-next-line no-console -- This error needs to be logged for debugging server-side errors
27
+ console.error("SERVER ERROR: ", e);
28
+ return DEFAULT_SERVER_ERROR_MESSAGE;
29
+ },
30
+ })
31
+ }
32
+ return internalActionClient;
34
33
  }
35
-
36
- //@ts-ignore
37
- const userId = session.user.id;
38
-
39
- //@ts-ignore
40
- const user = await getUser(userId);
41
- if (!user) {
42
- throw new AuthorizationError("User not found");
34
+ })();
35
+
36
+ export const authenticatedActionClient = (() => {
37
+ let internalActionClient: ReturnType<typeof createSafeActionClient> = null;
38
+ return () => {
39
+ if (internalActionClient == null) {
40
+ internalActionClient = actionClient().use(async ({ next }) => {
41
+ const session = await getServerSession(authOptions());
42
+ //@ts-ignore
43
+ if (!session?.user) {
44
+ throw new AuthenticationError("Not authenticated");
45
+ }
46
+
47
+ //@ts-ignore
48
+ const userId = session.user.id;
49
+
50
+ //@ts-ignore
51
+ const user = await getUser(userId);
52
+ if (!user) {
53
+ throw new AuthorizationError("User not found");
54
+ }
55
+
56
+ return next({ ctx: { user } });
57
+ });
58
+ }
59
+ return internalActionClient;
43
60
  }
44
-
45
- return next({ ctx: { user } });
46
- });
61
+ })();
@@ -8,7 +8,7 @@ import { CreateAgentSchema, GetAgentSchema, ListModelsSchema } from './schema';
8
8
  import { Agent, AIModel } from './types';
9
9
 
10
10
 
11
- export const ListAgents = actionClient
11
+ export const ListAgents = actionClient()
12
12
  //.schema(ListWaitlistSignupsSchema)
13
13
  .action(async ({ parsedInput }): Promise<Agent[]> => {
14
14
  try {
@@ -23,7 +23,7 @@ export const ListAgents = actionClient
23
23
 
24
24
 
25
25
 
26
- export const CreateAgent = actionClient
26
+ export const CreateAgent = actionClient()
27
27
  .schema(CreateAgentSchema)
28
28
  .action(async ({ parsedInput }): Promise<Agent> => {
29
29
  try {
@@ -37,7 +37,7 @@ export const CreateAgent = actionClient
37
37
  }
38
38
  });
39
39
 
40
- export const GetAgent = actionClient
40
+ export const GetAgent = actionClient()
41
41
  .schema(GetAgentSchema)
42
42
  .action(async ({ parsedInput }): Promise<Agent> => {
43
43
  try {
@@ -51,7 +51,7 @@ export const GetAgent = actionClient
51
51
  }
52
52
  });
53
53
 
54
- export const ListModelProviders = actionClient
54
+ export const ListModelProviders = actionClient()
55
55
  .action(async ({ parsedInput }): Promise<Agent[]> => {
56
56
  try {
57
57
 
@@ -63,7 +63,7 @@ export const ListModelProviders = actionClient
63
63
  }
64
64
  });
65
65
 
66
- export const ListModels = actionClient
66
+ export const ListModels = actionClient()
67
67
  .schema(ListModelsSchema)
68
68
  .action(async ({ parsedInput }): Promise<AIModel[]> => {
69
69
  try {
@@ -4,7 +4,7 @@ import { z } from "zod";
4
4
  import { actionClient } from "../../../actions/actionClient";
5
5
  import { getSDKForCurrentUser } from "../../../getSDKForCurrentUser";
6
6
 
7
- export const getAllNodesAction = actionClient
7
+ export const getAllNodesAction = actionClient()
8
8
  // .schema(listModelsSchema)
9
9
  .action(async ({ parsedInput }) => {
10
10
  try {
@@ -8,7 +8,7 @@ const getTenantActionSchema = z.object({
8
8
  tenantId: z.string()
9
9
  });
10
10
 
11
- export const getTenantAction = actionClient
11
+ export const getTenantAction = actionClient()
12
12
  .schema(getTenantActionSchema)
13
13
  .action(async ({ parsedInput }) => {
14
14
  const { tenantId } = parsedInput;
@@ -22,7 +22,7 @@ const listUserTenantsScheema = z.object({
22
22
  userId: z.string()
23
23
  });
24
24
 
25
- export const listUserTenantsAction = actionClient
25
+ export const listUserTenantsAction = actionClient()
26
26
  .schema(listUserTenantsScheema)
27
27
  .action(async ({ parsedInput }) => {
28
28
  const { userId } = parsedInput;
@@ -37,7 +37,7 @@ const createTenantScheema = z.object({
37
37
  slug: z.string()
38
38
  });
39
39
 
40
- export const createTenantAction = actionClient
40
+ export const createTenantAction = actionClient()
41
41
  .schema(createTenantScheema)
42
42
  .action(async ({ parsedInput }) => {
43
43
  const { id, name, slug } = parsedInput;
@@ -10,7 +10,7 @@ import { Waitlist, WaitlistSignup } from './types';
10
10
 
11
11
 
12
12
 
13
- export const ListWaitlistSignups = actionClient
13
+ export const ListWaitlistSignups = actionClient()
14
14
  .schema(ListWaitlistSignupsSchema)
15
15
  .action(async ({ parsedInput }): Promise<WaitlistSignup[]> => {
16
16
  try {
@@ -23,7 +23,7 @@ export const ListWaitlistSignups = actionClient
23
23
  }
24
24
  });
25
25
 
26
- export const ListWaitlists = actionClient
26
+ export const ListWaitlists = actionClient()
27
27
  .action(async (): Promise<Waitlist[]> => {
28
28
  try {
29
29
  const { waitlist } = await getSDKForService();
@@ -35,7 +35,7 @@ export const ListWaitlists = actionClient
35
35
  });
36
36
 
37
37
 
38
- export const CreateWaitlist = actionClient
38
+ export const CreateWaitlist = actionClient()
39
39
  .schema(CreateWaitlistSchema)
40
40
  .action(async ({ parsedInput }): Promise<Waitlist> => {
41
41
  try {
@@ -50,7 +50,7 @@ export const CreateWaitlist = actionClient
50
50
  });
51
51
 
52
52
 
53
- export const CreateWaitlistSignup = actionClient
53
+ export const CreateWaitlistSignup = actionClient()
54
54
  .schema(CreateWaitlistSignupSchema)
55
55
  .action(async ({ parsedInput }): Promise<WaitlistSignup> => {
56
56
  try {
@@ -64,7 +64,7 @@ export const CreateWaitlistSignup = actionClient
64
64
  }
65
65
  });
66
66
 
67
- export const CreateWaitlistOffboardedSignup = actionClient
67
+ export const CreateWaitlistOffboardedSignup = actionClient()
68
68
  .schema(CreateWaitlistOffboardedSignupSchema)
69
69
  .action(async ({ parsedInput }): Promise<WaitlistSignup> => {
70
70
  try {
@@ -78,7 +78,7 @@ export const CreateWaitlistSignup = actionClient
78
78
  }
79
79
  });
80
80
 
81
- export const ListWaitlistOffboardedSignups = actionClient
81
+ export const ListWaitlistOffboardedSignups = actionClient()
82
82
  .schema(ListWaitlistOffboardedSignupsSchema)
83
83
  .action(async ({ parsedInput }): Promise<WaitlistSignup> => {
84
84
  try {