@m5kdev/backend 0.1.5 → 0.3.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.
- package/dist/src/modules/access/access.repository.d.ts +2 -2
- package/dist/src/modules/access/access.repository.js +2 -2
- package/dist/src/modules/access/access.service.d.ts +4 -4
- package/dist/src/modules/access/access.service.js +1 -1
- package/dist/src/modules/access/access.test.js +4 -4
- package/dist/src/modules/ai/ai.db.js +1 -1
- package/dist/src/modules/ai/ai.prompt.js +1 -1
- package/dist/src/modules/ai/ai.repository.d.ts +2 -2
- package/dist/src/modules/ai/ai.repository.js +2 -2
- package/dist/src/modules/ai/ai.service.d.ts +6 -6
- package/dist/src/modules/ai/ai.service.js +1 -1
- package/dist/src/modules/ai/ai.trpc.d.ts +6 -42
- package/dist/src/modules/ai/ai.trpc.js +5 -5
- package/dist/src/modules/ai/ideogram/ideogram.dto.js +1 -1
- package/dist/src/modules/ai/ideogram/ideogram.prompt.d.ts +1 -1
- package/dist/src/modules/ai/ideogram/ideogram.prompt.js +1 -1
- package/dist/src/modules/ai/ideogram/ideogram.repository.d.ts +3 -3
- package/dist/src/modules/ai/ideogram/ideogram.repository.js +1 -1
- package/dist/src/modules/ai/ideogram/ideogram.service.d.ts +4 -4
- package/dist/src/modules/ai/ideogram/ideogram.service.js +1 -1
- package/dist/src/modules/auth/auth.dto.d.ts +5 -5
- package/dist/src/modules/auth/auth.lib.d.ts +10 -10
- package/dist/src/modules/auth/auth.lib.js +4 -4
- package/dist/src/modules/auth/auth.middleware.d.ts +1 -1
- package/dist/src/modules/auth/auth.middleware.js +2 -2
- package/dist/src/modules/auth/auth.repository.d.ts +4 -4
- package/dist/src/modules/auth/auth.repository.js +2 -2
- package/dist/src/modules/auth/auth.service.d.ts +7 -7
- package/dist/src/modules/auth/auth.service.js +2 -2
- package/dist/src/modules/auth/auth.trpc.d.ts +45 -81
- package/dist/src/modules/auth/auth.trpc.js +57 -55
- package/dist/src/modules/auth/auth.utils.js +1 -1
- package/dist/src/modules/base/base.abstract.d.ts +4 -4
- package/dist/src/modules/base/base.abstract.js +2 -2
- package/dist/src/modules/base/base.dto.d.ts +3 -3
- package/dist/src/modules/base/base.grants.d.ts +2 -2
- package/dist/src/modules/base/base.grants.test.js +2 -2
- package/dist/src/modules/base/base.repository.d.ts +2 -2
- package/dist/src/modules/base/base.repository.js +5 -5
- package/dist/src/modules/base/base.service.d.ts +6 -7
- package/dist/src/modules/base/base.service.js +2 -2
- package/dist/src/modules/billing/billing.repository.d.ts +2 -2
- package/dist/src/modules/billing/billing.repository.js +4 -4
- package/dist/src/modules/billing/billing.router.d.ts +2 -2
- package/dist/src/modules/billing/billing.service.d.ts +4 -4
- package/dist/src/modules/billing/billing.service.js +2 -2
- package/dist/src/modules/billing/billing.trpc.d.ts +7 -43
- package/dist/src/modules/billing/billing.trpc.js +7 -7
- package/dist/src/modules/clay/clay.repository.d.ts +2 -2
- package/dist/src/modules/clay/clay.repository.js +1 -1
- package/dist/src/modules/clay/clay.service.d.ts +3 -3
- package/dist/src/modules/clay/clay.service.js +1 -1
- package/dist/src/modules/connect/connect.dto.d.ts +4 -4
- package/dist/src/modules/connect/connect.oauth.js +1 -1
- package/dist/src/modules/connect/connect.repository.d.ts +4 -4
- package/dist/src/modules/connect/connect.repository.js +2 -2
- package/dist/src/modules/connect/connect.router.d.ts +1 -1
- package/dist/src/modules/connect/connect.service.d.ts +12 -12
- package/dist/src/modules/connect/connect.service.js +1 -1
- package/dist/src/modules/connect/connect.trpc.d.ts +7 -43
- package/dist/src/modules/connect/connect.trpc.js +7 -7
- package/dist/src/modules/crypto/crypto.repository.d.ts +1 -1
- package/dist/src/modules/crypto/crypto.repository.js +2 -2
- package/dist/src/modules/crypto/crypto.service.d.ts +3 -3
- package/dist/src/modules/crypto/crypto.service.js +1 -1
- package/dist/src/modules/email/email.service.d.ts +1 -1
- package/dist/src/modules/email/email.service.js +1 -1
- package/dist/src/modules/file/file.repository.d.ts +2 -2
- package/dist/src/modules/file/file.repository.js +1 -1
- package/dist/src/modules/file/file.router.js +2 -2
- package/dist/src/modules/file/file.service.d.ts +3 -3
- package/dist/src/modules/file/file.service.js +1 -1
- package/dist/src/modules/recurrence/recurrence.db.js +1 -1
- package/dist/src/modules/recurrence/recurrence.repository.d.ts +2 -2
- package/dist/src/modules/recurrence/recurrence.repository.js +2 -2
- package/dist/src/modules/recurrence/recurrence.service.d.ts +4 -4
- package/dist/src/modules/recurrence/recurrence.service.js +1 -1
- package/dist/src/modules/recurrence/recurrence.trpc.d.ts +12 -48
- package/dist/src/modules/recurrence/recurrence.trpc.js +17 -17
- package/dist/src/modules/social/social.service.d.ts +5 -5
- package/dist/src/modules/social/social.service.js +1 -1
- package/dist/src/modules/social/social.types.d.ts +2 -2
- package/dist/src/modules/tag/tag.db.js +1 -1
- package/dist/src/modules/tag/tag.dto.d.ts +1 -1
- package/dist/src/modules/tag/tag.dto.js +2 -2
- package/dist/src/modules/tag/tag.repository.d.ts +3 -3
- package/dist/src/modules/tag/tag.repository.js +2 -2
- package/dist/src/modules/tag/tag.service.d.ts +6 -6
- package/dist/src/modules/tag/tag.service.js +1 -1
- package/dist/src/modules/tag/tag.trpc.d.ts +11 -47
- package/dist/src/modules/tag/tag.trpc.js +16 -16
- package/dist/src/modules/utils/getConditionsFromFilters.d.ts +1 -1
- package/dist/src/modules/video/video.service.d.ts +2 -2
- package/dist/src/modules/video/video.service.js +1 -1
- package/dist/src/modules/webhook/webhook.dto.js +1 -1
- package/dist/src/modules/webhook/webhook.repository.d.ts +2 -2
- package/dist/src/modules/webhook/webhook.repository.js +1 -1
- package/dist/src/modules/webhook/webhook.service.d.ts +2 -2
- package/dist/src/modules/webhook/webhook.service.js +1 -1
- package/dist/src/modules/workflow/workflow.db.js +1 -1
- package/dist/src/modules/workflow/workflow.repository.d.ts +2 -2
- package/dist/src/modules/workflow/workflow.repository.js +2 -2
- package/dist/src/modules/workflow/workflow.service.d.ts +4 -4
- package/dist/src/modules/workflow/workflow.service.js +1 -1
- package/dist/src/modules/workflow/workflow.trpc.d.ts +7 -43
- package/dist/src/modules/workflow/workflow.trpc.js +7 -7
- package/dist/src/modules/workflow/workflow.types.d.ts +2 -2
- package/dist/src/modules/workflow/workflow.utils.js +3 -3
- package/dist/src/types.d.ts +56 -203
- package/dist/src/types.js +7 -8
- package/dist/src/utils/errors.d.ts +1 -1
- package/dist/src/utils/trpc.d.ts +58 -0
- package/dist/src/utils/trpc.js +63 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -30
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { transformer } from "@m5kdev/commons/utils/trpc";
|
|
2
|
+
import type { TRPCRootObject } from "@trpc/server";
|
|
3
|
+
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
|
|
4
|
+
import type { Result } from "neverthrow";
|
|
5
|
+
import type { BetterAuth, Context } from "../modules/auth/auth.lib";
|
|
6
|
+
import { ServerError } from "./errors";
|
|
7
|
+
type TRPCCreate = TRPCRootObject<Context, any, {
|
|
8
|
+
transformer: typeof transformer;
|
|
9
|
+
}>;
|
|
10
|
+
export type TRPCMethods = {
|
|
11
|
+
router: TRPCCreate["router"];
|
|
12
|
+
publicProcedure: TRPCCreate["procedure"];
|
|
13
|
+
privateProcedure: TRPCCreate["procedure"];
|
|
14
|
+
adminProcedure: TRPCCreate["procedure"];
|
|
15
|
+
};
|
|
16
|
+
export declare function createAuthContext(auth: BetterAuth): ({ req }: CreateExpressContextOptions) => Promise<{
|
|
17
|
+
session: {
|
|
18
|
+
id: string;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
updatedAt: Date;
|
|
21
|
+
userId: string;
|
|
22
|
+
token: string;
|
|
23
|
+
expiresAt: Date;
|
|
24
|
+
ipAddress: string | null;
|
|
25
|
+
userAgent: string | null;
|
|
26
|
+
impersonatedBy: string | null;
|
|
27
|
+
activeOrganizationId: string | null;
|
|
28
|
+
activeOrganizationRole: string | null;
|
|
29
|
+
activeTeamId: string | null;
|
|
30
|
+
activeTeamRole: string | null;
|
|
31
|
+
};
|
|
32
|
+
user: {
|
|
33
|
+
name: string;
|
|
34
|
+
id: string;
|
|
35
|
+
email: string;
|
|
36
|
+
metadata: Record<string, unknown>;
|
|
37
|
+
emailVerified: boolean;
|
|
38
|
+
image: string | null;
|
|
39
|
+
createdAt: Date;
|
|
40
|
+
updatedAt: Date;
|
|
41
|
+
role: string | null;
|
|
42
|
+
banned: boolean | null;
|
|
43
|
+
banReason: string | null;
|
|
44
|
+
banExpires: Date | null;
|
|
45
|
+
stripeCustomerId: string | null;
|
|
46
|
+
paymentCustomerId: string | null;
|
|
47
|
+
paymentPlanTier: string | null;
|
|
48
|
+
paymentPlanExpiresAt: Date | null;
|
|
49
|
+
preferences: string | null;
|
|
50
|
+
onboarding: number | null;
|
|
51
|
+
flags: string | null;
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
export declare function handleAsyncTRPCResult<T>(result: Promise<Result<T, ServerError>>): Promise<T>;
|
|
55
|
+
export declare function handleTRPCResult<T>(result: Result<T, ServerError>): T;
|
|
56
|
+
export declare function verifyProtectedProcedureContext(ctx: Context): void;
|
|
57
|
+
export declare function verifyAdminProcedureContext(ctx: Context): void;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthContext = createAuthContext;
|
|
4
|
+
exports.handleAsyncTRPCResult = handleAsyncTRPCResult;
|
|
5
|
+
exports.handleTRPCResult = handleTRPCResult;
|
|
6
|
+
exports.verifyProtectedProcedureContext = verifyProtectedProcedureContext;
|
|
7
|
+
exports.verifyAdminProcedureContext = verifyAdminProcedureContext;
|
|
8
|
+
const node_1 = require("better-auth/node");
|
|
9
|
+
const errors_1 = require("./errors");
|
|
10
|
+
const logger_1 = require("./logger");
|
|
11
|
+
function createAuthContext(auth) {
|
|
12
|
+
return async function createContext({ req }) {
|
|
13
|
+
const data = await auth.api.getSession({
|
|
14
|
+
headers: (0, node_1.fromNodeHeaders)(req.headers),
|
|
15
|
+
});
|
|
16
|
+
const user = data?.user || null;
|
|
17
|
+
const session = data?.session || null;
|
|
18
|
+
return {
|
|
19
|
+
session,
|
|
20
|
+
user,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function handleAsyncTRPCResult(result) {
|
|
25
|
+
return handleTRPCResult(await result);
|
|
26
|
+
}
|
|
27
|
+
function handleTRPCResult(result) {
|
|
28
|
+
if (result.isErr()) {
|
|
29
|
+
logger_1.logger.debug("Is tRPC Error");
|
|
30
|
+
logger_1.logger.error({
|
|
31
|
+
layer: result.error.layer,
|
|
32
|
+
layerName: result.error.layerName,
|
|
33
|
+
error: result.error.toJSON(),
|
|
34
|
+
});
|
|
35
|
+
throw result.error.toTRPC();
|
|
36
|
+
}
|
|
37
|
+
return result.value;
|
|
38
|
+
}
|
|
39
|
+
function verifyProtectedProcedureContext(ctx) {
|
|
40
|
+
if (!ctx.user || !ctx.session) {
|
|
41
|
+
throw new errors_1.ServerError({
|
|
42
|
+
code: "UNAUTHORIZED",
|
|
43
|
+
layer: "controller",
|
|
44
|
+
layerName: "TRPCController",
|
|
45
|
+
}).toTRPC();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function verifyAdminProcedureContext(ctx) {
|
|
49
|
+
if (!ctx.user || !ctx.session) {
|
|
50
|
+
throw new errors_1.ServerError({
|
|
51
|
+
code: "UNAUTHORIZED",
|
|
52
|
+
layer: "controller",
|
|
53
|
+
layerName: "TRPCController",
|
|
54
|
+
}).toTRPC();
|
|
55
|
+
}
|
|
56
|
+
if (ctx.user.role !== "admin") {
|
|
57
|
+
throw new errors_1.ServerError({
|
|
58
|
+
code: "FORBIDDEN",
|
|
59
|
+
layer: "controller",
|
|
60
|
+
layerName: "TRPCController",
|
|
61
|
+
}).toTRPC();
|
|
62
|
+
}
|
|
63
|
+
}
|