@m5kdev/backend 0.1.5 → 0.2.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.
@@ -2,20 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createWorkflowTRPC = createWorkflowTRPC;
4
4
  const workflow_schema_1 = require("@m5kdev/commons/modules/workflow/workflow.schema");
5
- const _trpc_1 = require("#trpc");
6
- function createWorkflowTRPC(workflowService) {
7
- return (0, _trpc_1.router)({
8
- read: _trpc_1.procedure
5
+ const trpc_1 = require("#utils/trpc");
6
+ function createWorkflowTRPC({ router, privateProcedure: procedure }, workflowService) {
7
+ return router({
8
+ read: procedure
9
9
  .input(workflow_schema_1.workflowReadInputSchema)
10
10
  .output(workflow_schema_1.workflowReadOutputSchema)
11
11
  .query(async ({ ctx, input }) => {
12
- return (0, _trpc_1.handleTRPCResult)(await workflowService.read(input, ctx));
12
+ return (0, trpc_1.handleTRPCResult)(await workflowService.read(input, ctx));
13
13
  }),
14
- list: _trpc_1.procedure
14
+ list: procedure
15
15
  .input(workflow_schema_1.workflowListInputSchema)
16
16
  .output(workflow_schema_1.workflowListOutputSchema)
17
17
  .query(async ({ ctx, input }) => {
18
- return (0, _trpc_1.handleTRPCResult)(await workflowService.list(input, ctx));
18
+ return (0, trpc_1.handleTRPCResult)(await workflowService.list(input, ctx));
19
19
  }),
20
20
  });
21
21
  }
@@ -2,96 +2,23 @@ import type { Mastra } from "@mastra/core";
2
2
  import type { AIService } from "#modules/ai/ai.service";
3
3
  import type { AuthService } from "#modules/auth/auth.service";
4
4
  import type { BillingService } from "#modules/billing/billing.service";
5
- export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authService: AuthService, aiService: AIService<MastraInstance>, billingService: BillingService) => import("@trpc/server").TRPCBuiltRouter<{
6
- ctx: {
7
- session: {
8
- id: string;
9
- createdAt: Date;
10
- updatedAt: Date;
11
- expiresAt: Date;
12
- token: string;
13
- ipAddress: string | null;
14
- userAgent: string | null;
15
- userId: string;
16
- impersonatedBy: string | null;
17
- activeOrganizationId: string | null;
18
- activeOrganizationRole: string | null;
19
- activeTeamId: string | null;
20
- activeTeamRole: string | null;
21
- };
22
- user: {
23
- id: string;
24
- name: string;
25
- email: string;
26
- emailVerified: boolean;
27
- image: string | null;
28
- createdAt: Date;
29
- updatedAt: Date;
30
- role: string | null;
31
- banned: boolean | null;
32
- banReason: string | null;
33
- banExpires: Date | null;
34
- stripeCustomerId: string | null;
35
- paymentCustomerId: string | null;
36
- paymentPlanTier: string | null;
37
- paymentPlanExpiresAt: Date | null;
38
- preferences: string | null;
39
- metadata: Record<string, unknown>;
40
- onboarding: number | null;
41
- flags: string | null;
42
- };
43
- };
44
- meta: import("trpc-to-openapi").OpenApiMeta;
5
+ import type { TRPCMethods } from "#utils/trpc";
6
+ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(trpcMethods: TRPCMethods, authService: AuthService, aiService: AIService<MastraInstance>, billingService: BillingService) => import("@trpc/server").TRPCBuiltRouter<{
7
+ ctx: import("./modules/auth/auth.lib").Context;
8
+ meta: any;
45
9
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
46
10
  transformer: true;
47
11
  }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
48
12
  auth: import("@trpc/server").TRPCBuiltRouter<{
49
- ctx: {
50
- session: {
51
- id: string;
52
- createdAt: Date;
53
- updatedAt: Date;
54
- expiresAt: Date;
55
- token: string;
56
- ipAddress: string | null;
57
- userAgent: string | null;
58
- userId: string;
59
- impersonatedBy: string | null;
60
- activeOrganizationId: string | null;
61
- activeOrganizationRole: string | null;
62
- activeTeamId: string | null;
63
- activeTeamRole: string | null;
64
- };
65
- user: {
66
- id: string;
67
- name: string;
68
- email: string;
69
- emailVerified: boolean;
70
- image: string | null;
71
- createdAt: Date;
72
- updatedAt: Date;
73
- role: string | null;
74
- banned: boolean | null;
75
- banReason: string | null;
76
- banExpires: Date | null;
77
- stripeCustomerId: string | null;
78
- paymentCustomerId: string | null;
79
- paymentPlanTier: string | null;
80
- paymentPlanExpiresAt: Date | null;
81
- preferences: string | null;
82
- metadata: Record<string, unknown>;
83
- onboarding: number | null;
84
- flags: string | null;
85
- };
86
- };
87
- meta: import("trpc-to-openapi").OpenApiMeta;
13
+ ctx: import("./modules/auth/auth.lib").Context;
14
+ meta: any;
88
15
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
89
16
  transformer: true;
90
17
  }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
91
18
  getUserWaitlistCount: import("@trpc/server").TRPCQueryProcedure<{
92
19
  input: void;
93
20
  output: number;
94
- meta: import("trpc-to-openapi").OpenApiMeta;
21
+ meta: any;
95
22
  }>;
96
23
  createInvitationCode: import("@trpc/server").TRPCMutationProcedure<{
97
24
  input: {
@@ -107,7 +34,7 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
107
34
  code: string | null;
108
35
  expiresAt: Date | null;
109
36
  };
110
- meta: import("trpc-to-openapi").OpenApiMeta;
37
+ meta: any;
111
38
  }>;
112
39
  createAccountClaimCode: import("@trpc/server").TRPCMutationProcedure<{
113
40
  input: {
@@ -125,21 +52,21 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
125
52
  createdAt: Date;
126
53
  updatedAt: Date | null;
127
54
  };
128
- meta: import("trpc-to-openapi").OpenApiMeta;
55
+ meta: any;
129
56
  }>;
130
57
  listAccountClaims: import("@trpc/server").TRPCQueryProcedure<{
131
58
  input: void;
132
59
  output: {
60
+ expiresAt: Date | null;
133
61
  id: string;
134
62
  createdAt: Date;
135
63
  updatedAt: Date | null;
136
- expiresAt: Date | null;
137
64
  status: string;
138
65
  claimUserId: string | null;
139
66
  claimedAt: Date | null;
140
67
  claimedEmail: string | null;
141
68
  }[];
142
- meta: import("trpc-to-openapi").OpenApiMeta;
69
+ meta: any;
143
70
  }>;
144
71
  generateAccountClaimMagicLink: import("@trpc/server").TRPCMutationProcedure<{
145
72
  input: {
@@ -147,30 +74,30 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
147
74
  email?: string | undefined;
148
75
  };
149
76
  output: {
150
- id: string;
151
77
  email: string;
152
- createdAt: Date;
78
+ url: string;
153
79
  expiresAt: Date | null;
80
+ id: string;
154
81
  userId: string;
82
+ createdAt: Date;
155
83
  claimId: string;
156
- url: string;
157
84
  };
158
- meta: import("trpc-to-openapi").OpenApiMeta;
85
+ meta: any;
159
86
  }>;
160
87
  listAccountClaimMagicLinks: import("@trpc/server").TRPCQueryProcedure<{
161
88
  input: {
162
89
  claimId: string;
163
90
  };
164
91
  output: {
165
- id: string;
166
92
  email: string;
167
- createdAt: Date;
93
+ url: string;
168
94
  expiresAt: Date | null;
95
+ id: string;
169
96
  userId: string;
97
+ createdAt: Date;
170
98
  claimId: string;
171
- url: string;
172
99
  }[];
173
- meta: import("trpc-to-openapi").OpenApiMeta;
100
+ meta: any;
174
101
  }>;
175
102
  getMyAccountClaimStatus: import("@trpc/server").TRPCQueryProcedure<{
176
103
  input: void;
@@ -185,7 +112,7 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
185
112
  createdAt: Date;
186
113
  updatedAt: Date | null;
187
114
  } | null;
188
- meta: import("trpc-to-openapi").OpenApiMeta;
115
+ meta: any;
189
116
  }>;
190
117
  setMyAccountClaimEmail: import("@trpc/server").TRPCMutationProcedure<{
191
118
  input: {
@@ -194,14 +121,14 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
194
121
  output: {
195
122
  status: boolean;
196
123
  };
197
- meta: import("trpc-to-openapi").OpenApiMeta;
124
+ meta: any;
198
125
  }>;
199
126
  acceptMyAccountClaim: import("@trpc/server").TRPCMutationProcedure<{
200
127
  input: void;
201
128
  output: {
202
129
  status: boolean;
203
130
  };
204
- meta: import("trpc-to-openapi").OpenApiMeta;
131
+ meta: any;
205
132
  }>;
206
133
  listWaitlist: import("@trpc/server").TRPCQueryProcedure<{
207
134
  input: void;
@@ -215,33 +142,33 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
215
142
  code: string | null;
216
143
  expiresAt: Date | null;
217
144
  }[];
218
- meta: import("trpc-to-openapi").OpenApiMeta;
145
+ meta: any;
219
146
  }>;
220
147
  listAdminWaitlist: import("@trpc/server").TRPCQueryProcedure<{
221
148
  input: void;
222
149
  output: {
150
+ email: string | null;
223
151
  id: string;
224
152
  name: string | null;
225
- email: string | null;
226
153
  createdAt: Date;
227
154
  updatedAt: Date | null;
228
155
  status: string;
229
156
  }[];
230
- meta: import("trpc-to-openapi").OpenApiMeta;
157
+ meta: any;
231
158
  }>;
232
159
  addToWaitlist: import("@trpc/server").TRPCMutationProcedure<{
233
160
  input: {
234
161
  email: string;
235
162
  };
236
163
  output: {
164
+ email: string | null;
237
165
  id: string;
238
166
  name: string | null;
239
- email: string | null;
240
167
  createdAt: Date;
241
168
  updatedAt: Date | null;
242
169
  status: string;
243
170
  };
244
- meta: import("trpc-to-openapi").OpenApiMeta;
171
+ meta: any;
245
172
  }>;
246
173
  inviteToWaitlist: import("@trpc/server").TRPCMutationProcedure<{
247
174
  input: {
@@ -258,89 +185,89 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
258
185
  code: string | null;
259
186
  expiresAt: Date | null;
260
187
  };
261
- meta: import("trpc-to-openapi").OpenApiMeta;
188
+ meta: any;
262
189
  }>;
263
190
  inviteFromWaitlist: import("@trpc/server").TRPCMutationProcedure<{
264
191
  input: {
265
192
  id: string;
266
193
  };
267
194
  output: {
195
+ email: string | null;
268
196
  id: string;
269
197
  name: string | null;
270
- email: string | null;
271
198
  createdAt: Date;
272
199
  updatedAt: Date | null;
273
200
  status: string;
274
201
  };
275
- meta: import("trpc-to-openapi").OpenApiMeta;
202
+ meta: any;
276
203
  }>;
277
204
  removeFromWaitlist: import("@trpc/server").TRPCMutationProcedure<{
278
205
  input: {
279
206
  id: string;
280
207
  };
281
208
  output: {
209
+ email: string | null;
282
210
  id: string;
283
211
  name: string | null;
284
- email: string | null;
285
212
  createdAt: Date;
286
213
  updatedAt: Date | null;
287
214
  status: string;
288
215
  };
289
- meta: import("trpc-to-openapi").OpenApiMeta;
216
+ meta: any;
290
217
  }>;
291
218
  joinWaitlist: import("@trpc/server").TRPCMutationProcedure<{
292
219
  input: {
293
220
  email: string;
294
221
  };
295
222
  output: {
223
+ email: string | null;
296
224
  id: string;
297
225
  name: string | null;
298
- email: string | null;
299
226
  createdAt: Date;
300
227
  updatedAt: Date | null;
301
228
  status: string;
302
229
  };
303
- meta: import("trpc-to-openapi").OpenApiMeta;
230
+ meta: any;
304
231
  }>;
305
232
  getOnboarding: import("@trpc/server").TRPCQueryProcedure<{
306
233
  input: void;
307
234
  output: number;
308
- meta: import("trpc-to-openapi").OpenApiMeta;
235
+ meta: any;
309
236
  }>;
310
237
  setOnboarding: import("@trpc/server").TRPCMutationProcedure<{
311
238
  input: number;
312
239
  output: number;
313
- meta: import("trpc-to-openapi").OpenApiMeta;
240
+ meta: any;
314
241
  }>;
315
242
  getPreferences: import("@trpc/server").TRPCQueryProcedure<{
316
243
  input: void;
317
244
  output: Record<string, unknown>;
318
- meta: import("trpc-to-openapi").OpenApiMeta;
245
+ meta: any;
319
246
  }>;
320
247
  setPreferences: import("@trpc/server").TRPCMutationProcedure<{
321
248
  input: Record<string, unknown>;
322
249
  output: Record<string, unknown>;
323
- meta: import("trpc-to-openapi").OpenApiMeta;
250
+ meta: any;
324
251
  }>;
325
252
  getMetadata: import("@trpc/server").TRPCQueryProcedure<{
326
253
  input: void;
327
254
  output: Record<string, unknown>;
328
- meta: import("trpc-to-openapi").OpenApiMeta;
255
+ meta: any;
329
256
  }>;
330
257
  setMetadata: import("@trpc/server").TRPCMutationProcedure<{
331
258
  input: Record<string, unknown>;
332
259
  output: Record<string, unknown>;
333
- meta: import("trpc-to-openapi").OpenApiMeta;
260
+ meta: any;
334
261
  }>;
335
262
  getFlags: import("@trpc/server").TRPCQueryProcedure<{
336
263
  input: void;
337
264
  output: string[];
338
- meta: import("trpc-to-openapi").OpenApiMeta;
265
+ meta: any;
339
266
  }>;
340
267
  setFlags: import("@trpc/server").TRPCMutationProcedure<{
341
268
  input: string[];
342
269
  output: string[];
343
- meta: import("trpc-to-openapi").OpenApiMeta;
270
+ meta: any;
344
271
  }>;
345
272
  validateWaitlistCode: import("@trpc/server").TRPCQueryProcedure<{
346
273
  input: {
@@ -349,49 +276,12 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
349
276
  output: {
350
277
  status: string;
351
278
  };
352
- meta: import("trpc-to-openapi").OpenApiMeta;
279
+ meta: any;
353
280
  }>;
354
281
  }>>;
355
282
  ai: import("@trpc/server").TRPCBuiltRouter<{
356
- ctx: {
357
- session: {
358
- id: string;
359
- createdAt: Date;
360
- updatedAt: Date;
361
- expiresAt: Date;
362
- token: string;
363
- ipAddress: string | null;
364
- userAgent: string | null;
365
- userId: string;
366
- impersonatedBy: string | null;
367
- activeOrganizationId: string | null;
368
- activeOrganizationRole: string | null;
369
- activeTeamId: string | null;
370
- activeTeamRole: string | null;
371
- };
372
- user: {
373
- id: string;
374
- name: string;
375
- email: string;
376
- emailVerified: boolean;
377
- image: string | null;
378
- createdAt: Date;
379
- updatedAt: Date;
380
- role: string | null;
381
- banned: boolean | null;
382
- banReason: string | null;
383
- banExpires: Date | null;
384
- stripeCustomerId: string | null;
385
- paymentCustomerId: string | null;
386
- paymentPlanTier: string | null;
387
- paymentPlanExpiresAt: Date | null;
388
- preferences: string | null;
389
- metadata: Record<string, unknown>;
390
- onboarding: number | null;
391
- flags: string | null;
392
- };
393
- };
394
- meta: import("trpc-to-openapi").OpenApiMeta;
283
+ ctx: import("./modules/auth/auth.lib").Context;
284
+ meta: any;
395
285
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
396
286
  transformer: true;
397
287
  }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
@@ -405,49 +295,12 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
405
295
  totalTokens: number | null;
406
296
  cost: number | null;
407
297
  };
408
- meta: import("trpc-to-openapi").OpenApiMeta;
298
+ meta: any;
409
299
  }>;
