@blyp/core 0.1.21 → 0.1.23
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/README.md +54 -522
- package/STABILITY.md +56 -0
- package/dist/ai/anthropic/index.d.ts +3 -0
- package/dist/ai/anthropic/normalize.d.ts +9 -0
- package/dist/ai/anthropic/stream.d.ts +3 -0
- package/dist/ai/anthropic/wrap.d.ts +13 -0
- package/dist/ai/anthropic.js +701 -0
- package/dist/ai/anthropic.mjs +701 -0
- package/dist/ai/better-agent/index.d.ts +3 -0
- package/dist/ai/better-agent/normalize.d.ts +18 -0
- package/dist/ai/better-agent/plugin.d.ts +3 -0
- package/dist/ai/better-agent/tracker.d.ts +35 -0
- package/dist/ai/better-agent.js +701 -0
- package/dist/ai/better-agent.mjs +701 -0
- package/dist/ai/fetch.js +701 -0
- package/dist/ai/fetch.mjs +701 -0
- package/dist/ai/openai/index.d.ts +3 -0
- package/dist/ai/openai/normalize.d.ts +10 -0
- package/dist/ai/openai/stream.d.ts +3 -0
- package/dist/ai/openai/wrap.d.ts +24 -0
- package/dist/ai/openai.js +701 -0
- package/dist/ai/openai.mjs +701 -0
- package/dist/ai/shared/fetch.d.ts +5 -0
- package/dist/ai/shared/index.d.ts +2 -0
- package/dist/ai/shared/normalize.d.ts +17 -0
- package/dist/ai/shared/redaction.d.ts +6 -0
- package/dist/ai/shared/stream.d.ts +7 -0
- package/dist/ai/shared/trace.d.ts +119 -0
- package/dist/ai/shared/types.d.ts +171 -0
- package/dist/ai/shared.js +701 -0
- package/dist/ai/shared.mjs +701 -0
- package/dist/ai/vercel/index.d.ts +3 -0
- package/dist/ai/vercel/middleware.d.ts +3 -0
- package/dist/ai/vercel/model.d.ts +3 -0
- package/dist/ai/vercel.js +701 -0
- package/dist/ai/vercel.mjs +701 -0
- package/dist/astro.js +618 -4519
- package/dist/astro.mjs +618 -4491
- package/dist/client.js +1 -1139
- package/dist/client.mjs +1 -1132
- package/dist/connectors/betterstack.js +9 -1532
- package/dist/connectors/betterstack.mjs +9 -1507
- package/dist/connectors/databuddy.js +9 -1456
- package/dist/connectors/databuddy.mjs +9 -1451
- package/dist/connectors/delivery/backoff.d.ts +2 -0
- package/dist/connectors/delivery/manager.d.ts +44 -0
- package/dist/connectors/delivery/queue-path.d.ts +1 -0
- package/dist/connectors/delivery/sqlite-adapter-bun.d.ts +1 -0
- package/dist/connectors/delivery/sqlite-adapter-node.d.ts +1 -0
- package/dist/connectors/delivery/sqlite-client.d.ts +37 -0
- package/dist/connectors/delivery/sqlite-worker.d.ts +1 -0
- package/dist/connectors/delivery/studio-queue.d.ts +12 -0
- package/dist/connectors/delivery/types.d.ts +98 -0
- package/dist/connectors/otlp/index.d.ts +1 -0
- package/dist/connectors/otlp.js +9 -1371
- package/dist/connectors/otlp.mjs +9 -1368
- package/dist/connectors/posthog/properties.d.ts +4 -0
- package/dist/connectors/posthog/sender.d.ts +0 -1
- package/dist/connectors/posthog.js +10 -1527
- package/dist/connectors/posthog.mjs +10 -1522
- package/dist/connectors/sentry.js +9 -1380
- package/dist/connectors/sentry.mjs +9 -1357
- package/dist/core/config.d.ts +7 -2
- package/dist/core/log-record.d.ts +5 -4
- package/dist/core/logger.d.ts +2 -0
- package/dist/core/optional-module.d.ts +1 -0
- package/dist/core/pino-pretty-loader.d.ts +4 -0
- package/dist/database.js +1 -24
- package/dist/database.mjs +1 -21
- package/dist/elysia.js +613 -4517
- package/dist/elysia.mjs +615 -4491
- package/dist/expo.js +1 -726
- package/dist/expo.mjs +1 -724
- package/dist/express.js +613 -4507
- package/dist/express.mjs +615 -4480
- package/dist/fastify.js +615 -4526
- package/dist/fastify.mjs +617 -4499
- package/dist/frameworks/elysia/index.d.ts +1 -1
- package/dist/frameworks/elysia/logger.d.ts +2 -35
- package/dist/frameworks/nestjs/helpers.d.ts +2 -0
- package/dist/frameworks/shared/http.d.ts +3 -2
- package/dist/frameworks/shared/index.d.ts +2 -1
- package/dist/frameworks/shared/logger.d.ts +2 -0
- package/dist/frameworks/shared/request-context.d.ts +2 -0
- package/dist/frameworks/shared/trace.d.ts +6 -0
- package/dist/hono.js +616 -4496
- package/dist/hono.mjs +618 -4470
- package/dist/index.d.ts +49 -19
- package/dist/index.js +615 -7557
- package/dist/index.mjs +618 -7465
- package/dist/nestjs.js +626 -4999
- package/dist/nestjs.mjs +621 -4966
- package/dist/nextjs.js +618 -4525
- package/dist/nextjs.mjs +620 -4499
- package/dist/nitro.js +617 -4642
- package/dist/nitro.mjs +619 -4616
- package/dist/nuxt.js +617 -4649
- package/dist/nuxt.mjs +619 -4623
- package/dist/react-router.js +616 -4559
- package/dist/react-router.mjs +618 -4533
- package/dist/shared/redaction.d.ts +17 -0
- package/dist/standalone.js +606 -3628
- package/dist/standalone.mjs +610 -3603
- package/dist/sveltekit.js +617 -4523
- package/dist/sveltekit.mjs +619 -4497
- package/dist/tanstack-start.js +616 -4522
- package/dist/tanstack-start.mjs +618 -4496
- package/dist/types/core/config.d.ts +57 -0
- package/dist/types/core/logger.d.ts +3 -0
- package/dist/types/core/structured-log.d.ts +2 -0
- package/dist/types/database.d.ts +1 -0
- package/dist/types/frameworks/astro.d.ts +1 -0
- package/dist/types/frameworks/client.d.ts +2 -0
- package/dist/types/frameworks/elysia.d.ts +2 -0
- package/dist/types/frameworks/express.d.ts +1 -0
- package/dist/types/frameworks/fastify.d.ts +1 -0
- package/dist/types/frameworks/hono.d.ts +1 -0
- package/dist/types/frameworks/http.d.ts +1 -0
- package/dist/types/frameworks/nestjs.d.ts +2 -0
- package/dist/types/frameworks/nextjs.d.ts +1 -0
- package/dist/types/frameworks/nitro.d.ts +1 -0
- package/dist/types/frameworks/react-router.d.ts +2 -0
- package/dist/types/frameworks/request-context.d.ts +1 -0
- package/dist/types/frameworks/shared.d.ts +4 -1
- package/dist/types/frameworks/standalone.d.ts +3 -2
- package/dist/types/frameworks/sveltekit.d.ts +1 -0
- package/dist/types/frameworks/tanstack-start.d.ts +9 -3
- package/dist/types/frameworks/workers.d.ts +3 -0
- package/dist/types/shared/client-log.d.ts +1 -0
- package/dist/workers.js +2 -626
- package/dist/workers.mjs +2 -623
- package/package.json +259 -173
- package/dist/astro.js.map +0 -1
- package/dist/astro.mjs.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/client.mjs.map +0 -1
- package/dist/connectors/betterstack.js.map +0 -1
- package/dist/connectors/betterstack.mjs.map +0 -1
- package/dist/connectors/databuddy.js.map +0 -1
- package/dist/connectors/databuddy.mjs.map +0 -1
- package/dist/connectors/otlp.js.map +0 -1
- package/dist/connectors/otlp.mjs.map +0 -1
- package/dist/connectors/posthog.js.map +0 -1
- package/dist/connectors/posthog.mjs.map +0 -1
- package/dist/connectors/sentry.js.map +0 -1
- package/dist/connectors/sentry.mjs.map +0 -1
- package/dist/database.js.map +0 -1
- package/dist/database.mjs.map +0 -1
- package/dist/elysia.js.map +0 -1
- package/dist/elysia.mjs.map +0 -1
- package/dist/expo.js.map +0 -1
- package/dist/expo.mjs.map +0 -1
- package/dist/express.js.map +0 -1
- package/dist/express.mjs.map +0 -1
- package/dist/fastify.js.map +0 -1
- package/dist/fastify.mjs.map +0 -1
- package/dist/hono.js.map +0 -1
- package/dist/hono.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/nestjs.js.map +0 -1
- package/dist/nestjs.mjs.map +0 -1
- package/dist/nextjs.js.map +0 -1
- package/dist/nextjs.mjs.map +0 -1
- package/dist/nitro.js.map +0 -1
- package/dist/nitro.mjs.map +0 -1
- package/dist/nuxt.js.map +0 -1
- package/dist/nuxt.mjs.map +0 -1
- package/dist/react-router.js.map +0 -1
- package/dist/react-router.mjs.map +0 -1
- package/dist/standalone.js.map +0 -1
- package/dist/standalone.mjs.map +0 -1
- package/dist/sveltekit.js.map +0 -1
- package/dist/sveltekit.mjs.map +0 -1
- package/dist/tanstack-start.js.map +0 -1
- package/dist/tanstack-start.mjs.map +0 -1
- package/dist/workers.js.map +0 -1
- package/dist/workers.mjs.map +0 -1
- package/exports/client.js +0 -3
- package/exports/client.mjs +0 -3
- package/exports/connectors/betterstack.js +0 -1
- package/exports/connectors/betterstack.mjs +0 -1
- package/exports/connectors/databuddy.js +0 -1
- package/exports/connectors/databuddy.mjs +0 -1
- package/exports/connectors/otlp.js +0 -1
- package/exports/connectors/otlp.mjs +0 -1
- package/exports/connectors/posthog.js +0 -1
- package/exports/connectors/posthog.mjs +0 -1
- package/exports/connectors/sentry.js +0 -1
- package/exports/connectors/sentry.mjs +0 -1
- package/exports/database.js +0 -1
- package/exports/database.mjs +0 -1
- package/exports/expo.js +0 -1
- package/exports/expo.mjs +0 -1
- package/exports/frameworks/astro.js +0 -1
- package/exports/frameworks/astro.mjs +0 -1
- package/exports/frameworks/elysia.js +0 -1
- package/exports/frameworks/elysia.mjs +0 -1
- package/exports/frameworks/express.js +0 -1
- package/exports/frameworks/express.mjs +0 -1
- package/exports/frameworks/fastify.js +0 -1
- package/exports/frameworks/fastify.mjs +0 -1
- package/exports/frameworks/hono.js +0 -1
- package/exports/frameworks/hono.mjs +0 -1
- package/exports/frameworks/nestjs.js +0 -1
- package/exports/frameworks/nestjs.mjs +0 -1
- package/exports/frameworks/nextjs.js +0 -1
- package/exports/frameworks/nextjs.mjs +0 -1
- package/exports/frameworks/nitro.js +0 -1
- package/exports/frameworks/nitro.mjs +0 -1
- package/exports/frameworks/nuxt.js +0 -1
- package/exports/frameworks/nuxt.mjs +0 -1
- package/exports/frameworks/react-router.js +0 -1
- package/exports/frameworks/react-router.mjs +0 -1
- package/exports/frameworks/standalone.js +0 -1
- package/exports/frameworks/standalone.mjs +0 -1
- package/exports/frameworks/sveltekit.js +0 -1
- package/exports/frameworks/sveltekit.mjs +0 -1
- package/exports/frameworks/tanstack-start.js +0 -1
- package/exports/frameworks/tanstack-start.mjs +0 -1
- package/exports/workers.js +0 -1
- package/exports/workers.mjs +0 -1
- package/types/client.d.ts +0 -34
- package/types/connectors/betterstack.d.ts +0 -1
- package/types/connectors/databuddy.d.ts +0 -1
- package/types/connectors/otlp.d.ts +0 -1
- package/types/connectors/posthog.d.ts +0 -1
- package/types/connectors/sentry.d.ts +0 -1
- package/types/database.d.ts +0 -1
- package/types/expo.d.ts +0 -17
- package/types/frameworks/astro.d.ts +0 -1
- package/types/frameworks/client.d.ts +0 -160
- package/types/frameworks/elysia.d.ts +0 -1
- package/types/frameworks/expo.d.ts +0 -50
- package/types/frameworks/express.d.ts +0 -1
- package/types/frameworks/fastify.d.ts +0 -1
- package/types/frameworks/hono.d.ts +0 -1
- package/types/frameworks/nestjs.d.ts +0 -1
- package/types/frameworks/nextjs.d.ts +0 -1
- package/types/frameworks/nitro.d.ts +0 -1
- package/types/frameworks/nuxt.d.ts +0 -1
- package/types/frameworks/react-router.d.ts +0 -1
- package/types/frameworks/standalone.d.ts +0 -1
- package/types/frameworks/sveltekit.d.ts +0 -1
- package/types/frameworks/tanstack-start.d.ts +0 -1
- package/types/frameworks/workers.d.ts +0 -115
- package/types/index.d.ts +0 -1
- package/types/workers.d.ts +0 -13
|
@@ -1,1456 +1,9 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// src/core/config.ts
|
|
11
|
-
|
|
12
|
-
// src/shared/log-value.ts
|
|
13
|
-
function normalizeError(error) {
|
|
14
|
-
const normalized = {
|
|
15
|
-
name: error.name,
|
|
16
|
-
message: error.message
|
|
17
|
-
};
|
|
18
|
-
if (error.stack) {
|
|
19
|
-
normalized.stack = error.stack;
|
|
20
|
-
}
|
|
21
|
-
const errorWithCause = error;
|
|
22
|
-
if (errorWithCause.cause !== void 0) {
|
|
23
|
-
normalized.cause = normalizeLogValue(errorWithCause.cause);
|
|
24
|
-
}
|
|
25
|
-
return normalized;
|
|
26
|
-
}
|
|
27
|
-
function normalizeLogValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
28
|
-
if (value instanceof Error) {
|
|
29
|
-
return normalizeError(value);
|
|
30
|
-
}
|
|
31
|
-
if (typeof value === "function") {
|
|
32
|
-
return `[Function: ${value.name || "anonymous"}]`;
|
|
33
|
-
}
|
|
34
|
-
if (typeof value === "symbol") {
|
|
35
|
-
return value.toString();
|
|
36
|
-
}
|
|
37
|
-
if (value === void 0 || value === null) {
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
if (Array.isArray(value)) {
|
|
41
|
-
return value.map((entry) => normalizeLogValue(entry, seen));
|
|
42
|
-
}
|
|
43
|
-
if (typeof value === "object") {
|
|
44
|
-
if (seen.has(value)) {
|
|
45
|
-
return "[Circular]";
|
|
46
|
-
}
|
|
47
|
-
seen.add(value);
|
|
48
|
-
const normalized = {};
|
|
49
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
50
|
-
normalized[key] = normalizeLogValue(entry, seen);
|
|
51
|
-
}
|
|
52
|
-
seen.delete(value);
|
|
53
|
-
return normalized;
|
|
54
|
-
}
|
|
55
|
-
return value;
|
|
56
|
-
}
|
|
57
|
-
function serializeLogMessage(message) {
|
|
58
|
-
if (typeof message === "string") {
|
|
59
|
-
return message;
|
|
60
|
-
}
|
|
61
|
-
if (message instanceof Error) {
|
|
62
|
-
return message.message || message.name;
|
|
63
|
-
}
|
|
64
|
-
const normalized = normalizeLogValue(message);
|
|
65
|
-
if (typeof normalized === "string") {
|
|
66
|
-
return normalized;
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const serialized = JSON.stringify(normalized, null, 2);
|
|
70
|
-
return serialized ?? String(normalized);
|
|
71
|
-
} catch {
|
|
72
|
-
return String(normalized);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
var absoluteHttpUrlSchema = zod.z.string().url().refine((value) => {
|
|
76
|
-
try {
|
|
77
|
-
const url = new URL(value);
|
|
78
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
79
|
-
} catch {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
message: "Expected an absolute http(s) URL"
|
|
84
|
-
});
|
|
85
|
-
var plainObjectSchema = zod.z.custom(
|
|
86
|
-
(value) => {
|
|
87
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
message: "Expected a plain object"
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
var nonEmptyStringSchema = zod.z.string().trim().min(1);
|
|
94
|
-
function isAbsoluteHttpUrl(value) {
|
|
95
|
-
return absoluteHttpUrlSchema.safeParse(value).success;
|
|
96
|
-
}
|
|
97
|
-
function isPlainObject(value) {
|
|
98
|
-
return plainObjectSchema.safeParse(value).success;
|
|
99
|
-
}
|
|
100
|
-
function hasNonEmptyString(value) {
|
|
101
|
-
return nonEmptyStringSchema.safeParse(value).success;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/shared/client-log.ts
|
|
105
|
-
var DEFAULT_CLIENT_LOG_ENDPOINT = "/inngest";
|
|
106
|
-
zod.z.union([
|
|
107
|
-
zod.z.literal("betterstack"),
|
|
108
|
-
zod.z.literal("databuddy"),
|
|
109
|
-
zod.z.literal("posthog"),
|
|
110
|
-
zod.z.literal("sentry"),
|
|
111
|
-
zod.z.undefined(),
|
|
112
|
-
zod.z.object({
|
|
113
|
-
type: zod.z.literal("otlp"),
|
|
114
|
-
name: nonEmptyStringSchema
|
|
115
|
-
})
|
|
116
|
-
]);
|
|
117
|
-
|
|
118
|
-
// src/shared/once.ts
|
|
119
|
-
function createConsoleOnceLogger(method, warnedKeys3 = /* @__PURE__ */ new Set()) {
|
|
120
|
-
return (key, message, error) => {
|
|
121
|
-
if (warnedKeys3.has(key) || typeof console === "undefined") {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const writer = console[method];
|
|
125
|
-
if (typeof writer !== "function") {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
warnedKeys3.add(key);
|
|
129
|
-
if (error === void 0) {
|
|
130
|
-
writer.call(console, message);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
writer.call(console, message, error);
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function createWarnOnceLogger(warnedKeys3) {
|
|
137
|
-
return createConsoleOnceLogger("warn", warnedKeys3);
|
|
138
|
-
}
|
|
139
|
-
function createErrorOnceLogger(warnedKeys3) {
|
|
140
|
-
return createConsoleOnceLogger("error", warnedKeys3);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// src/core/config.ts
|
|
144
|
-
var PACKAGE_NAME = "@blyp/core";
|
|
145
|
-
var GITIGNORE_FILE_NAME = ".gitignore";
|
|
146
|
-
var CONFIG_FILE_NAMES = [
|
|
147
|
-
"blyp.config.ts",
|
|
148
|
-
"blyp.config.mts",
|
|
149
|
-
"blyp.config.cts",
|
|
150
|
-
"blyp.config.js",
|
|
151
|
-
"blyp.config.mjs",
|
|
152
|
-
"blyp.config.cjs",
|
|
153
|
-
"blyp.config.json"
|
|
154
|
-
];
|
|
155
|
-
var CONFIG_FILE_NAME = "blyp.config.json";
|
|
156
|
-
var DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";
|
|
157
|
-
var DEFAULT_CONNECTOR_SERVICE_NAME = "blyp-app";
|
|
158
|
-
var DEFAULT_POSTHOG_SERVICE_NAME = DEFAULT_CONNECTOR_SERVICE_NAME;
|
|
159
|
-
var warnedKeys = /* @__PURE__ */ new Set();
|
|
160
|
-
var warnOnce = createWarnOnceLogger(warnedKeys);
|
|
161
|
-
var DEFAULT_ROTATION_CONFIG = {
|
|
162
|
-
enabled: true,
|
|
163
|
-
maxSizeBytes: 10 * 1024 * 1024,
|
|
164
|
-
maxArchives: 5,
|
|
165
|
-
compress: true
|
|
166
|
-
};
|
|
167
|
-
var DEFAULT_FILE_CONFIG = {
|
|
168
|
-
enabled: true,
|
|
169
|
-
dir: "",
|
|
170
|
-
archiveDir: "",
|
|
171
|
-
format: "ndjson",
|
|
172
|
-
rotation: DEFAULT_ROTATION_CONFIG
|
|
173
|
-
};
|
|
174
|
-
var DEFAULT_CLIENT_LOGGING_CONFIG = {
|
|
175
|
-
enabled: true,
|
|
176
|
-
path: DEFAULT_CLIENT_LOG_ENDPOINT
|
|
177
|
-
};
|
|
178
|
-
var DEFAULT_DATABASE_RETRY_CONFIG = {
|
|
179
|
-
maxRetries: 1,
|
|
180
|
-
backoffMs: 100
|
|
181
|
-
};
|
|
182
|
-
var DEFAULT_DATABASE_DELIVERY_CONFIG = {
|
|
183
|
-
strategy: "immediate",
|
|
184
|
-
batchSize: 1,
|
|
185
|
-
flushIntervalMs: 250,
|
|
186
|
-
maxQueueSize: 1e3,
|
|
187
|
-
overflowStrategy: "drop-oldest",
|
|
188
|
-
flushTimeoutMs: 5e3,
|
|
189
|
-
retry: DEFAULT_DATABASE_RETRY_CONFIG
|
|
190
|
-
};
|
|
191
|
-
var DEFAULT_CONFIG = {
|
|
192
|
-
pretty: true,
|
|
193
|
-
level: "info",
|
|
194
|
-
destination: "file",
|
|
195
|
-
file: DEFAULT_FILE_CONFIG,
|
|
196
|
-
clientLogging: DEFAULT_CLIENT_LOGGING_CONFIG,
|
|
197
|
-
connectors: {}
|
|
198
|
-
};
|
|
199
|
-
var cachedConfig = null;
|
|
200
|
-
function findNearestPackageName(startDir) {
|
|
201
|
-
let currentDir = startDir;
|
|
202
|
-
while (true) {
|
|
203
|
-
const packageJsonPath = path.resolve(currentDir, "package.json");
|
|
204
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
205
|
-
try {
|
|
206
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
207
|
-
if (hasNonEmptyString(packageJson.name)) {
|
|
208
|
-
return packageJson.name;
|
|
209
|
-
}
|
|
210
|
-
} catch {
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
const parentDir = path.dirname(currentDir);
|
|
214
|
-
if (parentDir === currentDir) {
|
|
215
|
-
return void 0;
|
|
216
|
-
}
|
|
217
|
-
currentDir = parentDir;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function resolveDefaultConnectorServiceName(cwd = process.cwd()) {
|
|
221
|
-
return findNearestPackageName(cwd) ?? DEFAULT_POSTHOG_SERVICE_NAME;
|
|
222
|
-
}
|
|
223
|
-
function getBootstrapConfig() {
|
|
224
|
-
return {
|
|
225
|
-
pretty: true,
|
|
226
|
-
level: "info",
|
|
227
|
-
destination: "file",
|
|
228
|
-
file: {
|
|
229
|
-
enabled: true,
|
|
230
|
-
format: "ndjson",
|
|
231
|
-
rotation: {
|
|
232
|
-
enabled: true,
|
|
233
|
-
maxSizeBytes: 10 * 1024 * 1024,
|
|
234
|
-
maxArchives: 5,
|
|
235
|
-
compress: true
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
clientLogging: {
|
|
239
|
-
enabled: true,
|
|
240
|
-
path: DEFAULT_CLIENT_LOG_ENDPOINT
|
|
241
|
-
},
|
|
242
|
-
connectors: {}
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
function shouldBootstrapProjectFiles(cwd) {
|
|
246
|
-
const packageJsonPath = path.resolve(cwd, "package.json");
|
|
247
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
try {
|
|
251
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
252
|
-
return packageJson.name !== PACKAGE_NAME;
|
|
253
|
-
} catch {
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
function ensureConfigFile(cwd) {
|
|
258
|
-
if (CONFIG_FILE_NAMES.some((fileName) => fs.existsSync(path.resolve(cwd, fileName)))) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
const configPath = path.resolve(cwd, CONFIG_FILE_NAME);
|
|
262
|
-
if (fs.existsSync(configPath)) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
try {
|
|
266
|
-
fs.writeFileSync(configPath, `${JSON.stringify(getBootstrapConfig(), null, 2)}
|
|
267
|
-
`);
|
|
268
|
-
} catch (error) {
|
|
269
|
-
console.error("[Blyp] Warning: Failed to create blyp.config.json:", error);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
function ensureLogsIgnored(cwd) {
|
|
273
|
-
const gitignorePath = path.resolve(cwd, GITIGNORE_FILE_NAME);
|
|
274
|
-
if (!fs.existsSync(gitignorePath)) {
|
|
275
|
-
try {
|
|
276
|
-
fs.writeFileSync(gitignorePath, "logs\n");
|
|
277
|
-
} catch (error) {
|
|
278
|
-
console.error("[Blyp] Warning: Failed to create .gitignore:", error);
|
|
279
|
-
}
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
try {
|
|
283
|
-
const currentContent = fs.readFileSync(gitignorePath, "utf-8");
|
|
284
|
-
if (/^(?:\/?logs\/?)\s*$/m.test(currentContent)) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const separator = currentContent.endsWith("\n") ? "" : "\n";
|
|
288
|
-
fs.appendFileSync(gitignorePath, `${separator}logs
|
|
289
|
-
`);
|
|
290
|
-
} catch (error) {
|
|
291
|
-
console.error("[Blyp] Warning: Failed to update .gitignore:", error);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
function bootstrapProjectFiles() {
|
|
295
|
-
const cwd = process.cwd();
|
|
296
|
-
if (!shouldBootstrapProjectFiles(cwd)) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
ensureConfigFile(cwd);
|
|
300
|
-
ensureLogsIgnored(cwd);
|
|
301
|
-
}
|
|
302
|
-
function findConfigFile() {
|
|
303
|
-
const cwd = process.cwd();
|
|
304
|
-
const matches = CONFIG_FILE_NAMES.map((fileName) => path.resolve(cwd, fileName)).filter((filePath) => fs.existsSync(filePath));
|
|
305
|
-
if (matches.length === 0) {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
if (matches.length > 1) {
|
|
309
|
-
const preferred = matches[0];
|
|
310
|
-
warnOnce(
|
|
311
|
-
`config-multiple:${preferred}`,
|
|
312
|
-
`[Blyp] Warning: Multiple config files found. Using ${preferred} and ignoring ${matches.slice(1).join(", ")}.`
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
const selectedPath = matches[0];
|
|
316
|
-
return {
|
|
317
|
-
path: selectedPath,
|
|
318
|
-
type: selectedPath.endsWith(".json") ? "json" : "jiti"
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
function normalizeLoadedConfig(value, configPath) {
|
|
322
|
-
const normalized = value && typeof value === "object" && "default" in value && value.default !== void 0 ? value.default : value;
|
|
323
|
-
if (!normalized || typeof normalized !== "object" || Array.isArray(normalized)) {
|
|
324
|
-
warnOnce(
|
|
325
|
-
`config-invalid:${configPath}`,
|
|
326
|
-
`[Blyp] Warning: Config file ${configPath} did not export an object. Falling back to defaults.`
|
|
327
|
-
);
|
|
328
|
-
return {};
|
|
329
|
-
}
|
|
330
|
-
return normalized;
|
|
331
|
-
}
|
|
332
|
-
function parseJsonConfigFile(configPath) {
|
|
333
|
-
try {
|
|
334
|
-
const content = fs.readFileSync(configPath, "utf-8");
|
|
335
|
-
return normalizeLoadedConfig(JSON.parse(content), configPath);
|
|
336
|
-
} catch (error) {
|
|
337
|
-
console.error("[Blyp] Warning: Failed to parse blyp.config.json:", error);
|
|
338
|
-
return {};
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
function parseExecutableConfigFile(configPath) {
|
|
342
|
-
try {
|
|
343
|
-
const jiti$1 = jiti.createJiti(process.cwd(), {
|
|
344
|
-
interopDefault: true,
|
|
345
|
-
moduleCache: false,
|
|
346
|
-
fsCache: false
|
|
347
|
-
});
|
|
348
|
-
return normalizeLoadedConfig(jiti$1(configPath), configPath);
|
|
349
|
-
} catch (error) {
|
|
350
|
-
console.error(`[Blyp] Warning: Failed to load ${configPath}:`, error);
|
|
351
|
-
return {};
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
function parseConfigFile(config) {
|
|
355
|
-
return config.type === "json" ? parseJsonConfigFile(config.path) : parseExecutableConfigFile(config.path);
|
|
356
|
-
}
|
|
357
|
-
function isPrismaAdapter(value) {
|
|
358
|
-
return !!value && typeof value === "object" && value.type === "prisma";
|
|
359
|
-
}
|
|
360
|
-
function isDrizzleAdapter(value) {
|
|
361
|
-
return !!value && typeof value === "object" && value.type === "drizzle";
|
|
362
|
-
}
|
|
363
|
-
function mergeDatabaseRetryConfig(base, override) {
|
|
364
|
-
return {
|
|
365
|
-
...DEFAULT_DATABASE_RETRY_CONFIG,
|
|
366
|
-
...base,
|
|
367
|
-
...override
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
function mergeDatabaseDeliveryConfig(base, override) {
|
|
371
|
-
return {
|
|
372
|
-
...DEFAULT_DATABASE_DELIVERY_CONFIG,
|
|
373
|
-
...base,
|
|
374
|
-
...override,
|
|
375
|
-
retry: mergeDatabaseRetryConfig(base?.retry, override?.retry)
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
function hasPrismaDelegate(adapter) {
|
|
379
|
-
const model = adapter.model ?? "blypLog";
|
|
380
|
-
const client = adapter.client;
|
|
381
|
-
const delegate = client?.[model];
|
|
382
|
-
return !!delegate && typeof delegate.create === "function";
|
|
383
|
-
}
|
|
384
|
-
function hasDrizzleAdapterShape(adapter) {
|
|
385
|
-
const db = adapter.db;
|
|
386
|
-
return !!db && typeof db.insert === "function" && adapter.table !== void 0;
|
|
387
|
-
}
|
|
388
|
-
function resolveDatabaseLoggerConfig(config, sourceType) {
|
|
389
|
-
if (!config) {
|
|
390
|
-
return void 0;
|
|
391
|
-
}
|
|
392
|
-
const adapter = config.adapter;
|
|
393
|
-
let ready = false;
|
|
394
|
-
if (sourceType === "json") {
|
|
395
|
-
warnOnce(
|
|
396
|
-
"database-json-config",
|
|
397
|
-
"[Blyp] Warning: Database logging requires an executable blyp config file. Database destination remains disabled until you move this config to blyp.config.ts/js."
|
|
398
|
-
);
|
|
399
|
-
} else if (config.dialect !== "postgres" && config.dialect !== "mysql") {
|
|
400
|
-
warnOnce(
|
|
401
|
-
`database-dialect:${String(config.dialect)}`,
|
|
402
|
-
`[Blyp] Warning: Unsupported database dialect "${String(config.dialect)}". Database logging is disabled.`
|
|
403
|
-
);
|
|
404
|
-
} else if (!adapter) {
|
|
405
|
-
warnOnce(
|
|
406
|
-
"database-adapter-missing",
|
|
407
|
-
"[Blyp] Warning: Database logging is enabled without an adapter. Database logging is disabled."
|
|
408
|
-
);
|
|
409
|
-
} else if (isPrismaAdapter(adapter)) {
|
|
410
|
-
ready = hasPrismaDelegate({
|
|
411
|
-
...adapter,
|
|
412
|
-
model: adapter.model ?? "blypLog"
|
|
413
|
-
});
|
|
414
|
-
if (!ready) {
|
|
415
|
-
warnOnce(
|
|
416
|
-
"database-prisma-missing",
|
|
417
|
-
`[Blyp] Warning: Prisma database adapter is missing the "${adapter.model ?? "blypLog"}" delegate or its create method. Database logging is disabled.`
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
} else if (isDrizzleAdapter(adapter)) {
|
|
421
|
-
ready = hasDrizzleAdapterShape(adapter);
|
|
422
|
-
if (!ready) {
|
|
423
|
-
warnOnce(
|
|
424
|
-
"database-drizzle-missing",
|
|
425
|
-
"[Blyp] Warning: Drizzle database adapter is missing a db.insert function or table reference. Database logging is disabled."
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
const normalizedAdapter = isPrismaAdapter(adapter) ? {
|
|
430
|
-
...adapter,
|
|
431
|
-
model: adapter.model ?? "blypLog"
|
|
432
|
-
} : adapter;
|
|
433
|
-
return {
|
|
434
|
-
dialect: config.dialect,
|
|
435
|
-
adapter: normalizedAdapter,
|
|
436
|
-
delivery: mergeDatabaseDeliveryConfig(void 0, config.delivery),
|
|
437
|
-
ready,
|
|
438
|
-
status: ready ? "enabled" : "missing"
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
function mergeRotationConfig(base, override) {
|
|
442
|
-
return {
|
|
443
|
-
...DEFAULT_ROTATION_CONFIG,
|
|
444
|
-
...base,
|
|
445
|
-
...override
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
function mergeFileConfig(base, override) {
|
|
449
|
-
return {
|
|
450
|
-
...DEFAULT_FILE_CONFIG,
|
|
451
|
-
...base,
|
|
452
|
-
...override,
|
|
453
|
-
rotation: mergeRotationConfig(base?.rotation, override?.rotation)
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
function mergeClientLoggingConfig(base, override) {
|
|
457
|
-
return {
|
|
458
|
-
...DEFAULT_CLIENT_LOGGING_CONFIG,
|
|
459
|
-
...base,
|
|
460
|
-
...override,
|
|
461
|
-
path: override?.path ?? base?.path ?? DEFAULT_CLIENT_LOGGING_CONFIG.path
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
function mergeDatabaseLoggerConfig(base, override, sourceType) {
|
|
465
|
-
if (!base && !override) {
|
|
466
|
-
return void 0;
|
|
467
|
-
}
|
|
468
|
-
return resolveDatabaseLoggerConfig(
|
|
469
|
-
{
|
|
470
|
-
dialect: override?.dialect ?? base?.dialect,
|
|
471
|
-
adapter: override?.adapter ?? base?.adapter,
|
|
472
|
-
delivery: {
|
|
473
|
-
...base?.delivery ?? {},
|
|
474
|
-
...override?.delivery ?? {},
|
|
475
|
-
retry: {
|
|
476
|
-
...base?.delivery?.retry ?? {},
|
|
477
|
-
...override?.delivery?.retry ?? {}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
},
|
|
481
|
-
sourceType
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
function mergePostHogConnectorConfig(base, override) {
|
|
485
|
-
const enabled = override?.enabled ?? base?.enabled ?? false;
|
|
486
|
-
const projectKey = override?.projectKey ?? base?.projectKey;
|
|
487
|
-
const baseErrorTracking = base?.enabled === true ? base?.errorTracking : void 0;
|
|
488
|
-
const errorTrackingMode = override?.errorTracking?.mode ?? baseErrorTracking?.mode ?? "auto";
|
|
489
|
-
const errorTrackingEnabled = override?.errorTracking?.enabled ?? baseErrorTracking?.enabled ?? enabled;
|
|
490
|
-
const errorTrackingReady = enabled && errorTrackingEnabled && typeof projectKey === "string" && projectKey.trim().length > 0;
|
|
491
|
-
return {
|
|
492
|
-
enabled,
|
|
493
|
-
mode: override?.mode ?? base?.mode ?? "auto",
|
|
494
|
-
projectKey,
|
|
495
|
-
host: override?.host ?? base?.host ?? DEFAULT_POSTHOG_HOST,
|
|
496
|
-
serviceName: override?.serviceName ?? base?.serviceName ?? resolveDefaultConnectorServiceName(),
|
|
497
|
-
errorTracking: {
|
|
498
|
-
enabled: errorTrackingEnabled,
|
|
499
|
-
mode: errorTrackingMode,
|
|
500
|
-
enableExceptionAutocapture: override?.errorTracking?.enableExceptionAutocapture ?? baseErrorTracking?.enableExceptionAutocapture ?? errorTrackingMode === "auto",
|
|
501
|
-
ready: errorTrackingReady,
|
|
502
|
-
status: errorTrackingReady ? "enabled" : "missing"
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
function mergeDatabuddyConnectorConfig(base, override) {
|
|
507
|
-
const enabled = override?.enabled ?? base?.enabled ?? false;
|
|
508
|
-
const apiKey = override?.apiKey ?? base?.apiKey;
|
|
509
|
-
const websiteId = override?.websiteId ?? base?.websiteId;
|
|
510
|
-
const ready = enabled && hasNonEmptyString(apiKey) && hasNonEmptyString(websiteId);
|
|
511
|
-
return {
|
|
512
|
-
enabled,
|
|
513
|
-
mode: override?.mode ?? base?.mode ?? "auto",
|
|
514
|
-
apiKey,
|
|
515
|
-
websiteId,
|
|
516
|
-
namespace: override?.namespace ?? base?.namespace,
|
|
517
|
-
source: override?.source ?? base?.source,
|
|
518
|
-
apiUrl: override?.apiUrl ?? base?.apiUrl,
|
|
519
|
-
debug: override?.debug ?? base?.debug ?? false,
|
|
520
|
-
enableBatching: override?.enableBatching ?? base?.enableBatching ?? true,
|
|
521
|
-
batchSize: override?.batchSize ?? base?.batchSize,
|
|
522
|
-
batchTimeout: override?.batchTimeout ?? base?.batchTimeout,
|
|
523
|
-
maxQueueSize: override?.maxQueueSize ?? base?.maxQueueSize,
|
|
524
|
-
ready,
|
|
525
|
-
status: ready ? "enabled" : "missing"
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
function mergeBetterStackConnectorConfig(base, override) {
|
|
529
|
-
const sourceToken = override?.sourceToken ?? base?.sourceToken;
|
|
530
|
-
const ingestingHost = override?.ingestingHost ?? base?.ingestingHost;
|
|
531
|
-
const enabled = override?.enabled ?? base?.enabled ?? false;
|
|
532
|
-
const baseErrorTracking = base?.enabled === true ? base?.errorTracking : void 0;
|
|
533
|
-
const errorTracking = mergeBetterStackErrorTrackingConfig(
|
|
534
|
-
enabled,
|
|
535
|
-
baseErrorTracking,
|
|
536
|
-
override?.errorTracking
|
|
537
|
-
);
|
|
538
|
-
const ready = enabled && hasNonEmptyString(sourceToken) && isAbsoluteHttpUrl(ingestingHost);
|
|
539
|
-
return {
|
|
540
|
-
enabled,
|
|
541
|
-
mode: override?.mode ?? base?.mode ?? "auto",
|
|
542
|
-
sourceToken,
|
|
543
|
-
ingestingHost,
|
|
544
|
-
serviceName: override?.serviceName ?? base?.serviceName ?? resolveDefaultConnectorServiceName(),
|
|
545
|
-
errorTracking,
|
|
546
|
-
ready,
|
|
547
|
-
status: ready ? "enabled" : "missing"
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
function mergeBetterStackErrorTrackingConfig(connectorEnabled, base, override) {
|
|
551
|
-
const dsn = override?.dsn ?? base?.dsn;
|
|
552
|
-
const enabled = override?.enabled ?? base?.enabled ?? connectorEnabled;
|
|
553
|
-
const ready = enabled && hasNonEmptyString(dsn);
|
|
554
|
-
return {
|
|
555
|
-
enabled,
|
|
556
|
-
dsn,
|
|
557
|
-
tracesSampleRate: override?.tracesSampleRate ?? base?.tracesSampleRate ?? 1,
|
|
558
|
-
environment: override?.environment ?? base?.environment,
|
|
559
|
-
release: override?.release ?? base?.release,
|
|
560
|
-
ready,
|
|
561
|
-
status: ready ? "enabled" : "missing"
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
function mergeSentryConnectorConfig(base, override) {
|
|
565
|
-
const dsn = override?.dsn ?? base?.dsn;
|
|
566
|
-
const enabled = override?.enabled ?? base?.enabled ?? false;
|
|
567
|
-
const ready = enabled && typeof dsn === "string" && dsn.trim().length > 0;
|
|
568
|
-
return {
|
|
569
|
-
enabled,
|
|
570
|
-
mode: override?.mode ?? base?.mode ?? "auto",
|
|
571
|
-
dsn,
|
|
572
|
-
environment: override?.environment ?? base?.environment,
|
|
573
|
-
release: override?.release ?? base?.release,
|
|
574
|
-
ready,
|
|
575
|
-
status: ready ? "enabled" : "missing"
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
function mergeOTLPConnectorConfig(base, override) {
|
|
579
|
-
const endpoint = override?.endpoint ?? base?.endpoint;
|
|
580
|
-
const enabled = override?.enabled ?? base?.enabled ?? false;
|
|
581
|
-
const resolvedHeaders = {
|
|
582
|
-
...{},
|
|
583
|
-
...override?.headers ?? {}
|
|
584
|
-
};
|
|
585
|
-
const ready = enabled && isAbsoluteHttpUrl(endpoint);
|
|
586
|
-
return {
|
|
587
|
-
name: override?.name ?? base?.name ?? "",
|
|
588
|
-
enabled,
|
|
589
|
-
mode: override?.mode ?? base?.mode ?? "auto",
|
|
590
|
-
endpoint,
|
|
591
|
-
headers: resolvedHeaders,
|
|
592
|
-
auth: override?.auth ?? base?.auth,
|
|
593
|
-
serviceName: override?.serviceName ?? base?.serviceName ?? resolveDefaultConnectorServiceName(),
|
|
594
|
-
ready,
|
|
595
|
-
status: ready ? "enabled" : "missing"
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
function mergeOTLPConnectorsConfig(base, override) {
|
|
599
|
-
const source = override ?? base ?? [];
|
|
600
|
-
const deduped = /* @__PURE__ */ new Map();
|
|
601
|
-
for (const connector of source) {
|
|
602
|
-
if (!connector || typeof connector.name !== "string" || connector.name.length === 0) {
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
if (deduped.has(connector.name)) {
|
|
606
|
-
warnOnce(
|
|
607
|
-
`otlp-duplicate:${connector.name}`,
|
|
608
|
-
`[Blyp] Warning: Duplicate OTLP connector name "${connector.name}" found. Using the last definition.`
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
deduped.set(connector.name, mergeOTLPConnectorConfig(void 0, connector));
|
|
612
|
-
}
|
|
613
|
-
return Array.from(deduped.values());
|
|
614
|
-
}
|
|
615
|
-
function mergeConnectorsConfig(base, override) {
|
|
616
|
-
return {
|
|
617
|
-
betterstack: mergeBetterStackConnectorConfig(base?.betterstack, override?.betterstack),
|
|
618
|
-
databuddy: mergeDatabuddyConnectorConfig(base?.databuddy, override?.databuddy),
|
|
619
|
-
posthog: mergePostHogConnectorConfig(base?.posthog, override?.posthog),
|
|
620
|
-
sentry: mergeSentryConnectorConfig(base?.sentry, override?.sentry),
|
|
621
|
-
otlp: mergeOTLPConnectorsConfig(base?.otlp, override?.otlp)
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
function mergeBlypConfig(base, override = {}, options = {}) {
|
|
625
|
-
return {
|
|
626
|
-
...base,
|
|
627
|
-
...override,
|
|
628
|
-
destination: override.destination ?? base.destination ?? "file",
|
|
629
|
-
file: mergeFileConfig(base.file, override.file),
|
|
630
|
-
database: mergeDatabaseLoggerConfig(base.database, override.database, options.configFileType),
|
|
631
|
-
clientLogging: mergeClientLoggingConfig(base.clientLogging, override.clientLogging),
|
|
632
|
-
connectors: mergeConnectorsConfig(base.connectors, override.connectors)
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
function loadConfig() {
|
|
636
|
-
if (cachedConfig !== null) {
|
|
637
|
-
return cachedConfig;
|
|
638
|
-
}
|
|
639
|
-
bootstrapProjectFiles();
|
|
640
|
-
const configFile = findConfigFile();
|
|
641
|
-
if (configFile) {
|
|
642
|
-
const userConfig = parseConfigFile(configFile);
|
|
643
|
-
cachedConfig = mergeBlypConfig(DEFAULT_CONFIG, userConfig, {
|
|
644
|
-
configFileType: configFile.type
|
|
645
|
-
});
|
|
646
|
-
} else {
|
|
647
|
-
cachedConfig = mergeBlypConfig(DEFAULT_CONFIG);
|
|
648
|
-
}
|
|
649
|
-
return cachedConfig;
|
|
650
|
-
}
|
|
651
|
-
function resolveConfig(overrides = {}) {
|
|
652
|
-
return mergeBlypConfig(loadConfig(), overrides);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
// src/core/log-record.ts
|
|
656
|
-
var RECORD_LEVELS = {
|
|
657
|
-
success: "success",
|
|
658
|
-
critical: "critical",
|
|
659
|
-
warning: "warning",
|
|
660
|
-
info: "info",
|
|
661
|
-
debug: "debug",
|
|
662
|
-
error: "error",
|
|
663
|
-
warn: "warning",
|
|
664
|
-
table: "table"
|
|
665
|
-
};
|
|
666
|
-
function normalizePath(filePath) {
|
|
667
|
-
return filePath.replace(/\\/g, "/");
|
|
668
|
-
}
|
|
669
|
-
function isInternalLoggerFrame(filePath) {
|
|
670
|
-
const normalizedPath = normalizePath(filePath);
|
|
671
|
-
return normalizedPath.startsWith("node:") || normalizedPath.includes("/node_modules/pino") || normalizedPath.includes("/node_modules/pino-pretty") || normalizedPath.includes("/node_modules/@blyp/core/") || normalizedPath.includes("/blyp/src/core/") || normalizedPath.includes("/blyp/src/frameworks/") || normalizedPath.includes("/blyp/src/posthog/") || normalizedPath.includes("/blyp/dist/");
|
|
672
|
-
}
|
|
673
|
-
function formatCallerPath(filePath) {
|
|
674
|
-
const normalizedPath = normalizePath(filePath);
|
|
675
|
-
const normalizedCwd = normalizePath(process.cwd());
|
|
676
|
-
return normalizedPath.startsWith(`${normalizedCwd}/`) ? normalizedPath.slice(normalizedCwd.length + 1) : normalizedPath;
|
|
677
|
-
}
|
|
678
|
-
function getCallerLocation() {
|
|
679
|
-
try {
|
|
680
|
-
const stack = new Error().stack;
|
|
681
|
-
if (!stack) {
|
|
682
|
-
return { file: null, line: null };
|
|
683
|
-
}
|
|
684
|
-
const lines = stack.split("\n");
|
|
685
|
-
let fallback = null;
|
|
686
|
-
for (let index = 2; index < lines.length; index += 1) {
|
|
687
|
-
const line = lines[index];
|
|
688
|
-
if (!line) {
|
|
689
|
-
continue;
|
|
690
|
-
}
|
|
691
|
-
const match = line.match(/\((.*):(\d+):\d+\)/) || line.match(/at\s+(.*):(\d+):(\d+)/);
|
|
692
|
-
if (!match) {
|
|
693
|
-
continue;
|
|
694
|
-
}
|
|
695
|
-
const fileName = match[1] || "";
|
|
696
|
-
const lineNumber = parseInt(match[2] || "0", 10) || null;
|
|
697
|
-
if (fileName && !fileName.includes("node_modules") && !isInternalLoggerFrame(fileName)) {
|
|
698
|
-
const formattedPath = formatCallerPath(fileName);
|
|
699
|
-
const normalizedFormattedPath = normalizePath(formattedPath);
|
|
700
|
-
if (!normalizedFormattedPath.startsWith("dist/")) {
|
|
701
|
-
return { file: formattedPath, line: lineNumber };
|
|
702
|
-
}
|
|
703
|
-
fallback ?? (fallback = { file: formattedPath, line: lineNumber });
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
if (fallback) {
|
|
707
|
-
return fallback;
|
|
708
|
-
}
|
|
709
|
-
} catch {
|
|
710
|
-
return { file: null, line: null };
|
|
711
|
-
}
|
|
712
|
-
return { file: null, line: null };
|
|
713
|
-
}
|
|
714
|
-
var serializeMessage = serializeLogMessage;
|
|
715
|
-
function stripAnsi(value) {
|
|
716
|
-
return value.replace(/\u001b\[[0-9;]*m/g, "");
|
|
717
|
-
}
|
|
718
|
-
function buildRecord(level, message, args, bindings) {
|
|
719
|
-
const { file, line } = getCallerLocation();
|
|
720
|
-
const serializedMessage = serializeMessage(message);
|
|
721
|
-
const record = {
|
|
722
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
723
|
-
level: RECORD_LEVELS[level],
|
|
724
|
-
message: stripAnsi(serializedMessage)
|
|
725
|
-
};
|
|
726
|
-
if (message instanceof Error) {
|
|
727
|
-
record.error = normalizeError(message);
|
|
728
|
-
}
|
|
729
|
-
if (file) {
|
|
730
|
-
record.caller = line !== null ? `${file}:${line}` : file;
|
|
731
|
-
}
|
|
732
|
-
if (args.length === 1) {
|
|
733
|
-
record.data = normalizeLogValue(args[0]);
|
|
734
|
-
} else if (args.length > 1) {
|
|
735
|
-
record.data = normalizeLogValue(args);
|
|
736
|
-
}
|
|
737
|
-
if (Object.keys(bindings).length > 0) {
|
|
738
|
-
record.bindings = normalizeLogValue(bindings);
|
|
739
|
-
}
|
|
740
|
-
return record;
|
|
741
|
-
}
|
|
742
|
-
function buildStructuredRecord(level, message, payload, bindings) {
|
|
743
|
-
const { file, line } = getCallerLocation();
|
|
744
|
-
const normalizedPayload = normalizeLogValue(payload);
|
|
745
|
-
const record = {
|
|
746
|
-
message: stripAnsi(message),
|
|
747
|
-
...normalizedPayload
|
|
748
|
-
};
|
|
749
|
-
if (file) {
|
|
750
|
-
record.caller = line !== null ? `${file}:${line}` : file;
|
|
751
|
-
}
|
|
752
|
-
if (Object.keys(bindings).length > 0) {
|
|
753
|
-
record.bindings = normalizeLogValue(bindings);
|
|
754
|
-
}
|
|
755
|
-
record.level = typeof normalizedPayload.level === "string" && normalizedPayload.level.length > 0 ? normalizedPayload.level : RECORD_LEVELS[level];
|
|
756
|
-
record.timestamp = typeof normalizedPayload.timestamp === "string" && normalizedPayload.timestamp.length > 0 ? normalizedPayload.timestamp : (/* @__PURE__ */ new Date()).toISOString();
|
|
757
|
-
return record;
|
|
758
|
-
}
|
|
759
|
-
function resolveStructuredWriteLevel(level) {
|
|
760
|
-
switch (level) {
|
|
761
|
-
case "debug":
|
|
762
|
-
return "debug";
|
|
763
|
-
case "warning":
|
|
764
|
-
return "warning";
|
|
765
|
-
case "warn":
|
|
766
|
-
return "warn";
|
|
767
|
-
case "error":
|
|
768
|
-
return "error";
|
|
769
|
-
case "success":
|
|
770
|
-
return "success";
|
|
771
|
-
case "critical":
|
|
772
|
-
return "critical";
|
|
773
|
-
case "table":
|
|
774
|
-
return "table";
|
|
775
|
-
case "info":
|
|
776
|
-
default:
|
|
777
|
-
return "info";
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// src/core/structured-log.ts
|
|
782
|
-
function serializeMessage2(message) {
|
|
783
|
-
if (typeof message === "string") {
|
|
784
|
-
return message;
|
|
785
|
-
}
|
|
786
|
-
if (message !== null && typeof message === "object") {
|
|
787
|
-
try {
|
|
788
|
-
return JSON.stringify(
|
|
789
|
-
message,
|
|
790
|
-
(_key, value) => {
|
|
791
|
-
if (typeof value === "function") {
|
|
792
|
-
return `[Function: ${value.name || "anonymous"}]`;
|
|
793
|
-
}
|
|
794
|
-
if (value === void 0) {
|
|
795
|
-
return "[undefined]";
|
|
796
|
-
}
|
|
797
|
-
if (typeof value === "symbol") {
|
|
798
|
-
return value.toString();
|
|
799
|
-
}
|
|
800
|
-
return value;
|
|
801
|
-
},
|
|
802
|
-
2
|
|
803
|
-
);
|
|
804
|
-
} catch {
|
|
805
|
-
return "[Object]";
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
return String(message);
|
|
809
|
-
}
|
|
810
|
-
function normalizeEventData(message, args) {
|
|
811
|
-
if (typeof message === "string") {
|
|
812
|
-
if (args.length === 0) {
|
|
813
|
-
return void 0;
|
|
814
|
-
}
|
|
815
|
-
return args.length === 1 ? args[0] : args;
|
|
816
|
-
}
|
|
817
|
-
const values = [message, ...args];
|
|
818
|
-
return values.length === 1 ? values[0] : values;
|
|
819
|
-
}
|
|
820
|
-
function normalizeDetails(value) {
|
|
821
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
822
|
-
return void 0;
|
|
823
|
-
}
|
|
824
|
-
return value;
|
|
825
|
-
}
|
|
826
|
-
function normalizeError2(error, fallbackStatus) {
|
|
827
|
-
if (error === void 0 || error === null) {
|
|
828
|
-
return fallbackStatus === void 0 || fallbackStatus < 400 ? void 0 : {
|
|
829
|
-
message: `HTTP ${fallbackStatus}`,
|
|
830
|
-
code: fallbackStatus,
|
|
831
|
-
type: "HttpError"
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
if (error instanceof Error) {
|
|
835
|
-
const errorLike = error;
|
|
836
|
-
return {
|
|
837
|
-
message: error.message,
|
|
838
|
-
code: errorLike.code,
|
|
839
|
-
type: errorLike.type ?? error.name ?? error.constructor?.name,
|
|
840
|
-
stack: error.stack,
|
|
841
|
-
why: errorLike.why,
|
|
842
|
-
fix: errorLike.fix,
|
|
843
|
-
link: errorLike.link,
|
|
844
|
-
details: normalizeDetails(errorLike.details),
|
|
845
|
-
cause: errorLike.cause
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
if (typeof error === "object") {
|
|
849
|
-
const record = error;
|
|
850
|
-
const statusCode = typeof record.statusCode === "number" ? record.statusCode : typeof record.status === "number" ? record.status : fallbackStatus;
|
|
851
|
-
return {
|
|
852
|
-
message: typeof record.message === "string" ? record.message : `HTTP ${statusCode ?? 500}`,
|
|
853
|
-
code: typeof record.code === "string" || typeof record.code === "number" ? record.code : statusCode,
|
|
854
|
-
type: typeof record.type === "string" ? record.type : typeof record.name === "string" ? record.name : "Error",
|
|
855
|
-
stack: typeof record.stack === "string" ? record.stack : void 0,
|
|
856
|
-
why: typeof record.why === "string" ? record.why : void 0,
|
|
857
|
-
fix: typeof record.fix === "string" ? record.fix : void 0,
|
|
858
|
-
link: typeof record.link === "string" ? record.link : void 0,
|
|
859
|
-
details: normalizeDetails(record.details),
|
|
860
|
-
cause: record.cause
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
return {
|
|
864
|
-
message: String(error),
|
|
865
|
-
code: fallbackStatus,
|
|
866
|
-
type: typeof error
|
|
867
|
-
};
|
|
868
|
-
}
|
|
869
|
-
function resolveEmitStatus(options) {
|
|
870
|
-
if (options.response && typeof options.response.status === "number") {
|
|
871
|
-
return options.response.status;
|
|
872
|
-
}
|
|
873
|
-
if (typeof options.status === "number") {
|
|
874
|
-
return options.status;
|
|
875
|
-
}
|
|
876
|
-
if (options.error && typeof options.error === "object" && options.error !== null && typeof options.error.statusCode === "number") {
|
|
877
|
-
return options.error.statusCode;
|
|
878
|
-
}
|
|
879
|
-
if (options.error && typeof options.error === "object" && options.error !== null && typeof options.error.status === "number") {
|
|
880
|
-
return options.error.status;
|
|
881
|
-
}
|
|
882
|
-
return options.error ? 500 : void 0;
|
|
883
|
-
}
|
|
884
|
-
function createStructuredLog(groupId, options) {
|
|
885
|
-
const startedAt = performance.now();
|
|
886
|
-
const fields = { ...options.initialFields ?? {} };
|
|
887
|
-
const events = [];
|
|
888
|
-
let emittedPayload;
|
|
889
|
-
options.onCreate?.();
|
|
890
|
-
const appendEvent = (level, message, args) => {
|
|
891
|
-
events.push({
|
|
892
|
-
level,
|
|
893
|
-
message: serializeMessage2(message),
|
|
894
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
895
|
-
...normalizeEventData(message, args) === void 0 ? {} : { data: normalizeEventData(message, args) }
|
|
896
|
-
});
|
|
897
|
-
return structuredLog;
|
|
898
|
-
};
|
|
899
|
-
const structuredLog = {
|
|
900
|
-
set(extraFields) {
|
|
901
|
-
Object.assign(fields, extraFields);
|
|
902
|
-
return structuredLog;
|
|
903
|
-
},
|
|
904
|
-
debug(message, ...args) {
|
|
905
|
-
return appendEvent("debug", message, args);
|
|
906
|
-
},
|
|
907
|
-
info(message, ...args) {
|
|
908
|
-
return appendEvent("info", message, args);
|
|
909
|
-
},
|
|
910
|
-
warn(message, ...args) {
|
|
911
|
-
return appendEvent("warn", message, args);
|
|
912
|
-
},
|
|
913
|
-
warning(message, ...args) {
|
|
914
|
-
return appendEvent("warning", message, args);
|
|
915
|
-
},
|
|
916
|
-
error(message, ...args) {
|
|
917
|
-
return appendEvent("error", message, args);
|
|
918
|
-
},
|
|
919
|
-
success(message, ...args) {
|
|
920
|
-
return appendEvent("success", message, args);
|
|
921
|
-
},
|
|
922
|
-
critical(message, ...args) {
|
|
923
|
-
return appendEvent("critical", message, args);
|
|
924
|
-
},
|
|
925
|
-
table(message, data) {
|
|
926
|
-
return appendEvent("table", message, data === void 0 ? [] : [data]);
|
|
927
|
-
},
|
|
928
|
-
emit(emitOptions = {}) {
|
|
929
|
-
if (emittedPayload) {
|
|
930
|
-
return emittedPayload;
|
|
931
|
-
}
|
|
932
|
-
const defaultFields = options.resolveDefaultFields?.() ?? {};
|
|
933
|
-
const status = resolveEmitStatus(emitOptions);
|
|
934
|
-
const error = normalizeError2(emitOptions.error, status);
|
|
935
|
-
const level = emitOptions.level ?? (error ? "error" : "info");
|
|
936
|
-
const payload = {
|
|
937
|
-
...defaultFields,
|
|
938
|
-
...fields,
|
|
939
|
-
groupId,
|
|
940
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
941
|
-
level,
|
|
942
|
-
duration: Math.round(performance.now() - startedAt),
|
|
943
|
-
...typeof status === "number" ? { status } : {},
|
|
944
|
-
...events.length > 0 ? { events: [...events] } : {},
|
|
945
|
-
...error ? { error } : {}
|
|
946
|
-
};
|
|
947
|
-
options.write(payload, emitOptions.message ?? "structured_log");
|
|
948
|
-
emittedPayload = payload;
|
|
949
|
-
options.onEmit?.(payload);
|
|
950
|
-
return payload;
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
return structuredLog;
|
|
954
|
-
}
|
|
955
|
-
function createSafeReplacer() {
|
|
956
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
957
|
-
return (_key, value) => {
|
|
958
|
-
if (typeof value === "function") {
|
|
959
|
-
return `[Function: ${value.name || "anonymous"}]`;
|
|
960
|
-
}
|
|
961
|
-
if (value === void 0) {
|
|
962
|
-
return "[undefined]";
|
|
963
|
-
}
|
|
964
|
-
if (typeof value === "symbol") {
|
|
965
|
-
return value.toString();
|
|
966
|
-
}
|
|
967
|
-
if (value !== null && typeof value === "object") {
|
|
968
|
-
if (seen.has(value)) {
|
|
969
|
-
return "[Circular]";
|
|
970
|
-
}
|
|
971
|
-
seen.add(value);
|
|
972
|
-
}
|
|
973
|
-
return value;
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
function serializeLogRecord(record) {
|
|
977
|
-
return JSON.stringify(record, createSafeReplacer());
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
// src/connectors/shared.ts
|
|
981
|
-
function isBlypConfig(config) {
|
|
982
|
-
return isPlainObject(config) && ("connectors" in config || "pretty" in config || "level" in config);
|
|
983
|
-
}
|
|
984
|
-
function getPrimaryPayload(record) {
|
|
985
|
-
return isPlainObject(record.data) ? record.data : record;
|
|
986
|
-
}
|
|
987
|
-
function getField(record, key) {
|
|
988
|
-
if (key in record) {
|
|
989
|
-
const direct = record[key];
|
|
990
|
-
if (typeof direct === "string" || typeof direct === "number") {
|
|
991
|
-
return direct;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
const payload = getPrimaryPayload(record);
|
|
995
|
-
const nested = payload[key];
|
|
996
|
-
if (typeof nested === "string" || typeof nested === "number") {
|
|
997
|
-
return nested;
|
|
998
|
-
}
|
|
999
|
-
return void 0;
|
|
1000
|
-
}
|
|
1001
|
-
function getClientPageField(record, key) {
|
|
1002
|
-
const payload = getPrimaryPayload(record);
|
|
1003
|
-
const page = isPlainObject(payload.page) ? payload.page : void 0;
|
|
1004
|
-
const value = page?.[key];
|
|
1005
|
-
return typeof value === "string" ? value : void 0;
|
|
1006
|
-
}
|
|
1007
|
-
function getClientSessionField(record, key) {
|
|
1008
|
-
const payload = getPrimaryPayload(record);
|
|
1009
|
-
const session = isPlainObject(payload.session) ? payload.session : void 0;
|
|
1010
|
-
const value = session?.[key];
|
|
1011
|
-
return typeof value === "string" ? value : void 0;
|
|
1012
|
-
}
|
|
1013
|
-
function getRecordType(record) {
|
|
1014
|
-
return getField(record, "type");
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
// src/connectors/databuddy/sender.ts
|
|
1018
|
-
var warnedKeys2 = /* @__PURE__ */ new Set();
|
|
1019
|
-
var senderCache = /* @__PURE__ */ new Map();
|
|
1020
|
-
var testHooks = {};
|
|
1021
|
-
var warnOnce2 = createErrorOnceLogger(warnedKeys2);
|
|
1022
|
-
function registerShutdownHooks(key, shutdown) {
|
|
1023
|
-
const handlers = ["beforeExit", "SIGINT", "SIGTERM"];
|
|
1024
|
-
for (const event of handlers) {
|
|
1025
|
-
process.once(event, () => {
|
|
1026
|
-
void shutdown().catch((error) => {
|
|
1027
|
-
warnOnce2(
|
|
1028
|
-
`${key}:shutdown`,
|
|
1029
|
-
"[Blyp] Failed to flush Databuddy telemetry during shutdown.",
|
|
1030
|
-
error
|
|
1031
|
-
);
|
|
1032
|
-
});
|
|
1033
|
-
});
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
function resolveConnectorConfig(config) {
|
|
1037
|
-
const connector = isBlypConfig(config) ? config.connectors?.databuddy : config;
|
|
1038
|
-
const enabled = connector?.enabled ?? false;
|
|
1039
|
-
const apiKey = connector?.apiKey;
|
|
1040
|
-
const websiteId = connector?.websiteId;
|
|
1041
|
-
const ready = enabled && hasNonEmptyString(apiKey) && hasNonEmptyString(websiteId);
|
|
1042
|
-
return {
|
|
1043
|
-
enabled,
|
|
1044
|
-
mode: connector?.mode ?? "auto",
|
|
1045
|
-
apiKey,
|
|
1046
|
-
websiteId,
|
|
1047
|
-
namespace: connector?.namespace,
|
|
1048
|
-
source: connector?.source,
|
|
1049
|
-
apiUrl: connector?.apiUrl,
|
|
1050
|
-
debug: connector?.debug ?? false,
|
|
1051
|
-
enableBatching: connector?.enableBatching ?? true,
|
|
1052
|
-
batchSize: connector?.batchSize,
|
|
1053
|
-
batchTimeout: connector?.batchTimeout,
|
|
1054
|
-
maxQueueSize: connector?.maxQueueSize,
|
|
1055
|
-
ready,
|
|
1056
|
-
status: ready ? "enabled" : "missing"
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
function createDefaultClient(connector) {
|
|
1060
|
-
return new node.Databuddy({
|
|
1061
|
-
apiKey: connector.apiKey ?? "",
|
|
1062
|
-
...connector.websiteId ? { websiteId: connector.websiteId } : {},
|
|
1063
|
-
...connector.namespace ? { namespace: connector.namespace } : {},
|
|
1064
|
-
...connector.source ? { source: connector.source } : {},
|
|
1065
|
-
...connector.apiUrl ? { apiUrl: connector.apiUrl } : {},
|
|
1066
|
-
debug: connector.debug,
|
|
1067
|
-
enableBatching: connector.enableBatching,
|
|
1068
|
-
...connector.batchSize !== void 0 ? { batchSize: connector.batchSize } : {},
|
|
1069
|
-
...connector.batchTimeout !== void 0 ? { batchTimeout: connector.batchTimeout } : {},
|
|
1070
|
-
...connector.maxQueueSize !== void 0 ? { maxQueueSize: connector.maxQueueSize } : {}
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
function getDatabuddySenderKey(connector) {
|
|
1074
|
-
return JSON.stringify({
|
|
1075
|
-
enabled: connector.enabled,
|
|
1076
|
-
mode: connector.mode,
|
|
1077
|
-
apiKey: connector.apiKey ?? null,
|
|
1078
|
-
websiteId: connector.websiteId ?? null,
|
|
1079
|
-
namespace: connector.namespace ?? null,
|
|
1080
|
-
source: connector.source ?? null,
|
|
1081
|
-
apiUrl: connector.apiUrl ?? null,
|
|
1082
|
-
debug: connector.debug,
|
|
1083
|
-
enableBatching: connector.enableBatching,
|
|
1084
|
-
batchSize: connector.batchSize ?? null,
|
|
1085
|
-
batchTimeout: connector.batchTimeout ?? null,
|
|
1086
|
-
maxQueueSize: connector.maxQueueSize ?? null
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
function getSessionId(record) {
|
|
1090
|
-
const direct = getField(record, "sessionId");
|
|
1091
|
-
if (hasNonEmptyString(direct)) {
|
|
1092
|
-
return direct;
|
|
1093
|
-
}
|
|
1094
|
-
return getClientSessionField(record, "sessionId");
|
|
1095
|
-
}
|
|
1096
|
-
function getAnonymousId(record) {
|
|
1097
|
-
const direct = getField(record, "anonymousId");
|
|
1098
|
-
if (hasNonEmptyString(direct)) {
|
|
1099
|
-
return direct;
|
|
1100
|
-
}
|
|
1101
|
-
const payload = getPrimaryPayload(record);
|
|
1102
|
-
if (isPlainObject(payload.metadata) && hasNonEmptyString(payload.metadata.databuddyAnonymousId)) {
|
|
1103
|
-
return payload.metadata.databuddyAnonymousId;
|
|
1104
|
-
}
|
|
1105
|
-
return void 0;
|
|
1106
|
-
}
|
|
1107
|
-
function getDatabuddyEventName(record) {
|
|
1108
|
-
const recordType = getRecordType(record);
|
|
1109
|
-
if (hasNonEmptyString(recordType)) {
|
|
1110
|
-
return recordType;
|
|
1111
|
-
}
|
|
1112
|
-
return "log";
|
|
1113
|
-
}
|
|
1114
|
-
function buildRecordProperties(record, source) {
|
|
1115
|
-
const properties = {
|
|
1116
|
-
blyp_level: record.level,
|
|
1117
|
-
blyp_source: source,
|
|
1118
|
-
blyp_payload: serializeLogRecord(record),
|
|
1119
|
-
message: typeof record.message === "string" ? record.message : String(record.message)
|
|
1120
|
-
};
|
|
1121
|
-
const caller = typeof record.caller === "string" ? record.caller : void 0;
|
|
1122
|
-
const groupId = getField(record, "groupId");
|
|
1123
|
-
const method = getField(record, "method");
|
|
1124
|
-
const path = getField(record, "path");
|
|
1125
|
-
const status = getField(record, "status");
|
|
1126
|
-
const duration = getField(record, "duration");
|
|
1127
|
-
const pagePath = getClientPageField(record, "pathname");
|
|
1128
|
-
const pageUrl = getClientPageField(record, "url");
|
|
1129
|
-
const sessionId = getClientSessionField(record, "sessionId");
|
|
1130
|
-
const pageId = getClientSessionField(record, "pageId");
|
|
1131
|
-
const ifTruthy = [
|
|
1132
|
-
["blyp_type", getRecordType(record)],
|
|
1133
|
-
["caller", caller],
|
|
1134
|
-
["group_id", groupId],
|
|
1135
|
-
["method", method],
|
|
1136
|
-
["path", path],
|
|
1137
|
-
["page_path", pagePath],
|
|
1138
|
-
["page_url", pageUrl],
|
|
1139
|
-
["session_id", sessionId],
|
|
1140
|
-
["page_id", pageId]
|
|
1141
|
-
];
|
|
1142
|
-
const ifDefined = [
|
|
1143
|
-
["status_code", status],
|
|
1144
|
-
["duration_ms", duration]
|
|
1145
|
-
];
|
|
1146
|
-
for (const [key, value] of ifTruthy) {
|
|
1147
|
-
if (value) {
|
|
1148
|
-
properties[key] = value;
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
for (const [key, value] of ifDefined) {
|
|
1152
|
-
if (value !== void 0) {
|
|
1153
|
-
properties[key] = value;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
return properties;
|
|
1157
|
-
}
|
|
1158
|
-
function createTrackEvent(record, source) {
|
|
1159
|
-
return {
|
|
1160
|
-
name: getDatabuddyEventName(record),
|
|
1161
|
-
anonymousId: getAnonymousId(record),
|
|
1162
|
-
sessionId: getSessionId(record),
|
|
1163
|
-
properties: buildRecordProperties(record, source)
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
function normalizeExceptionProperties(value) {
|
|
1167
|
-
if (!isPlainObject(value)) {
|
|
1168
|
-
return {};
|
|
1169
|
-
}
|
|
1170
|
-
return normalizeLogValue(value);
|
|
1171
|
-
}
|
|
1172
|
-
function normalizeExceptionInput(value, fallbackMessage) {
|
|
1173
|
-
if (value instanceof Error) {
|
|
1174
|
-
return {
|
|
1175
|
-
message: value.message || fallbackMessage,
|
|
1176
|
-
properties: {
|
|
1177
|
-
error_type: value.name,
|
|
1178
|
-
...value.stack ? { stack: value.stack } : {},
|
|
1179
|
-
...normalizeExceptionProperties(value)
|
|
1180
|
-
}
|
|
1181
|
-
};
|
|
1182
|
-
}
|
|
1183
|
-
if (isPlainObject(value)) {
|
|
1184
|
-
const message = hasNonEmptyString(value.message) ? value.message : hasNonEmptyString(value.error) ? value.error : fallbackMessage;
|
|
1185
|
-
return {
|
|
1186
|
-
message,
|
|
1187
|
-
properties: normalizeExceptionProperties(value)
|
|
1188
|
-
};
|
|
1189
|
-
}
|
|
1190
|
-
if (typeof value === "string") {
|
|
1191
|
-
return {
|
|
1192
|
-
message: value,
|
|
1193
|
-
properties: {
|
|
1194
|
-
message: value
|
|
1195
|
-
}
|
|
1196
|
-
};
|
|
1197
|
-
}
|
|
1198
|
-
return {
|
|
1199
|
-
message: fallbackMessage,
|
|
1200
|
-
properties: {
|
|
1201
|
-
value: normalizeLogValue(value)
|
|
1202
|
-
}
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
|
-
function createDatabuddySender(config) {
|
|
1206
|
-
const connector = resolveConnectorConfig(config);
|
|
1207
|
-
const senderKey = getDatabuddySenderKey(connector);
|
|
1208
|
-
const cached = senderCache.get(senderKey);
|
|
1209
|
-
if (cached) {
|
|
1210
|
-
return cached;
|
|
1211
|
-
}
|
|
1212
|
-
const key = `${connector.apiUrl ?? "default"}:${connector.mode}:${connector.apiKey ?? "missing"}`;
|
|
1213
|
-
const client = connector.ready ? testHooks.createClient?.(connector) ?? createDefaultClient(connector) : void 0;
|
|
1214
|
-
if (client) {
|
|
1215
|
-
registerShutdownHooks(key, async () => {
|
|
1216
|
-
await client.flush();
|
|
1217
|
-
});
|
|
1218
|
-
}
|
|
1219
|
-
const emitUnavailableWarning = () => {
|
|
1220
|
-
warnOnce2(
|
|
1221
|
-
`databuddy-unavailable:${key}`,
|
|
1222
|
-
"[Blyp] Databuddy connector is not configured. Databuddy requires both apiKey and websiteId. Skipping Databuddy delivery."
|
|
1223
|
-
);
|
|
1224
|
-
};
|
|
1225
|
-
const emitExceptionUnavailableWarning = () => {
|
|
1226
|
-
warnOnce2(
|
|
1227
|
-
`databuddy-exception-unavailable:${key}`,
|
|
1228
|
-
"[Blyp] Databuddy error tracking is not configured. Databuddy requires both apiKey and websiteId. Skipping Databuddy exception capture."
|
|
1229
|
-
);
|
|
1230
|
-
};
|
|
1231
|
-
const sender = {
|
|
1232
|
-
enabled: connector.enabled,
|
|
1233
|
-
ready: connector.ready,
|
|
1234
|
-
mode: connector.mode,
|
|
1235
|
-
status: connector.status,
|
|
1236
|
-
shouldAutoForwardServerLogs() {
|
|
1237
|
-
return connector.ready && connector.mode === "auto";
|
|
1238
|
-
},
|
|
1239
|
-
shouldAutoCaptureExceptions() {
|
|
1240
|
-
return connector.ready && connector.mode === "auto";
|
|
1241
|
-
},
|
|
1242
|
-
send(record, options = {}) {
|
|
1243
|
-
if (!connector.ready || !client) {
|
|
1244
|
-
if (options.warnIfUnavailable) {
|
|
1245
|
-
emitUnavailableWarning();
|
|
1246
|
-
}
|
|
1247
|
-
return;
|
|
1248
|
-
}
|
|
1249
|
-
try {
|
|
1250
|
-
const result = client.track(createTrackEvent(record, options.source ?? "server"));
|
|
1251
|
-
if (result && typeof result.catch === "function") {
|
|
1252
|
-
void result.catch((error) => {
|
|
1253
|
-
warnOnce2(
|
|
1254
|
-
`databuddy-send:${key}`,
|
|
1255
|
-
"[Blyp] Failed to deliver log to Databuddy.",
|
|
1256
|
-
error
|
|
1257
|
-
);
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
} catch (error) {
|
|
1261
|
-
warnOnce2(
|
|
1262
|
-
`databuddy-send:${key}`,
|
|
1263
|
-
"[Blyp] Failed to deliver log to Databuddy.",
|
|
1264
|
-
error
|
|
1265
|
-
);
|
|
1266
|
-
}
|
|
1267
|
-
},
|
|
1268
|
-
captureException(error, options = {}) {
|
|
1269
|
-
if (!connector.ready || !client) {
|
|
1270
|
-
if (options.warnIfUnavailable) {
|
|
1271
|
-
emitExceptionUnavailableWarning();
|
|
1272
|
-
}
|
|
1273
|
-
return;
|
|
1274
|
-
}
|
|
1275
|
-
const normalized = normalizeExceptionInput(
|
|
1276
|
-
error,
|
|
1277
|
-
options.source === "client" ? "Client error" : "Server error"
|
|
1278
|
-
);
|
|
1279
|
-
try {
|
|
1280
|
-
const result = client.track({
|
|
1281
|
-
name: "error",
|
|
1282
|
-
anonymousId: options.anonymousId,
|
|
1283
|
-
sessionId: options.sessionId,
|
|
1284
|
-
properties: {
|
|
1285
|
-
message: normalized.message,
|
|
1286
|
-
blyp_source: options.source ?? "server",
|
|
1287
|
-
blyp_level: "error",
|
|
1288
|
-
...normalized.properties,
|
|
1289
|
-
...options.properties ?? {}
|
|
1290
|
-
}
|
|
1291
|
-
});
|
|
1292
|
-
if (result && typeof result.catch === "function") {
|
|
1293
|
-
void result.catch((captureError) => {
|
|
1294
|
-
warnOnce2(
|
|
1295
|
-
`databuddy-capture:${key}`,
|
|
1296
|
-
"[Blyp] Failed to capture exception in Databuddy.",
|
|
1297
|
-
captureError
|
|
1298
|
-
);
|
|
1299
|
-
});
|
|
1300
|
-
}
|
|
1301
|
-
} catch (captureError) {
|
|
1302
|
-
warnOnce2(
|
|
1303
|
-
`databuddy-capture:${key}`,
|
|
1304
|
-
"[Blyp] Failed to capture exception in Databuddy.",
|
|
1305
|
-
captureError
|
|
1306
|
-
);
|
|
1307
|
-
}
|
|
1308
|
-
},
|
|
1309
|
-
async flush() {
|
|
1310
|
-
try {
|
|
1311
|
-
if (client) {
|
|
1312
|
-
await client.flush();
|
|
1313
|
-
}
|
|
1314
|
-
} catch (error) {
|
|
1315
|
-
warnOnce2(
|
|
1316
|
-
`databuddy-flush:${key}`,
|
|
1317
|
-
"[Blyp] Failed to flush Databuddy telemetry.",
|
|
1318
|
-
error
|
|
1319
|
-
);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
};
|
|
1323
|
-
senderCache.set(senderKey, sender);
|
|
1324
|
-
return sender;
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
// src/connectors/databuddy/index.ts
|
|
1328
|
-
function resolveSender(config = {}) {
|
|
1329
|
-
return createDatabuddySender(resolveConfig({
|
|
1330
|
-
...config.connectors ? { connectors: config.connectors } : {}
|
|
1331
|
-
}));
|
|
1332
|
-
}
|
|
1333
|
-
function createDatabuddyLoggerInstance(sender, bindings = {}) {
|
|
1334
|
-
const writeRecord = (level, message, args) => {
|
|
1335
|
-
sender.send(buildRecord(level, message, args, bindings), {
|
|
1336
|
-
source: "server",
|
|
1337
|
-
warnIfUnavailable: true
|
|
1338
|
-
});
|
|
1339
|
-
};
|
|
1340
|
-
const writeStructured = (payload, message) => {
|
|
1341
|
-
sender.send(
|
|
1342
|
-
buildStructuredRecord(
|
|
1343
|
-
resolveStructuredWriteLevel(payload.level),
|
|
1344
|
-
message,
|
|
1345
|
-
payload,
|
|
1346
|
-
bindings
|
|
1347
|
-
),
|
|
1348
|
-
{
|
|
1349
|
-
source: "server",
|
|
1350
|
-
warnIfUnavailable: true
|
|
1351
|
-
}
|
|
1352
|
-
);
|
|
1353
|
-
};
|
|
1354
|
-
return {
|
|
1355
|
-
debug: (message, ...args) => {
|
|
1356
|
-
writeRecord("debug", message, args);
|
|
1357
|
-
},
|
|
1358
|
-
info: (message, ...args) => {
|
|
1359
|
-
writeRecord("info", message, args);
|
|
1360
|
-
},
|
|
1361
|
-
error: (message, ...args) => {
|
|
1362
|
-
writeRecord("error", message, args);
|
|
1363
|
-
},
|
|
1364
|
-
warn: (message, ...args) => {
|
|
1365
|
-
writeRecord("warn", message, args);
|
|
1366
|
-
},
|
|
1367
|
-
warning: (message, ...args) => {
|
|
1368
|
-
writeRecord("warning", message, args);
|
|
1369
|
-
},
|
|
1370
|
-
success: (message, ...args) => {
|
|
1371
|
-
writeRecord("success", message, args);
|
|
1372
|
-
},
|
|
1373
|
-
critical: (message, ...args) => {
|
|
1374
|
-
writeRecord("critical", message, args);
|
|
1375
|
-
},
|
|
1376
|
-
table: (message, data) => {
|
|
1377
|
-
writeRecord("table", message, data === void 0 ? [] : [data]);
|
|
1378
|
-
},
|
|
1379
|
-
flush: async () => {
|
|
1380
|
-
await sender.flush();
|
|
1381
|
-
},
|
|
1382
|
-
shutdown: async () => {
|
|
1383
|
-
await sender.flush();
|
|
1384
|
-
},
|
|
1385
|
-
createStructuredLog: (groupId, initial) => {
|
|
1386
|
-
return createStructuredLog(groupId, {
|
|
1387
|
-
initialFields: initial,
|
|
1388
|
-
write: writeStructured
|
|
1389
|
-
});
|
|
1390
|
-
},
|
|
1391
|
-
child: (childBindings) => {
|
|
1392
|
-
return createDatabuddyLoggerInstance(sender, {
|
|
1393
|
-
...bindings,
|
|
1394
|
-
...childBindings
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
};
|
|
1398
|
-
}
|
|
1399
|
-
function createDatabuddyErrorTrackerInstance(sender, bindings = {}) {
|
|
1400
|
-
return {
|
|
1401
|
-
capture: (error, options = {}) => {
|
|
1402
|
-
sender.captureException(error, {
|
|
1403
|
-
source: "server",
|
|
1404
|
-
warnIfUnavailable: true,
|
|
1405
|
-
properties: {
|
|
1406
|
-
...bindings,
|
|
1407
|
-
...options.properties ?? {},
|
|
1408
|
-
blyp_source: "server",
|
|
1409
|
-
blyp_manual: true
|
|
1410
|
-
}
|
|
1411
|
-
});
|
|
1412
|
-
},
|
|
1413
|
-
child: (childBindings) => {
|
|
1414
|
-
return createDatabuddyErrorTrackerInstance(sender, {
|
|
1415
|
-
...bindings,
|
|
1416
|
-
...childBindings
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
function createDatabuddyLogger(config = {}) {
|
|
1422
|
-
return createDatabuddyLoggerInstance(resolveSender(config));
|
|
1423
|
-
}
|
|
1424
|
-
function createStructuredDatabuddyLogger(groupId, initial, config = {}) {
|
|
1425
|
-
const sender = resolveSender(config);
|
|
1426
|
-
return createStructuredLog(groupId, {
|
|
1427
|
-
initialFields: initial,
|
|
1428
|
-
write: (payload, message) => {
|
|
1429
|
-
sender.send(
|
|
1430
|
-
buildStructuredRecord(
|
|
1431
|
-
resolveStructuredWriteLevel(payload.level),
|
|
1432
|
-
message,
|
|
1433
|
-
payload,
|
|
1434
|
-
{}
|
|
1435
|
-
),
|
|
1436
|
-
{
|
|
1437
|
-
source: "server",
|
|
1438
|
-
warnIfUnavailable: true
|
|
1439
|
-
}
|
|
1440
|
-
);
|
|
1441
|
-
}
|
|
1442
|
-
});
|
|
1443
|
-
}
|
|
1444
|
-
function createDatabuddyErrorTracker(config = {}) {
|
|
1445
|
-
return createDatabuddyErrorTrackerInstance(resolveSender(config));
|
|
1446
|
-
}
|
|
1447
|
-
function captureDatabuddyException(error, options = {}, config = {}) {
|
|
1448
|
-
createDatabuddyErrorTracker(config).capture(error, options);
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
exports.captureDatabuddyException = captureDatabuddyException;
|
|
1452
|
-
exports.createDatabuddyErrorTracker = createDatabuddyErrorTracker;
|
|
1453
|
-
exports.createDatabuddyLogger = createDatabuddyLogger;
|
|
1454
|
-
exports.createStructuredDatabuddyLogger = createStructuredDatabuddyLogger;
|
|
1455
|
-
//# sourceMappingURL=databuddy.js.map
|
|
1456
|
-
//# sourceMappingURL=databuddy.js.map
|
|
1
|
+
'use strict';var fs=require('fs'),jiti=require('jiti'),Oe=require('path'),_e=require('os'),zod=require('zod'),async_hooks=require('async_hooks'),node=require('@databuddy/sdk/node');require('fflate');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Oe__default=/*#__PURE__*/_interopDefault(Oe);var _e__default=/*#__PURE__*/_interopDefault(_e);function ne(){return Oe__default.default.join(_e__default.default.homedir(),".blyp","queue.db")}function F(e){let t={name:e.name,message:e.message};e.stack&&(t.stack=e.stack);let n=e;return n.cause!==void 0&&(t.cause=h(n.cause)),t}function h(e,t=new WeakSet){if(e instanceof Error)return F(e);if(typeof e=="function")return `[Function: ${e.name||"anonymous"}]`;if(typeof e=="symbol")return e.toString();if(e==null)return e;if(Array.isArray(e))return e.map(n=>h(n,t));if(typeof e=="object"){if(t.has(e))return "[Circular]";t.add(e);let n={};for(let[o,r]of Object.entries(e))n[o]=h(r,t);return t.delete(e),n}return e}function M(e){if(typeof e=="string")return e;if(e instanceof Error)return e.message||e.name;let t=h(e);if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)??String(t)}catch{return String(t)}}var Ne=zod.z.string().url().refine(e=>{try{let t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return false}},{message:"Expected an absolute http(s) URL"}),re=zod.z.custom(e=>e!==null&&typeof e=="object"&&!Array.isArray(e),{message:"Expected a plain object"}),q=zod.z.string().trim().min(1);function $(e){return Ne.safeParse(e).success}function b(e){return re.safeParse(e).success}function f(e){return q.safeParse(e).success}var U="/inngest";zod.z.union([zod.z.literal("betterstack"),zod.z.literal("databuddy"),zod.z.literal("posthog"),zod.z.literal("sentry"),zod.z.undefined(),zod.z.object({type:zod.z.literal("otlp"),name:q})]);function oe(e,t=new Set){return (n,o,r)=>{if(t.has(n)||typeof console>"u")return;let i=console[e];if(typeof i=="function"){if(t.add(n),r===void 0){i.call(console,o);return}i.call(console,o,r);}}}function ie(e){return oe("warn",e)}function ae(e){return oe("error",e)}var Me="[REDACTED]",je=["password","passwd","pwd","secret","token","api_key","apikey","api_secret","authorization","auth","x-api-key","private_key","privatekey","access_token","refresh_token","client_secret","session","cookie","set-cookie","ssn","credit_card","card_number","cvv","cvc","otp","pin"];var qe=[{type:"bearer",pattern:/\bBearer\s+(?:sk-[A-Za-z0-9]{20,}|pk_(?:live|test)_[A-Za-z0-9]{16,}|eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+|[A-Za-z0-9._~+/-]{20,})\b/g},{type:"jwt",pattern:/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g},{type:"api_key",pattern:/\b(?:sk-[A-Za-z0-9]{20,}|pk_(?:live|test)_[A-Za-z0-9]{16,})\b/g}],$e=/\b(?:\d[ -]*?){16}\b/g;function se(e){let t=new Set,n=[];for(let o of e)typeof o!="string"||o.length===0||t.has(o)||(t.add(o),n.push(o));return n}function Ue(e){let t=e.flags.includes("g")?e.flags:`${e.flags}g`;return new RegExp(e.source,t)}function He(e){if(!e||typeof e!="object"||Array.isArray(e))return false;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function We(e){return new Set(e.keys.map(t=>t.toLowerCase()))}function Qe(e){return e.split(".").filter(Boolean)}function H(e,t,n=0,o=0){if(n===e.length)return o===t.length;let r=e[n];if(r==="**"){if(n===e.length-1)return true;for(let i=o;i<=t.length;i+=1)if(H(e,t,n+1,i))return true;return false}return o>=t.length||r!=="*"&&r!==t[o]?false:H(e,t,n+1,o+1)}function Ge(e,t){return e.length===0||t.paths.length===0?false:t.paths.some(n=>H(Qe(n),e))}function Ke(e){let t=e.replace(/\D/g,"");if(t.length!==16)return false;let n=0,o=false;for(let r=t.length-1;r>=0;r-=1){let i=Number(t[r]);o&&(i*=2,i>9&&(i-=9)),n+=i,o=!o;}return n%10===0}function ce(e,t,n){if(n||t.disablePatternScanning)return e;let o=e;for(let{type:r,pattern:i}of qe)o=o.replace(i,`[REDACTED:${r}]`);o=o.replace($e,r=>Ke(r)?"[REDACTED:card]":r);for(let r of t.patterns)o=o.replace(Ue(r),"[REDACTED:pattern]");return o}function I(e,t,n,o){if(typeof e=="string")return ce(e,t,!!o.skipPatternScanning);if(e==null||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map((i,s)=>I(i,t,n,{path:[...o.path,String(s)],skipPatternScanning:o.skipPatternScanning}));if(!He(e))return e;let r={};for(let[i,s]of Object.entries(e)){let c=[...o.path,i];if(n.has(i.toLowerCase())||Ge(c,t)){if(s==null||typeof s=="string"||typeof s=="number"||typeof s=="boolean"){r[i]=Me;continue}r[i]=I(s,t,n,{path:c,skipPatternScanning:o.skipPatternScanning});continue}r[i]=I(s,t,n,{path:c,skipPatternScanning:o.skipPatternScanning});}return r}function L(e,t){return {keys:se([...je,...e?.keys??[],...t?.keys??[]]),paths:se([...e?.paths??[],...t?.paths??[]]),patterns:[...e?.patterns??[],...t?.patterns??[]].filter(n=>n instanceof RegExp),disablePatternScanning:t?.disablePatternScanning??e?.disablePatternScanning??false}}function y(e,t,n={path:[]}){let o=h(e);return I(o,t,We(t),n)}function A(e,t){return typeof e=="string"?ce(e,t,false):M(y(e,t))}var Ye="@blyp/core",Xe=".gitignore",ge=["blyp.config.ts","blyp.config.mts","blyp.config.cts","blyp.config.js","blyp.config.mjs","blyp.config.cjs","blyp.config.json"],et="blyp.config.json",tt="https://us.i.posthog.com",nt="blyp-app",rt=nt,ot=new Set,D=ie(ot),fe={enabled:true,maxSizeBytes:10*1024*1024,maxArchives:5,compress:true},pe={enabled:true,dir:"",archiveDir:"",format:"ndjson",rotation:fe},W={enabled:true,path:U},ye=L(),v={maxAttempts:8,initialBackoffMs:500,maxBackoffMs:3e4,multiplier:2,jitter:true},C={enabled:false,memoryBufferSize:500,durableQueuePath:ne(),durableSpillStrategy:"after-first-failure",memoryBatchSize:25,sqliteWriteBatchSize:100,sqliteReadBatchSize:50,dispatchConcurrency:4,pollIntervalMs:1e3,overflowStrategy:"drop-oldest",retry:v},me={maxRetries:1,backoffMs:100},it={strategy:"immediate",batchSize:1,flushIntervalMs:250,maxQueueSize:1e3,overflowStrategy:"drop-oldest",flushTimeoutMs:5e3,retry:me},ue={pretty:true,level:"info",destination:"file",file:pe,clientLogging:W,redact:ye,connectors:{delivery:C}},z=null;function at(e){let t=e;for(;;){let n=Oe.resolve(t,"package.json");if(fs.existsSync(n))try{let r=JSON.parse(fs.readFileSync(n,"utf-8"));if(f(r.name))return r.name}catch{}let o=Oe.dirname(t);if(o===t)return;t=o;}}function G(e=process.cwd()){return at(e)??rt}function st(){return {pretty:true,level:"info",destination:"file",file:{enabled:true,format:"ndjson",rotation:{enabled:true,maxSizeBytes:10*1024*1024,maxArchives:5,compress:true}},clientLogging:{enabled:true,path:U},redact:ye,connectors:{delivery:C}}}function ct(e){let t=Oe.resolve(e,"package.json");if(!fs.existsSync(t))return true;try{return JSON.parse(fs.readFileSync(t,"utf-8")).name!==Ye}catch{return true}}function ut(e){if(ge.some(n=>fs.existsSync(Oe.resolve(e,n))))return;let t=Oe.resolve(e,et);if(!fs.existsSync(t))try{fs.writeFileSync(t,`${JSON.stringify(st(),null,2)}
|
|
2
|
+
`);}catch(n){console.error("[Blyp] Warning: Failed to create blyp.config.json:",n);}}function dt(e){let t=Oe.resolve(e,Xe);if(!fs.existsSync(t)){try{fs.writeFileSync(t,`logs
|
|
3
|
+
.blyp
|
|
4
|
+
`);}catch(n){console.error("[Blyp] Warning: Failed to create .gitignore:",n);}return}try{let n=fs.readFileSync(t,"utf-8"),o=["logs",".blyp"].filter(i=>{let s=i.replace(".","\\.");return !new RegExp(`^(?:/?${s}/?)\\s*$`,"m").test(n)});if(o.length===0)return;let r=n.endsWith(`
|
|
5
|
+
`)?"":`
|
|
6
|
+
`;fs.appendFileSync(t,`${r}${o.join(`
|
|
7
|
+
`)}
|
|
8
|
+
`);}catch(n){console.error("[Blyp] Warning: Failed to update .gitignore:",n);}}function lt(){let e=process.cwd();ct(e)&&(ut(e),dt(e));}function gt(){let e=process.cwd(),t=ge.map(o=>Oe.resolve(e,o)).filter(o=>fs.existsSync(o));if(t.length===0)return null;if(t.length>1){let o=t[0];D(`config-multiple:${o}`,`[Blyp] Warning: Multiple config files found. Using ${o} and ignoring ${t.slice(1).join(", ")}.`);}let n=t[0];return {path:n,type:n.endsWith(".json")?"json":"jiti"}}function Ce(e,t){let n=e&&typeof e=="object"&&"default"in e&&e.default!==void 0?e.default:e;return !n||typeof n!="object"||Array.isArray(n)?(D(`config-invalid:${t}`,`[Blyp] Warning: Config file ${t} did not export an object. Falling back to defaults.`),{}):n}function ft(e){try{let t=fs.readFileSync(e,"utf-8");return Ce(JSON.parse(t),e)}catch(t){return console.error("[Blyp] Warning: Failed to parse blyp.config.json:",t),{}}}function pt(e){try{let t=jiti.createJiti(process.cwd(),{interopDefault:!0,moduleCache:!1,fsCache:!1});return Ce(t(e),e)}catch(t){return console.error(`[Blyp] Warning: Failed to load ${e}:`,t),{}}}function yt(e){return e.type==="json"?ft(e.path):pt(e.path)}function de(e){return !!e&&typeof e=="object"&&e.type==="prisma"}function mt(e){return !!e&&typeof e=="object"&&e.type==="drizzle"}function Ct(e,t){return {...me,...e,...t}}function bt(e,t){return {...it,...e,...t,retry:Ct(e?.retry,t?.retry)}}function ht(e){let t=e.model??"blypLog",o=e.client?.[t];return !!o&&typeof o.create=="function"}function Rt(e){let t=e.db;return !!t&&typeof t.insert=="function"&&e.table!==void 0}function St(e,t){if(!e)return;let n=e.adapter,o=false;t==="json"?D("database-json-config","[Blyp] Warning: Database logging requires an executable blyp config file. Database destination remains disabled until you move this config to blyp.config.ts/js."):e.dialect!=="postgres"&&e.dialect!=="mysql"?D(`database-dialect:${String(e.dialect)}`,`[Blyp] Warning: Unsupported database dialect "${String(e.dialect)}". Database logging is disabled.`):n?de(n)?(o=ht({...n,model:n.model??"blypLog"}),o||D("database-prisma-missing",`[Blyp] Warning: Prisma database adapter is missing the "${n.model??"blypLog"}" delegate or its create method. Database logging is disabled.`)):mt(n)&&(o=Rt(n),o||D("database-drizzle-missing","[Blyp] Warning: Drizzle database adapter is missing a db.insert function or table reference. Database logging is disabled.")):D("database-adapter-missing","[Blyp] Warning: Database logging is enabled without an adapter. Database logging is disabled.");let r=de(n)?{...n,model:n.model??"blypLog"}:n;return {dialect:e.dialect,adapter:r,delivery:bt(void 0,e.delivery),ready:o,status:o?"enabled":"missing"}}function Lt(e,t){return {...fe,...e,...t}}function Dt(e,t){return {...pe,...e,...t,rotation:Lt(e?.rotation,t?.rotation)}}function kt(e,t){return {...W,...e,...t,path:t?.path??e?.path??W.path}}function wt(e,t){return L(e,t)}function xt(e,t){return {maxAttempts:Math.max(1,Math.floor(t?.maxAttempts??e?.maxAttempts??v.maxAttempts)),initialBackoffMs:Math.max(0,Math.floor(t?.initialBackoffMs??e?.initialBackoffMs??v.initialBackoffMs)),maxBackoffMs:Math.max(0,Math.floor(t?.maxBackoffMs??e?.maxBackoffMs??v.maxBackoffMs)),multiplier:Math.max(1,t?.multiplier??e?.multiplier??v.multiplier),jitter:t?.jitter??e?.jitter??v.jitter}}function vt(e,t){let n=t?.durableQueuePath??e?.durableQueuePath??C.durableQueuePath;return {enabled:t?.enabled??e?.enabled??C.enabled,memoryBufferSize:Math.max(1,Math.floor(t?.memoryBufferSize??e?.memoryBufferSize??C.memoryBufferSize)),durableQueuePath:f(n)?n:C.durableQueuePath,durableSpillStrategy:t?.durableSpillStrategy??e?.durableSpillStrategy??C.durableSpillStrategy,memoryBatchSize:Math.max(1,Math.floor(t?.memoryBatchSize??e?.memoryBatchSize??C.memoryBatchSize)),sqliteWriteBatchSize:Math.max(1,Math.floor(t?.sqliteWriteBatchSize??e?.sqliteWriteBatchSize??C.sqliteWriteBatchSize)),sqliteReadBatchSize:Math.max(1,Math.floor(t?.sqliteReadBatchSize??e?.sqliteReadBatchSize??C.sqliteReadBatchSize)),dispatchConcurrency:Math.max(1,Math.floor(t?.dispatchConcurrency??e?.dispatchConcurrency??C.dispatchConcurrency)),pollIntervalMs:Math.max(50,Math.floor(t?.pollIntervalMs??e?.pollIntervalMs??C.pollIntervalMs)),overflowStrategy:t?.overflowStrategy??e?.overflowStrategy??C.overflowStrategy,retry:xt(e?.retry,t?.retry),durableReady:false}}function Et(e,t,n){if(!(!e&&!t))return St({dialect:t?.dialect??e?.dialect,adapter:t?.adapter??e?.adapter,delivery:{...e?.delivery??{},...t?.delivery??{},retry:{...e?.delivery?.retry??{},...t?.delivery?.retry??{}}}},n)}function Tt(e,t){let n=t?.enabled??e?.enabled??false,o=t?.projectKey??e?.projectKey,r=e?.enabled===true?e?.errorTracking:void 0,i=t?.errorTracking?.mode??r?.mode??"auto",s=t?.errorTracking?.enabled??r?.enabled??n,c=n&&s&&typeof o=="string"&&o.trim().length>0;return {enabled:n,mode:t?.mode??e?.mode??"auto",projectKey:o,host:t?.host??e?.host??tt,serviceName:t?.serviceName??e?.serviceName??G(),errorTracking:{enabled:s,mode:i,enableExceptionAutocapture:t?.errorTracking?.enableExceptionAutocapture??r?.enableExceptionAutocapture??i==="auto",ready:c,status:c?"enabled":"missing"}}}function Bt(e,t){let n=t?.enabled??e?.enabled??false,o=t?.apiKey??e?.apiKey,r=t?.websiteId??e?.websiteId,i=n&&f(o)&&f(r);return {enabled:n,mode:t?.mode??e?.mode??"auto",apiKey:o,websiteId:r,namespace:t?.namespace??e?.namespace,source:t?.source??e?.source,apiUrl:t?.apiUrl??e?.apiUrl,debug:t?.debug??e?.debug??false,enableBatching:t?.enableBatching??e?.enableBatching??true,batchSize:t?.batchSize??e?.batchSize,batchTimeout:t?.batchTimeout??e?.batchTimeout,maxQueueSize:t?.maxQueueSize??e?.maxQueueSize,ready:i,status:i?"enabled":"missing"}}function At(e,t){let n=t?.sourceToken??e?.sourceToken,o=t?.ingestingHost??e?.ingestingHost,r=t?.enabled??e?.enabled??false,i=e?.enabled===true?e?.errorTracking:void 0,s=zt(r,i,t?.errorTracking),c=r&&f(n)&&$(o);return {enabled:r,mode:t?.mode??e?.mode??"auto",sourceToken:n,ingestingHost:o,serviceName:t?.serviceName??e?.serviceName??G(),errorTracking:s,ready:c,status:c?"enabled":"missing"}}function zt(e,t,n){let o=n?.dsn??t?.dsn,r=n?.enabled??t?.enabled??e,i=r&&f(o);return {enabled:r,dsn:o,tracesSampleRate:n?.tracesSampleRate??t?.tracesSampleRate??1,environment:n?.environment??t?.environment,release:n?.release??t?.release,ready:i,status:i?"enabled":"missing"}}function Pt(e,t){let n=t?.dsn??e?.dsn,o=t?.enabled??e?.enabled??false,r=o&&typeof n=="string"&&n.trim().length>0;return {enabled:o,mode:t?.mode??e?.mode??"auto",dsn:n,environment:t?.environment??e?.environment,release:t?.release??e?.release,ready:r,status:r?"enabled":"missing"}}function Ft(e,t){let n=t?.endpoint??e?.endpoint,o=t?.enabled??e?.enabled??false,r={...{},...t?.headers??{}},i=o&&$(n);return {name:t?.name??e?.name??"",enabled:o,mode:t?.mode??e?.mode??"auto",endpoint:n,headers:r,auth:t?.auth??e?.auth,serviceName:t?.serviceName??e?.serviceName??G(),ready:i,status:i?"enabled":"missing"}}function It(e,t){let n=t??e??[],o=new Map;for(let r of n)!r||typeof r.name!="string"||r.name.length===0||(o.has(r.name)&&D(`otlp-duplicate:${r.name}`,`[Blyp] Warning: Duplicate OTLP connector name "${r.name}" found. Using the last definition.`),o.set(r.name,Ft(void 0,r)));return Array.from(o.values())}function _t(e,t){return {betterstack:At(e?.betterstack,t?.betterstack),databuddy:Bt(e?.databuddy,t?.databuddy),posthog:Tt(e?.posthog,t?.posthog),sentry:Pt(e?.sentry,t?.sentry),otlp:It(e?.otlp,t?.otlp),delivery:vt(e?.delivery,t?.delivery)}}function Q(e,t={},n={}){return {...e,...t,destination:t.destination??e.destination??"file",file:Dt(e.file,t.file),database:Et(e.database,t.database,n.configFileType),clientLogging:kt(e.clientLogging,t.clientLogging),redact:wt(e.redact,t.redact),connectors:_t(e.connectors,t.connectors)}}function Ot(){if(z!==null)return z;lt();let e=gt();if(e){let t=yt(e);z=Q(ue,t,{configFileType:e.type});}else z=Q(ue);return z}function be(e={}){return Q(Ot(),e)}var Mt=new async_hooks.AsyncLocalStorage;function jt(){return Mt.getStore()}function K(){return jt()?.traceId}var he={success:"success",critical:"critical",warning:"warning",info:"info",debug:"debug",error:"error",warn:"warning",table:"table"};function O(e){return e.replace(/\\/g,"/")}function qt(e){let t=O(e);return t.startsWith("node:")||t.includes("/node_modules/pino")||t.includes("/node_modules/pino-pretty")||t.includes("/node_modules/@blyp/core/")||t.includes("/blyp/src/core/")||t.includes("/blyp/src/frameworks/")||t.includes("/blyp/src/posthog/")||t.includes("/blyp/dist/")}function $t(e){let t=O(e),n=O(process.cwd());return t.startsWith(`${n}/`)?t.slice(n.length+1):t}function Re(){try{let e=new Error().stack;if(!e)return {file:null,line:null};let t=e.split(`
|
|
9
|
+
`),n=null;for(let o=2;o<t.length;o+=1){let r=t[o];if(!r)continue;let i=r.match(/\((.*):(\d+):\d+\)/)||r.match(/at\s+(.*):(\d+):(\d+)/);if(!i)continue;let s=i[1]||"",c=parseInt(i[2]||"0",10)||null;if(s&&!s.includes("node_modules")&&!qt(s)){let d=$t(s);if(!O(d).startsWith("dist/"))return {file:d,line:c};n??(n={file:d,line:c});}}if(n)return n}catch{return {file:null,line:null}}return {file:null,line:null}}var Se=A;function Le(e){return e.replace(/\u001b\[[0-9;]*m/g,"")}function De(e,t,n,o,r=L()){let{file:i,line:s}=Re(),c=Se(t,r),d={timestamp:new Date().toISOString(),level:he[e],message:Le(c)},a=K();return t instanceof Error&&(d.error=y(F(t),r)),i&&(d.caller=s!==null?`${i}:${s}`:i),n.length===1?d.data=y(n[0],r):n.length>1&&(d.data=y(n,r)),Object.keys(o).length>0&&(d.bindings=y(o,r)),a&&(d.traceId=a),d}function J(e,t,n,o,r=L()){let{file:i,line:s}=Re(),c=y(n,r),d=K(),a={message:Le(Se(t,r)),...c};return i&&(a.caller=s!==null?`${i}:${s}`:i),Object.keys(o).length>0&&(a.bindings=y(o,r)),d&&a.traceId===void 0&&(a.traceId=d),a.level=typeof c.level=="string"&&c.level.length>0?c.level:he[e],a.timestamp=typeof c.timestamp=="string"&&c.timestamp.length>0?c.timestamp:new Date().toISOString(),a}function V(e){switch(e){case "debug":return "debug";case "warning":return "warning";case "warn":return "warn";case "error":return "error";case "success":return "success";case "critical":return "critical";case "table":return "table";default:return "info"}}function ke(e,t){if(typeof e=="string")return t.length===0?void 0:t.length===1?t[0]:t;let n=[e,...t];return n.length===1?n[0]:n}function we(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return e}function Ut(e,t){if(e==null)return t===void 0||t<400?void 0:{message:`HTTP ${t}`,code:t,type:"HttpError"};if(e instanceof Error){let n=e;return {message:e.message,code:n.code,type:n.type??e.name??e.constructor?.name,stack:e.stack,why:n.why,fix:n.fix,link:n.link,details:we(n.details),cause:n.cause}}if(typeof e=="object"){let n=e,o=typeof n.statusCode=="number"?n.statusCode:typeof n.status=="number"?n.status:t;return {message:typeof n.message=="string"?n.message:`HTTP ${o??500}`,code:typeof n.code=="string"||typeof n.code=="number"?n.code:o,type:typeof n.type=="string"?n.type:typeof n.name=="string"?n.name:"Error",stack:typeof n.stack=="string"?n.stack:void 0,why:typeof n.why=="string"?n.why:void 0,fix:typeof n.fix=="string"?n.fix:void 0,link:typeof n.link=="string"?n.link:void 0,details:we(n.details),cause:n.cause}}return {message:String(e),code:t,type:typeof e}}function Ht(e){return e.response&&typeof e.response.status=="number"?e.response.status:typeof e.status=="number"?e.status:e.error&&typeof e.error=="object"&&e.error!==null&&typeof e.error.statusCode=="number"?e.error.statusCode:e.error&&typeof e.error=="object"&&e.error!==null&&typeof e.error.status=="number"?e.error.status:e.error?500:void 0}function Z(e,t){let n=t.redact??L(),o=performance.now(),r=y(t.initialFields??{},n),i=[],s;t.onCreate?.();let c=(a,u,g)=>(i.push({level:a,message:A(u,n),timestamp:new Date().toISOString(),...ke(u,g)===void 0?{}:{data:y(ke(u,g),n)}}),d),d={set(a){return Object.assign(r,y(a,n)),d},debug(a,...u){return c("debug",a,u)},info(a,...u){return c("info",a,u)},warn(a,...u){return c("warn",a,u)},warning(a,...u){return c("warning",a,u)},error(a,...u){return c("error",a,u)},success(a,...u){return c("success",a,u)},critical(a,...u){return c("critical",a,u)},table(a,u){return c("table",a,u===void 0?[]:[u])},emit(a={}){if(s)return s;let u=y(t.resolveDefaultFields?.()??{},n),g=Ht(a),l=y(Ut(a.error,g),n),m=a.level??(l?"error":"info"),p=y({...u,...r,groupId:e,timestamp:new Date().toISOString(),level:m,duration:Math.round(performance.now()-o),...typeof g=="number"?{status:g}:{},...i.length>0?{events:[...i]}:{},...l?{error:l}:{}},n);return t.write(p,A(a.message??"structured_log",n)),s=p,t.onEmit?.(p),p}};return d}function Wt(){let e=new WeakSet;return (t,n)=>{if(typeof n=="function")return `[Function: ${n.name||"anonymous"}]`;if(n===void 0)return "[undefined]";if(typeof n=="symbol")return n.toString();if(n!==null&&typeof n=="object"){if(e.has(n))return "[Circular]";e.add(n);}return n}}function xe(e){return JSON.stringify(e,Wt())}var Y=Symbol("blyp.connector.batch-dispatch"),ve=Symbol("blyp.connector.delivery-binder");function Ee(e){return b(e)&&("connectors"in e||"pretty"in e||"level"in e)}function P(e){return b(e.data)?e.data:e}function R(e,t){if(t in e){let r=e[t];if(typeof r=="string"||typeof r=="number")return r}let o=P(e)[t];if(typeof o=="string"||typeof o=="number")return o}function X(e,t){let n=P(e),r=(b(n.page)?n.page:void 0)?.[t];return typeof r=="string"?r:void 0}function N(e,t){let n=P(e),r=(b(n.session)?n.session:void 0)?.[t];return typeof r=="string"?r:void 0}function ee(e){return R(e,"type")}var Gt=new Set,Te=new Map,Kt={},k=ae(Gt);function Jt(e,t){let n=["beforeExit","SIGINT","SIGTERM"];for(let o of n)process.once(o,()=>{t().catch(r=>{k(`${e}:shutdown`,"[Blyp] Failed to flush Databuddy telemetry during shutdown.",r);});});}function Vt(e){let t=Ee(e)?e.connectors?.databuddy:e,n=t?.enabled??false,o=t?.apiKey,r=t?.websiteId,i=n&&f(o)&&f(r);return {enabled:n,mode:t?.mode??"auto",apiKey:o,websiteId:r,namespace:t?.namespace,source:t?.source,apiUrl:t?.apiUrl,debug:t?.debug??false,enableBatching:t?.enableBatching??true,batchSize:t?.batchSize,batchTimeout:t?.batchTimeout,maxQueueSize:t?.maxQueueSize,ready:i,status:i?"enabled":"missing"}}function Zt(e){return new node.Databuddy({apiKey:e.apiKey??"",...e.websiteId?{websiteId:e.websiteId}:{},...e.namespace?{namespace:e.namespace}:{},...e.source?{source:e.source}:{},...e.apiUrl?{apiUrl:e.apiUrl}:{},debug:e.debug,enableBatching:e.enableBatching,...e.batchSize!==void 0?{batchSize:e.batchSize}:{},...e.batchTimeout!==void 0?{batchTimeout:e.batchTimeout}:{},...e.maxQueueSize!==void 0?{maxQueueSize:e.maxQueueSize}:{}})}function Yt(e){return JSON.stringify({enabled:e.enabled,mode:e.mode,apiKey:e.apiKey??null,websiteId:e.websiteId??null,namespace:e.namespace??null,source:e.source??null,apiUrl:e.apiUrl??null,debug:e.debug,enableBatching:e.enableBatching,batchSize:e.batchSize??null,batchTimeout:e.batchTimeout??null,maxQueueSize:e.maxQueueSize??null})}function Xt(e){let t=R(e,"sessionId");return f(t)?t:N(e,"sessionId")}function en(e){let t=R(e,"anonymousId");if(f(t))return t;let n=P(e);if(b(n.metadata)&&f(n.metadata.databuddyAnonymousId))return n.metadata.databuddyAnonymousId}function tn(e){let t=ee(e);return f(t)?t:"log"}function nn(e,t){let n={blyp_level:e.level,blyp_source:t,blyp_payload:xe(e),message:typeof e.message=="string"?e.message:String(e.message)},o=typeof e.caller=="string"?e.caller:void 0,r=R(e,"groupId"),i=R(e,"traceId"),s=R(e,"method"),c=R(e,"path"),d=R(e,"status"),a=R(e,"duration"),u=X(e,"pathname"),g=X(e,"url"),l=N(e,"sessionId"),m=N(e,"pageId"),p=[["blyp_type",ee(e)],["caller",o],["group_id",r],["trace_id",i],["method",s],["path",c],["page_path",u],["page_url",g],["session_id",l],["page_id",m]],w=[["status_code",d],["duration_ms",a]];for(let[x,B]of p)B&&(n[x]=B);for(let[x,B]of w)B!==void 0&&(n[x]=B);return n}function Be(e,t){return {name:tn(e),anonymousId:en(e),sessionId:Xt(e),properties:nn(e,t)}}function Ae(e){return b(e)?h(e):{}}function rn(e,t){return e instanceof Error?{message:e.message||t,properties:{error_type:e.name,...e.stack?{stack:e.stack}:{},...Ae(e)}}:b(e)?{message:f(e.message)?e.message:f(e.error)?e.error:t,properties:Ae(e)}:typeof e=="string"?{message:e,properties:{message:e}}:{message:t,properties:{value:h(e)}}}function ze(e){return !b(e)||e.success!==false?null:f(e.error)?e.error:f(e.message)?e.message:"Databuddy SDK reported delivery failure."}function Pe(e){let t=Vt(e),n=Yt(t),o=Te.get(n);if(o)return o;let r=`${t.apiUrl??"default"}:${t.mode}:${t.apiKey??"missing"}`,i=t.ready?Kt.createClient?.(t)??Zt(t):void 0;i&&Jt(r,async()=>{await i.flush();});let s=()=>{k(`databuddy-unavailable:${r}`,"[Blyp] Databuddy connector is not configured. Databuddy requires both apiKey and websiteId. Skipping Databuddy delivery.");},c=()=>{k(`databuddy-exception-unavailable:${r}`,"[Blyp] Databuddy error tracking is not configured. Databuddy requires both apiKey and websiteId. Skipping Databuddy exception capture.");},d=null,a=async g=>{if(!t.ready||!i)return {ok:false,retryable:false,error:"Databuddy connector is not configured."};try{let l=await Promise.all(g.map(w=>Promise.resolve(i.track(Be(w,"server")))));for(let w of l){let x=ze(w);if(x)return {ok:!1,retryable:!0,error:x}}let m=await i.flush(),p=ze(m);return p?{ok:!1,retryable:!0,error:p}:{ok:!0}}catch(l){return {ok:false,retryable:true,error:l instanceof Error?l.message:String(l)}}},u={enabled:t.enabled,ready:t.ready,mode:t.mode,status:t.status,shouldAutoForwardServerLogs(){return t.ready&&t.mode==="auto"},shouldAutoCaptureExceptions(){return t.ready&&t.mode==="auto"},send(g,l={}){if(l.source!=="client"&&d){d.enqueue("databuddy",g,u[Y]);return}if(!t.ready||!i){l.warnIfUnavailable&&s();return}try{let m=i.track(Be(g,l.source??"server"));m&&typeof m.catch=="function"&&m.catch(p=>{k(`databuddy-send:${r}`,"[Blyp] Failed to deliver log to Databuddy.",p);});}catch(m){k(`databuddy-send:${r}`,"[Blyp] Failed to deliver log to Databuddy.",m);}},captureException(g,l={}){if(!t.ready||!i){l.warnIfUnavailable&&c();return}let m=rn(g,l.source==="client"?"Client error":"Server error");try{let p=i.track({name:"error",anonymousId:l.anonymousId,sessionId:l.sessionId,properties:{message:m.message,blyp_source:l.source??"server",blyp_level:"error",...m.properties,...l.properties??{}}});p&&typeof p.catch=="function"&&p.catch(w=>{k(`databuddy-capture:${r}`,"[Blyp] Failed to capture exception in Databuddy.",w);});}catch(p){k(`databuddy-capture:${r}`,"[Blyp] Failed to capture exception in Databuddy.",p);}},async flush(){try{i&&await i.flush();}catch(g){k(`databuddy-flush:${r}`,"[Blyp] Failed to flush Databuddy telemetry.",g);}},[Y]:{dispatchKey:"databuddy",dispatch:g=>a(g)},[ve](g){d=g;}};return Te.set(n,u),u}function te(e={}){return Pe(be({...e.connectors?{connectors:e.connectors}:{}}))}function Fe(e,t={}){let n=(r,i,s)=>{e.send(De(r,i,s,t),{source:"server",warnIfUnavailable:true});},o=(r,i)=>{e.send(J(V(r.level),i,r,t),{source:"server",warnIfUnavailable:true});};return {debug:(r,...i)=>{n("debug",r,i);},info:(r,...i)=>{n("info",r,i);},error:(r,...i)=>{n("error",r,i);},warn:(r,...i)=>{n("warn",r,i);},warning:(r,...i)=>{n("warning",r,i);},success:(r,...i)=>{n("success",r,i);},critical:(r,...i)=>{n("critical",r,i);},table:(r,i)=>{n("table",r,i===void 0?[]:[i]);},flush:async()=>{await e.flush();},shutdown:async()=>{await e.flush();},createStructuredLog:(r,i)=>Z(r,{initialFields:i,write:o}),child:r=>Fe(e,{...t,...r})}}function Ie(e,t={}){return {capture:(n,o={})=>{e.captureException(n,{source:"server",warnIfUnavailable:true,properties:{...t,...o.properties??{},blyp_source:"server",blyp_manual:true}});},child:n=>Ie(e,{...t,...n})}}function or(e={}){return Fe(te(e))}function ir(e,t,n={}){let o=te(n);return Z(e,{initialFields:t,write:(r,i)=>{o.send(J(V(r.level),i,r,{}),{source:"server",warnIfUnavailable:true});}})}function on(e={}){return Ie(te(e))}function ar(e,t={},n={}){on(n).capture(e,t);}exports.captureDatabuddyException=ar;exports.createDatabuddyErrorTracker=on;exports.createDatabuddyLogger=or;exports.createStructuredDatabuddyLogger=ir;
|