@m5kdev/backend 0.1.1 → 0.1.2
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 +9 -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
package/dist/src/types.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
7
7
|
session: {
|
|
8
8
|
id: string;
|
|
9
9
|
userId: string;
|
|
10
|
-
expiresAt: Date;
|
|
11
|
-
createdAt: Date;
|
|
12
10
|
updatedAt: Date;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
expiresAt: Date;
|
|
13
13
|
token: string;
|
|
14
14
|
ipAddress: string | null;
|
|
15
15
|
userAgent: string | null;
|
|
@@ -21,13 +21,12 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
21
21
|
};
|
|
22
22
|
user: {
|
|
23
23
|
name: string;
|
|
24
|
-
image: string | null;
|
|
25
24
|
id: string;
|
|
26
|
-
createdAt: Date;
|
|
27
25
|
updatedAt: Date;
|
|
28
26
|
email: string;
|
|
29
|
-
metadata: Record<string, unknown>;
|
|
30
27
|
emailVerified: boolean;
|
|
28
|
+
image: string | null;
|
|
29
|
+
createdAt: Date;
|
|
31
30
|
role: string | null;
|
|
32
31
|
banned: boolean | null;
|
|
33
32
|
banReason: string | null;
|
|
@@ -37,6 +36,7 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
37
36
|
paymentPlanTier: string | null;
|
|
38
37
|
paymentPlanExpiresAt: Date | null;
|
|
39
38
|
preferences: string | null;
|
|
39
|
+
metadata: Record<string, unknown>;
|
|
40
40
|
onboarding: number | null;
|
|
41
41
|
flags: string | null;
|
|
42
42
|
};
|
|
@@ -50,9 +50,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
50
50
|
session: {
|
|
51
51
|
id: string;
|
|
52
52
|
userId: string;
|
|
53
|
-
expiresAt: Date;
|
|
54
|
-
createdAt: Date;
|
|
55
53
|
updatedAt: Date;
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
expiresAt: Date;
|
|
56
56
|
token: string;
|
|
57
57
|
ipAddress: string | null;
|
|
58
58
|
userAgent: string | null;
|
|
@@ -64,13 +64,12 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
64
64
|
};
|
|
65
65
|
user: {
|
|
66
66
|
name: string;
|
|
67
|
-
image: string | null;
|
|
68
67
|
id: string;
|
|
69
|
-
createdAt: Date;
|
|
70
68
|
updatedAt: Date;
|
|
71
69
|
email: string;
|
|
72
|
-
metadata: Record<string, unknown>;
|
|
73
70
|
emailVerified: boolean;
|
|
71
|
+
image: string | null;
|
|
72
|
+
createdAt: Date;
|
|
74
73
|
role: string | null;
|
|
75
74
|
banned: boolean | null;
|
|
76
75
|
banReason: string | null;
|
|
@@ -80,6 +79,7 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
80
79
|
paymentPlanTier: string | null;
|
|
81
80
|
paymentPlanExpiresAt: Date | null;
|
|
82
81
|
preferences: string | null;
|
|
82
|
+
metadata: Record<string, unknown>;
|
|
83
83
|
onboarding: number | null;
|
|
84
84
|
flags: string | null;
|
|
85
85
|
};
|
|
@@ -131,9 +131,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
131
131
|
input: void;
|
|
132
132
|
output: {
|
|
133
133
|
id: string;
|
|
134
|
-
expiresAt: Date | null;
|
|
135
|
-
createdAt: Date;
|
|
136
134
|
updatedAt: Date | null;
|
|
135
|
+
createdAt: Date;
|
|
136
|
+
expiresAt: Date | null;
|
|
137
137
|
status: string;
|
|
138
138
|
claimUserId: string | null;
|
|
139
139
|
claimedAt: Date | null;
|
|
@@ -149,11 +149,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
149
149
|
output: {
|
|
150
150
|
id: string;
|
|
151
151
|
userId: string;
|
|
152
|
-
expiresAt: Date | null;
|
|
153
|
-
createdAt: Date;
|
|
154
152
|
email: string;
|
|
155
|
-
|
|
153
|
+
createdAt: Date;
|
|
154
|
+
expiresAt: Date | null;
|
|
156
155
|
claimId: string;
|
|
156
|
+
url: string;
|
|
157
157
|
};
|
|
158
158
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
159
159
|
}>;
|
|
@@ -164,11 +164,11 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
164
164
|
output: {
|
|
165
165
|
id: string;
|
|
166
166
|
userId: string;
|
|
167
|
-
expiresAt: Date | null;
|
|
168
|
-
createdAt: Date;
|
|
169
167
|
email: string;
|
|
170
|
-
|
|
168
|
+
createdAt: Date;
|
|
169
|
+
expiresAt: Date | null;
|
|
171
170
|
claimId: string;
|
|
171
|
+
url: string;
|
|
172
172
|
}[];
|
|
173
173
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
174
174
|
}>;
|
|
@@ -222,9 +222,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
222
222
|
output: {
|
|
223
223
|
name: string | null;
|
|
224
224
|
id: string;
|
|
225
|
-
createdAt: Date;
|
|
226
225
|
updatedAt: Date | null;
|
|
227
226
|
email: string | null;
|
|
227
|
+
createdAt: Date;
|
|
228
228
|
status: string;
|
|
229
229
|
}[];
|
|
230
230
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
@@ -236,9 +236,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
236
236
|
output: {
|
|
237
237
|
name: string | null;
|
|
238
238
|
id: string;
|
|
239
|
-
createdAt: Date;
|
|
240
239
|
updatedAt: Date | null;
|
|
241
240
|
email: string | null;
|
|
241
|
+
createdAt: Date;
|
|
242
242
|
status: string;
|
|
243
243
|
};
|
|
244
244
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
@@ -267,9 +267,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
267
267
|
output: {
|
|
268
268
|
name: string | null;
|
|
269
269
|
id: string;
|
|
270
|
-
createdAt: Date;
|
|
271
270
|
updatedAt: Date | null;
|
|
272
271
|
email: string | null;
|
|
272
|
+
createdAt: Date;
|
|
273
273
|
status: string;
|
|
274
274
|
};
|
|
275
275
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
@@ -281,9 +281,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
281
281
|
output: {
|
|
282
282
|
name: string | null;
|
|
283
283
|
id: string;
|
|
284
|
-
createdAt: Date;
|
|
285
284
|
updatedAt: Date | null;
|
|
286
285
|
email: string | null;
|
|
286
|
+
createdAt: Date;
|
|
287
287
|
status: string;
|
|
288
288
|
};
|
|
289
289
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
@@ -295,9 +295,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
295
295
|
output: {
|
|
296
296
|
name: string | null;
|
|
297
297
|
id: string;
|
|
298
|
-
createdAt: Date;
|
|
299
298
|
updatedAt: Date | null;
|
|
300
299
|
email: string | null;
|
|
300
|
+
createdAt: Date;
|
|
301
301
|
status: string;
|
|
302
302
|
};
|
|
303
303
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
@@ -357,9 +357,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
357
357
|
session: {
|
|
358
358
|
id: string;
|
|
359
359
|
userId: string;
|
|
360
|
-
expiresAt: Date;
|
|
361
|
-
createdAt: Date;
|
|
362
360
|
updatedAt: Date;
|
|
361
|
+
createdAt: Date;
|
|
362
|
+
expiresAt: Date;
|
|
363
363
|
token: string;
|
|
364
364
|
ipAddress: string | null;
|
|
365
365
|
userAgent: string | null;
|
|
@@ -371,13 +371,12 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
371
371
|
};
|
|
372
372
|
user: {
|
|
373
373
|
name: string;
|
|
374
|
-
image: string | null;
|
|
375
374
|
id: string;
|
|
376
|
-
createdAt: Date;
|
|
377
375
|
updatedAt: Date;
|
|
378
376
|
email: string;
|
|
379
|
-
metadata: Record<string, unknown>;
|
|
380
377
|
emailVerified: boolean;
|
|
378
|
+
image: string | null;
|
|
379
|
+
createdAt: Date;
|
|
381
380
|
role: string | null;
|
|
382
381
|
banned: boolean | null;
|
|
383
382
|
banReason: string | null;
|
|
@@ -387,6 +386,7 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
387
386
|
paymentPlanTier: string | null;
|
|
388
387
|
paymentPlanExpiresAt: Date | null;
|
|
389
388
|
preferences: string | null;
|
|
389
|
+
metadata: Record<string, unknown>;
|
|
390
390
|
onboarding: number | null;
|
|
391
391
|
flags: string | null;
|
|
392
392
|
};
|
|
@@ -413,9 +413,9 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
413
413
|
session: {
|
|
414
414
|
id: string;
|
|
415
415
|
userId: string;
|
|
416
|
-
expiresAt: Date;
|
|
417
|
-
createdAt: Date;
|
|
418
416
|
updatedAt: Date;
|
|
417
|
+
createdAt: Date;
|
|
418
|
+
expiresAt: Date;
|
|
419
419
|
token: string;
|
|
420
420
|
ipAddress: string | null;
|
|
421
421
|
userAgent: string | null;
|
|
@@ -427,13 +427,12 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
427
427
|
};
|
|
428
428
|
user: {
|
|
429
429
|
name: string;
|
|
430
|
-
image: string | null;
|
|
431
430
|
id: string;
|
|
432
|
-
createdAt: Date;
|
|
433
431
|
updatedAt: Date;
|
|
434
432
|
email: string;
|
|
435
|
-
metadata: Record<string, unknown>;
|
|
436
433
|
emailVerified: boolean;
|
|
434
|
+
image: string | null;
|
|
435
|
+
createdAt: Date;
|
|
437
436
|
role: string | null;
|
|
438
437
|
banned: boolean | null;
|
|
439
438
|
banReason: string | null;
|
|
@@ -443,6 +442,7 @@ export declare const createAuthTRPCRouter: <MastraInstance extends Mastra>(authS
|
|
|
443
442
|
paymentPlanTier: string | null;
|
|
444
443
|
paymentPlanExpiresAt: Date | null;
|
|
445
444
|
preferences: string | null;
|
|
445
|
+
metadata: Record<string, unknown>;
|
|
446
446
|
onboarding: number | null;
|
|
447
447
|
flags: string | null;
|
|
448
448
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthTRPCRouter = void 0;
|
|
4
|
+
const ai_trpc_1 = require("#modules/ai/ai.trpc");
|
|
5
|
+
const auth_trpc_1 = require("#modules/auth/auth.trpc");
|
|
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),
|
|
12
|
+
});
|
|
13
|
+
exports.createAuthTRPCRouter = createAuthTRPCRouter;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerError = void 0;
|
|
4
|
+
exports.getErrorReporter = getErrorReporter;
|
|
5
|
+
exports.setErrorReporter = setErrorReporter;
|
|
6
|
+
exports.reportError = reportError;
|
|
7
|
+
const server_1 = require("@trpc/server");
|
|
8
|
+
const http_1 = require("@trpc/server/http");
|
|
9
|
+
const radashi_1 = require("radashi");
|
|
10
|
+
const logger_1 = require("./logger");
|
|
11
|
+
class ServerError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
layer;
|
|
14
|
+
layerName;
|
|
15
|
+
clientMessage;
|
|
16
|
+
context;
|
|
17
|
+
boundaryStack; // where we wrapped it
|
|
18
|
+
constructor({ code, layer, layerName, message, clientMessage, cause, context, captureBoundary = true, }) {
|
|
19
|
+
// keep native cause chain when the cause is an Error
|
|
20
|
+
super(message ?? `server.error.${layer}.${(0, radashi_1.camel)(code)}`, {
|
|
21
|
+
cause: cause instanceof Error ? cause : undefined,
|
|
22
|
+
});
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.layer = layer ?? "unknown";
|
|
25
|
+
this.layerName = layerName ?? "UnknownLayer";
|
|
26
|
+
this.clientMessage = clientMessage ?? `server.error.${layer}.${(0, radashi_1.camel)(code)}`;
|
|
27
|
+
this.context = context;
|
|
28
|
+
if (captureBoundary)
|
|
29
|
+
this.boundaryStack = new Error().stack;
|
|
30
|
+
Error.captureStackTrace?.(this, ServerError);
|
|
31
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
32
|
+
}
|
|
33
|
+
is5xxError() {
|
|
34
|
+
const statusCode = this.getHTTPStatusCode();
|
|
35
|
+
return statusCode >= 500 && statusCode < 600;
|
|
36
|
+
}
|
|
37
|
+
getHTTPStatusCode() {
|
|
38
|
+
return (0, http_1.getHTTPStatusCodeFromError)(this.toTRPC());
|
|
39
|
+
}
|
|
40
|
+
toTRPC() {
|
|
41
|
+
return new server_1.TRPCError({
|
|
42
|
+
code: this.code,
|
|
43
|
+
message: this.message,
|
|
44
|
+
cause: this.cause,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
return {
|
|
49
|
+
code: this.code,
|
|
50
|
+
layer: this.layer,
|
|
51
|
+
layerName: this.layerName,
|
|
52
|
+
message: this.message,
|
|
53
|
+
context: this.context,
|
|
54
|
+
stack: process.env.NODE_ENV !== "production" ? this.stack : undefined,
|
|
55
|
+
boundaryStack: process.env.NODE_ENV !== "production" ? this.boundaryStack : undefined,
|
|
56
|
+
// Shallow representation of cause to avoid cycles
|
|
57
|
+
cause: this.cause instanceof Error
|
|
58
|
+
? { name: this.cause.name, message: this.cause.message, stack: this.cause.stack }
|
|
59
|
+
: this.cause,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
static fromUnknown(code, cause, opts) {
|
|
63
|
+
const msg = cause instanceof Error ? cause.message : undefined;
|
|
64
|
+
return new ServerError({
|
|
65
|
+
code,
|
|
66
|
+
layer: opts?.layer,
|
|
67
|
+
layerName: opts?.layerName,
|
|
68
|
+
message: msg,
|
|
69
|
+
cause,
|
|
70
|
+
context: opts?.context,
|
|
71
|
+
captureBoundary: true,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.ServerError = ServerError;
|
|
76
|
+
function getErrorReporter() {
|
|
77
|
+
return globalThis.m5ErrorReporter;
|
|
78
|
+
}
|
|
79
|
+
function setErrorReporter(reporter) {
|
|
80
|
+
globalThis.m5ErrorReporter = reporter;
|
|
81
|
+
}
|
|
82
|
+
function reportError(err, hint) {
|
|
83
|
+
let eventHint = hint;
|
|
84
|
+
const reporter = getErrorReporter();
|
|
85
|
+
if (!reporter) {
|
|
86
|
+
logger_1.logger.error("[reportError] No error reporter set!");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (err instanceof ServerError) {
|
|
90
|
+
// Merge - don't clobber caller-provided hint
|
|
91
|
+
eventHint = {
|
|
92
|
+
...hint,
|
|
93
|
+
captureContext: {
|
|
94
|
+
...hint?.captureContext,
|
|
95
|
+
extra: {
|
|
96
|
+
...(hint?.captureContext?.extra ?? {}),
|
|
97
|
+
layer: err.layer,
|
|
98
|
+
layerName: err.layerName,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return reporter.captureException(err, eventHint);
|
|
104
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pino_1 = tslib_1.__importDefault(require("pino"));
|
|
6
|
+
exports.logger = (0, pino_1.default)({
|
|
7
|
+
transport: {
|
|
8
|
+
target: "pino-pretty",
|
|
9
|
+
},
|
|
10
|
+
level: "debug",
|
|
11
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPosthog = getPosthog;
|
|
4
|
+
exports.setPosthog = setPosthog;
|
|
5
|
+
exports.runWithPosthogRequestState = runWithPosthogRequestState;
|
|
6
|
+
exports.isPosthogCaptureDisabled = isPosthogCaptureDisabled;
|
|
7
|
+
exports.posthogCapture = posthogCapture;
|
|
8
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
9
|
+
function getPosthog() {
|
|
10
|
+
return globalThis.m5Posthog;
|
|
11
|
+
}
|
|
12
|
+
function setPosthog(posthog) {
|
|
13
|
+
globalThis.m5Posthog = posthog;
|
|
14
|
+
}
|
|
15
|
+
const posthogRequestState = new node_async_hooks_1.AsyncLocalStorage();
|
|
16
|
+
function runWithPosthogRequestState(state, callback) {
|
|
17
|
+
return posthogRequestState.run(state, callback);
|
|
18
|
+
}
|
|
19
|
+
function isPosthogCaptureDisabled() {
|
|
20
|
+
return posthogRequestState.getStore()?.disableCapture ?? false;
|
|
21
|
+
}
|
|
22
|
+
function posthogCapture(event) {
|
|
23
|
+
if (isPosthogCaptureDisabled()) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const posthog = getPosthog();
|
|
27
|
+
if (!posthog) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return posthog.capture(event);
|
|
31
|
+
}
|