410
300
  }>>;
411
301
  billing: import("@trpc/server").TRPCBuiltRouter<{
412
- ctx: {
413
- session: {
414
- id: string;
415
- createdAt: Date;
416
- updatedAt: Date;
417
- expiresAt: Date;
418
- token: string;
419
- ipAddress: string | null;
420
- userAgent: string | null;
421
- userId: string;
422
- impersonatedBy: string | null;
423
- activeOrganizationId: string | null;
424
- activeOrganizationRole: string | null;
425
- activeTeamId: string | null;
426
- activeTeamRole: string | null;
427
- };
428
- user: {
429
- id: string;
430
- name: string;
431
- email: string;
432
- emailVerified: boolean;
433
- image: string | null;
434
- createdAt: Date;
435
- updatedAt: Date;
436
- role: string | null;
437
- banned: boolean | null;
438
- banReason: string | null;
439
- banExpires: Date | null;
440
- stripeCustomerId: string | null;
441
- paymentCustomerId: string | null;
442
- paymentPlanTier: string | null;
443
- paymentPlanExpiresAt: Date | null;
444
- preferences: string | null;
445
- metadata: Record<string, unknown>;
446
- onboarding: number | null;
447
- flags: string | null;
448
- };
449
- };
450
- meta: import("trpc-to-openapi").OpenApiMeta;
302
+ ctx: import("./modules/auth/auth.lib").Context;
303
+ meta: any;
451
304
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
452
305
  transformer: true;
453
306
  }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
