@blyp/core 0.1.21 → 0.1.22
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 +217 -11
- 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/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 +116 -0
- package/dist/ai/shared/types.d.ts +161 -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 +246 -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
package/dist/expo.js
CHANGED
|
@@ -1,726 +1 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var zod = require('zod');
|
|
4
|
-
|
|
5
|
-
// src/shared/client-log.ts
|
|
6
|
-
|
|
7
|
-
// src/shared/log-value.ts
|
|
8
|
-
function normalizeError(error) {
|
|
9
|
-
const normalized = {
|
|
10
|
-
name: error.name,
|
|
11
|
-
message: error.message
|
|
12
|
-
};
|
|
13
|
-
if (error.stack) {
|
|
14
|
-
normalized.stack = error.stack;
|
|
15
|
-
}
|
|
16
|
-
const errorWithCause = error;
|
|
17
|
-
if (errorWithCause.cause !== void 0) {
|
|
18
|
-
normalized.cause = normalizeLogValue(errorWithCause.cause);
|
|
19
|
-
}
|
|
20
|
-
return normalized;
|
|
21
|
-
}
|
|
22
|
-
function normalizeLogValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
23
|
-
if (value instanceof Error) {
|
|
24
|
-
return normalizeError(value);
|
|
25
|
-
}
|
|
26
|
-
if (typeof value === "function") {
|
|
27
|
-
return `[Function: ${value.name || "anonymous"}]`;
|
|
28
|
-
}
|
|
29
|
-
if (typeof value === "symbol") {
|
|
30
|
-
return value.toString();
|
|
31
|
-
}
|
|
32
|
-
if (value === void 0 || value === null) {
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
if (Array.isArray(value)) {
|
|
36
|
-
return value.map((entry) => normalizeLogValue(entry, seen));
|
|
37
|
-
}
|
|
38
|
-
if (typeof value === "object") {
|
|
39
|
-
if (seen.has(value)) {
|
|
40
|
-
return "[Circular]";
|
|
41
|
-
}
|
|
42
|
-
seen.add(value);
|
|
43
|
-
const normalized = {};
|
|
44
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
45
|
-
normalized[key] = normalizeLogValue(entry, seen);
|
|
46
|
-
}
|
|
47
|
-
seen.delete(value);
|
|
48
|
-
return normalized;
|
|
49
|
-
}
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
function serializeLogMessage(message) {
|
|
53
|
-
if (typeof message === "string") {
|
|
54
|
-
return message;
|
|
55
|
-
}
|
|
56
|
-
if (message instanceof Error) {
|
|
57
|
-
return message.message || message.name;
|
|
58
|
-
}
|
|
59
|
-
const normalized = normalizeLogValue(message);
|
|
60
|
-
if (typeof normalized === "string") {
|
|
61
|
-
return normalized;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const serialized = JSON.stringify(normalized, null, 2);
|
|
65
|
-
return serialized ?? String(normalized);
|
|
66
|
-
} catch {
|
|
67
|
-
return String(normalized);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
var absoluteHttpUrlSchema = zod.z.string().url().refine((value) => {
|
|
71
|
-
try {
|
|
72
|
-
const url = new URL(value);
|
|
73
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
74
|
-
} catch {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}, {
|
|
78
|
-
message: "Expected an absolute http(s) URL"
|
|
79
|
-
});
|
|
80
|
-
var plainObjectSchema = zod.z.custom(
|
|
81
|
-
(value) => {
|
|
82
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
message: "Expected a plain object"
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
var nonEmptyStringSchema = zod.z.string().trim().min(1);
|
|
89
|
-
function isAbsoluteHttpUrl(value) {
|
|
90
|
-
return absoluteHttpUrlSchema.safeParse(value).success;
|
|
91
|
-
}
|
|
92
|
-
function isPlainObject(value) {
|
|
93
|
-
return plainObjectSchema.safeParse(value).success;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// src/shared/client-log.ts
|
|
97
|
-
zod.z.union([
|
|
98
|
-
zod.z.literal("betterstack"),
|
|
99
|
-
zod.z.literal("databuddy"),
|
|
100
|
-
zod.z.literal("posthog"),
|
|
101
|
-
zod.z.literal("sentry"),
|
|
102
|
-
zod.z.undefined(),
|
|
103
|
-
zod.z.object({
|
|
104
|
-
type: zod.z.literal("otlp"),
|
|
105
|
-
name: nonEmptyStringSchema
|
|
106
|
-
})
|
|
107
|
-
]);
|
|
108
|
-
function safeGet(getter) {
|
|
109
|
-
try {
|
|
110
|
-
return getter();
|
|
111
|
-
} catch {
|
|
112
|
-
return void 0;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function randomSegment() {
|
|
116
|
-
return Math.random().toString(36).slice(2, 10);
|
|
117
|
-
}
|
|
118
|
-
function createRandomId() {
|
|
119
|
-
const maybeCrypto = safeGet(() => globalThis.crypto);
|
|
120
|
-
const randomUUID = maybeCrypto && typeof maybeCrypto.randomUUID === "function" ? maybeCrypto.randomUUID.bind(maybeCrypto) : void 0;
|
|
121
|
-
if (randomUUID) {
|
|
122
|
-
return randomUUID();
|
|
123
|
-
}
|
|
124
|
-
return `${Date.now().toString(36)}-${randomSegment()}`;
|
|
125
|
-
}
|
|
126
|
-
function normalizeClientLogLevel(level) {
|
|
127
|
-
return level === "warn" ? "warning" : level;
|
|
128
|
-
}
|
|
129
|
-
function normalizeClientPayloadData(message, args) {
|
|
130
|
-
const normalizedArgs = args.map((entry) => normalizeLogValue(entry));
|
|
131
|
-
const messageData = message instanceof Error ? normalizeError(message) : void 0;
|
|
132
|
-
if (messageData !== void 0 && normalizedArgs.length === 0) {
|
|
133
|
-
return messageData;
|
|
134
|
-
}
|
|
135
|
-
const combined = messageData === void 0 ? normalizedArgs : [messageData, ...normalizedArgs];
|
|
136
|
-
if (combined.length === 0) {
|
|
137
|
-
return void 0;
|
|
138
|
-
}
|
|
139
|
-
if (combined.length === 1) {
|
|
140
|
-
return combined[0];
|
|
141
|
-
}
|
|
142
|
-
return combined;
|
|
143
|
-
}
|
|
144
|
-
function normalizeMetadata(metadata) {
|
|
145
|
-
if (metadata === void 0) {
|
|
146
|
-
return void 0;
|
|
147
|
-
}
|
|
148
|
-
const resolved = typeof metadata === "function" ? safeGet(metadata) : metadata;
|
|
149
|
-
if (!isPlainObject(resolved)) {
|
|
150
|
-
return void 0;
|
|
151
|
-
}
|
|
152
|
-
return normalizeLogValue(resolved);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// src/shared/remote-delivery.ts
|
|
156
|
-
var DEFAULT_MAX_RETRIES = 3;
|
|
157
|
-
var DEFAULT_RETRY_DELAY_MS = 5e3;
|
|
158
|
-
var DEFAULT_MAX_QUEUE_SIZE = 100;
|
|
159
|
-
function clampInteger(value, fallback, minimum) {
|
|
160
|
-
if (!Number.isFinite(value)) {
|
|
161
|
-
return fallback;
|
|
162
|
-
}
|
|
163
|
-
return Math.max(minimum, Math.floor(value));
|
|
164
|
-
}
|
|
165
|
-
function safeCall(callback, value) {
|
|
166
|
-
if (!callback) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
try {
|
|
170
|
-
callback(value);
|
|
171
|
-
} catch {
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function warn(message) {
|
|
175
|
-
if (typeof console === "undefined" || typeof console.warn !== "function") {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
console.warn(message);
|
|
179
|
-
}
|
|
180
|
-
function formatWarningValue(value) {
|
|
181
|
-
return value === void 0 ? "unknown" : String(value);
|
|
182
|
-
}
|
|
183
|
-
function createRemoteDeliveryManager(options) {
|
|
184
|
-
const deliveryConfig = {
|
|
185
|
-
maxRetries: clampInteger(options.delivery?.maxRetries, DEFAULT_MAX_RETRIES, 0),
|
|
186
|
-
retryDelayMs: clampInteger(options.delivery?.retryDelayMs, DEFAULT_RETRY_DELAY_MS, 0),
|
|
187
|
-
maxQueueSize: clampInteger(options.delivery?.maxQueueSize, DEFAULT_MAX_QUEUE_SIZE, 1),
|
|
188
|
-
warnOnFailure: options.delivery?.warnOnFailure ?? true,
|
|
189
|
-
onSuccess: options.delivery?.onSuccess,
|
|
190
|
-
onRetry: options.delivery?.onRetry,
|
|
191
|
-
onFailure: options.delivery?.onFailure,
|
|
192
|
-
onDrop: options.delivery?.onDrop
|
|
193
|
-
};
|
|
194
|
-
const queue = [];
|
|
195
|
-
let inFlight;
|
|
196
|
-
let flushTimer;
|
|
197
|
-
let isProcessing = false;
|
|
198
|
-
let unsubscribeFromResume;
|
|
199
|
-
const runtimeLabel = options.runtime === "browser" ? "client" : options.runtime;
|
|
200
|
-
const clearFlushTimer = () => {
|
|
201
|
-
if (!flushTimer) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
clearTimeout(flushTimer);
|
|
205
|
-
flushTimer = void 0;
|
|
206
|
-
};
|
|
207
|
-
const hasUnsentEvents = () => queue.length > 0 || inFlight !== void 0;
|
|
208
|
-
const refreshResumeSubscription = (flush2) => {
|
|
209
|
-
if (!options.subscribeToResume) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (hasUnsentEvents()) {
|
|
213
|
-
if (!unsubscribeFromResume) {
|
|
214
|
-
unsubscribeFromResume = options.subscribeToResume(() => {
|
|
215
|
-
const now = Date.now();
|
|
216
|
-
for (const item of queue) {
|
|
217
|
-
item.nextAttemptAt = now;
|
|
218
|
-
}
|
|
219
|
-
clearFlushTimer();
|
|
220
|
-
flush2();
|
|
221
|
-
}) ?? void 0;
|
|
222
|
-
}
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
if (unsubscribeFromResume) {
|
|
226
|
-
unsubscribeFromResume();
|
|
227
|
-
unsubscribeFromResume = void 0;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
const warnDrop = (ctx) => {
|
|
231
|
-
if (!deliveryConfig.warnOnFailure) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
warn(
|
|
235
|
-
`[blyp/${runtimeLabel}] Dropped queued log "${ctx.droppedEvent.message}" (id: ${ctx.droppedEvent.id}) because the delivery queue reached ${ctx.maxQueueSize}. Keeping "${ctx.replacementEvent.message}" (id: ${ctx.replacementEvent.id}) instead.`
|
|
236
|
-
);
|
|
237
|
-
};
|
|
238
|
-
const warnFailure = (ctx, suppressWarning) => {
|
|
239
|
-
if (!deliveryConfig.warnOnFailure || suppressWarning) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
const details = [
|
|
243
|
-
`reason=${ctx.reason}`,
|
|
244
|
-
`attempt=${formatWarningValue(ctx.attempt)}`,
|
|
245
|
-
`status=${formatWarningValue(ctx.status)}`
|
|
246
|
-
];
|
|
247
|
-
if (ctx.error) {
|
|
248
|
-
details.push(`error=${ctx.error}`);
|
|
249
|
-
}
|
|
250
|
-
warn(
|
|
251
|
-
`[blyp/${runtimeLabel}] Failed to deliver log "${ctx.event.message}" (id: ${ctx.event.id}, ${details.join(", ")})`
|
|
252
|
-
);
|
|
253
|
-
};
|
|
254
|
-
const totalUnsentEvents = () => queue.length + (inFlight ? 1 : 0);
|
|
255
|
-
const scheduleFlush = (flush2) => {
|
|
256
|
-
clearFlushTimer();
|
|
257
|
-
if (queue.length === 0) {
|
|
258
|
-
refreshResumeSubscription(flush2);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
const nextAttemptAt = queue.reduce((lowest, item) => {
|
|
262
|
-
return Math.min(lowest, item.nextAttemptAt);
|
|
263
|
-
}, Number.POSITIVE_INFINITY);
|
|
264
|
-
const delay = Math.max(nextAttemptAt - Date.now(), 0);
|
|
265
|
-
flushTimer = setTimeout(() => {
|
|
266
|
-
flushTimer = void 0;
|
|
267
|
-
flush2();
|
|
268
|
-
}, delay);
|
|
269
|
-
refreshResumeSubscription(flush2);
|
|
270
|
-
};
|
|
271
|
-
const emitDrop = (droppedEvent, replacementEvent) => {
|
|
272
|
-
const context = {
|
|
273
|
-
runtime: options.runtime,
|
|
274
|
-
droppedEvent,
|
|
275
|
-
replacementEvent,
|
|
276
|
-
maxQueueSize: deliveryConfig.maxQueueSize,
|
|
277
|
-
reason: "queue_overflow"
|
|
278
|
-
};
|
|
279
|
-
safeCall(deliveryConfig.onDrop, context);
|
|
280
|
-
warnDrop(context);
|
|
281
|
-
};
|
|
282
|
-
const enforceQueueCapacity = () => {
|
|
283
|
-
while (totalUnsentEvents() > deliveryConfig.maxQueueSize && queue.length > 0) {
|
|
284
|
-
const droppedItem = queue.shift();
|
|
285
|
-
const replacementEvent = queue[queue.length - 1]?.event ?? inFlight?.event;
|
|
286
|
-
if (!droppedItem || !replacementEvent) {
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
emitDrop(droppedItem.event, replacementEvent);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
const getNextReadyIndex = () => {
|
|
293
|
-
const now = Date.now();
|
|
294
|
-
for (let index = 0; index < queue.length; index += 1) {
|
|
295
|
-
if (queue[index].nextAttemptAt <= now) {
|
|
296
|
-
return index;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return -1;
|
|
300
|
-
};
|
|
301
|
-
const flush = async () => {
|
|
302
|
-
if (isProcessing) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
isProcessing = true;
|
|
306
|
-
try {
|
|
307
|
-
while (true) {
|
|
308
|
-
const nextIndex = getNextReadyIndex();
|
|
309
|
-
if (nextIndex === -1) {
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
const item = queue.splice(nextIndex, 1)[0];
|
|
313
|
-
if (!item) {
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
inFlight = item;
|
|
317
|
-
refreshResumeSubscription(() => {
|
|
318
|
-
void flush();
|
|
319
|
-
});
|
|
320
|
-
item.attempt += 1;
|
|
321
|
-
const result = await options.send(item.event);
|
|
322
|
-
inFlight = void 0;
|
|
323
|
-
if (result.outcome === "success") {
|
|
324
|
-
const context = {
|
|
325
|
-
runtime: options.runtime,
|
|
326
|
-
event: item.event,
|
|
327
|
-
attempt: item.attempt,
|
|
328
|
-
status: result.status,
|
|
329
|
-
transport: result.transport
|
|
330
|
-
};
|
|
331
|
-
safeCall(deliveryConfig.onSuccess, context);
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
if (result.outcome === "retry" && item.attempt <= deliveryConfig.maxRetries) {
|
|
335
|
-
item.nextAttemptAt = Date.now() + deliveryConfig.retryDelayMs;
|
|
336
|
-
queue.push(item);
|
|
337
|
-
const context = {
|
|
338
|
-
runtime: options.runtime,
|
|
339
|
-
event: item.event,
|
|
340
|
-
attempt: item.attempt,
|
|
341
|
-
retriesRemaining: deliveryConfig.maxRetries - (item.attempt - 1),
|
|
342
|
-
nextRetryAt: new Date(item.nextAttemptAt).toISOString(),
|
|
343
|
-
reason: result.reason,
|
|
344
|
-
status: result.status,
|
|
345
|
-
error: result.error
|
|
346
|
-
};
|
|
347
|
-
safeCall(deliveryConfig.onRetry, context);
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
const failureContext = {
|
|
351
|
-
runtime: options.runtime,
|
|
352
|
-
event: item.event,
|
|
353
|
-
attempt: item.attempt,
|
|
354
|
-
reason: result.reason,
|
|
355
|
-
status: result.status,
|
|
356
|
-
error: result.error
|
|
357
|
-
};
|
|
358
|
-
safeCall(deliveryConfig.onFailure, failureContext);
|
|
359
|
-
warnFailure(
|
|
360
|
-
failureContext,
|
|
361
|
-
result.outcome === "failure" ? result.suppressWarning : void 0
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
} finally {
|
|
365
|
-
isProcessing = false;
|
|
366
|
-
scheduleFlush(() => {
|
|
367
|
-
void flush();
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
return {
|
|
372
|
-
enqueue(event) {
|
|
373
|
-
queue.push({
|
|
374
|
-
event,
|
|
375
|
-
attempt: 0,
|
|
376
|
-
nextAttemptAt: Date.now()
|
|
377
|
-
});
|
|
378
|
-
enforceQueueCapacity();
|
|
379
|
-
scheduleFlush(() => {
|
|
380
|
-
void flush();
|
|
381
|
-
});
|
|
382
|
-
void flush();
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// src/shared/once.ts
|
|
388
|
-
function createConsoleOnceLogger(method, warnedKeys = /* @__PURE__ */ new Set()) {
|
|
389
|
-
return (key, message, error) => {
|
|
390
|
-
if (warnedKeys.has(key) || typeof console === "undefined") {
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
const writer = console[method];
|
|
394
|
-
if (typeof writer !== "function") {
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
warnedKeys.add(key);
|
|
398
|
-
if (error === void 0) {
|
|
399
|
-
writer.call(console, message);
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
writer.call(console, message, error);
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function createWarnOnceLogger(warnedKeys) {
|
|
406
|
-
return createConsoleOnceLogger("warn", warnedKeys);
|
|
407
|
-
}
|
|
408
|
-
function createErrorOnceLogger(warnedKeys) {
|
|
409
|
-
return createConsoleOnceLogger("error", warnedKeys);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// src/frameworks/expo/network.ts
|
|
413
|
-
var expoNetworkLoader = async () => {
|
|
414
|
-
try {
|
|
415
|
-
const module = await import('expo-network');
|
|
416
|
-
if (typeof module.getNetworkStateAsync !== "function") {
|
|
417
|
-
return null;
|
|
418
|
-
}
|
|
419
|
-
return module;
|
|
420
|
-
} catch {
|
|
421
|
-
return null;
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
var expoNetworkModulePromise;
|
|
425
|
-
var lastKnownExpoNetworkState;
|
|
426
|
-
function normalizeNetworkState(state) {
|
|
427
|
-
if (!state) {
|
|
428
|
-
return void 0;
|
|
429
|
-
}
|
|
430
|
-
return {
|
|
431
|
-
type: typeof state.type === "string" ? state.type : void 0,
|
|
432
|
-
isConnected: typeof state.isConnected === "boolean" ? state.isConnected : void 0,
|
|
433
|
-
isInternetReachable: typeof state.isInternetReachable === "boolean" ? state.isInternetReachable : void 0
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
function loadExpoNetworkModule() {
|
|
437
|
-
if (!expoNetworkModulePromise) {
|
|
438
|
-
expoNetworkModulePromise = expoNetworkLoader();
|
|
439
|
-
}
|
|
440
|
-
return expoNetworkModulePromise;
|
|
441
|
-
}
|
|
442
|
-
async function getExpoNetworkSnapshot() {
|
|
443
|
-
const module = await loadExpoNetworkModule();
|
|
444
|
-
if (!module) {
|
|
445
|
-
return void 0;
|
|
446
|
-
}
|
|
447
|
-
try {
|
|
448
|
-
const state = normalizeNetworkState(await module.getNetworkStateAsync());
|
|
449
|
-
lastKnownExpoNetworkState = state;
|
|
450
|
-
return state;
|
|
451
|
-
} catch {
|
|
452
|
-
return lastKnownExpoNetworkState;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
function subscribeToExpoNetworkState(listener) {
|
|
456
|
-
let isActive = true;
|
|
457
|
-
let subscription;
|
|
458
|
-
void loadExpoNetworkModule().then((module) => {
|
|
459
|
-
if (!isActive || !module || typeof module.addNetworkStateListener !== "function") {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
subscription = module.addNetworkStateListener((event) => {
|
|
463
|
-
const state = normalizeNetworkState(event);
|
|
464
|
-
lastKnownExpoNetworkState = state;
|
|
465
|
-
listener(state);
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
return () => {
|
|
469
|
-
isActive = false;
|
|
470
|
-
subscription?.remove();
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// src/frameworks/expo/logger.ts
|
|
475
|
-
var expoSessionId = createRandomId();
|
|
476
|
-
var warnedMessages = /* @__PURE__ */ new Set();
|
|
477
|
-
var warnOnce = createWarnOnceLogger(warnedMessages);
|
|
478
|
-
var errorOnce = createErrorOnceLogger(warnedMessages);
|
|
479
|
-
function isRetryableStatus(status) {
|
|
480
|
-
return status === 429 || status >= 500;
|
|
481
|
-
}
|
|
482
|
-
function resolveHeaders(headers) {
|
|
483
|
-
return {
|
|
484
|
-
"content-type": "application/json",
|
|
485
|
-
...headers ?? {}
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
function emitLocalConsole(level, message, args) {
|
|
489
|
-
if (typeof console === "undefined") {
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
const normalizedArgs = args.map((entry) => normalizeLogValue(entry));
|
|
493
|
-
const text = serializeLogMessage(message);
|
|
494
|
-
switch (level) {
|
|
495
|
-
case "table":
|
|
496
|
-
console.log(text);
|
|
497
|
-
if (normalizedArgs.length > 0 && typeof console.table === "function") {
|
|
498
|
-
console.table(normalizedArgs[0]);
|
|
499
|
-
}
|
|
500
|
-
return;
|
|
501
|
-
case "warning":
|
|
502
|
-
case "warn":
|
|
503
|
-
console.warn(text, ...normalizedArgs);
|
|
504
|
-
return;
|
|
505
|
-
case "error":
|
|
506
|
-
case "critical":
|
|
507
|
-
console.error(text, ...normalizedArgs);
|
|
508
|
-
return;
|
|
509
|
-
case "debug":
|
|
510
|
-
console.debug(text, ...normalizedArgs);
|
|
511
|
-
return;
|
|
512
|
-
case "success":
|
|
513
|
-
console.log(text, ...normalizedArgs);
|
|
514
|
-
return;
|
|
515
|
-
case "info":
|
|
516
|
-
default:
|
|
517
|
-
console.info(text, ...normalizedArgs);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
async function sendRemoteLog(config, event) {
|
|
521
|
-
if (!isAbsoluteHttpUrl(config.endpoint)) {
|
|
522
|
-
warnOnce(
|
|
523
|
-
"invalid-endpoint",
|
|
524
|
-
"[blyp/expo] `endpoint` must be an absolute http(s) URL. Remote sync skipped."
|
|
525
|
-
);
|
|
526
|
-
return {
|
|
527
|
-
outcome: "failure",
|
|
528
|
-
reason: "invalid_endpoint",
|
|
529
|
-
suppressWarning: true
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
const expoNetworkModule = await loadExpoNetworkModule();
|
|
533
|
-
if (!expoNetworkModule) {
|
|
534
|
-
warnOnce(
|
|
535
|
-
"missing-expo-network",
|
|
536
|
-
"[blyp/expo] Install `expo-network` to enable remote sync in Expo."
|
|
537
|
-
);
|
|
538
|
-
return {
|
|
539
|
-
outcome: "failure",
|
|
540
|
-
reason: "missing_transport",
|
|
541
|
-
suppressWarning: true
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
if (typeof fetch !== "function") {
|
|
545
|
-
return {
|
|
546
|
-
outcome: "failure",
|
|
547
|
-
reason: "missing_transport"
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
const network = await getExpoNetworkSnapshot();
|
|
551
|
-
if (network?.isConnected === false || network?.isInternetReachable === false) {
|
|
552
|
-
return {
|
|
553
|
-
outcome: "retry",
|
|
554
|
-
reason: "offline"
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
const payload = {
|
|
558
|
-
...event,
|
|
559
|
-
device: {
|
|
560
|
-
runtime: "expo",
|
|
561
|
-
network
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
try {
|
|
565
|
-
const response = await fetch(config.endpoint, {
|
|
566
|
-
method: "POST",
|
|
567
|
-
headers: resolveHeaders(config.headers),
|
|
568
|
-
body: JSON.stringify(payload)
|
|
569
|
-
});
|
|
570
|
-
if (response.ok) {
|
|
571
|
-
if (config.connector === "betterstack" && response.headers.get("x-blyp-betterstack-status") === "missing") {
|
|
572
|
-
errorOnce(
|
|
573
|
-
"missing-betterstack-server-config",
|
|
574
|
-
"[blyp/expo] Better Stack connector requested but not configured on the server. Continuing without Better Stack forwarding."
|
|
575
|
-
);
|
|
576
|
-
}
|
|
577
|
-
if (config.connector === "databuddy" && response.headers.get("x-blyp-databuddy-status") === "missing") {
|
|
578
|
-
errorOnce(
|
|
579
|
-
"missing-databuddy-server-config",
|
|
580
|
-
"[blyp/expo] Databuddy connector requested but not configured on the server. Continuing without Databuddy forwarding."
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
|
-
if (config.connector === "posthog" && response.headers.get("x-blyp-posthog-status") === "missing") {
|
|
584
|
-
errorOnce(
|
|
585
|
-
"missing-posthog-server-config",
|
|
586
|
-
"[blyp/expo] PostHog connector requested but not configured on the server. Continuing without PostHog forwarding."
|
|
587
|
-
);
|
|
588
|
-
}
|
|
589
|
-
if (config.connector === "sentry" && response.headers.get("x-blyp-sentry-status") === "missing") {
|
|
590
|
-
errorOnce(
|
|
591
|
-
"missing-sentry-server-config",
|
|
592
|
-
"[blyp/expo] Sentry not setup. Continuing without Sentry forwarding."
|
|
593
|
-
);
|
|
594
|
-
}
|
|
595
|
-
if (config.connector && typeof config.connector === "object" && config.connector.type === "otlp" && response.headers.get("x-blyp-otlp-status") === "missing") {
|
|
596
|
-
errorOnce(
|
|
597
|
-
`missing-otlp-server-config:${config.connector.name}`,
|
|
598
|
-
`[blyp/expo] OTLP target "${config.connector.name}" was requested but not configured on the server. Continuing without OTLP forwarding.`
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
return {
|
|
602
|
-
outcome: "success",
|
|
603
|
-
transport: "fetch",
|
|
604
|
-
status: response.status
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
if (isRetryableStatus(response.status)) {
|
|
608
|
-
return {
|
|
609
|
-
outcome: "retry",
|
|
610
|
-
reason: "response_status",
|
|
611
|
-
status: response.status
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
return {
|
|
615
|
-
outcome: "failure",
|
|
616
|
-
reason: "response_status",
|
|
617
|
-
status: response.status
|
|
618
|
-
};
|
|
619
|
-
} catch (error) {
|
|
620
|
-
return {
|
|
621
|
-
outcome: "retry",
|
|
622
|
-
reason: "network_error",
|
|
623
|
-
error: error instanceof Error ? error.message : String(error)
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
function buildExpoLogger(config, state) {
|
|
628
|
-
const resolvedConfig = {
|
|
629
|
-
endpoint: config?.endpoint,
|
|
630
|
-
headers: config?.headers,
|
|
631
|
-
localConsole: config?.localConsole ?? true,
|
|
632
|
-
remoteSync: config?.remoteSync ?? true,
|
|
633
|
-
connector: config?.connector,
|
|
634
|
-
metadata: config?.metadata
|
|
635
|
-
};
|
|
636
|
-
const delivery = state.delivery ?? (resolvedConfig.remoteSync ? createRemoteDeliveryManager({
|
|
637
|
-
runtime: "expo",
|
|
638
|
-
delivery: config?.delivery,
|
|
639
|
-
send: (event) => sendRemoteLog(resolvedConfig, event),
|
|
640
|
-
subscribeToResume: (resume) => {
|
|
641
|
-
return subscribeToExpoNetworkState((network) => {
|
|
642
|
-
if (network?.isConnected === false || network?.isInternetReachable === false) {
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
resume();
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
}) : void 0);
|
|
649
|
-
const writeLog = (level, message, args) => {
|
|
650
|
-
if (resolvedConfig.localConsole) {
|
|
651
|
-
emitLocalConsole(level, message, args);
|
|
652
|
-
}
|
|
653
|
-
if (!resolvedConfig.remoteSync) {
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
const payload = {
|
|
657
|
-
type: "client_log",
|
|
658
|
-
source: "client",
|
|
659
|
-
id: createRandomId(),
|
|
660
|
-
level: normalizeClientLogLevel(level),
|
|
661
|
-
message: serializeLogMessage(message),
|
|
662
|
-
connector: resolvedConfig.connector,
|
|
663
|
-
data: normalizeClientPayloadData(message, args),
|
|
664
|
-
bindings: Object.keys(state.bindings).length > 0 ? normalizeLogValue(state.bindings) : void 0,
|
|
665
|
-
clientTimestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
666
|
-
page: {},
|
|
667
|
-
browser: {},
|
|
668
|
-
device: {
|
|
669
|
-
runtime: "expo"
|
|
670
|
-
},
|
|
671
|
-
session: {
|
|
672
|
-
pageId: state.pageId,
|
|
673
|
-
sessionId: state.sessionId
|
|
674
|
-
},
|
|
675
|
-
metadata: normalizeMetadata(resolvedConfig.metadata)
|
|
676
|
-
};
|
|
677
|
-
delivery?.enqueue(payload);
|
|
678
|
-
};
|
|
679
|
-
return {
|
|
680
|
-
debug: (message, ...args) => {
|
|
681
|
-
writeLog("debug", message, args);
|
|
682
|
-
},
|
|
683
|
-
info: (message, ...args) => {
|
|
684
|
-
writeLog("info", message, args);
|
|
685
|
-
},
|
|
686
|
-
error: (message, ...args) => {
|
|
687
|
-
writeLog("error", message, args);
|
|
688
|
-
},
|
|
689
|
-
warn: (message, ...args) => {
|
|
690
|
-
writeLog("warn", message, args);
|
|
691
|
-
},
|
|
692
|
-
warning: (message, ...args) => {
|
|
693
|
-
writeLog("warning", message, args);
|
|
694
|
-
},
|
|
695
|
-
success: (message, ...args) => {
|
|
696
|
-
writeLog("success", message, args);
|
|
697
|
-
},
|
|
698
|
-
critical: (message, ...args) => {
|
|
699
|
-
writeLog("critical", message, args);
|
|
700
|
-
},
|
|
701
|
-
table: (message, data) => {
|
|
702
|
-
writeLog("table", message, data === void 0 ? [] : [data]);
|
|
703
|
-
},
|
|
704
|
-
child: (bindings) => {
|
|
705
|
-
return buildExpoLogger(config, {
|
|
706
|
-
...state,
|
|
707
|
-
bindings: {
|
|
708
|
-
...state.bindings,
|
|
709
|
-
...bindings
|
|
710
|
-
},
|
|
711
|
-
delivery
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
function createExpoLogger(config) {
|
|
717
|
-
return buildExpoLogger(config, {
|
|
718
|
-
pageId: createRandomId(),
|
|
719
|
-
sessionId: expoSessionId,
|
|
720
|
-
bindings: {}
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
exports.createExpoLogger = createExpoLogger;
|
|
725
|
-
//# sourceMappingURL=expo.js.map
|
|
726
|
-
//# sourceMappingURL=expo.js.map
|
|
1
|
+
'use strict';var zod=require('zod');function E(e){let t={name:e.name,message:e.message};e.stack&&(t.stack=e.stack);let o=e;return o.cause!==void 0&&(t.cause=l(o.cause)),t}function l(e,t=new WeakSet){if(e instanceof Error)return E(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(o=>l(o,t));if(typeof e=="object"){if(t.has(e))return "[Circular]";t.add(e);let o={};for(let[r,i]of Object.entries(e))o[r]=l(i,t);return t.delete(e),o}return e}function m(e){if(typeof e=="string")return e;if(e instanceof Error)return e.message||e.name;let t=l(e);if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)??String(t)}catch{return String(t)}}var le=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"}),N=zod.z.custom(e=>e!==null&&typeof e=="object"&&!Array.isArray(e),{message:"Expected a plain object"}),O=zod.z.string().trim().min(1);function I(e){return le.safeParse(e).success}function F(e){return N.safeParse(e).success}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:O})]);function M(e){try{return e()}catch{return}}function de(){return Math.random().toString(36).slice(2,10)}function v(){let e=M(()=>globalThis.crypto),t=e&&typeof e.randomUUID=="function"?e.randomUUID.bind(e):void 0;return t?t():`${Date.now().toString(36)}-${de()}`}function U(e){return e==="warn"?"warning":e}function q(e,t){let o=t.map(n=>l(n)),r=e instanceof Error?E(e):void 0;if(r!==void 0&&o.length===0)return r;let i=r===void 0?o:[r,...o];if(i.length!==0)return i.length===1?i[0]:i}function $(e){if(e===void 0)return;let t=typeof e=="function"?M(e):e;if(F(t))return l(t)}function D(e,t,o){return Number.isFinite(e)?Math.max(o,Math.floor(e)):t}function b(e,t){if(e)try{e(t);}catch{}}function j(e){typeof console>"u"||typeof console.warn!="function"||console.warn(e);}function H(e){return e===void 0?"unknown":String(e)}function Q(e){let t={maxRetries:D(e.delivery?.maxRetries,3,0),retryDelayMs:D(e.delivery?.retryDelayMs,5e3,0),maxQueueSize:D(e.delivery?.maxQueueSize,100,1),warnOnFailure:e.delivery?.warnOnFailure??true,onSuccess:e.delivery?.onSuccess,onRetry:e.delivery?.onRetry,onFailure:e.delivery?.onFailure,onDrop:e.delivery?.onDrop},o=[],r,i,n=false,s,d=e.runtime==="browser"?"client":e.runtime,w=()=>{i&&(clearTimeout(i),i=void 0);},oe=()=>o.length>0||r!==void 0,h=a=>{if(e.subscribeToResume){if(oe()){s||(s=e.subscribeToResume(()=>{let u=Date.now();for(let c of o)c.nextAttemptAt=u;w(),a();})??void 0);return}s&&(s(),s=void 0);}},re=a=>{t.warnOnFailure&&j(`[blyp/${d}] Dropped queued log "${a.droppedEvent.message}" (id: ${a.droppedEvent.id}) because the delivery queue reached ${a.maxQueueSize}. Keeping "${a.replacementEvent.message}" (id: ${a.replacementEvent.id}) instead.`);},ie=(a,u)=>{if(!t.warnOnFailure||u)return;let c=[`reason=${a.reason}`,`attempt=${H(a.attempt)}`,`status=${H(a.status)}`];a.error&&c.push(`error=${a.error}`),j(`[blyp/${d}] Failed to deliver log "${a.event.message}" (id: ${a.event.id}, ${c.join(", ")})`);},se=()=>o.length+(r?1:0),P=a=>{if(w(),o.length===0){h(a);return}let u=o.reduce((x,y)=>Math.min(x,y.nextAttemptAt),Number.POSITIVE_INFINITY),c=Math.max(u-Date.now(),0);i=setTimeout(()=>{i=void 0,a();},c),h(a);},ae=(a,u)=>{let c={runtime:e.runtime,droppedEvent:a,replacementEvent:u,maxQueueSize:t.maxQueueSize,reason:"queue_overflow"};b(t.onDrop,c),re(c);},ue=()=>{for(;se()>t.maxQueueSize&&o.length>0;){let a=o.shift(),u=o[o.length-1]?.event??r?.event;if(!a||!u)break;ae(a.event,u);}},ce=()=>{let a=Date.now();for(let u=0;u<o.length;u+=1)if(o[u].nextAttemptAt<=a)return u;return -1},C=async()=>{if(!n){n=true;try{for(;;){let a=ce();if(a===-1)break;let u=o.splice(a,1)[0];if(!u)continue;r=u,h(()=>{C();}),u.attempt+=1;let c=await e.send(u.event);if(r=void 0,c.outcome==="success"){let y={runtime:e.runtime,event:u.event,attempt:u.attempt,status:c.status,transport:c.transport};b(t.onSuccess,y);continue}if(c.outcome==="retry"&&u.attempt<=t.maxRetries){u.nextAttemptAt=Date.now()+t.retryDelayMs,o.push(u);let y={runtime:e.runtime,event:u.event,attempt:u.attempt,retriesRemaining:t.maxRetries-(u.attempt-1),nextRetryAt:new Date(u.nextAttemptAt).toISOString(),reason:c.reason,status:c.status,error:c.error};b(t.onRetry,y);continue}let x={runtime:e.runtime,event:u.event,attempt:u.attempt,reason:c.reason,status:c.status,error:c.error};b(t.onFailure,x),ie(x,c.outcome==="failure"?c.suppressWarning:void 0);}}finally{n=false,P(()=>{C();});}}};return {enqueue(a){o.push({event:a,attempt:0,nextAttemptAt:Date.now()}),ue(),P(()=>{C();}),C();}}}var fe="[REDACTED]",ge=["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 pe=[{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}],me=/\b(?:\d[ -]*?){16}\b/g;function Z(e){let t=new Set,o=[];for(let r of e)typeof r!="string"||r.length===0||t.has(r)||(t.add(r),o.push(r));return o}function ye(e){let t=e.flags.includes("g")?e.flags:`${e.flags}g`;return new RegExp(e.source,t)}function Re(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 Ce(e){return e.split(".").filter(Boolean)}function A(e,t,o=0,r=0){if(o===e.length)return r===t.length;let i=e[o];if(i==="**"){if(o===e.length-1)return true;for(let n=r;n<=t.length;n+=1)if(A(e,t,o+1,n))return true;return false}return r>=t.length||i!=="*"&&i!==t[r]?false:A(e,t,o+1,r+1)}function xe(e,t){return e.length===0||t.paths.length===0?false:t.paths.some(o=>A(Ce(o),e))}function ve(e){let t=e.replace(/\D/g,"");if(t.length!==16)return false;let o=0,r=false;for(let i=t.length-1;i>=0;i-=1){let n=Number(t[i]);r&&(n*=2,n>9&&(n-=9)),o+=n,r=!r;}return o%10===0}function V(e,t,o){if(o||t.disablePatternScanning)return e;let r=e;for(let{type:i,pattern:n}of pe)r=r.replace(n,`[REDACTED:${i}]`);r=r.replace(me,i=>ve(i)?"[REDACTED:card]":i);for(let i of t.patterns)r=r.replace(ye(i),"[REDACTED:pattern]");return r}function k(e,t,o,r){if(typeof e=="string")return V(e,t,!!r.skipPatternScanning);if(e==null||typeof e=="number"||typeof e=="boolean")return e;if(Array.isArray(e))return e.map((n,s)=>k(n,t,o,{path:[...r.path,String(s)],skipPatternScanning:r.skipPatternScanning}));if(!Re(e))return e;let i={};for(let[n,s]of Object.entries(e)){let d=[...r.path,n];if(o.has(n.toLowerCase())||xe(d,t)){if(s==null||typeof s=="string"||typeof s=="number"||typeof s=="boolean"){i[n]=fe;continue}i[n]=k(s,t,o,{path:d,skipPatternScanning:r.skipPatternScanning});continue}i[n]=k(s,t,o,{path:d,skipPatternScanning:r.skipPatternScanning});}return i}function B(e,t){return {keys:Z([...ge,...[],...[]]),paths:Z([...[],...[]]),patterns:[...[],...[]].filter(o=>o instanceof RegExp),disablePatternScanning:false}}function g(e,t,o={path:[]}){let r=l(e);return k(r,t,we(t),o)}function T(e,t){return typeof e=="string"?V(e,t,false):m(g(e,t))}function W(e,t=new Set){return (o,r,i)=>{if(t.has(o)||typeof console>"u")return;let n=console[e];if(typeof n=="function"){if(t.add(o),i===void 0){n.call(console,r);return}n.call(console,r,i);}}}function Y(e){return W("warn",e)}function G(e){return W("error",e)}var be=async()=>{try{let e=await import('expo-network');return typeof e.getNetworkStateAsync!="function"?null:e}catch{return null}},z,_;function J(e){if(e)return {type:typeof e.type=="string"?e.type:void 0,isConnected:typeof e.isConnected=="boolean"?e.isConnected:void 0,isInternetReachable:typeof e.isInternetReachable=="boolean"?e.isInternetReachable:void 0}}function L(){return z||(z=be()),z}async function K(){let e=await L();if(e)try{let t=J(await e.getNetworkStateAsync());return _=t,t}catch{return _}}function X(e){let t=true,o;return L().then(r=>{!t||!r||typeof r.addNetworkStateListener!="function"||(o=r.addNetworkStateListener(i=>{let n=J(i);_=n,e(n);}));}),()=>{t=false,o?.remove();}}var ke=v(),te=new Set,ee=Y(te),R=G(te),p=B();function Le(e){return e===429||e>=500}function he(e){return {"content-type":"application/json",...e??{}}}function Ee(e,t,o){if(typeof console>"u")return;let r=o.map(s=>l(s)),i=r.map(s=>g(s,p)),n=T(m(t),p);switch(e){case "table":console.log(n),r.length>0&&typeof console.table=="function"&&console.table(i[0]);return;case "warning":case "warn":console.warn(n,...i);return;case "error":case "critical":console.error(n,...i);return;case "debug":console.debug(n,...i);return;case "success":console.log(n,...i);return;default:console.info(n,...i);}}async function Se(e,t){if(!I(e.endpoint))return ee("invalid-endpoint","[blyp/expo] `endpoint` must be an absolute http(s) URL. Remote sync skipped."),{outcome:"failure",reason:"invalid_endpoint",suppressWarning:true};if(!await L())return ee("missing-expo-network","[blyp/expo] Install `expo-network` to enable remote sync in Expo."),{outcome:"failure",reason:"missing_transport",suppressWarning:true};if(typeof fetch!="function")return {outcome:"failure",reason:"missing_transport"};let r=await K();if(r?.isConnected===false||r?.isInternetReachable===false)return {outcome:"retry",reason:"offline"};let i={...t,device:{runtime:"expo",network:r}};try{let n=await fetch(e.endpoint,{method:"POST",headers:he(e.headers),body:JSON.stringify(g(i,p))});return n.ok?(e.connector==="betterstack"&&n.headers.get("x-blyp-betterstack-status")==="missing"&&R("missing-betterstack-server-config","[blyp/expo] Better Stack connector requested but not configured on the server. Continuing without Better Stack forwarding."),e.connector==="databuddy"&&n.headers.get("x-blyp-databuddy-status")==="missing"&&R("missing-databuddy-server-config","[blyp/expo] Databuddy connector requested but not configured on the server. Continuing without Databuddy forwarding."),e.connector==="posthog"&&n.headers.get("x-blyp-posthog-status")==="missing"&&R("missing-posthog-server-config","[blyp/expo] PostHog connector requested but not configured on the server. Continuing without PostHog forwarding."),e.connector==="sentry"&&n.headers.get("x-blyp-sentry-status")==="missing"&&R("missing-sentry-server-config","[blyp/expo] Sentry not setup. Continuing without Sentry forwarding."),e.connector&&typeof e.connector=="object"&&e.connector.type==="otlp"&&n.headers.get("x-blyp-otlp-status")==="missing"&&R(`missing-otlp-server-config:${e.connector.name}`,`[blyp/expo] OTLP target "${e.connector.name}" was requested but not configured on the server. Continuing without OTLP forwarding.`),{outcome:"success",transport:"fetch",status:n.status}):Le(n.status)?{outcome:"retry",reason:"response_status",status:n.status}:{outcome:"failure",reason:"response_status",status:n.status}}catch(n){return {outcome:"retry",reason:"network_error",error:n instanceof Error?n.message:String(n)}}}function ne(e,t){let o={endpoint:e?.endpoint,headers:e?.headers,localConsole:e?.localConsole??true,remoteSync:e?.remoteSync??true,connector:e?.connector,metadata:e?.metadata},r=t.delivery??(o.remoteSync?Q({runtime:"expo",delivery:e?.delivery,send:n=>Se(o,n),subscribeToResume:n=>X(s=>{s?.isConnected===false||s?.isInternetReachable===false||n();})}):void 0),i=(n,s,d)=>{if(o.localConsole&&Ee(n,s,d),!o.remoteSync)return;let w={type:"client_log",source:"client",id:v(),level:U(n),message:T(m(s),p),connector:o.connector,data:g(q(s,d),p),bindings:Object.keys(t.bindings).length>0?g(t.bindings,p):void 0,clientTimestamp:new Date().toISOString(),page:{},browser:{},device:{runtime:"expo"},session:{pageId:t.pageId,sessionId:t.sessionId},metadata:g($(o.metadata),p)};r?.enqueue(g(w,p));};return {debug:(n,...s)=>{i("debug",n,s);},info:(n,...s)=>{i("info",n,s);},error:(n,...s)=>{i("error",n,s);},warn:(n,...s)=>{i("warn",n,s);},warning:(n,...s)=>{i("warning",n,s);},success:(n,...s)=>{i("success",n,s);},critical:(n,...s)=>{i("critical",n,s);},table:(n,s)=>{i("table",n,s===void 0?[]:[s]);},child:n=>ne(e,{...t,bindings:{...t.bindings,...n},delivery:r})}}function De(e){return ne(e,{pageId:v(),sessionId:ke,bindings:{}})}exports.createExpoLogger=De;
|