nextjs-cms 0.9.38 → 0.9.39
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.
- package/dist/api/actions/pages.d.ts +27 -7
- package/dist/api/actions/pages.d.ts.map +1 -1
- package/dist/api/actions/pages.js +111 -27
- package/dist/api/trpc/root.d.ts +27 -6
- package/dist/api/trpc/root.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.d.ts +23 -2
- package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.js +2 -1
- package/dist/api/trpc/routers/navigation.d.ts +3 -3
- package/dist/api/trpc/routers/simpleSection.d.ts +1 -1
- package/dist/api/trpc/server.d.ts +81 -18
- package/dist/api/trpc/server.d.ts.map +1 -1
- package/dist/core/config/config-loader.d.ts +2 -2
- package/dist/core/factories/FieldFactory.d.ts +1 -6
- package/dist/core/factories/FieldFactory.d.ts.map +1 -1
- package/dist/core/factories/FieldFactory.js +3 -68
- package/dist/core/fields/checkbox.d.ts +3 -3
- package/dist/core/fields/color.d.ts +3 -3
- package/dist/core/fields/date-range.d.ts +2 -2
- package/dist/core/fields/date.d.ts +3 -3
- package/dist/core/fields/document.d.ts +3 -3
- package/dist/core/fields/field.d.ts +25 -12
- package/dist/core/fields/field.d.ts.map +1 -1
- package/dist/core/fields/field.js +51 -23
- package/dist/core/fields/index.d.ts +1 -0
- package/dist/core/fields/index.d.ts.map +1 -1
- package/dist/core/fields/index.js +2 -0
- package/dist/core/fields/map.d.ts +3 -3
- package/dist/core/fields/number.d.ts +4 -4
- package/dist/core/fields/password.d.ts +3 -3
- package/dist/core/fields/photo.d.ts +9 -9
- package/dist/core/fields/richText.d.ts +12 -12
- package/dist/core/fields/select.d.ts +7 -7
- package/dist/core/fields/selectMultiple.d.ts +4 -4
- package/dist/core/fields/slug.d.ts +9 -9
- package/dist/core/fields/tags.d.ts +3 -3
- package/dist/core/fields/text.d.ts +2 -2
- package/dist/core/fields/textArea.d.ts +2 -2
- package/dist/core/fields/video.d.ts +3 -3
- package/dist/core/helpers/conditional-rules.d.ts +63 -0
- package/dist/core/helpers/conditional-rules.d.ts.map +1 -0
- package/dist/core/helpers/conditional-rules.js +113 -0
- package/dist/core/helpers/index.d.ts +1 -0
- package/dist/core/helpers/index.d.ts.map +1 -1
- package/dist/core/helpers/index.js +4 -0
- package/dist/core/sections/category.d.ts +50 -50
- package/dist/core/sections/hasItems.d.ts +74 -74
- package/dist/core/sections/section.d.ts +23 -23
- package/dist/core/sections/simple.d.ts +6 -6
- package/dist/core/submit/submit.d.ts +4 -1
- package/dist/core/submit/submit.d.ts.map +1 -1
- package/dist/core/submit/submit.js +9 -19
- package/dist/core/types/index.d.ts +30 -8
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/translations/client.d.ts +4 -4
- package/dist/translations/server.d.ts +4 -4
- package/package.json +3 -3
- package/dist/api/axios/axiosInstance.d.ts +0 -2
- package/dist/api/axios/axiosInstance.d.ts.map +0 -1
- package/dist/api/axios/axiosInstance.js +0 -8
- package/dist/api/index.d.ts +0 -975
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -13
- package/dist/api/lib/serverActions.d.ts +0 -374
- package/dist/api/lib/serverActions.d.ts.map +0 -1
- package/dist/api/lib/serverActions.js +0 -1445
- package/dist/api/root.d.ts +0 -1917
- package/dist/api/root.d.ts.map +0 -1
- package/dist/api/root.js +0 -115
- package/dist/api/routers/accountSettings.d.ts +0 -66
- package/dist/api/routers/accountSettings.d.ts.map +0 -1
- package/dist/api/routers/accountSettings.js +0 -202
- package/dist/api/routers/admins.d.ts +0 -112
- package/dist/api/routers/admins.d.ts.map +0 -1
- package/dist/api/routers/admins.js +0 -323
- package/dist/api/routers/auth.d.ts +0 -54
- package/dist/api/routers/auth.d.ts.map +0 -1
- package/dist/api/routers/auth.js +0 -50
- package/dist/api/routers/categorySection.d.ts +0 -105
- package/dist/api/routers/categorySection.d.ts.map +0 -1
- package/dist/api/routers/categorySection.js +0 -49
- package/dist/api/routers/config.d.ts +0 -48
- package/dist/api/routers/config.d.ts.map +0 -1
- package/dist/api/routers/config.js +0 -18
- package/dist/api/routers/cpanel.d.ts +0 -82
- package/dist/api/routers/cpanel.d.ts.map +0 -1
- package/dist/api/routers/cpanel.js +0 -216
- package/dist/api/routers/fields.d.ts +0 -35
- package/dist/api/routers/fields.d.ts.map +0 -1
- package/dist/api/routers/fields.js +0 -81
- package/dist/api/routers/files.d.ts +0 -34
- package/dist/api/routers/files.d.ts.map +0 -1
- package/dist/api/routers/files.js +0 -14
- package/dist/api/routers/gallery.d.ts +0 -34
- package/dist/api/routers/gallery.d.ts.map +0 -1
- package/dist/api/routers/gallery.js +0 -64
- package/dist/api/routers/hasItemsSection.d.ts +0 -219
- package/dist/api/routers/hasItemsSection.d.ts.map +0 -1
- package/dist/api/routers/hasItemsSection.js +0 -86
- package/dist/api/routers/logs.d.ts +0 -59
- package/dist/api/routers/logs.d.ts.map +0 -1
- package/dist/api/routers/logs.js +0 -76
- package/dist/api/routers/navigation.d.ts +0 -50
- package/dist/api/routers/navigation.d.ts.map +0 -1
- package/dist/api/routers/navigation.js +0 -11
- package/dist/api/routers/simpleSection.d.ts +0 -105
- package/dist/api/routers/simpleSection.d.ts.map +0 -1
- package/dist/api/routers/simpleSection.js +0 -54
- package/dist/api/trpc.d.ts +0 -111
- package/dist/api/trpc.d.ts.map +0 -1
- package/dist/api/trpc.js +0 -99
- package/dist/auth/axios/axiosInstance.d.ts +0 -2
- package/dist/auth/axios/axiosInstance.d.ts.map +0 -1
- package/dist/auth/axios/axiosInstance.js +0 -8
- package/dist/auth/hooks/useAxiosPrivate.d.ts +0 -5
- package/dist/auth/hooks/useAxiosPrivate.d.ts.map +0 -1
- package/dist/auth/hooks/useAxiosPrivate.js +0 -74
- package/dist/auth/trpc.d.ts +0 -6
- package/dist/auth/trpc.d.ts.map +0 -1
- package/dist/auth/trpc.js +0 -82
- package/dist/core/fields/dateRange.d.ts +0 -115
- package/dist/core/fields/dateRange.d.ts.map +0 -1
- package/dist/core/fields/dateRange.js +0 -149
- package/dist/translations/locale-cookie.d.ts +0 -24
- package/dist/translations/locale-cookie.d.ts.map +0 -1
- package/dist/translations/locale-cookie.js +0 -44
- package/dist/translations/locale-utils.d.ts +0 -8
- package/dist/translations/locale-utils.d.ts.map +0 -1
- package/dist/translations/locale-utils.js +0 -11
- package/dist/translations/localization.d.ts +0 -40
- package/dist/translations/localization.d.ts.map +0 -1
- package/dist/translations/localization.js +0 -48
- package/dist/validators/dateRange.d.ts +0 -11
- package/dist/validators/dateRange.d.ts.map +0 -1
- package/dist/validators/dateRange.js +0 -16
package/dist/api/trpc.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import superjson from 'superjson';
|
|
2
|
-
/**
|
|
3
|
-
* Creates context for an incoming request
|
|
4
|
-
* @link https://trpc.io/docs/v11/context
|
|
5
|
-
*/
|
|
6
|
-
export declare const createTRPCContext: (opts: {
|
|
7
|
-
headers: Headers;
|
|
8
|
-
}) => Promise<{
|
|
9
|
-
headers: Headers;
|
|
10
|
-
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../db/schema.js")> & {
|
|
11
|
-
$client: import("mysql2/promise").Pool;
|
|
12
|
-
};
|
|
13
|
-
session: import("../index.js").Session | null;
|
|
14
|
-
}>;
|
|
15
|
-
type Context = Awaited<ReturnType<typeof createTRPCContext>>;
|
|
16
|
-
export type TRPCContext = Context;
|
|
17
|
-
export declare const transformer: {
|
|
18
|
-
input: typeof superjson;
|
|
19
|
-
output: typeof superjson;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Create a server-side caller
|
|
23
|
-
* @see https://trpc.io/docs/server/server-side-calls
|
|
24
|
-
*/
|
|
25
|
-
export declare const createCallerFactory: import("@trpc/server").TRPCRouterCallerFactory<{
|
|
26
|
-
ctx: {
|
|
27
|
-
headers: Headers;
|
|
28
|
-
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../db/schema.js")> & {
|
|
29
|
-
$client: import("mysql2/promise").Pool;
|
|
30
|
-
};
|
|
31
|
-
session: import("../index.js").Session | null;
|
|
32
|
-
};
|
|
33
|
-
meta: object;
|
|
34
|
-
errorShape: {
|
|
35
|
-
data: {
|
|
36
|
-
zodError: import("zod").ZodFlattenedError<unknown, string> | null;
|
|
37
|
-
code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
|
|
38
|
-
httpStatus: number;
|
|
39
|
-
path?: string;
|
|
40
|
-
stack?: string;
|
|
41
|
-
};
|
|
42
|
-
message: string;
|
|
43
|
-
code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
|
|
44
|
-
};
|
|
45
|
-
transformer: true;
|
|
46
|
-
}>;
|
|
47
|
-
/**
|
|
48
|
-
* This is how you create new routers and sub-routers in your tRPC API
|
|
49
|
-
* @see https://trpc.io/docs/router
|
|
50
|
-
*/
|
|
51
|
-
export declare const router: import("@trpc/server").TRPCRouterBuilder<{
|
|
52
|
-
ctx: {
|
|
53
|
-
headers: Headers;
|
|
54
|
-
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../db/schema.js")> & {
|
|
55
|
-
$client: import("mysql2/promise").Pool;
|
|
56
|
-
};
|
|
57
|
-
session: import("../index.js").Session | null;
|
|
58
|
-
};
|
|
59
|
-
meta: object;
|
|
60
|
-
errorShape: {
|
|
61
|
-
data: {
|
|
62
|
-
zodError: import("zod").ZodFlattenedError<unknown, string> | null;
|
|
63
|
-
code: import("@trpc/server").TRPC_ERROR_CODE_KEY;
|
|
64
|
-
httpStatus: number;
|
|
65
|
-
path?: string;
|
|
66
|
-
stack?: string;
|
|
67
|
-
};
|
|
68
|
-
message: string;
|
|
69
|
-
code: import("@trpc/server").TRPC_ERROR_CODE_NUMBER;
|
|
70
|
-
};
|
|
71
|
-
transformer: true;
|
|
72
|
-
}>;
|
|
73
|
-
/**
|
|
74
|
-
* Public procedure that doesn't require authentication
|
|
75
|
-
*/
|
|
76
|
-
export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
77
|
-
headers: Headers;
|
|
78
|
-
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../db/schema.js")> & {
|
|
79
|
-
$client: import("mysql2/promise").Pool;
|
|
80
|
-
};
|
|
81
|
-
session: import("../index.js").Session | null;
|
|
82
|
-
}, object, object, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
|
|
83
|
-
/**
|
|
84
|
-
* Private procedure that uses the `isAuthedMiddleware` middleware to require authentication
|
|
85
|
-
* @see https://trpc.io/docs/procedures
|
|
86
|
-
*/
|
|
87
|
-
export declare const privateProcedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
88
|
-
headers: Headers;
|
|
89
|
-
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../db/schema.js")> & {
|
|
90
|
-
$client: import("mysql2/promise").Pool;
|
|
91
|
-
};
|
|
92
|
-
session: import("../index.js").Session | null;
|
|
93
|
-
}, object, {
|
|
94
|
-
session: {
|
|
95
|
-
user: import("../index.js").User;
|
|
96
|
-
};
|
|
97
|
-
}, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
|
|
98
|
-
type PrivilegeOperation = 'C' | 'U' | 'D';
|
|
99
|
-
export declare const pluginProcedure: (sectionName: string, requiredRole?: PrivilegeOperation) => import("@trpc/server").TRPCProcedureBuilder<{
|
|
100
|
-
headers: Headers;
|
|
101
|
-
db: import("drizzle-orm/mysql2").MySql2Database<typeof import("../db/schema.js")> & {
|
|
102
|
-
$client: import("mysql2/promise").Pool;
|
|
103
|
-
};
|
|
104
|
-
session: import("../index.js").Session | null;
|
|
105
|
-
}, object, {
|
|
106
|
-
session: {
|
|
107
|
-
user: import("../index.js").User;
|
|
108
|
-
};
|
|
109
|
-
}, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
|
|
110
|
-
export {};
|
|
111
|
-
//# sourceMappingURL=trpc.d.ts.map
|
package/dist/api/trpc.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trpc.d.ts","sourceRoot":"","sources":["../../src/api/trpc.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAA;AASjC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAU,MAAM;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE;aAAT,OAAO;;;;;EAQ/D,CAAA;AAED,KAAK,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAA;AAC5D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAA;AAEjC,eAAO,MAAM,WAAW;;;CAGvB,CAAA;AAkBD;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;iBAtCyB,OAAO;;;;;;;;;;;;;;;;;;;EAsCR,CAAA;AAiBxD;;;GAGG;AACH,eAAO,MAAM,MAAM;;iBA3DsC,OAAO;;;;;;;;;;;;;;;;;;;EA2DlC,CAAA;AAE9B;;GAEG;AACH,eAAO,MAAM,eAAe;aAhE6B,OAAO;;;;;yLAgEtB,CAAA;AAE1C;;;GAGG;AACH,eAAO,MAAM,gBAAgB;aAtE4B,OAAO;;;;;;;;;yKAsEG,CAAA;AAEnE,KAAK,kBAAkB,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAoCzC,eAAO,MAAM,eAAe,GAAI,aAAa,MAAM,EAAE,eAAe,kBAAkB;aA5G7B,OAAO;;;;;;;;;yKA6GO,CAAA"}
|
package/dist/api/trpc.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { initTRPC, TRPCError } from '@trpc/server';
|
|
2
|
-
import superjson from 'superjson';
|
|
3
|
-
import { ZodError } from 'zod';
|
|
4
|
-
import auth from '../auth/index.js';
|
|
5
|
-
import { db } from '../db/client.js';
|
|
6
|
-
import { and, eq } from 'drizzle-orm';
|
|
7
|
-
import { AdminPrivilegesTable } from '../db/schema.js';
|
|
8
|
-
import getString from '../translations/index.js';
|
|
9
|
-
import { isDashboardOverridePlugin } from '../plugins/loader.js';
|
|
10
|
-
/**
|
|
11
|
-
* Creates context for an incoming request
|
|
12
|
-
* @link https://trpc.io/docs/v11/context
|
|
13
|
-
*/
|
|
14
|
-
export const createTRPCContext = async (opts) => {
|
|
15
|
-
const session = await auth();
|
|
16
|
-
return {
|
|
17
|
-
db,
|
|
18
|
-
session,
|
|
19
|
-
...opts,
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export const transformer = {
|
|
23
|
-
input: superjson,
|
|
24
|
-
output: superjson,
|
|
25
|
-
};
|
|
26
|
-
const t = initTRPC.context().create({
|
|
27
|
-
transformer: transformer,
|
|
28
|
-
errorFormatter({ shape, error }) {
|
|
29
|
-
return {
|
|
30
|
-
...shape,
|
|
31
|
-
data: {
|
|
32
|
-
...shape.data,
|
|
33
|
-
zodError: error.cause instanceof ZodError ? error.cause.flatten() : null,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
/*errorFormatter({ shape }) {
|
|
38
|
-
return shape
|
|
39
|
-
},*/
|
|
40
|
-
});
|
|
41
|
-
/**
|
|
42
|
-
* Create a server-side caller
|
|
43
|
-
* @see https://trpc.io/docs/server/server-side-calls
|
|
44
|
-
*/
|
|
45
|
-
export const createCallerFactory = t.createCallerFactory;
|
|
46
|
-
const isAuthedMiddleware = t.middleware(async ({ ctx, next }) => {
|
|
47
|
-
if (!ctx.session || !ctx.session.user)
|
|
48
|
-
throw new TRPCError({ code: 'UNAUTHORIZED', message: getString('noTokenProvided', 'en') });
|
|
49
|
-
return next({
|
|
50
|
-
/*ctx: {
|
|
51
|
-
user: user,
|
|
52
|
-
headers: ctx.opts.headers,
|
|
53
|
-
},*/
|
|
54
|
-
ctx: {
|
|
55
|
-
// infers the `session` as non-nullable
|
|
56
|
-
session: { ...ctx.session, user: ctx.session.user },
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
/**
|
|
61
|
-
* This is how you create new routers and sub-routers in your tRPC API
|
|
62
|
-
* @see https://trpc.io/docs/router
|
|
63
|
-
*/
|
|
64
|
-
export const router = t.router;
|
|
65
|
-
/**
|
|
66
|
-
* Public procedure that doesn't require authentication
|
|
67
|
-
*/
|
|
68
|
-
export const publicProcedure = t.procedure;
|
|
69
|
-
/**
|
|
70
|
-
* Private procedure that uses the `isAuthedMiddleware` middleware to require authentication
|
|
71
|
-
* @see https://trpc.io/docs/procedures
|
|
72
|
-
*/
|
|
73
|
-
export const privateProcedure = t.procedure.use(isAuthedMiddleware);
|
|
74
|
-
const accessControlMiddleware = (sectionName, requiredRole) => isAuthedMiddleware.unstable_pipe(async ({ ctx, next }) => {
|
|
75
|
-
// Bypass privilege check for dashboard override plugin
|
|
76
|
-
if (await isDashboardOverridePlugin(sectionName)) {
|
|
77
|
-
return next();
|
|
78
|
-
}
|
|
79
|
-
const privilege = await db
|
|
80
|
-
.select()
|
|
81
|
-
.from(AdminPrivilegesTable)
|
|
82
|
-
.where(and(eq(AdminPrivilegesTable.adminId, ctx.session.user.id), eq(AdminPrivilegesTable.sectionName, sectionName)))
|
|
83
|
-
.limit(1);
|
|
84
|
-
const allowed = privilege[0];
|
|
85
|
-
if (!allowed) {
|
|
86
|
-
throw new TRPCError({
|
|
87
|
-
code: 'NOT_FOUND',
|
|
88
|
-
message: getString('sectionNotFound', ctx.session.user.language),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (requiredRole && !allowed.operations.includes(requiredRole)) {
|
|
92
|
-
throw new TRPCError({
|
|
93
|
-
code: 'NOT_FOUND',
|
|
94
|
-
message: getString('noAccessToThisOperation', ctx.session.user.language),
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return next();
|
|
98
|
-
});
|
|
99
|
-
export const pluginProcedure = (sectionName, requiredRole) => t.procedure.use(accessControlMiddleware(sectionName, requiredRole));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"axiosInstance.d.ts","sourceRoot":"","sources":["../../../src/auth/axios/axiosInstance.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,+BAMvB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAxiosPrivate.d.ts","sourceRoot":"","sources":["../../../src/auth/hooks/useAxiosPrivate.tsx"],"names":[],"mappings":"AAMA,QAAA,MAAM,eAAe,GAAI,UAAU;IAAE,cAAc,CAAC,EAAE,GAAG,GAAG,GAAG,CAAA;CAAE,kCAgFhE,CAAA;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { axiosPrivate } from '../axios/axiosInstance.js';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
import useRefreshToken from './useRefreshToken.js';
|
|
4
|
-
import axios from 'axios';
|
|
5
|
-
import { getCsrfToken } from '../react.js';
|
|
6
|
-
const useAxiosPrivate = (options) => {
|
|
7
|
-
const refresh = useRefreshToken();
|
|
8
|
-
const { refreshTokenOn = 401 } = options || {};
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
/**
|
|
11
|
-
* Add a request interceptor
|
|
12
|
-
*/
|
|
13
|
-
const requestIntercept = axiosPrivate.interceptors.request.use(
|
|
14
|
-
/**
|
|
15
|
-
* Do something before request is sent
|
|
16
|
-
* @param config The request config object
|
|
17
|
-
*/
|
|
18
|
-
async (config) => {
|
|
19
|
-
if (config.method && ['post', 'put', 'delete'].includes(config.method.toLowerCase())) {
|
|
20
|
-
/**
|
|
21
|
-
* If the request is a POST, PUT, or DELETE request, the XSRF-TOKEN header is added to the request.
|
|
22
|
-
*/
|
|
23
|
-
config.headers['x-csrf-token'] = await getCsrfToken();
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Return the config object
|
|
27
|
-
*/
|
|
28
|
-
return config;
|
|
29
|
-
}, (error) => Promise.reject(error));
|
|
30
|
-
/**
|
|
31
|
-
* This is the response interceptor
|
|
32
|
-
*/
|
|
33
|
-
const responseIntercept = axiosPrivate.interceptors.response.use((response) => response, // Do nothing if the request is successful,
|
|
34
|
-
async (error) => {
|
|
35
|
-
// If the access token has expired, refresh it and retry the request
|
|
36
|
-
const prevRequest = error?.config; // The request that caused the error (the one that returned 401) is saved in the error object
|
|
37
|
-
if (error?.response?.status === refreshTokenOn && !prevRequest?.sent) {
|
|
38
|
-
// If the error is 401 and the request hasn't been sent before
|
|
39
|
-
prevRequest.sent = true; // Prevent infinite loops
|
|
40
|
-
const refreshStatus = await refresh(); // Refresh the access token cookie
|
|
41
|
-
if (refreshStatus === false)
|
|
42
|
-
return Promise.reject(error); // If the refresh failed, reject the promise
|
|
43
|
-
// NOTICE: This is needed to send the request as multipart form data,
|
|
44
|
-
// because resending the request with axios resets the Content-Type to application/json for some reason
|
|
45
|
-
// Use transformRequest to set Content-Type and include boundary for multipart form data
|
|
46
|
-
prevRequest.headers['Content-Type'] = 'multipart/form-data';
|
|
47
|
-
prevRequest.transformRequest = [
|
|
48
|
-
(data, headers) => {
|
|
49
|
-
// If the request data is FormData, set the boundary
|
|
50
|
-
if (data instanceof FormData) {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
headers['Content-Type'] += `; boundary=${data._boundary}`;
|
|
53
|
-
}
|
|
54
|
-
return data;
|
|
55
|
-
},
|
|
56
|
-
...axios.defaults.transformRequest, // Keep the default transformRequest functions
|
|
57
|
-
];
|
|
58
|
-
return axiosPrivate(prevRequest); // The request that returned 401 is retried with the new access token
|
|
59
|
-
}
|
|
60
|
-
return Promise.reject(error);
|
|
61
|
-
});
|
|
62
|
-
// Remove the interceptors when the component unmounts
|
|
63
|
-
// This is needed to prevent memory leaks
|
|
64
|
-
return () => {
|
|
65
|
-
// Eject the interceptors
|
|
66
|
-
axiosPrivate.interceptors.request.eject(requestIntercept);
|
|
67
|
-
axiosPrivate.interceptors.response.eject(responseIntercept);
|
|
68
|
-
};
|
|
69
|
-
}, [
|
|
70
|
-
/*auth, refresh*/
|
|
71
|
-
]);
|
|
72
|
-
return axiosPrivate;
|
|
73
|
-
};
|
|
74
|
-
export default useAxiosPrivate;
|
package/dist/auth/trpc.d.ts
DELETED
package/dist/auth/trpc.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trpc.d.ts","sourceRoot":"","sources":["../../src/auth/trpc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAM5C;;GAEG;AACH,eAAO,MAAM,gBAAgB,QAAO,QAAQ,CAAC,aAAa,CAAC,GAAG,CA6E7D,CAAA"}
|
package/dist/auth/trpc.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { observable } from '@trpc/server/observable';
|
|
2
|
-
// import type { AppRouter } from '../api'
|
|
3
|
-
import { logout, refreshSession } from './react.js';
|
|
4
|
-
/**
|
|
5
|
-
* tRPC link that refreshes the token if it's expired
|
|
6
|
-
*/
|
|
7
|
-
export const refreshTokenLink = () => {
|
|
8
|
-
/**
|
|
9
|
-
* Add a lock state to prevent multiple refreshes at the same time
|
|
10
|
-
*/
|
|
11
|
-
let isRefreshing = false;
|
|
12
|
-
let refreshPromise = null;
|
|
13
|
-
return () => {
|
|
14
|
-
return ({ next, op }) => {
|
|
15
|
-
return observable((observer) => {
|
|
16
|
-
let next$ = null;
|
|
17
|
-
let shouldRetry = true; // Flag to control the retry
|
|
18
|
-
function attempt() {
|
|
19
|
-
next$?.unsubscribe();
|
|
20
|
-
next$ = next(op).subscribe({
|
|
21
|
-
async error(err) {
|
|
22
|
-
if (err.data?.code === 'UNAUTHORIZED' && shouldRetry) {
|
|
23
|
-
if (!isRefreshing) {
|
|
24
|
-
isRefreshing = true;
|
|
25
|
-
refreshPromise = (async () => {
|
|
26
|
-
try {
|
|
27
|
-
const response = await fetch('/api/auth/refresh');
|
|
28
|
-
const data = await response.json();
|
|
29
|
-
if (response.status !== 200) {
|
|
30
|
-
await logout({
|
|
31
|
-
/**
|
|
32
|
-
* No need to delete the cookies, because they are both invalid.
|
|
33
|
-
*/
|
|
34
|
-
deleteCookies: false,
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
await refreshSession(data.session);
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
await logout({
|
|
42
|
-
/**
|
|
43
|
-
* No need to delete the cookies, because they are both invalid.
|
|
44
|
-
*/
|
|
45
|
-
deleteCookies: false,
|
|
46
|
-
});
|
|
47
|
-
throw e;
|
|
48
|
-
}
|
|
49
|
-
finally {
|
|
50
|
-
isRefreshing = false;
|
|
51
|
-
refreshPromise = null;
|
|
52
|
-
}
|
|
53
|
-
})();
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
await refreshPromise;
|
|
57
|
-
shouldRetry = false;
|
|
58
|
-
attempt();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
catch (e) {
|
|
62
|
-
// Don't throw under-the-hood refresh flow's errors
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
observer.error(err);
|
|
66
|
-
},
|
|
67
|
-
next(value) {
|
|
68
|
-
observer.next(value);
|
|
69
|
-
},
|
|
70
|
-
complete() {
|
|
71
|
-
observer.complete();
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
attempt();
|
|
76
|
-
return () => {
|
|
77
|
-
next$?.unsubscribe();
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type { BaseFieldConfig } from './field.js';
|
|
2
|
-
import { Field } from './field.js';
|
|
3
|
-
import { entityKind } from '../helpers/index.js';
|
|
4
|
-
import * as z from 'zod';
|
|
5
|
-
declare const configSchema: z.ZodObject<{
|
|
6
|
-
startName: z.ZodString;
|
|
7
|
-
endName: z.ZodString;
|
|
8
|
-
format: z.ZodOptional<z.ZodEnum<{
|
|
9
|
-
date: "date";
|
|
10
|
-
datetime: "datetime";
|
|
11
|
-
}>>;
|
|
12
|
-
defaultStartValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
|
|
13
|
-
defaultEndValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
|
|
14
|
-
}, z.core.$strict>;
|
|
15
|
-
type Config = z.infer<typeof configSchema>;
|
|
16
|
-
/**
|
|
17
|
-
* DateRangeField stores two DB columns: startName and endName.
|
|
18
|
-
*
|
|
19
|
-
* Because Field expects a single `name`, we pass `startName` as `name` to the
|
|
20
|
-
* super constructor (used for label generation / identity only).
|
|
21
|
-
* The field opts out of the normal single-column SQL path via hasSqlNameAndValue()=false
|
|
22
|
-
* and instead exposes setValues() / getSqlNamesAndValues() which submit.ts calls
|
|
23
|
-
* via an is(field, DateRangeField) guard — the same pattern used for SelectField.
|
|
24
|
-
*/
|
|
25
|
-
export declare class DateRangeField extends Field<'date_range', Config> {
|
|
26
|
-
static readonly [entityKind]: string;
|
|
27
|
-
readonly startName: string;
|
|
28
|
-
readonly endName: string;
|
|
29
|
-
readonly format: 'date' | 'datetime';
|
|
30
|
-
private startValue;
|
|
31
|
-
private endValue;
|
|
32
|
-
constructor(config: Omit<BaseFieldConfig<Config>, 'name'> & Config);
|
|
33
|
-
hasSqlNameAndValue(): boolean;
|
|
34
|
-
setValues(postData: FormData): void;
|
|
35
|
-
getSqlNamesAndValues(): Record<string, string | null>;
|
|
36
|
-
getValue(): {
|
|
37
|
-
from: string | null;
|
|
38
|
-
to: string | null;
|
|
39
|
-
};
|
|
40
|
-
exportForClient(): {
|
|
41
|
-
startName: string;
|
|
42
|
-
endName: string;
|
|
43
|
-
format: "date" | "datetime";
|
|
44
|
-
startValue: any;
|
|
45
|
-
endValue: any;
|
|
46
|
-
type: "date_range";
|
|
47
|
-
name: string;
|
|
48
|
-
label: string;
|
|
49
|
-
required: boolean;
|
|
50
|
-
localized?: boolean;
|
|
51
|
-
conditionalFields: import("../types/index.js").ConditionalField[];
|
|
52
|
-
readonly: boolean;
|
|
53
|
-
defaultValue: any;
|
|
54
|
-
value: any;
|
|
55
|
-
};
|
|
56
|
-
checkRequired(): void;
|
|
57
|
-
prepareForSubmission(): Promise<void>;
|
|
58
|
-
private parseDate;
|
|
59
|
-
private formatDate;
|
|
60
|
-
}
|
|
61
|
-
export type DateRangeFieldClientConfig = ReturnType<DateRangeField['exportForClient']>;
|
|
62
|
-
declare const optionsSchema: z.ZodObject<{
|
|
63
|
-
startName: z.ZodString;
|
|
64
|
-
endName: z.ZodString;
|
|
65
|
-
format: z.ZodOptional<z.ZodEnum<{
|
|
66
|
-
date: "date";
|
|
67
|
-
datetime: "datetime";
|
|
68
|
-
}>>;
|
|
69
|
-
defaultStartValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
|
|
70
|
-
defaultEndValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
|
|
71
|
-
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
72
|
-
required: z.ZodOptional<z.ZodBoolean>;
|
|
73
|
-
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
74
|
-
order: z.ZodOptional<z.ZodNumber>;
|
|
75
|
-
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
76
|
-
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
77
|
-
localized: z.ZodOptional<z.ZodBoolean>;
|
|
78
|
-
}, z.core.$strict>;
|
|
79
|
-
declare const dateRangeFieldConfigSchema: z.ZodObject<{
|
|
80
|
-
/**
|
|
81
|
-
* Auto-computed as `${startName}|${endName}`.
|
|
82
|
-
* Satisfies the `FieldConfig` union constraint that every config has a `name` property.
|
|
83
|
-
* Never set manually — use `startName` and `endName` instead.
|
|
84
|
-
*/
|
|
85
|
-
name: z.ZodString;
|
|
86
|
-
type: z.ZodLiteral<"date_range">;
|
|
87
|
-
build: z.ZodFunction<z.core.$ZodFunctionArgs, z.ZodCustom<DateRangeField, DateRangeField>>;
|
|
88
|
-
startName: z.ZodString;
|
|
89
|
-
endName: z.ZodString;
|
|
90
|
-
format: z.ZodOptional<z.ZodEnum<{
|
|
91
|
-
date: "date";
|
|
92
|
-
datetime: "datetime";
|
|
93
|
-
}>>;
|
|
94
|
-
defaultStartValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
|
|
95
|
-
defaultEndValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
|
|
96
|
-
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
97
|
-
required: z.ZodOptional<z.ZodBoolean>;
|
|
98
|
-
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
99
|
-
order: z.ZodOptional<z.ZodNumber>;
|
|
100
|
-
conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>>>;
|
|
101
|
-
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
102
|
-
localized: z.ZodOptional<z.ZodBoolean>;
|
|
103
|
-
}, z.core.$strict>;
|
|
104
|
-
export type DateRangeFieldConfig = z.infer<typeof dateRangeFieldConfigSchema>;
|
|
105
|
-
/**
|
|
106
|
-
* Helper to create a date range field configuration.
|
|
107
|
-
* Uses `startName` and `endName` instead of the usual `name`.
|
|
108
|
-
* The `name` property is auto-computed as `${startName}|${endName}`.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* dateRangeField({ startName: 'event_start', endName: 'event_end', label: 'Event Dates' })
|
|
112
|
-
*/
|
|
113
|
-
export declare function dateRangeField(field: z.infer<typeof optionsSchema>): DateRangeFieldConfig;
|
|
114
|
-
export {};
|
|
115
|
-
//# sourceMappingURL=dateRange.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dateRange.d.ts","sourceRoot":"","sources":["../../../src/core/fields/dateRange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,KAAK,EAAyB,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAIxB,QAAA,MAAM,YAAY;;;;;;;;;kBAMhB,CAAA;AAEF,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAE1C;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC;IAC3D,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAmB;IAEhE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAA;IAEpC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAK;gBAET,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM;IAYzD,kBAAkB,IAAI,OAAO;IAMtC,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IASnC,oBAAoB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IASrD,QAAQ,IAAI;QAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE;IAO7C,eAAe;;;;;;;;;;;;;;;;IAWxB,aAAa,IAAI,IAAI;IASf,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB3C,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,UAAU;CAOrB;AAED,MAAM,MAAM,0BAA0B,GAAG,UAAU,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAA;AAItF,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;kBAGjB,CAAA;AAEF,QAAA,MAAM,0BAA0B;IAE5B;;;;OAIG;;;;;;;;;;;;;;;;;;;kBAOL,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAE7E;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GAAG,oBAAoB,CAczF"}
|