@@ -473,12 +326,12 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
473
326
  unitAmount?: number | null | undefined;
474
327
  discounts?: string[] | null | undefined;
475
328
  } | null;
476
- meta: import("trpc-to-openapi").OpenApiMeta;
329
+ meta: any;
477
330
  }>;
478
331
  listInvoices: import("@trpc/server").TRPCQueryProcedure<{
479
332
  input: void;
480
333
  output: import("stripe").Stripe.Invoice[];
481
- meta: import("trpc-to-openapi").OpenApiMeta;
334
+ meta: any;
482
335
  }>;
483
336
  }>>;
484
337
  }>>;
package/dist/src/types.js CHANGED
@@ -4,10 +4,9 @@ exports.createAuthTRPCRouter = void 0;
4
4
  const ai_trpc_1 = require("#modules/ai/ai.trpc");
5
5
  const auth_trpc_1 = require("#modules/auth/auth.trpc");
6
6
  const billing_trpc_1 = require("#modules/billing/billing.trpc");
7
- const _trpc_1 = require("#trpc");
8
- const createAuthTRPCRouter = (authService, aiService, billingService) => (0, _trpc_1.router)({
9
- auth: (0, auth_trpc_1.createAuthTRPC)(authService),
10
- ai: (0, ai_trpc_1.createAITRPC)(aiService),
11
- billing: (0, billing_trpc_1.createBillingTRPC)(billingService),
7
+ const createAuthTRPCRouter = (trpcMethods, authService, aiService, billingService) => trpcMethods.router({
8
+ auth: (0, auth_trpc_1.createAuthTRPC)(trpcMethods, authService),
9
+ ai: (0, ai_trpc_1.createAITRPC)(trpcMethods, aiService),
10
+ billing: (0, billing_trpc_1.createBillingTRPC)(trpcMethods, billingService),
12
11
  });
13
12
  exports.createAuthTRPCRouter = createAuthTRPCRouter;
@@ -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 "#utils/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
+ token: string;
19
+ expiresAt: Date;
20
+ id: string;
21
+ userId: string;
22
+ createdAt: Date;
23
+ updatedAt: 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
+ email: string;
34
+ metadata: Record<string, unknown>;
35
+ id: string;
36
+ name: string;
37
+ image: string | null;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ emailVerified: boolean;
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("#utils/errors");
10
+ const logger_1 = require("#utils/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
+ }