@heyramzi/utils 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/image.js +220 -0
- package/dist/ai/models.js +261 -0
- package/dist/analytics/client.js +57 -0
- package/dist/analytics/server.js +54 -0
- package/dist/analytics/svelte.js +24 -0
- package/dist/analytics/types.js +0 -0
- package/dist/analytics/umami/protocol.js +35 -0
- package/dist/analytics/umami/reporting.js +189 -0
- package/dist/auth/config/otp.js +4 -0
- package/dist/auth/config/rate-limits.js +20 -0
- package/dist/auth/config/trusted-origins.js +15 -0
- package/dist/auth/email/index.js +3 -0
- package/dist/auth/email/layout.js +84 -0
- package/dist/auth/email/resend.js +30 -0
- package/dist/auth/email/template.js +57 -0
- package/dist/auth/email/types.js +0 -0
- package/dist/auth/index.js +3 -0
- package/dist/cache.js +4 -0
- package/dist/cn.js +5 -0
- package/dist/collection.js +8 -0
- package/dist/crypto.js +117 -0
- package/dist/error.js +15 -0
- package/dist/errors/sentry/index.js +15 -0
- package/dist/errors/sentry/protocol.js +130 -0
- package/dist/errors/sentry/sveltekit.js +145 -0
- package/dist/format.js +62 -0
- package/dist/grab.js +112 -0
- package/dist/index.js +10 -0
- package/dist/logger-types.js +0 -0
- package/dist/logger.js +22 -0
- package/dist/math.js +3 -0
- package/dist/og/fonts.js +46 -0
- package/dist/og/index.js +3 -0
- package/dist/og/markup.js +31 -0
- package/dist/og/renderer.js +29 -0
- package/dist/og/types.js +0 -0
- package/dist/result.js +26 -0
- package/dist/string.js +32 -0
- package/dist/testimonials/render-content.js +15 -0
- package/dist/testimonials/server.js +21 -0
- package/dist/testimonials/types.js +0 -0
- package/dist/timing.js +20 -0
- package/dist/vite.js +265 -0
- package/package.json +125 -27
- package/src/auth/email/template.ts +2 -2
- package/src/errors/sentry/sveltekit.test.ts +63 -2
- package/src/errors/sentry/sveltekit.ts +43 -5
|
@@ -16,7 +16,7 @@ export type CaughtInput = {
|
|
|
16
16
|
type BaseOptions<R> = {
|
|
17
17
|
/** Public client key on the browser, private on the server. Empty or missing sends nothing. */
|
|
18
18
|
dsn: string | undefined;
|
|
19
|
-
/** `dev` from `$app/env`. Reports nothing while true. */
|
|
19
|
+
/** `dev` from `$app/env`. Reports nothing while true, and answers a crash with its real message and stack. */
|
|
20
20
|
dev: boolean;
|
|
21
21
|
/** `version` from `$app/env`. Set `kit.version.name` to the commit SHA so a fix is traceable. */
|
|
22
22
|
release: string | undefined;
|
|
@@ -109,6 +109,34 @@ function toError(raw: unknown): unknown {
|
|
|
109
109
|
return typeof message === "string" ? new Error(message) : raw;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
/** What the dev-only "Error details" block on an error page shows. */
|
|
113
|
+
export type DevErrorDetails = { message: string; stack?: string };
|
|
114
|
+
|
|
115
|
+
const STACK_LINES = 8;
|
|
116
|
+
|
|
117
|
+
/** The real message and first stack frames, for dev only: kit answers a crash with "Internal Error". */
|
|
118
|
+
export function devErrorDetails(error: unknown): DevErrorDetails {
|
|
119
|
+
// A framework error is a plain { status, message }: a stack made for it would point here.
|
|
120
|
+
if (!(error instanceof Error)) {
|
|
121
|
+
const message = (error as { message?: unknown } | null)?.message;
|
|
122
|
+
if (typeof message === "string") return { message };
|
|
123
|
+
try {
|
|
124
|
+
return { message: typeof error === "object" ? JSON.stringify(error) : String(error) };
|
|
125
|
+
} catch {
|
|
126
|
+
return { message: String(error) };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// WHY strip the header: V8 starts the stack with "Name: message", which the block already shows.
|
|
130
|
+
const header = String(error);
|
|
131
|
+
const stack = error.stack?.startsWith(header) ? error.stack.slice(header.length) : error.stack;
|
|
132
|
+
const frames = stack
|
|
133
|
+
?.split("\n")
|
|
134
|
+
.map((line) => line.trim())
|
|
135
|
+
.filter(Boolean)
|
|
136
|
+
.slice(0, STACK_LINES);
|
|
137
|
+
return { message: error.message, stack: frames?.length ? frames.join("\n") : undefined };
|
|
138
|
+
}
|
|
139
|
+
|
|
112
140
|
function isLocalHost(input: CaughtInput): boolean {
|
|
113
141
|
return LOCAL_HOSTS.has(input.event.url.hostname);
|
|
114
142
|
}
|
|
@@ -142,13 +170,23 @@ async function respondTo<R>(options: BaseOptions<R>, input: CaughtInput): Promis
|
|
|
142
170
|
}
|
|
143
171
|
}
|
|
144
172
|
|
|
173
|
+
/** The app's answer, with the real message and stack laid over it in dev for an error we'd report. */
|
|
174
|
+
async function answer<R>(
|
|
175
|
+
options: BaseOptions<R>,
|
|
176
|
+
input: CaughtInput,
|
|
177
|
+
): Promise<R | DevErrorDetails | undefined> {
|
|
178
|
+
const body = await respondTo(options, input);
|
|
179
|
+
if (!options.dev || !shouldReport(input)) return body;
|
|
180
|
+
return { ...body, ...devErrorDetails(input.error) };
|
|
181
|
+
}
|
|
182
|
+
|
|
145
183
|
/**
|
|
146
184
|
* `handleError` for `hooks.client.ts`. A stale-chunk error reloads the page once instead
|
|
147
185
|
* of reporting. Everything else that's ours goes to Sentry, tagged with the environment
|
|
148
186
|
* and release.
|
|
149
187
|
*/
|
|
150
188
|
export function createHandleClientError<R = undefined>(options: ClientErrorOptions<R>) {
|
|
151
|
-
return async (input: CaughtInput): Promise<R | undefined> => {
|
|
189
|
+
return async (input: CaughtInput): Promise<R | DevErrorDetails | undefined> => {
|
|
152
190
|
try {
|
|
153
191
|
let tags: Record<string, SentryScalar> | undefined;
|
|
154
192
|
if (isStaleChunk(input.error)) {
|
|
@@ -163,7 +201,7 @@ export function createHandleClientError<R = undefined>(options: ClientErrorOptio
|
|
|
163
201
|
} catch (err) {
|
|
164
202
|
console.error("[handleError] reporting failed:", err);
|
|
165
203
|
}
|
|
166
|
-
return
|
|
204
|
+
return answer(options, input);
|
|
167
205
|
};
|
|
168
206
|
}
|
|
169
207
|
|
|
@@ -173,7 +211,7 @@ export function createHandleClientError<R = undefined>(options: ClientErrorOptio
|
|
|
173
211
|
* in the event (see `buildErrorRequest`).
|
|
174
212
|
*/
|
|
175
213
|
export function createHandleServerError<R = undefined>(options: ServerErrorOptions<R>) {
|
|
176
|
-
return async (input: CaughtInput): Promise<R | undefined> => {
|
|
214
|
+
return async (input: CaughtInput): Promise<R | DevErrorDetails | undefined> => {
|
|
177
215
|
try {
|
|
178
216
|
if (shouldReport(input)) {
|
|
179
217
|
// WHY the error itself, not its stack: Node and workerd print `cause` for an Error.
|
|
@@ -183,6 +221,6 @@ export function createHandleServerError<R = undefined>(options: ServerErrorOptio
|
|
|
183
221
|
} catch (err) {
|
|
184
222
|
console.error("[handleError] reporting failed:", err);
|
|
185
223
|
}
|
|
186
|
-
return
|
|
224
|
+
return answer(options, input);
|
|
187
225
|
};
|
|
188
226
|
}
|