@better-auth/telemetry 1.4.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +17 -0
- package/LICENSE.md +17 -0
- package/dist/index.cjs +541 -0
- package/dist/index.d.cts +312 -0
- package/dist/index.d.ts +312 -0
- package/dist/index.js +512 -0
- package/package.json +44 -0
- package/src/detectors/detect-auth-config.ts +200 -0
- package/src/detectors/detect-database.ts +22 -0
- package/src/detectors/detect-framework.ts +23 -0
- package/src/detectors/detect-project-info.ts +18 -0
- package/src/detectors/detect-runtime.ts +31 -0
- package/src/detectors/detect-system-info.ts +209 -0
- package/src/index.ts +82 -0
- package/src/project-id.ts +27 -0
- package/src/telemetry.test.ts +321 -0
- package/src/types.ts +46 -0
- package/src/utils/hash.ts +9 -0
- package/src/utils/id.ts +5 -0
- package/src/utils/import-util.ts +3 -0
- package/src/utils/package-json.ts +74 -0
- package/tsconfig.json +9 -0
- package/tsdown.config.ts +7 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
> @better-auth/telemetry@1.4.0-beta.10 build /home/runner/work/better-auth/better-auth/packages/telemetry
|
|
3
|
+
> tsdown
|
|
4
|
+
|
|
5
|
+
[34mℹ[39m tsdown [2mv0.15.6[22m powered by rolldown [2mv1.0.0-beta.43[22m
|
|
6
|
+
[34mℹ[39m Using tsdown config: [4m/home/runner/work/better-auth/better-auth/packages/telemetry/tsdown.config.ts[24m
|
|
7
|
+
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
|
+
[34mℹ[39m Build start
|
|
10
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [2m19.82 kB[22m [2m│ gzip: 5.22 kB[22m
|
|
11
|
+
[34mℹ[39m [33m[CJS][39m 1 files, total: 19.82 kB
|
|
12
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.js[22m [2m17.86 kB[22m [2m│ gzip: 4.73 kB[22m
|
|
13
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.ts[22m[39m [2m 9.33 kB[22m [2m│ gzip: 2.52 kB[22m
|
|
14
|
+
[34mℹ[39m [34m[ESM][39m 2 files, total: 27.19 kB
|
|
15
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m9.33 kB[22m [2m│ gzip: 2.52 kB[22m
|
|
16
|
+
[34mℹ[39m [33m[CJS][39m 1 files, total: 9.33 kB
|
|
17
|
+
[32m✔[39m Build complete in [32m2183ms[39m
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2024 - present, Bereket Engida
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
5
|
+
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
6
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
7
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
8
|
+
is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
|
11
|
+
substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
14
|
+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
15
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
16
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
17
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let __better_auth_core_env = require("@better-auth/core/env");
|
|
25
|
+
__better_auth_core_env = __toESM(__better_auth_core_env);
|
|
26
|
+
let __better_auth_utils_random = require("@better-auth/utils/random");
|
|
27
|
+
__better_auth_utils_random = __toESM(__better_auth_utils_random);
|
|
28
|
+
let __better_auth_utils_hash = require("@better-auth/utils/hash");
|
|
29
|
+
__better_auth_utils_hash = __toESM(__better_auth_utils_hash);
|
|
30
|
+
let __better_auth_utils_base64 = require("@better-auth/utils/base64");
|
|
31
|
+
__better_auth_utils_base64 = __toESM(__better_auth_utils_base64);
|
|
32
|
+
let __better_fetch_fetch = require("@better-fetch/fetch");
|
|
33
|
+
__better_fetch_fetch = __toESM(__better_fetch_fetch);
|
|
34
|
+
|
|
35
|
+
//#region src/utils/id.ts
|
|
36
|
+
const generateId = (size) => {
|
|
37
|
+
return (0, __better_auth_utils_random.createRandomStringGenerator)("a-z", "A-Z", "0-9")(size || 32);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/utils/hash.ts
|
|
42
|
+
async function hashToBase64(data) {
|
|
43
|
+
const buffer = await (0, __better_auth_utils_hash.createHash)("SHA-256").digest(data);
|
|
44
|
+
return __better_auth_utils_base64.base64.encode(buffer);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/utils/package-json.ts
|
|
49
|
+
let packageJSONCache;
|
|
50
|
+
async function readRootPackageJson() {
|
|
51
|
+
if (packageJSONCache) return packageJSONCache;
|
|
52
|
+
try {
|
|
53
|
+
const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "";
|
|
54
|
+
if (!cwd) return void 0;
|
|
55
|
+
const importRuntime$1 = (m) => Function("mm", "return import(mm)")(m);
|
|
56
|
+
const [{ default: fs }, { default: path }] = await Promise.all([importRuntime$1("fs/promises"), importRuntime$1("path")]);
|
|
57
|
+
const raw = await fs.readFile(path.join(cwd, "package.json"), "utf-8");
|
|
58
|
+
packageJSONCache = JSON.parse(raw);
|
|
59
|
+
return packageJSONCache;
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
async function getPackageVersion(pkg) {
|
|
63
|
+
if (packageJSONCache) return packageJSONCache.dependencies?.[pkg] || packageJSONCache.devDependencies?.[pkg] || packageJSONCache.peerDependencies?.[pkg];
|
|
64
|
+
try {
|
|
65
|
+
const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "";
|
|
66
|
+
if (!cwd) throw new Error("no-cwd");
|
|
67
|
+
const importRuntime$1 = (m) => Function("mm", "return import(mm)")(m);
|
|
68
|
+
const [{ default: fs }, { default: path }] = await Promise.all([importRuntime$1("fs/promises"), importRuntime$1("path")]);
|
|
69
|
+
const pkgJsonPath = path.join(cwd, "node_modules", pkg, "package.json");
|
|
70
|
+
const raw = await fs.readFile(pkgJsonPath, "utf-8");
|
|
71
|
+
return JSON.parse(raw).version || await getVersionFromLocalPackageJson(pkg) || void 0;
|
|
72
|
+
} catch {}
|
|
73
|
+
return await getVersionFromLocalPackageJson(pkg);
|
|
74
|
+
}
|
|
75
|
+
async function getVersionFromLocalPackageJson(pkg) {
|
|
76
|
+
const json = await readRootPackageJson();
|
|
77
|
+
if (!json) return void 0;
|
|
78
|
+
return {
|
|
79
|
+
...json.dependencies,
|
|
80
|
+
...json.devDependencies,
|
|
81
|
+
...json.peerDependencies
|
|
82
|
+
}[pkg];
|
|
83
|
+
}
|
|
84
|
+
async function getNameFromLocalPackageJson() {
|
|
85
|
+
return (await readRootPackageJson())?.name;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/project-id.ts
|
|
90
|
+
let projectIdCached = null;
|
|
91
|
+
async function getProjectId(baseUrl) {
|
|
92
|
+
if (projectIdCached) return projectIdCached;
|
|
93
|
+
const projectName = await getNameFromLocalPackageJson();
|
|
94
|
+
if (projectName) {
|
|
95
|
+
projectIdCached = await hashToBase64(baseUrl ? baseUrl + projectName : projectName);
|
|
96
|
+
return projectIdCached;
|
|
97
|
+
}
|
|
98
|
+
if (baseUrl) {
|
|
99
|
+
projectIdCached = await hashToBase64(baseUrl);
|
|
100
|
+
return projectIdCached;
|
|
101
|
+
}
|
|
102
|
+
projectIdCached = generateId(32);
|
|
103
|
+
return projectIdCached;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/utils/import-util.ts
|
|
108
|
+
const importRuntime = (m) => {
|
|
109
|
+
return Function("mm", "return import(mm)")(m);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/detectors/detect-system-info.ts
|
|
114
|
+
function getVendor() {
|
|
115
|
+
const hasAny = (...keys) => keys.some((k) => Boolean(__better_auth_core_env.env[k]));
|
|
116
|
+
if (hasAny("CF_PAGES", "CF_PAGES_URL", "CF_ACCOUNT_ID") || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") return "cloudflare";
|
|
117
|
+
if (hasAny("VERCEL", "VERCEL_URL", "VERCEL_ENV")) return "vercel";
|
|
118
|
+
if (hasAny("NETLIFY", "NETLIFY_URL")) return "netlify";
|
|
119
|
+
if (hasAny("RENDER", "RENDER_URL", "RENDER_INTERNAL_HOSTNAME", "RENDER_SERVICE_ID")) return "render";
|
|
120
|
+
if (hasAny("AWS_LAMBDA_FUNCTION_NAME", "AWS_EXECUTION_ENV", "LAMBDA_TASK_ROOT")) return "aws";
|
|
121
|
+
if (hasAny("GOOGLE_CLOUD_FUNCTION_NAME", "GOOGLE_CLOUD_PROJECT", "GCP_PROJECT", "K_SERVICE")) return "gcp";
|
|
122
|
+
if (hasAny("AZURE_FUNCTION_NAME", "FUNCTIONS_WORKER_RUNTIME", "WEBSITE_INSTANCE_ID", "WEBSITE_SITE_NAME")) return "azure";
|
|
123
|
+
if (hasAny("DENO_DEPLOYMENT_ID", "DENO_REGION")) return "deno-deploy";
|
|
124
|
+
if (hasAny("FLY_APP_NAME", "FLY_REGION", "FLY_ALLOC_ID")) return "fly-io";
|
|
125
|
+
if (hasAny("RAILWAY_STATIC_URL", "RAILWAY_ENVIRONMENT_NAME")) return "railway";
|
|
126
|
+
if (hasAny("DYNO", "HEROKU_APP_NAME")) return "heroku";
|
|
127
|
+
if (hasAny("DO_DEPLOYMENT_ID", "DO_APP_NAME", "DIGITALOCEAN")) return "digitalocean";
|
|
128
|
+
if (hasAny("KOYEB", "KOYEB_DEPLOYMENT_ID", "KOYEB_APP_NAME")) return "koyeb";
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
async function detectSystemInfo() {
|
|
132
|
+
try {
|
|
133
|
+
if (getVendor() === "cloudflare") return "cloudflare";
|
|
134
|
+
const os = await importRuntime("os");
|
|
135
|
+
const cpus = os.cpus();
|
|
136
|
+
return {
|
|
137
|
+
deploymentVendor: getVendor(),
|
|
138
|
+
systemPlatform: os.platform(),
|
|
139
|
+
systemRelease: os.release(),
|
|
140
|
+
systemArchitecture: os.arch(),
|
|
141
|
+
cpuCount: cpus.length,
|
|
142
|
+
cpuModel: cpus.length ? cpus[0].model : null,
|
|
143
|
+
cpuSpeed: cpus.length ? cpus[0].speed : null,
|
|
144
|
+
memory: os.totalmem(),
|
|
145
|
+
isWSL: await isWsl(),
|
|
146
|
+
isDocker: await isDocker(),
|
|
147
|
+
isTTY: typeof process !== "undefined" && process.stdout ? process.stdout.isTTY : null
|
|
148
|
+
};
|
|
149
|
+
} catch (e) {
|
|
150
|
+
return {
|
|
151
|
+
systemPlatform: null,
|
|
152
|
+
systemRelease: null,
|
|
153
|
+
systemArchitecture: null,
|
|
154
|
+
cpuCount: null,
|
|
155
|
+
cpuModel: null,
|
|
156
|
+
cpuSpeed: null,
|
|
157
|
+
memory: null,
|
|
158
|
+
isWSL: null,
|
|
159
|
+
isDocker: null,
|
|
160
|
+
isTTY: null
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
let isDockerCached;
|
|
165
|
+
async function hasDockerEnv() {
|
|
166
|
+
if (getVendor() === "cloudflare") return false;
|
|
167
|
+
try {
|
|
168
|
+
(await importRuntime("fs")).statSync("/.dockerenv");
|
|
169
|
+
return true;
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async function hasDockerCGroup() {
|
|
175
|
+
if (getVendor() === "cloudflare") return false;
|
|
176
|
+
try {
|
|
177
|
+
return (await importRuntime("fs")).readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
178
|
+
} catch {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function isDocker() {
|
|
183
|
+
if (getVendor() === "cloudflare") return false;
|
|
184
|
+
if (isDockerCached === void 0) isDockerCached = await hasDockerEnv() || await hasDockerCGroup();
|
|
185
|
+
return isDockerCached;
|
|
186
|
+
}
|
|
187
|
+
async function isWsl() {
|
|
188
|
+
try {
|
|
189
|
+
if (getVendor() === "cloudflare") return false;
|
|
190
|
+
if (typeof process === "undefined" || process?.platform !== "linux") return false;
|
|
191
|
+
const fs = await importRuntime("fs");
|
|
192
|
+
if ((await importRuntime("os")).release().toLowerCase().includes("microsoft")) {
|
|
193
|
+
if (await isInsideContainer()) return false;
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
return fs.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !await isInsideContainer() : false;
|
|
197
|
+
} catch {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
let isInsideContainerCached;
|
|
202
|
+
const hasContainerEnv = async () => {
|
|
203
|
+
if (getVendor() === "cloudflare") return false;
|
|
204
|
+
try {
|
|
205
|
+
(await importRuntime("fs")).statSync("/run/.containerenv");
|
|
206
|
+
return true;
|
|
207
|
+
} catch {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
async function isInsideContainer() {
|
|
212
|
+
if (isInsideContainerCached === void 0) isInsideContainerCached = await hasContainerEnv() || await isDocker();
|
|
213
|
+
return isInsideContainerCached;
|
|
214
|
+
}
|
|
215
|
+
function isCI() {
|
|
216
|
+
return __better_auth_core_env.env.CI !== "false" && ("BUILD_ID" in __better_auth_core_env.env || "BUILD_NUMBER" in __better_auth_core_env.env || "CI" in __better_auth_core_env.env || "CI_APP_ID" in __better_auth_core_env.env || "CI_BUILD_ID" in __better_auth_core_env.env || "CI_BUILD_NUMBER" in __better_auth_core_env.env || "CI_NAME" in __better_auth_core_env.env || "CONTINUOUS_INTEGRATION" in __better_auth_core_env.env || "RUN_ID" in __better_auth_core_env.env);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/detectors/detect-runtime.ts
|
|
221
|
+
function detectRuntime() {
|
|
222
|
+
if (typeof Deno !== "undefined") return {
|
|
223
|
+
name: "deno",
|
|
224
|
+
version: Deno?.version?.deno ?? null
|
|
225
|
+
};
|
|
226
|
+
if (typeof Bun !== "undefined") return {
|
|
227
|
+
name: "bun",
|
|
228
|
+
version: Bun?.version ?? null
|
|
229
|
+
};
|
|
230
|
+
if (typeof process !== "undefined" && process?.versions?.node) return {
|
|
231
|
+
name: "node",
|
|
232
|
+
version: process.versions.node ?? null
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
name: "edge",
|
|
236
|
+
version: null
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function detectEnvironment() {
|
|
240
|
+
return (0, __better_auth_core_env.getEnvVar)("NODE_ENV") === "production" ? "production" : isCI() ? "ci" : (0, __better_auth_core_env.isTest)() ? "test" : "development";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/detectors/detect-database.ts
|
|
245
|
+
const DATABASES = {
|
|
246
|
+
pg: "postgresql",
|
|
247
|
+
mysql: "mysql",
|
|
248
|
+
mariadb: "mariadb",
|
|
249
|
+
sqlite3: "sqlite",
|
|
250
|
+
"better-sqlite3": "sqlite",
|
|
251
|
+
"@prisma/client": "prisma",
|
|
252
|
+
mongoose: "mongodb",
|
|
253
|
+
mongodb: "mongodb",
|
|
254
|
+
"drizzle-orm": "drizzle"
|
|
255
|
+
};
|
|
256
|
+
async function detectDatabase() {
|
|
257
|
+
for (const [pkg, name] of Object.entries(DATABASES)) {
|
|
258
|
+
const version = await getPackageVersion(pkg);
|
|
259
|
+
if (version) return {
|
|
260
|
+
name,
|
|
261
|
+
version
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/detectors/detect-framework.ts
|
|
268
|
+
const FRAMEWORKS = {
|
|
269
|
+
next: "next",
|
|
270
|
+
nuxt: "nuxt",
|
|
271
|
+
"@remix-run/server-runtime": "remix",
|
|
272
|
+
astro: "astro",
|
|
273
|
+
"@sveltejs/kit": "sveltekit",
|
|
274
|
+
"solid-start": "solid-start",
|
|
275
|
+
"tanstack-start": "tanstack-start",
|
|
276
|
+
hono: "hono",
|
|
277
|
+
express: "express",
|
|
278
|
+
elysia: "elysia",
|
|
279
|
+
expo: "expo"
|
|
280
|
+
};
|
|
281
|
+
async function detectFramework() {
|
|
282
|
+
for (const [pkg, name] of Object.entries(FRAMEWORKS)) {
|
|
283
|
+
const version = await getPackageVersion(pkg);
|
|
284
|
+
if (version) return {
|
|
285
|
+
name,
|
|
286
|
+
version
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/detectors/detect-project-info.ts
|
|
293
|
+
function detectPackageManager() {
|
|
294
|
+
const userAgent = __better_auth_core_env.env.npm_config_user_agent;
|
|
295
|
+
if (!userAgent) return;
|
|
296
|
+
const pmSpec = userAgent.split(" ")[0];
|
|
297
|
+
const separatorPos = pmSpec.lastIndexOf("/");
|
|
298
|
+
const name = pmSpec.substring(0, separatorPos);
|
|
299
|
+
return {
|
|
300
|
+
name: name === "npminstall" ? "cnpm" : name,
|
|
301
|
+
version: pmSpec.substring(separatorPos + 1)
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/detectors/detect-auth-config.ts
|
|
307
|
+
function getTelemetryAuthConfig(options, context) {
|
|
308
|
+
return {
|
|
309
|
+
database: context?.database,
|
|
310
|
+
adapter: context?.adapter,
|
|
311
|
+
emailVerification: {
|
|
312
|
+
sendVerificationEmail: !!options.emailVerification?.sendVerificationEmail,
|
|
313
|
+
sendOnSignUp: !!options.emailVerification?.sendOnSignUp,
|
|
314
|
+
sendOnSignIn: !!options.emailVerification?.sendOnSignIn,
|
|
315
|
+
autoSignInAfterVerification: !!options.emailVerification?.autoSignInAfterVerification,
|
|
316
|
+
expiresIn: options.emailVerification?.expiresIn,
|
|
317
|
+
onEmailVerification: !!options.emailVerification?.onEmailVerification,
|
|
318
|
+
afterEmailVerification: !!options.emailVerification?.afterEmailVerification
|
|
319
|
+
},
|
|
320
|
+
emailAndPassword: {
|
|
321
|
+
enabled: !!options.emailAndPassword?.enabled,
|
|
322
|
+
disableSignUp: !!options.emailAndPassword?.disableSignUp,
|
|
323
|
+
requireEmailVerification: !!options.emailAndPassword?.requireEmailVerification,
|
|
324
|
+
maxPasswordLength: options.emailAndPassword?.maxPasswordLength,
|
|
325
|
+
minPasswordLength: options.emailAndPassword?.minPasswordLength,
|
|
326
|
+
sendResetPassword: !!options.emailAndPassword?.sendResetPassword,
|
|
327
|
+
resetPasswordTokenExpiresIn: options.emailAndPassword?.resetPasswordTokenExpiresIn,
|
|
328
|
+
onPasswordReset: !!options.emailAndPassword?.onPasswordReset,
|
|
329
|
+
password: {
|
|
330
|
+
hash: !!options.emailAndPassword?.password?.hash,
|
|
331
|
+
verify: !!options.emailAndPassword?.password?.verify
|
|
332
|
+
},
|
|
333
|
+
autoSignIn: !!options.emailAndPassword?.autoSignIn,
|
|
334
|
+
revokeSessionsOnPasswordReset: !!options.emailAndPassword?.revokeSessionsOnPasswordReset
|
|
335
|
+
},
|
|
336
|
+
socialProviders: Object.keys(options.socialProviders || {}).map((p) => {
|
|
337
|
+
const provider = options.socialProviders?.[p];
|
|
338
|
+
if (!provider) return {};
|
|
339
|
+
return {
|
|
340
|
+
id: p,
|
|
341
|
+
mapProfileToUser: !!provider.mapProfileToUser,
|
|
342
|
+
disableDefaultScope: !!provider.disableDefaultScope,
|
|
343
|
+
disableIdTokenSignIn: !!provider.disableIdTokenSignIn,
|
|
344
|
+
disableImplicitSignUp: provider.disableImplicitSignUp,
|
|
345
|
+
disableSignUp: provider.disableSignUp,
|
|
346
|
+
getUserInfo: !!provider.getUserInfo,
|
|
347
|
+
overrideUserInfoOnSignIn: !!provider.overrideUserInfoOnSignIn,
|
|
348
|
+
prompt: provider.prompt,
|
|
349
|
+
verifyIdToken: !!provider.verifyIdToken,
|
|
350
|
+
scope: provider.scope,
|
|
351
|
+
refreshAccessToken: !!provider.refreshAccessToken
|
|
352
|
+
};
|
|
353
|
+
}),
|
|
354
|
+
plugins: options.plugins?.map((p) => p.id.toString()),
|
|
355
|
+
user: {
|
|
356
|
+
modelName: options.user?.modelName,
|
|
357
|
+
fields: options.user?.fields,
|
|
358
|
+
additionalFields: options.user?.additionalFields,
|
|
359
|
+
changeEmail: {
|
|
360
|
+
enabled: options.user?.changeEmail?.enabled,
|
|
361
|
+
sendChangeEmailVerification: !!options.user?.changeEmail?.sendChangeEmailVerification
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
verification: {
|
|
365
|
+
modelName: options.verification?.modelName,
|
|
366
|
+
disableCleanup: options.verification?.disableCleanup,
|
|
367
|
+
fields: options.verification?.fields
|
|
368
|
+
},
|
|
369
|
+
session: {
|
|
370
|
+
modelName: options.session?.modelName,
|
|
371
|
+
additionalFields: options.session?.additionalFields,
|
|
372
|
+
cookieCache: {
|
|
373
|
+
enabled: options.session?.cookieCache?.enabled,
|
|
374
|
+
maxAge: options.session?.cookieCache?.maxAge
|
|
375
|
+
},
|
|
376
|
+
disableSessionRefresh: options.session?.disableSessionRefresh,
|
|
377
|
+
expiresIn: options.session?.expiresIn,
|
|
378
|
+
fields: options.session?.fields,
|
|
379
|
+
freshAge: options.session?.freshAge,
|
|
380
|
+
preserveSessionInDatabase: options.session?.preserveSessionInDatabase,
|
|
381
|
+
storeSessionInDatabase: options.session?.storeSessionInDatabase,
|
|
382
|
+
updateAge: options.session?.updateAge
|
|
383
|
+
},
|
|
384
|
+
account: {
|
|
385
|
+
modelName: options.account?.modelName,
|
|
386
|
+
fields: options.account?.fields,
|
|
387
|
+
encryptOAuthTokens: options.account?.encryptOAuthTokens,
|
|
388
|
+
updateAccountOnSignIn: options.account?.updateAccountOnSignIn,
|
|
389
|
+
accountLinking: {
|
|
390
|
+
enabled: options.account?.accountLinking?.enabled,
|
|
391
|
+
trustedProviders: options.account?.accountLinking?.trustedProviders,
|
|
392
|
+
updateUserInfoOnLink: options.account?.accountLinking?.updateUserInfoOnLink,
|
|
393
|
+
allowUnlinkingAll: options.account?.accountLinking?.allowUnlinkingAll
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
hooks: {
|
|
397
|
+
after: !!options.hooks?.after,
|
|
398
|
+
before: !!options.hooks?.before
|
|
399
|
+
},
|
|
400
|
+
secondaryStorage: !!options.secondaryStorage,
|
|
401
|
+
advanced: {
|
|
402
|
+
cookiePrefix: !!options.advanced?.cookiePrefix,
|
|
403
|
+
cookies: !!options.advanced?.cookies,
|
|
404
|
+
crossSubDomainCookies: {
|
|
405
|
+
domain: !!options.advanced?.crossSubDomainCookies?.domain,
|
|
406
|
+
enabled: options.advanced?.crossSubDomainCookies?.enabled,
|
|
407
|
+
additionalCookies: options.advanced?.crossSubDomainCookies?.additionalCookies
|
|
408
|
+
},
|
|
409
|
+
database: {
|
|
410
|
+
useNumberId: !!options.advanced?.database?.useNumberId,
|
|
411
|
+
generateId: options.advanced?.database?.generateId,
|
|
412
|
+
defaultFindManyLimit: options.advanced?.database?.defaultFindManyLimit
|
|
413
|
+
},
|
|
414
|
+
useSecureCookies: options.advanced?.useSecureCookies,
|
|
415
|
+
ipAddress: {
|
|
416
|
+
disableIpTracking: options.advanced?.ipAddress?.disableIpTracking,
|
|
417
|
+
ipAddressHeaders: options.advanced?.ipAddress?.ipAddressHeaders
|
|
418
|
+
},
|
|
419
|
+
disableCSRFCheck: options.advanced?.disableCSRFCheck,
|
|
420
|
+
cookieAttributes: {
|
|
421
|
+
expires: options.advanced?.defaultCookieAttributes?.expires,
|
|
422
|
+
secure: options.advanced?.defaultCookieAttributes?.secure,
|
|
423
|
+
sameSite: options.advanced?.defaultCookieAttributes?.sameSite,
|
|
424
|
+
domain: !!options.advanced?.defaultCookieAttributes?.domain,
|
|
425
|
+
path: options.advanced?.defaultCookieAttributes?.path,
|
|
426
|
+
httpOnly: options.advanced?.defaultCookieAttributes?.httpOnly
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
trustedOrigins: options.trustedOrigins?.length,
|
|
430
|
+
rateLimit: {
|
|
431
|
+
storage: options.rateLimit?.storage,
|
|
432
|
+
modelName: options.rateLimit?.modelName,
|
|
433
|
+
window: options.rateLimit?.window,
|
|
434
|
+
customStorage: !!options.rateLimit?.customStorage,
|
|
435
|
+
enabled: options.rateLimit?.enabled,
|
|
436
|
+
max: options.rateLimit?.max
|
|
437
|
+
},
|
|
438
|
+
onAPIError: {
|
|
439
|
+
errorURL: options.onAPIError?.errorURL,
|
|
440
|
+
onError: !!options.onAPIError?.onError,
|
|
441
|
+
throw: options.onAPIError?.throw
|
|
442
|
+
},
|
|
443
|
+
logger: {
|
|
444
|
+
disabled: options.logger?.disabled,
|
|
445
|
+
level: options.logger?.level,
|
|
446
|
+
log: !!options.logger?.log
|
|
447
|
+
},
|
|
448
|
+
databaseHooks: {
|
|
449
|
+
user: {
|
|
450
|
+
create: {
|
|
451
|
+
after: !!options.databaseHooks?.user?.create?.after,
|
|
452
|
+
before: !!options.databaseHooks?.user?.create?.before
|
|
453
|
+
},
|
|
454
|
+
update: {
|
|
455
|
+
after: !!options.databaseHooks?.user?.update?.after,
|
|
456
|
+
before: !!options.databaseHooks?.user?.update?.before
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
session: {
|
|
460
|
+
create: {
|
|
461
|
+
after: !!options.databaseHooks?.session?.create?.after,
|
|
462
|
+
before: !!options.databaseHooks?.session?.create?.before
|
|
463
|
+
},
|
|
464
|
+
update: {
|
|
465
|
+
after: !!options.databaseHooks?.session?.update?.after,
|
|
466
|
+
before: !!options.databaseHooks?.session?.update?.before
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
account: {
|
|
470
|
+
create: {
|
|
471
|
+
after: !!options.databaseHooks?.account?.create?.after,
|
|
472
|
+
before: !!options.databaseHooks?.account?.create?.before
|
|
473
|
+
},
|
|
474
|
+
update: {
|
|
475
|
+
after: !!options.databaseHooks?.account?.update?.after,
|
|
476
|
+
before: !!options.databaseHooks?.account?.update?.before
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
verification: {
|
|
480
|
+
create: {
|
|
481
|
+
after: !!options.databaseHooks?.verification?.create?.after,
|
|
482
|
+
before: !!options.databaseHooks?.verification?.create?.before
|
|
483
|
+
},
|
|
484
|
+
update: {
|
|
485
|
+
after: !!options.databaseHooks?.verification?.update?.after,
|
|
486
|
+
before: !!options.databaseHooks?.verification?.update?.before
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/index.ts
|
|
495
|
+
async function createTelemetry(options, context) {
|
|
496
|
+
const debugEnabled = options.telemetry?.debug || (0, __better_auth_core_env.getBooleanEnvVar)("BETTER_AUTH_TELEMETRY_DEBUG", false);
|
|
497
|
+
const TELEMETRY_ENDPOINT = __better_auth_core_env.ENV.BETTER_AUTH_TELEMETRY_ENDPOINT;
|
|
498
|
+
const track = async (event) => {
|
|
499
|
+
if (context?.customTrack) await context.customTrack(event).catch(__better_auth_core_env.logger.error);
|
|
500
|
+
else if (debugEnabled) __better_auth_core_env.logger.info("telemetry event", JSON.stringify(event, null, 2));
|
|
501
|
+
else await (0, __better_fetch_fetch.betterFetch)(TELEMETRY_ENDPOINT, {
|
|
502
|
+
method: "POST",
|
|
503
|
+
body: event
|
|
504
|
+
}).catch(__better_auth_core_env.logger.error);
|
|
505
|
+
};
|
|
506
|
+
const isEnabled = async () => {
|
|
507
|
+
const telemetryEnabled = options.telemetry?.enabled !== void 0 ? options.telemetry.enabled : false;
|
|
508
|
+
return ((0, __better_auth_core_env.getBooleanEnvVar)("BETTER_AUTH_TELEMETRY", false) || telemetryEnabled) && (context?.skipTestCheck || !(0, __better_auth_core_env.isTest)());
|
|
509
|
+
};
|
|
510
|
+
const enabled = await isEnabled();
|
|
511
|
+
let anonymousId;
|
|
512
|
+
if (enabled) {
|
|
513
|
+
anonymousId = await getProjectId(options.baseURL);
|
|
514
|
+
track({
|
|
515
|
+
type: "init",
|
|
516
|
+
payload: {
|
|
517
|
+
config: getTelemetryAuthConfig(options),
|
|
518
|
+
runtime: detectRuntime(),
|
|
519
|
+
database: await detectDatabase(),
|
|
520
|
+
framework: await detectFramework(),
|
|
521
|
+
environment: detectEnvironment(),
|
|
522
|
+
systemInfo: await detectSystemInfo(),
|
|
523
|
+
packageManager: detectPackageManager()
|
|
524
|
+
},
|
|
525
|
+
anonymousId
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
return { publish: async (event) => {
|
|
529
|
+
if (!enabled) return;
|
|
530
|
+
if (!anonymousId) anonymousId = await getProjectId(options.baseURL);
|
|
531
|
+
await track({
|
|
532
|
+
type: event.type,
|
|
533
|
+
payload: event.payload,
|
|
534
|
+
anonymousId
|
|
535
|
+
});
|
|
536
|
+
} };
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
//#endregion
|
|
540
|
+
exports.createTelemetry = createTelemetry;
|
|
541
|
+
exports.getTelemetryAuthConfig = getTelemetryAuthConfig;
|