@m5kdev/backend 0.1.1 → 0.1.3
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +18 -0
- package/dist/src/lib/posthog.js +7 -0
- package/dist/src/lib/sentry.js +9 -0
- package/dist/src/modules/access/access.repository.js +32 -0
- package/dist/src/modules/access/access.service.js +51 -0
- package/dist/src/modules/access/access.test.js +182 -0
- package/dist/src/modules/access/access.utils.js +20 -0
- package/dist/src/modules/ai/ai.db.js +39 -0
- package/dist/src/modules/ai/ai.prompt.js +30 -0
- package/dist/src/modules/ai/ai.repository.js +26 -0
- package/dist/src/modules/ai/ai.router.js +132 -0
- package/dist/src/modules/ai/ai.service.js +207 -0
- package/dist/src/modules/ai/ai.trpc.d.ts +5 -5
- package/dist/src/modules/ai/ai.trpc.js +20 -0
- package/dist/src/modules/ai/ideogram/ideogram.constants.js +167 -0
- package/dist/src/modules/ai/ideogram/ideogram.dto.js +49 -0
- package/dist/src/modules/ai/ideogram/ideogram.prompt.js +860 -0
- package/dist/src/modules/ai/ideogram/ideogram.repository.js +46 -0
- package/dist/src/modules/ai/ideogram/ideogram.service.js +11 -0
- package/dist/src/modules/auth/auth.db.js +215 -0
- package/dist/src/modules/auth/auth.dto.js +38 -0
- package/dist/src/modules/auth/auth.lib.d.ts +4 -4
- package/dist/src/modules/auth/auth.lib.js +284 -0
- package/dist/src/modules/auth/auth.middleware.js +52 -0
- package/dist/src/modules/auth/auth.repository.js +541 -0
- package/dist/src/modules/auth/auth.service.js +201 -0
- package/dist/src/modules/auth/auth.trpc.d.ts +18 -18
- package/dist/src/modules/auth/auth.trpc.js +157 -0
- package/dist/src/modules/auth/auth.utils.js +97 -0
- package/dist/src/modules/base/base.abstract.js +53 -0
- package/dist/src/modules/base/base.dto.js +112 -0
- package/dist/src/modules/base/base.grants.js +123 -0
- package/dist/src/modules/base/base.grants.test.js +668 -0
- package/dist/src/modules/base/base.repository.js +307 -0
- package/dist/src/modules/base/base.service.js +109 -0
- package/dist/src/modules/base/base.types.js +2 -0
- package/dist/src/modules/billing/billing.db.js +29 -0
- package/dist/src/modules/billing/billing.repository.js +235 -0
- package/dist/src/modules/billing/billing.router.js +56 -0
- package/dist/src/modules/billing/billing.service.js +147 -0
- package/dist/src/modules/billing/billing.trpc.d.ts +5 -5
- package/dist/src/modules/billing/billing.trpc.js +17 -0
- package/dist/src/modules/clay/clay.repository.js +26 -0
- package/dist/src/modules/clay/clay.service.js +24 -0
- package/dist/src/modules/connect/connect.db.js +30 -0
- package/dist/src/modules/connect/connect.dto.js +36 -0
- package/dist/src/modules/connect/connect.linkedin.js +53 -0
- package/dist/src/modules/connect/connect.oauth.js +198 -0
- package/dist/src/modules/connect/connect.repository.d.ts +7 -7
- package/dist/src/modules/connect/connect.repository.js +54 -0
- package/dist/src/modules/connect/connect.router.js +54 -0
- package/dist/src/modules/connect/connect.service.d.ts +14 -14
- package/dist/src/modules/connect/connect.service.js +114 -0
- package/dist/src/modules/connect/connect.trpc.d.ts +10 -10
- package/dist/src/modules/connect/connect.trpc.js +21 -0
- package/dist/src/modules/connect/connect.types.js +2 -0
- package/dist/src/modules/crypto/crypto.db.js +17 -0
- package/dist/src/modules/crypto/crypto.repository.js +10 -0
- package/dist/src/modules/crypto/crypto.service.js +52 -0
- package/dist/src/modules/email/email.service.js +107 -0
- package/dist/src/modules/file/file.repository.js +79 -0
- package/dist/src/modules/file/file.router.js +99 -0
- package/dist/src/modules/file/file.service.js +150 -0
- package/dist/src/modules/recurrence/recurrence.db.js +66 -0
- package/dist/src/modules/recurrence/recurrence.repository.js +39 -0
- package/dist/src/modules/recurrence/recurrence.service.js +70 -0
- package/dist/src/modules/recurrence/recurrence.trpc.d.ts +15 -15
- package/dist/src/modules/recurrence/recurrence.trpc.js +65 -0
- package/dist/src/modules/social/social.dto.js +18 -0
- package/dist/src/modules/social/social.linkedin.js +427 -0
- package/dist/src/modules/social/social.linkedin.test.js +235 -0
- package/dist/src/modules/social/social.service.js +76 -0
- package/dist/src/modules/social/social.types.js +2 -0
- package/dist/src/modules/tag/tag.db.js +42 -0
- package/dist/src/modules/tag/tag.dto.js +9 -0
- package/dist/src/modules/tag/tag.repository.js +154 -0
- package/dist/src/modules/tag/tag.service.js +31 -0
- package/dist/src/modules/tag/tag.trpc.d.ts +5 -5
- package/dist/src/modules/tag/tag.trpc.js +47 -0
- package/dist/src/modules/utils/applyPagination.js +16 -0
- package/dist/src/modules/utils/applySorting.js +18 -0
- package/dist/src/modules/utils/getConditionsFromFilters.js +200 -0
- package/dist/src/modules/video/video.service.js +84 -0
- package/dist/src/modules/webhook/webhook.constants.js +10 -0
- package/dist/src/modules/webhook/webhook.db.js +17 -0
- package/dist/src/modules/webhook/webhook.dto.js +7 -0
- package/dist/src/modules/webhook/webhook.repository.js +56 -0
- package/dist/src/modules/webhook/webhook.router.js +30 -0
- package/dist/src/modules/webhook/webhook.service.js +68 -0
- package/dist/src/modules/workflow/workflow.db.js +30 -0
- package/dist/src/modules/workflow/workflow.repository.js +105 -0
- package/dist/src/modules/workflow/workflow.service.js +37 -0
- package/dist/src/modules/workflow/workflow.trpc.d.ts +5 -5
- package/dist/src/modules/workflow/workflow.trpc.js +21 -0
- package/dist/src/modules/workflow/workflow.types.js +2 -0
- package/dist/src/modules/workflow/workflow.utils.js +173 -0
- package/dist/src/test/stubs/utils.js +5 -0
- package/dist/src/trpc/context.d.ts +5 -5
- package/dist/src/trpc/context.js +17 -0
- package/dist/src/trpc/index.js +6 -0
- package/dist/src/trpc/procedures.d.ts +56 -56
- package/dist/src/trpc/procedures.js +32 -0
- package/dist/src/trpc/utils.js +20 -0
- package/dist/src/types.d.ts +33 -33
- package/dist/src/types.js +13 -0
- package/dist/src/utils/errors.js +104 -0
- package/dist/src/utils/logger.js +11 -0
- package/dist/src/utils/posthog.js +31 -0
- package/dist/src/utils/types.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/tsconfig.json +2 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkflowTrigger = createWorkflowTrigger;
|
|
4
|
+
exports.createWorkflowWorker = createWorkflowWorker;
|
|
5
|
+
exports.createWorkflowWorkers = createWorkflowWorkers;
|
|
6
|
+
const bullmq_1 = require("bullmq");
|
|
7
|
+
const neverthrow_1 = require("neverthrow");
|
|
8
|
+
const errors_1 = require("#utils/errors");
|
|
9
|
+
const logger_1 = require("#utils/logger");
|
|
10
|
+
const posthog_1 = require("#utils/posthog");
|
|
11
|
+
const errorOptions = {
|
|
12
|
+
layer: "workflow",
|
|
13
|
+
layerName: "WorkflowTrigger",
|
|
14
|
+
};
|
|
15
|
+
function shouldDisablePosthogFromPayload(payload) {
|
|
16
|
+
if (!payload || typeof payload !== "object")
|
|
17
|
+
return false;
|
|
18
|
+
const session = payload.ctx?.session;
|
|
19
|
+
return Boolean(session?.impersonatedBy);
|
|
20
|
+
}
|
|
21
|
+
function createWorkflowTrigger(service, queues, defaultQueue) {
|
|
22
|
+
const trigger = async ({ name, payload, meta, options, }) => {
|
|
23
|
+
const { queue: queueName, userId, tags, timeout = 60 * 60 * 1000 } = meta || {};
|
|
24
|
+
const disablePosthogCapture = meta?.disablePosthogCapture ?? shouldDisablePosthogFromPayload(payload);
|
|
25
|
+
const compiledQueueName = queueName || defaultQueue;
|
|
26
|
+
if (!compiledQueueName || !Object.keys(queues).includes(compiledQueueName)) {
|
|
27
|
+
return (0, neverthrow_1.err)(new errors_1.ServerError({ code: "NOT_FOUND", ...errorOptions }));
|
|
28
|
+
}
|
|
29
|
+
const queue = queues[compiledQueueName];
|
|
30
|
+
if (!queue) {
|
|
31
|
+
return (0, neverthrow_1.err)(new errors_1.ServerError({ code: "NOT_FOUND", ...errorOptions }));
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const job = await queue.add(name, {
|
|
35
|
+
payload,
|
|
36
|
+
meta: { ...meta, timeout, disablePosthogCapture },
|
|
37
|
+
}, {
|
|
38
|
+
removeOnComplete: {
|
|
39
|
+
age: 24 * 3600, // keep up to 24 hours
|
|
40
|
+
},
|
|
41
|
+
removeOnFail: {
|
|
42
|
+
age: 7 * 24 * 3600, // keep up to week
|
|
43
|
+
},
|
|
44
|
+
...options,
|
|
45
|
+
});
|
|
46
|
+
if (!job || !job.id) {
|
|
47
|
+
return (0, neverthrow_1.err)(new errors_1.ServerError({ code: "INTERNAL_SERVER_ERROR", ...errorOptions }));
|
|
48
|
+
}
|
|
49
|
+
return await service.added({
|
|
50
|
+
userId,
|
|
51
|
+
jobId: job.id,
|
|
52
|
+
jobName: name,
|
|
53
|
+
input: payload,
|
|
54
|
+
timeout,
|
|
55
|
+
queueName: compiledQueueName,
|
|
56
|
+
tags,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return (0, neverthrow_1.err)(new errors_1.ServerError({ code: "INTERNAL_SERVER_ERROR", ...errorOptions }));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const triggerMany = async ({ name, payload, meta, options, }) => {
|
|
64
|
+
const { queue: queueName, userId, tags, timeout = 60 * 60 * 1000 } = meta || {};
|
|
65
|
+
const compiledQueueName = queueName || defaultQueue;
|
|
66
|
+
if (!compiledQueueName || !Object.keys(queues).includes(compiledQueueName)) {
|
|
67
|
+
return (0, neverthrow_1.err)(new errors_1.ServerError({ code: "NOT_FOUND", ...errorOptions }));
|
|
68
|
+
}
|
|
69
|
+
const queue = queues[compiledQueueName];
|
|
70
|
+
if (!queue) {
|
|
71
|
+
return (0, neverthrow_1.err)(new errors_1.ServerError({ code: "NOT_FOUND", ...errorOptions }));
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const jobs = await queue.addBulk(payload.map((p) => {
|
|
75
|
+
const disablePosthogCapture = meta?.disablePosthogCapture ?? shouldDisablePosthogFromPayload(p);
|
|
76
|
+
return {
|
|
77
|
+
name,
|
|
78
|
+
data: { payload: p, meta: { ...meta, timeout, disablePosthogCapture } },
|
|
79
|
+
options: {
|
|
80
|
+
removeOnComplete: {
|
|
81
|
+
age: 24 * 3600, // keep up to 24 hours
|
|
82
|
+
},
|
|
83
|
+
removeOnFail: {
|
|
84
|
+
age: 7 * 24 * 3600, // keep up to week
|
|
85
|
+
},
|
|
86
|
+
...options,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}));
|
|
90
|
+
if (!jobs || jobs.length === 0) {
|
|
91
|
+
return (0, neverthrow_1.err)(new errors_1.ServerError({ code: "INTERNAL_SERVER_ERROR", ...errorOptions }));
|
|
92
|
+
}
|
|
93
|
+
return await service.addedMany(jobs.map((j) => ({
|
|
94
|
+
userId,
|
|
95
|
+
jobId: j.id,
|
|
96
|
+
jobName: name,
|
|
97
|
+
input: j.data.payload,
|
|
98
|
+
timeout,
|
|
99
|
+
queueName: compiledQueueName,
|
|
100
|
+
tags,
|
|
101
|
+
})));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return (0, neverthrow_1.err)(new errors_1.ServerError({ code: "INTERNAL_SERVER_ERROR", ...errorOptions }));
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return { trigger, triggerMany };
|
|
108
|
+
}
|
|
109
|
+
function createWorkflowWorker(service, queueName, workerOptions, jobs, errorHandler) {
|
|
110
|
+
const logger = logger_1.logger.child({ layer: "worker" });
|
|
111
|
+
const worker = new bullmq_1.Worker(queueName, async (job) => {
|
|
112
|
+
const { meta } = job.data;
|
|
113
|
+
return await (0, posthog_1.runWithPosthogRequestState)({ disableCapture: Boolean(meta?.disablePosthogCapture) }, async () => {
|
|
114
|
+
const timer = meta?.timeout &&
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
const error = new Error("Job timed out");
|
|
117
|
+
errorHandler?.(error);
|
|
118
|
+
throw error;
|
|
119
|
+
}, job.data.meta.timeout);
|
|
120
|
+
const handler = jobs[job.name];
|
|
121
|
+
if (!handler) {
|
|
122
|
+
const error = new Error(`Unknown job: ${job.name}`);
|
|
123
|
+
errorHandler?.(error);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
await service.started(job);
|
|
128
|
+
const result = await handler.run(job);
|
|
129
|
+
if (result.isErr()) {
|
|
130
|
+
await handler.onFailure?.(job, result.error);
|
|
131
|
+
const error = new Error(result.error.message);
|
|
132
|
+
errorHandler?.(error);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
await handler.onSuccess?.(job).catch((err) => {
|
|
136
|
+
const error = new Error(`Job ${job.id}:${job.name} failed to run onSuccess: ${err}`);
|
|
137
|
+
logger.error(error.message);
|
|
138
|
+
errorHandler?.(error);
|
|
139
|
+
});
|
|
140
|
+
return result.value ?? null;
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
await handler.onFailure?.(job, err).catch((err) => {
|
|
144
|
+
const error = new Error(`Job ${job.id}:${job.name} failed to run onFailure: ${err}`);
|
|
145
|
+
logger.error(error.message);
|
|
146
|
+
errorHandler?.(error);
|
|
147
|
+
});
|
|
148
|
+
if (err instanceof Error && err.message === "Job timed out")
|
|
149
|
+
logger.error(`Job ${job.id}:${job.name} timed out`);
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
await handler.onComplete?.(job).catch((err) => {
|
|
154
|
+
const error = new Error(`Job ${job.id}:${job.name} failed to run onComplete: ${err}`);
|
|
155
|
+
logger.error(error.message);
|
|
156
|
+
errorHandler?.(error);
|
|
157
|
+
});
|
|
158
|
+
if (timer)
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}, workerOptions);
|
|
163
|
+
worker.on("completed", service.completed.bind(service));
|
|
164
|
+
worker.on("failed", service.failed.bind(service));
|
|
165
|
+
return worker;
|
|
166
|
+
}
|
|
167
|
+
function createWorkflowWorkers(service, workerSettings, jobs, errorHandler) {
|
|
168
|
+
const workers = {};
|
|
169
|
+
for (const [queueName, workerOptions] of Object.entries(workerSettings)) {
|
|
170
|
+
workers[queueName] = createWorkflowWorker(service, queueName, workerOptions, jobs, errorHandler);
|
|
171
|
+
}
|
|
172
|
+
return workers;
|
|
173
|
+
}
|
|
@@ -5,9 +5,9 @@ export declare function createAuthContext(auth: BetterAuth): ({ req }: CreateExp
|
|
|
5
5
|
session: {
|
|
6
6
|
id: string;
|
|
7
7
|
userId: string;
|
|
8
|
-
expiresAt: Date;
|
|
9
|
-
createdAt: Date;
|
|
10
8
|
updatedAt: Date;
|
|
9
|
+
createdAt: Date;
|
|
10
|
+
expiresAt: Date;
|
|
11
11
|
token: string;
|
|
12
12
|
ipAddress: string | null;
|
|
13
13
|
userAgent: string | null;
|
|
@@ -19,13 +19,12 @@ export declare function createAuthContext(auth: BetterAuth): ({ req }: CreateExp
|
|
|
19
19
|
};
|
|
20
20
|
user: {
|
|
21
21
|
name: string;
|
|
22
|
-
image: string | null;
|
|
23
22
|
id: string;
|
|
24
|
-
createdAt: Date;
|
|
25
23
|
updatedAt: Date;
|
|
26
24
|
email: string;
|
|
27
|
-
metadata: Record<string, unknown>;
|
|
28
25
|
emailVerified: boolean;
|
|
26
|
+
image: string | null;
|
|
27
|
+
createdAt: Date;
|
|
29
28
|
role: string | null;
|
|
30
29
|
banned: boolean | null;
|
|
31
30
|
banReason: string | null;
|
|
@@ -35,6 +34,7 @@ export declare function createAuthContext(auth: BetterAuth): ({ req }: CreateExp
|
|
|
35
34
|
paymentPlanTier: string | null;
|
|
36
35
|
paymentPlanExpiresAt: Date | null;
|
|
37
36
|
preferences: string | null;
|
|
37
|
+
metadata: Record<string, unknown>;
|
|
38
38
|
onboarding: number | null;
|
|
39
39
|
flags: string | null;
|
|
40
40
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthContext = createAuthContext;
|
|
4
|
+
const node_1 = require("better-auth/node");
|
|
5
|
+
function createAuthContext(auth) {
|
|
6
|
+
return async function createContext({ req }) {
|
|
7
|
+
const data = await auth.api.getSession({
|
|
8
|
+
headers: (0, node_1.fromNodeHeaders)(req.headers),
|
|
9
|
+
});
|
|
10
|
+
const user = data?.user || null;
|
|
11
|
+
const session = data?.session || null;
|
|
12
|
+
return {
|
|
13
|
+
session,
|
|
14
|
+
user,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./context"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./procedures"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./utils"), exports);
|
|
@@ -3,9 +3,9 @@ export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilde
|
|
|
3
3
|
session: {
|
|
4
4
|
id: string;
|
|
5
5
|
userId: string;
|
|
6
|
-
expiresAt: Date;
|
|
7
|
-
createdAt: Date;
|
|
8
6
|
updatedAt: Date;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
expiresAt: Date;
|
|
9
9
|
token: string;
|
|
10
10
|
ipAddress: string | null;
|
|
11
11
|
userAgent: string | null;
|
|
@@ -17,13 +17,12 @@ export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilde
|
|
|
17
17
|
};
|
|
18
18
|
user: {
|
|
19
19
|
name: string;
|
|
20
|
-
image: string | null;
|
|
21
20
|
id: string;
|
|
22
|
-
createdAt: Date;
|
|
23
21
|
updatedAt: Date;
|
|
24
22
|
email: string;
|
|
25
|
-
metadata: Record<string, unknown>;
|
|
26
23
|
emailVerified: boolean;
|
|
24
|
+
image: string | null;
|
|
25
|
+
createdAt: Date;
|
|
27
26
|
role: string | null;
|
|
28
27
|
banned: boolean | null;
|
|
29
28
|
banReason: string | null;
|
|
@@ -33,6 +32,7 @@ export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilde
|
|
|
33
32
|
paymentPlanTier: string | null;
|
|
34
33
|
paymentPlanExpiresAt: Date | null;
|
|
35
34
|
preferences: string | null;
|
|
35
|
+
metadata: Record<string, unknown>;
|
|
36
36
|
onboarding: number | null;
|
|
37
37
|
flags: string | null;
|
|
38
38
|
};
|
|
@@ -41,9 +41,9 @@ export declare const procedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
|
41
41
|
session: {
|
|
42
42
|
id: string;
|
|
43
43
|
userId: string;
|
|
44
|
-
expiresAt: Date;
|
|
45
|
-
createdAt: Date;
|
|
46
44
|
updatedAt: Date;
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
expiresAt: Date;
|
|
47
47
|
token: string;
|
|
48
48
|
ipAddress: string | null;
|
|
49
49
|
userAgent: string | null;
|
|
@@ -55,13 +55,12 @@ export declare const procedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
|
55
55
|
};
|
|
56
56
|
user: {
|
|
57
57
|
name: string;
|
|
58
|
-
image: string | null;
|
|
59
58
|
id: string;
|
|
60
|
-
createdAt: Date;
|
|
61
59
|
updatedAt: Date;
|
|
62
60
|
email: string;
|
|
63
|
-
metadata: Record<string, unknown>;
|
|
64
61
|
emailVerified: boolean;
|
|
62
|
+
image: string | null;
|
|
63
|
+
createdAt: Date;
|
|
65
64
|
role: string | null;
|
|
66
65
|
banned: boolean | null;
|
|
67
66
|
banReason: string | null;
|
|
@@ -71,34 +70,19 @@ export declare const procedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
|
71
70
|
paymentPlanTier: string | null;
|
|
72
71
|
paymentPlanExpiresAt: Date | null;
|
|
73
72
|
preferences: string | null;
|
|
73
|
+
metadata: Record<string, unknown>;
|
|
74
74
|
onboarding: number | null;
|
|
75
75
|
flags: string | null;
|
|
76
76
|
};
|
|
77
77
|
}, OpenApiMeta, {
|
|
78
|
-
session: {
|
|
79
|
-
id: string;
|
|
80
|
-
userId: string;
|
|
81
|
-
expiresAt: Date;
|
|
82
|
-
createdAt: Date;
|
|
83
|
-
updatedAt: Date;
|
|
84
|
-
token: string;
|
|
85
|
-
ipAddress: string | null;
|
|
86
|
-
userAgent: string | null;
|
|
87
|
-
impersonatedBy: string | null;
|
|
88
|
-
activeOrganizationId: string | null;
|
|
89
|
-
activeOrganizationRole: string | null;
|
|
90
|
-
activeTeamId: string | null;
|
|
91
|
-
activeTeamRole: string | null;
|
|
92
|
-
};
|
|
93
78
|
user: {
|
|
94
79
|
name: string;
|
|
95
|
-
image: string | null;
|
|
96
80
|
id: string;
|
|
97
|
-
createdAt: Date;
|
|
98
81
|
updatedAt: Date;
|
|
99
82
|
email: string;
|
|
100
|
-
metadata: Record<string, unknown>;
|
|
101
83
|
emailVerified: boolean;
|
|
84
|
+
image: string | null;
|
|
85
|
+
createdAt: Date;
|
|
102
86
|
role: string | null;
|
|
103
87
|
banned: boolean | null;
|
|
104
88
|
banReason: string | null;
|
|
@@ -108,17 +92,33 @@ export declare const procedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
|
108
92
|
paymentPlanTier: string | null;
|
|
109
93
|
paymentPlanExpiresAt: Date | null;
|
|
110
94
|
preferences: string | null;
|
|
95
|
+
metadata: Record<string, unknown>;
|
|
111
96
|
onboarding: number | null;
|
|
112
97
|
flags: string | null;
|
|
113
98
|
};
|
|
99
|
+
session: {
|
|
100
|
+
id: string;
|
|
101
|
+
userId: string;
|
|
102
|
+
updatedAt: Date;
|
|
103
|
+
createdAt: Date;
|
|
104
|
+
expiresAt: Date;
|
|
105
|
+
token: string;
|
|
106
|
+
ipAddress: string | null;
|
|
107
|
+
userAgent: string | null;
|
|
108
|
+
impersonatedBy: string | null;
|
|
109
|
+
activeOrganizationId: string | null;
|
|
110
|
+
activeOrganizationRole: string | null;
|
|
111
|
+
activeTeamId: string | null;
|
|
112
|
+
activeTeamRole: string | null;
|
|
113
|
+
};
|
|
114
114
|
}, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
|
|
115
115
|
export declare const adminProcedure: import("@trpc/server").TRPCProcedureBuilder<{
|
|
116
116
|
session: {
|
|
117
117
|
id: string;
|
|
118
118
|
userId: string;
|
|
119
|
-
expiresAt: Date;
|
|
120
|
-
createdAt: Date;
|
|
121
119
|
updatedAt: Date;
|
|
120
|
+
createdAt: Date;
|
|
121
|
+
expiresAt: Date;
|
|
122
122
|
token: string;
|
|
123
123
|
ipAddress: string | null;
|
|
124
124
|
userAgent: string | null;
|
|
@@ -130,13 +130,12 @@ export declare const adminProcedure: import("@trpc/server").TRPCProcedureBuilder
|
|
|
130
130
|
};
|
|
131
131
|
user: {
|
|
132
132
|
name: string;
|
|
133
|
-
image: string | null;
|
|
134
133
|
id: string;
|
|
135
|
-
createdAt: Date;
|
|
136
134
|
updatedAt: Date;
|
|
137
135
|
email: string;
|
|
138
|
-
metadata: Record<string, unknown>;
|
|
139
136
|
emailVerified: boolean;
|
|
137
|
+
image: string | null;
|
|
138
|
+
createdAt: Date;
|
|
140
139
|
role: string | null;
|
|
141
140
|
banned: boolean | null;
|
|
142
141
|
banReason: string | null;
|
|
@@ -146,34 +145,19 @@ export declare const adminProcedure: import("@trpc/server").TRPCProcedureBuilder
|
|
|
146
145
|
paymentPlanTier: string | null;
|
|
147
146
|
paymentPlanExpiresAt: Date | null;
|
|
148
147
|
preferences: string | null;
|
|
148
|
+
metadata: Record<string, unknown>;
|
|
149
149
|
onboarding: number | null;
|
|
150
150
|
flags: string | null;
|
|
151
151
|
};
|
|
152
152
|
}, OpenApiMeta, {
|
|
153
|
-
session: {
|
|
154
|
-
id: string;
|
|
155
|
-
userId: string;
|
|
156
|
-
expiresAt: Date;
|
|
157
|
-
createdAt: Date;
|
|
158
|
-
updatedAt: Date;
|
|
159
|
-
token: string;
|
|
160
|
-
ipAddress: string | null;
|
|
161
|
-
userAgent: string | null;
|
|
162
|
-
impersonatedBy: string | null;
|
|
163
|
-
activeOrganizationId: string | null;
|
|
164
|
-
activeOrganizationRole: string | null;
|
|
165
|
-
activeTeamId: string | null;
|
|
166
|
-
activeTeamRole: string | null;
|
|
167
|
-
};
|
|
168
153
|
user: {
|
|
169
154
|
name: string;
|
|
170
|
-
image: string | null;
|
|
171
155
|
id: string;
|
|
172
|
-
createdAt: Date;
|
|
173
156
|
updatedAt: Date;
|
|
174
157
|
email: string;
|
|
175
|
-
metadata: Record<string, unknown>;
|
|
176
158
|
emailVerified: boolean;
|
|
159
|
+
image: string | null;
|
|
160
|
+
createdAt: Date;
|
|
177
161
|
role: string | null;
|
|
178
162
|
banned: boolean | null;
|
|
179
163
|
banReason: string | null;
|
|
@@ -183,9 +167,25 @@ export declare const adminProcedure: import("@trpc/server").TRPCProcedureBuilder
|
|
|
183
167
|
paymentPlanTier: string | null;
|
|
184
168
|
paymentPlanExpiresAt: Date | null;
|
|
185
169
|
preferences: string | null;
|
|
170
|
+
metadata: Record<string, unknown>;
|
|
186
171
|
onboarding: number | null;
|
|
187
172
|
flags: string | null;
|
|
188
173
|
};
|
|
174
|
+
session: {
|
|
175
|
+
id: string;
|
|
176
|
+
userId: string;
|
|
177
|
+
updatedAt: Date;
|
|
178
|
+
createdAt: Date;
|
|
179
|
+
expiresAt: Date;
|
|
180
|
+
token: string;
|
|
181
|
+
ipAddress: string | null;
|
|
182
|
+
userAgent: string | null;
|
|
183
|
+
impersonatedBy: string | null;
|
|
184
|
+
activeOrganizationId: string | null;
|
|
185
|
+
activeOrganizationRole: string | null;
|
|
186
|
+
activeTeamId: string | null;
|
|
187
|
+
activeTeamRole: string | null;
|
|
188
|
+
};
|
|
189
189
|
}, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
|
|
190
190
|
export declare const mergeRouters: <TRouters extends import("@trpc/server").AnyRouter[]>(...routerList: TRouters) => import("@trpc/server").TRPCMergeRouters<TRouters>;
|
|
191
191
|
export declare const router: import("@trpc/server").TRPCRouterBuilder<{
|
|
@@ -193,9 +193,9 @@ export declare const router: import("@trpc/server").TRPCRouterBuilder<{
|
|
|
193
193
|
session: {
|
|
194
194
|
id: string;
|
|
195
195
|
userId: string;
|
|
196
|
-
expiresAt: Date;
|
|
197
|
-
createdAt: Date;
|
|
198
196
|
updatedAt: Date;
|
|
197
|
+
createdAt: Date;
|
|
198
|
+
expiresAt: Date;
|
|
199
199
|
token: string;
|
|
200
200
|
ipAddress: string | null;
|
|
201
201
|
userAgent: string | null;
|
|
@@ -207,13 +207,12 @@ export declare const router: import("@trpc/server").TRPCRouterBuilder<{
|
|
|
207
207
|
};
|
|
208
208
|
user: {
|
|
209
209
|
name: string;
|
|
210
|
-
image: string | null;
|
|
211
210
|
id: string;
|
|
212
|
-
createdAt: Date;
|
|
213
211
|
updatedAt: Date;
|
|
214
212
|
email: string;
|
|
215
|
-
metadata: Record<string, unknown>;
|
|
216
213
|
emailVerified: boolean;
|
|
214
|
+
image: string | null;
|
|
215
|
+
createdAt: Date;
|
|
217
216
|
role: string | null;
|
|
218
217
|
banned: boolean | null;
|
|
219
218
|
banReason: string | null;
|
|
@@ -223,6 +222,7 @@ export declare const router: import("@trpc/server").TRPCRouterBuilder<{
|
|
|
223
222
|
paymentPlanTier: string | null;
|
|
224
223
|
paymentPlanExpiresAt: Date | null;
|
|
225
224
|
preferences: string | null;
|
|
225
|
+
metadata: Record<string, unknown>;
|
|
226
226
|
onboarding: number | null;
|
|
227
227
|
flags: string | null;
|
|
228
228
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.router = exports.mergeRouters = exports.adminProcedure = exports.procedure = exports.publicProcedure = void 0;
|
|
4
|
+
const trpc_1 = require("@m5kdev/commons/utils/trpc");
|
|
5
|
+
const server_1 = require("@trpc/server");
|
|
6
|
+
const errors_1 = require("#utils/errors");
|
|
7
|
+
const posthog_1 = require("#utils/posthog");
|
|
8
|
+
const errorOptions = {
|
|
9
|
+
layer: "controller",
|
|
10
|
+
layerName: "TRPCController",
|
|
11
|
+
};
|
|
12
|
+
const t = server_1.initTRPC.meta().context().create({ transformer: trpc_1.transformer });
|
|
13
|
+
// Base router and procedure helpers
|
|
14
|
+
const baseProcedure = t.procedure.use(({ ctx, next }) => (0, posthog_1.runWithPosthogRequestState)({ disableCapture: Boolean(ctx.session?.impersonatedBy) }, () => next()));
|
|
15
|
+
exports.publicProcedure = baseProcedure;
|
|
16
|
+
exports.procedure = baseProcedure.use(({ ctx: { user, session }, next }) => {
|
|
17
|
+
if (!user || !session) {
|
|
18
|
+
throw new errors_1.ServerError({ code: "UNAUTHORIZED", ...errorOptions }).toTRPC();
|
|
19
|
+
}
|
|
20
|
+
return next({ ctx: { user, session } });
|
|
21
|
+
});
|
|
22
|
+
exports.adminProcedure = baseProcedure.use(({ ctx: { user, session }, next }) => {
|
|
23
|
+
if (!user || !session) {
|
|
24
|
+
throw new errors_1.ServerError({ code: "UNAUTHORIZED", ...errorOptions }).toTRPC();
|
|
25
|
+
}
|
|
26
|
+
if (user.role !== "admin") {
|
|
27
|
+
throw new errors_1.ServerError({ code: "FORBIDDEN", ...errorOptions }).toTRPC();
|
|
28
|
+
}
|
|
29
|
+
return next({ ctx: { user, session } });
|
|
30
|
+
});
|
|
31
|
+
exports.mergeRouters = t.mergeRouters;
|
|
32
|
+
exports.router = t.router;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleAsyncTRPCResult = handleAsyncTRPCResult;
|
|
4
|
+
exports.handleTRPCResult = handleTRPCResult;
|
|
5
|
+
const logger_1 = require("#utils/logger");
|
|
6
|
+
async function handleAsyncTRPCResult(result) {
|
|
7
|
+
return handleTRPCResult(await result);
|
|
8
|
+
}
|
|
9
|
+
function handleTRPCResult(result) {
|
|
10
|
+
if (result.isErr()) {
|
|
11
|
+
logger_1.logger.debug("Is tRPC Error");
|
|
12
|
+
logger_1.logger.error({
|
|
13
|
+
layer: result.error.layer,
|
|
14
|
+
layerName: result.error.layerName,
|
|
15
|
+
error: result.error.toJSON(),
|
|
16
|
+
});
|
|
17
|
+
throw result.error.toTRPC();
|
|
18
|
+
}
|
|
19
|
+
return result.value;
|
|
20
|
+
}
|