@playcademy/better-auth 0.0.14-beta.1 → 0.0.14-beta.3
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/server.d.ts +1 -1
- package/dist/server.js +713 -1
- package/package.json +2 -2
package/dist/server.d.ts
CHANGED
package/dist/server.js
CHANGED
|
@@ -15177,6 +15177,718 @@ var defuReplaceArrays = createDefu((obj, key, value) => {
|
|
|
15177
15177
|
return true;
|
|
15178
15178
|
}
|
|
15179
15179
|
});
|
|
15180
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/error.mjs
|
|
15181
|
+
function isErrorStackTraceLimitWritable2() {
|
|
15182
|
+
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
15183
|
+
if (desc === undefined)
|
|
15184
|
+
return Object.isExtensible(Error);
|
|
15185
|
+
return Object.prototype.hasOwnProperty.call(desc, "writable") ? desc.writable : desc.set !== undefined;
|
|
15186
|
+
}
|
|
15187
|
+
function hideInternalStackFrames2(stack) {
|
|
15188
|
+
const lines = stack.split(`
|
|
15189
|
+
at `);
|
|
15190
|
+
if (lines.length <= 1)
|
|
15191
|
+
return stack;
|
|
15192
|
+
lines.splice(1, 1);
|
|
15193
|
+
return lines.join(`
|
|
15194
|
+
at `);
|
|
15195
|
+
}
|
|
15196
|
+
function makeErrorForHideStackFrame2(Base, clazz) {
|
|
15197
|
+
|
|
15198
|
+
class HideStackFramesError extends Base {
|
|
15199
|
+
#hiddenStack;
|
|
15200
|
+
constructor(...args) {
|
|
15201
|
+
if (isErrorStackTraceLimitWritable2()) {
|
|
15202
|
+
const limit = Error.stackTraceLimit;
|
|
15203
|
+
Error.stackTraceLimit = 0;
|
|
15204
|
+
super(...args);
|
|
15205
|
+
Error.stackTraceLimit = limit;
|
|
15206
|
+
} else
|
|
15207
|
+
super(...args);
|
|
15208
|
+
const stack = (/* @__PURE__ */ new Error()).stack;
|
|
15209
|
+
if (stack)
|
|
15210
|
+
this.#hiddenStack = hideInternalStackFrames2(stack.replace(/^Error/, this.name));
|
|
15211
|
+
}
|
|
15212
|
+
get errorStack() {
|
|
15213
|
+
return this.#hiddenStack;
|
|
15214
|
+
}
|
|
15215
|
+
}
|
|
15216
|
+
Object.defineProperty(HideStackFramesError.prototype, "constructor", {
|
|
15217
|
+
get() {
|
|
15218
|
+
return clazz;
|
|
15219
|
+
},
|
|
15220
|
+
enumerable: false,
|
|
15221
|
+
configurable: true
|
|
15222
|
+
});
|
|
15223
|
+
return HideStackFramesError;
|
|
15224
|
+
}
|
|
15225
|
+
var statusCodes = {
|
|
15226
|
+
OK: 200,
|
|
15227
|
+
CREATED: 201,
|
|
15228
|
+
ACCEPTED: 202,
|
|
15229
|
+
NO_CONTENT: 204,
|
|
15230
|
+
MULTIPLE_CHOICES: 300,
|
|
15231
|
+
MOVED_PERMANENTLY: 301,
|
|
15232
|
+
FOUND: 302,
|
|
15233
|
+
SEE_OTHER: 303,
|
|
15234
|
+
NOT_MODIFIED: 304,
|
|
15235
|
+
TEMPORARY_REDIRECT: 307,
|
|
15236
|
+
BAD_REQUEST: 400,
|
|
15237
|
+
UNAUTHORIZED: 401,
|
|
15238
|
+
PAYMENT_REQUIRED: 402,
|
|
15239
|
+
FORBIDDEN: 403,
|
|
15240
|
+
NOT_FOUND: 404,
|
|
15241
|
+
METHOD_NOT_ALLOWED: 405,
|
|
15242
|
+
NOT_ACCEPTABLE: 406,
|
|
15243
|
+
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
15244
|
+
REQUEST_TIMEOUT: 408,
|
|
15245
|
+
CONFLICT: 409,
|
|
15246
|
+
GONE: 410,
|
|
15247
|
+
LENGTH_REQUIRED: 411,
|
|
15248
|
+
PRECONDITION_FAILED: 412,
|
|
15249
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
15250
|
+
URI_TOO_LONG: 414,
|
|
15251
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
15252
|
+
RANGE_NOT_SATISFIABLE: 416,
|
|
15253
|
+
EXPECTATION_FAILED: 417,
|
|
15254
|
+
"I'M_A_TEAPOT": 418,
|
|
15255
|
+
MISDIRECTED_REQUEST: 421,
|
|
15256
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
15257
|
+
LOCKED: 423,
|
|
15258
|
+
FAILED_DEPENDENCY: 424,
|
|
15259
|
+
TOO_EARLY: 425,
|
|
15260
|
+
UPGRADE_REQUIRED: 426,
|
|
15261
|
+
PRECONDITION_REQUIRED: 428,
|
|
15262
|
+
TOO_MANY_REQUESTS: 429,
|
|
15263
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
15264
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451,
|
|
15265
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
15266
|
+
NOT_IMPLEMENTED: 501,
|
|
15267
|
+
BAD_GATEWAY: 502,
|
|
15268
|
+
SERVICE_UNAVAILABLE: 503,
|
|
15269
|
+
GATEWAY_TIMEOUT: 504,
|
|
15270
|
+
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
15271
|
+
VARIANT_ALSO_NEGOTIATES: 506,
|
|
15272
|
+
INSUFFICIENT_STORAGE: 507,
|
|
15273
|
+
LOOP_DETECTED: 508,
|
|
15274
|
+
NOT_EXTENDED: 510,
|
|
15275
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511
|
|
15276
|
+
};
|
|
15277
|
+
var InternalAPIError2 = class extends Error {
|
|
15278
|
+
constructor(status = "INTERNAL_SERVER_ERROR", body = undefined, headers = {}, statusCode = typeof status === "number" ? status : statusCodes[status]) {
|
|
15279
|
+
super(body?.message, body?.cause ? { cause: body.cause } : undefined);
|
|
15280
|
+
this.status = status;
|
|
15281
|
+
this.body = body;
|
|
15282
|
+
this.headers = headers;
|
|
15283
|
+
this.statusCode = statusCode;
|
|
15284
|
+
this.name = "APIError";
|
|
15285
|
+
this.status = status;
|
|
15286
|
+
this.headers = headers;
|
|
15287
|
+
this.statusCode = statusCode;
|
|
15288
|
+
this.body = body;
|
|
15289
|
+
}
|
|
15290
|
+
};
|
|
15291
|
+
var ValidationError2 = class extends InternalAPIError2 {
|
|
15292
|
+
constructor(message2, issues) {
|
|
15293
|
+
super(400, {
|
|
15294
|
+
message: message2,
|
|
15295
|
+
code: "VALIDATION_ERROR"
|
|
15296
|
+
});
|
|
15297
|
+
this.message = message2;
|
|
15298
|
+
this.issues = issues;
|
|
15299
|
+
this.issues = issues;
|
|
15300
|
+
}
|
|
15301
|
+
};
|
|
15302
|
+
var BetterCallError = class extends Error {
|
|
15303
|
+
constructor(message2) {
|
|
15304
|
+
super(message2);
|
|
15305
|
+
this.name = "BetterCallError";
|
|
15306
|
+
}
|
|
15307
|
+
};
|
|
15308
|
+
var kAPIErrorHeaderSymbol = Symbol.for("better-call:api-error-headers");
|
|
15309
|
+
var APIError2 = makeErrorForHideStackFrame2(InternalAPIError2, Error);
|
|
15310
|
+
|
|
15311
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/utils.mjs
|
|
15312
|
+
function isAPIError2(error3) {
|
|
15313
|
+
return error3 instanceof APIError2 || error3?.name === "APIError";
|
|
15314
|
+
}
|
|
15315
|
+
function tryDecode2(str) {
|
|
15316
|
+
try {
|
|
15317
|
+
return str.includes("%") ? decodeURIComponent(str) : str;
|
|
15318
|
+
} catch {
|
|
15319
|
+
return str;
|
|
15320
|
+
}
|
|
15321
|
+
}
|
|
15322
|
+
async function tryCatch(promise) {
|
|
15323
|
+
try {
|
|
15324
|
+
return {
|
|
15325
|
+
data: await promise,
|
|
15326
|
+
error: null
|
|
15327
|
+
};
|
|
15328
|
+
} catch (error3) {
|
|
15329
|
+
return {
|
|
15330
|
+
data: null,
|
|
15331
|
+
error: error3
|
|
15332
|
+
};
|
|
15333
|
+
}
|
|
15334
|
+
}
|
|
15335
|
+
function isRequest(obj) {
|
|
15336
|
+
return obj instanceof Request || Object.prototype.toString.call(obj) === "[object Request]";
|
|
15337
|
+
}
|
|
15338
|
+
|
|
15339
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/to-response.mjs
|
|
15340
|
+
function isJSONSerializable3(value) {
|
|
15341
|
+
if (value === undefined)
|
|
15342
|
+
return false;
|
|
15343
|
+
const t = typeof value;
|
|
15344
|
+
if (t === "string" || t === "number" || t === "boolean" || t === null)
|
|
15345
|
+
return true;
|
|
15346
|
+
if (t !== "object")
|
|
15347
|
+
return false;
|
|
15348
|
+
if (Array.isArray(value))
|
|
15349
|
+
return true;
|
|
15350
|
+
if (value.buffer)
|
|
15351
|
+
return false;
|
|
15352
|
+
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
15353
|
+
}
|
|
15354
|
+
function safeStringify2(obj, replacer, space) {
|
|
15355
|
+
let id = 0;
|
|
15356
|
+
const seen = /* @__PURE__ */ new WeakMap;
|
|
15357
|
+
const safeReplacer = (key, value) => {
|
|
15358
|
+
if (typeof value === "bigint")
|
|
15359
|
+
return value.toString();
|
|
15360
|
+
if (typeof value === "object" && value !== null) {
|
|
15361
|
+
if (seen.has(value))
|
|
15362
|
+
return `[Circular ref-${seen.get(value)}]`;
|
|
15363
|
+
seen.set(value, id++);
|
|
15364
|
+
}
|
|
15365
|
+
if (replacer)
|
|
15366
|
+
return replacer(key, value);
|
|
15367
|
+
return value;
|
|
15368
|
+
};
|
|
15369
|
+
return JSON.stringify(obj, safeReplacer, space);
|
|
15370
|
+
}
|
|
15371
|
+
function isJSONResponse2(value) {
|
|
15372
|
+
if (!value || typeof value !== "object")
|
|
15373
|
+
return false;
|
|
15374
|
+
return "_flag" in value && value._flag === "json";
|
|
15375
|
+
}
|
|
15376
|
+
var REQUEST_ONLY_HEADERS = new Set([
|
|
15377
|
+
"host",
|
|
15378
|
+
"user-agent",
|
|
15379
|
+
"referer",
|
|
15380
|
+
"from",
|
|
15381
|
+
"expect",
|
|
15382
|
+
"authorization",
|
|
15383
|
+
"proxy-authorization",
|
|
15384
|
+
"cookie",
|
|
15385
|
+
"origin",
|
|
15386
|
+
"accept-charset",
|
|
15387
|
+
"accept-encoding",
|
|
15388
|
+
"accept-language",
|
|
15389
|
+
"if-match",
|
|
15390
|
+
"if-none-match",
|
|
15391
|
+
"if-modified-since",
|
|
15392
|
+
"if-unmodified-since",
|
|
15393
|
+
"if-range",
|
|
15394
|
+
"range",
|
|
15395
|
+
"max-forwards",
|
|
15396
|
+
"connection",
|
|
15397
|
+
"keep-alive",
|
|
15398
|
+
"transfer-encoding",
|
|
15399
|
+
"te",
|
|
15400
|
+
"upgrade",
|
|
15401
|
+
"trailer",
|
|
15402
|
+
"proxy-connection",
|
|
15403
|
+
"content-length"
|
|
15404
|
+
]);
|
|
15405
|
+
function stripRequestOnlyHeaders(headers) {
|
|
15406
|
+
for (const name of REQUEST_ONLY_HEADERS)
|
|
15407
|
+
headers.delete(name);
|
|
15408
|
+
}
|
|
15409
|
+
function toResponse2(data, init) {
|
|
15410
|
+
if (data instanceof Response) {
|
|
15411
|
+
if (init?.headers) {
|
|
15412
|
+
const safeHeaders = new Headers(init.headers);
|
|
15413
|
+
stripRequestOnlyHeaders(safeHeaders);
|
|
15414
|
+
safeHeaders.forEach((value, key) => {
|
|
15415
|
+
data.headers.set(key, value);
|
|
15416
|
+
});
|
|
15417
|
+
}
|
|
15418
|
+
return data;
|
|
15419
|
+
}
|
|
15420
|
+
if (isJSONResponse2(data)) {
|
|
15421
|
+
const body2 = data.body;
|
|
15422
|
+
const routerResponse = data.routerResponse;
|
|
15423
|
+
if (routerResponse instanceof Response)
|
|
15424
|
+
return routerResponse;
|
|
15425
|
+
const headers2 = new Headers;
|
|
15426
|
+
if (routerResponse?.headers) {
|
|
15427
|
+
const headers3 = new Headers(routerResponse.headers);
|
|
15428
|
+
for (const [key, value] of headers3.entries())
|
|
15429
|
+
headers3.set(key, value);
|
|
15430
|
+
}
|
|
15431
|
+
if (data.headers)
|
|
15432
|
+
for (const [key, value] of new Headers(data.headers).entries())
|
|
15433
|
+
headers2.set(key, value);
|
|
15434
|
+
if (init?.headers) {
|
|
15435
|
+
const safeHeaders = new Headers(init.headers);
|
|
15436
|
+
stripRequestOnlyHeaders(safeHeaders);
|
|
15437
|
+
for (const [key, value] of safeHeaders.entries())
|
|
15438
|
+
headers2.set(key, value);
|
|
15439
|
+
}
|
|
15440
|
+
headers2.set("Content-Type", "application/json");
|
|
15441
|
+
return new Response(JSON.stringify(body2), {
|
|
15442
|
+
...routerResponse,
|
|
15443
|
+
headers: headers2,
|
|
15444
|
+
status: data.status ?? init?.status ?? routerResponse?.status,
|
|
15445
|
+
statusText: init?.statusText ?? routerResponse?.statusText
|
|
15446
|
+
});
|
|
15447
|
+
}
|
|
15448
|
+
if (isAPIError2(data))
|
|
15449
|
+
return toResponse2(data.body, {
|
|
15450
|
+
status: init?.status ?? data.statusCode,
|
|
15451
|
+
statusText: data.status.toString(),
|
|
15452
|
+
headers: init?.headers || data.headers
|
|
15453
|
+
});
|
|
15454
|
+
let body = data;
|
|
15455
|
+
const headers = new Headers(init?.headers);
|
|
15456
|
+
stripRequestOnlyHeaders(headers);
|
|
15457
|
+
if (!data) {
|
|
15458
|
+
if (data === null)
|
|
15459
|
+
body = JSON.stringify(null);
|
|
15460
|
+
headers.set("content-type", "application/json");
|
|
15461
|
+
} else if (typeof data === "string") {
|
|
15462
|
+
body = data;
|
|
15463
|
+
headers.set("Content-Type", "text/plain");
|
|
15464
|
+
} else if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
|
|
15465
|
+
body = data;
|
|
15466
|
+
headers.set("Content-Type", "application/octet-stream");
|
|
15467
|
+
} else if (data instanceof Blob) {
|
|
15468
|
+
body = data;
|
|
15469
|
+
headers.set("Content-Type", data.type || "application/octet-stream");
|
|
15470
|
+
} else if (data instanceof FormData)
|
|
15471
|
+
body = data;
|
|
15472
|
+
else if (data instanceof URLSearchParams) {
|
|
15473
|
+
body = data;
|
|
15474
|
+
headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
15475
|
+
} else if (data instanceof ReadableStream) {
|
|
15476
|
+
body = data;
|
|
15477
|
+
headers.set("Content-Type", "application/octet-stream");
|
|
15478
|
+
} else if (isJSONSerializable3(data)) {
|
|
15479
|
+
body = safeStringify2(data);
|
|
15480
|
+
headers.set("Content-Type", "application/json");
|
|
15481
|
+
}
|
|
15482
|
+
return new Response(body, {
|
|
15483
|
+
...init,
|
|
15484
|
+
headers
|
|
15485
|
+
});
|
|
15486
|
+
}
|
|
15487
|
+
|
|
15488
|
+
// ../../node_modules/.bun/@better-auth+utils@0.4.0/node_modules/@better-auth/utils/dist/index.mjs
|
|
15489
|
+
function getWebcryptoSubtle2() {
|
|
15490
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
15491
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null)
|
|
15492
|
+
return cr.subtle;
|
|
15493
|
+
throw new Error("crypto.subtle must be defined");
|
|
15494
|
+
}
|
|
15495
|
+
|
|
15496
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/crypto.mjs
|
|
15497
|
+
var algorithm2 = {
|
|
15498
|
+
name: "HMAC",
|
|
15499
|
+
hash: "SHA-256"
|
|
15500
|
+
};
|
|
15501
|
+
var getCryptoKey2 = async (secret) => {
|
|
15502
|
+
const secretBuf = typeof secret === "string" ? new TextEncoder().encode(secret) : secret;
|
|
15503
|
+
return await getWebcryptoSubtle2().importKey("raw", secretBuf, algorithm2, false, ["sign", "verify"]);
|
|
15504
|
+
};
|
|
15505
|
+
var verifySignature2 = async (base64Signature, value, secret) => {
|
|
15506
|
+
try {
|
|
15507
|
+
const signatureBinStr = atob(base64Signature);
|
|
15508
|
+
const signature = new Uint8Array(signatureBinStr.length);
|
|
15509
|
+
for (let i = 0, len = signatureBinStr.length;i < len; i++)
|
|
15510
|
+
signature[i] = signatureBinStr.charCodeAt(i);
|
|
15511
|
+
return await getWebcryptoSubtle2().verify(algorithm2, secret, signature, new TextEncoder().encode(value));
|
|
15512
|
+
} catch (e) {
|
|
15513
|
+
return false;
|
|
15514
|
+
}
|
|
15515
|
+
};
|
|
15516
|
+
var makeSignature2 = async (value, secret) => {
|
|
15517
|
+
const key = await getCryptoKey2(secret);
|
|
15518
|
+
const signature = await getWebcryptoSubtle2().sign(algorithm2.name, key, new TextEncoder().encode(value));
|
|
15519
|
+
return btoa(String.fromCharCode(...new Uint8Array(signature)));
|
|
15520
|
+
};
|
|
15521
|
+
var signCookieValue2 = async (value, secret) => {
|
|
15522
|
+
const signature = await makeSignature2(value, secret);
|
|
15523
|
+
value = `${value}.${signature}`;
|
|
15524
|
+
value = encodeURIComponent(value);
|
|
15525
|
+
return value;
|
|
15526
|
+
};
|
|
15527
|
+
|
|
15528
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/cookies.mjs
|
|
15529
|
+
var getCookieKey2 = (key, prefix) => {
|
|
15530
|
+
let finalKey = key;
|
|
15531
|
+
if (prefix)
|
|
15532
|
+
if (prefix === "secure")
|
|
15533
|
+
finalKey = "__Secure-" + key;
|
|
15534
|
+
else if (prefix === "host")
|
|
15535
|
+
finalKey = "__Host-" + key;
|
|
15536
|
+
else
|
|
15537
|
+
return;
|
|
15538
|
+
return finalKey;
|
|
15539
|
+
};
|
|
15540
|
+
function parseCookies2(str) {
|
|
15541
|
+
if (typeof str !== "string")
|
|
15542
|
+
throw new TypeError("argument str must be a string");
|
|
15543
|
+
const cookies = /* @__PURE__ */ new Map;
|
|
15544
|
+
let index = 0;
|
|
15545
|
+
while (index < str.length) {
|
|
15546
|
+
const eqIdx = str.indexOf("=", index);
|
|
15547
|
+
if (eqIdx === -1)
|
|
15548
|
+
break;
|
|
15549
|
+
let endIdx = str.indexOf(";", index);
|
|
15550
|
+
if (endIdx === -1)
|
|
15551
|
+
endIdx = str.length;
|
|
15552
|
+
else if (endIdx < eqIdx) {
|
|
15553
|
+
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
15554
|
+
continue;
|
|
15555
|
+
}
|
|
15556
|
+
const key = str.slice(index, eqIdx).trim();
|
|
15557
|
+
if (!cookies.has(key)) {
|
|
15558
|
+
let val = str.slice(eqIdx + 1, endIdx).trim();
|
|
15559
|
+
if (val.codePointAt(0) === 34)
|
|
15560
|
+
val = val.slice(1, -1);
|
|
15561
|
+
cookies.set(key, tryDecode2(val));
|
|
15562
|
+
}
|
|
15563
|
+
index = endIdx + 1;
|
|
15564
|
+
}
|
|
15565
|
+
return cookies;
|
|
15566
|
+
}
|
|
15567
|
+
var _serialize2 = (key, value, opt = {}) => {
|
|
15568
|
+
let cookie;
|
|
15569
|
+
if (opt?.prefix === "secure")
|
|
15570
|
+
cookie = `${`__Secure-${key}`}=${value}`;
|
|
15571
|
+
else if (opt?.prefix === "host")
|
|
15572
|
+
cookie = `${`__Host-${key}`}=${value}`;
|
|
15573
|
+
else
|
|
15574
|
+
cookie = `${key}=${value}`;
|
|
15575
|
+
if (key.startsWith("__Secure-") && !opt.secure)
|
|
15576
|
+
opt.secure = true;
|
|
15577
|
+
if (key.startsWith("__Host-")) {
|
|
15578
|
+
if (!opt.secure)
|
|
15579
|
+
opt.secure = true;
|
|
15580
|
+
if (opt.path !== "/")
|
|
15581
|
+
opt.path = "/";
|
|
15582
|
+
if (opt.domain)
|
|
15583
|
+
opt.domain = undefined;
|
|
15584
|
+
}
|
|
15585
|
+
if (opt && typeof opt.maxAge === "number" && opt.maxAge >= 0) {
|
|
15586
|
+
if (opt.maxAge > 34560000)
|
|
15587
|
+
throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");
|
|
15588
|
+
cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
|
|
15589
|
+
}
|
|
15590
|
+
if (opt.domain && opt.prefix !== "host")
|
|
15591
|
+
cookie += `; Domain=${opt.domain}`;
|
|
15592
|
+
if (opt.path)
|
|
15593
|
+
cookie += `; Path=${opt.path}`;
|
|
15594
|
+
if (opt.expires) {
|
|
15595
|
+
if (opt.expires.getTime() - Date.now() > 34560000000)
|
|
15596
|
+
throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");
|
|
15597
|
+
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
|
15598
|
+
}
|
|
15599
|
+
if (opt.httpOnly)
|
|
15600
|
+
cookie += "; HttpOnly";
|
|
15601
|
+
if (opt.secure)
|
|
15602
|
+
cookie += "; Secure";
|
|
15603
|
+
if (opt.sameSite)
|
|
15604
|
+
cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
|
|
15605
|
+
if (opt.partitioned) {
|
|
15606
|
+
if (!opt.secure)
|
|
15607
|
+
opt.secure = true;
|
|
15608
|
+
cookie += "; Partitioned";
|
|
15609
|
+
}
|
|
15610
|
+
return cookie;
|
|
15611
|
+
};
|
|
15612
|
+
var serializeCookie2 = (key, value, opt) => {
|
|
15613
|
+
value = encodeURIComponent(value);
|
|
15614
|
+
return _serialize2(key, value, opt);
|
|
15615
|
+
};
|
|
15616
|
+
var serializeSignedCookie2 = async (key, value, secret, opt) => {
|
|
15617
|
+
value = await signCookieValue2(value, secret);
|
|
15618
|
+
return _serialize2(key, value, opt);
|
|
15619
|
+
};
|
|
15620
|
+
|
|
15621
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/validator.mjs
|
|
15622
|
+
async function runValidation2(options, context = {}) {
|
|
15623
|
+
let request = {
|
|
15624
|
+
body: context.body,
|
|
15625
|
+
query: context.query
|
|
15626
|
+
};
|
|
15627
|
+
if (options.body) {
|
|
15628
|
+
const result = await options.body["~standard"].validate(context.body);
|
|
15629
|
+
if (result.issues)
|
|
15630
|
+
return {
|
|
15631
|
+
data: null,
|
|
15632
|
+
error: fromError2(result.issues, "body")
|
|
15633
|
+
};
|
|
15634
|
+
request.body = result.value;
|
|
15635
|
+
}
|
|
15636
|
+
if (options.query) {
|
|
15637
|
+
const result = await options.query["~standard"].validate(context.query);
|
|
15638
|
+
if (result.issues)
|
|
15639
|
+
return {
|
|
15640
|
+
data: null,
|
|
15641
|
+
error: fromError2(result.issues, "query")
|
|
15642
|
+
};
|
|
15643
|
+
request.query = result.value;
|
|
15644
|
+
}
|
|
15645
|
+
if (options.requireHeaders && !context.headers)
|
|
15646
|
+
return {
|
|
15647
|
+
data: null,
|
|
15648
|
+
error: {
|
|
15649
|
+
message: "Headers is required",
|
|
15650
|
+
issues: []
|
|
15651
|
+
}
|
|
15652
|
+
};
|
|
15653
|
+
if (options.requireRequest && !context.request)
|
|
15654
|
+
return {
|
|
15655
|
+
data: null,
|
|
15656
|
+
error: {
|
|
15657
|
+
message: "Request is required",
|
|
15658
|
+
issues: []
|
|
15659
|
+
}
|
|
15660
|
+
};
|
|
15661
|
+
return {
|
|
15662
|
+
data: request,
|
|
15663
|
+
error: null
|
|
15664
|
+
};
|
|
15665
|
+
}
|
|
15666
|
+
function fromError2(error3, validating) {
|
|
15667
|
+
return {
|
|
15668
|
+
message: error3.map((e) => {
|
|
15669
|
+
return `[${e.path?.length ? `${validating}.` + e.path.map((x) => typeof x === "object" ? x.key : x).join(".") : validating}] ${e.message}`;
|
|
15670
|
+
}).join("; "),
|
|
15671
|
+
issues: error3
|
|
15672
|
+
};
|
|
15673
|
+
}
|
|
15674
|
+
|
|
15675
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/context.mjs
|
|
15676
|
+
var createInternalContext2 = async (context, { options, path }) => {
|
|
15677
|
+
const headers = new Headers;
|
|
15678
|
+
let responseStatus = undefined;
|
|
15679
|
+
const { data, error: error3 } = await runValidation2(options, context);
|
|
15680
|
+
if (error3)
|
|
15681
|
+
throw new ValidationError2(error3.message, error3.issues);
|
|
15682
|
+
const requestHeaders = "headers" in context ? context.headers instanceof Headers ? context.headers : new Headers(context.headers) : ("request" in context) && isRequest(context.request) ? context.request.headers : null;
|
|
15683
|
+
const requestCookies = requestHeaders?.get("cookie");
|
|
15684
|
+
const parsedCookies = requestCookies ? parseCookies2(requestCookies) : undefined;
|
|
15685
|
+
const internalContext = {
|
|
15686
|
+
...context,
|
|
15687
|
+
body: data.body,
|
|
15688
|
+
query: data.query,
|
|
15689
|
+
path: context.path || path || "virtual:",
|
|
15690
|
+
context: "context" in context && context.context ? context.context : {},
|
|
15691
|
+
returned: undefined,
|
|
15692
|
+
headers: context?.headers,
|
|
15693
|
+
request: context?.request,
|
|
15694
|
+
params: "params" in context ? context.params : undefined,
|
|
15695
|
+
method: context.method ?? (Array.isArray(options.method) ? options.method[0] : options.method === "*" ? "GET" : options.method),
|
|
15696
|
+
setHeader: (key, value) => {
|
|
15697
|
+
headers.set(key, value);
|
|
15698
|
+
},
|
|
15699
|
+
getHeader: (key) => {
|
|
15700
|
+
if (!requestHeaders)
|
|
15701
|
+
return null;
|
|
15702
|
+
return requestHeaders.get(key);
|
|
15703
|
+
},
|
|
15704
|
+
getCookie: (key, prefix) => {
|
|
15705
|
+
const finalKey = getCookieKey2(key, prefix);
|
|
15706
|
+
if (!finalKey)
|
|
15707
|
+
return null;
|
|
15708
|
+
return parsedCookies?.get(finalKey) || null;
|
|
15709
|
+
},
|
|
15710
|
+
getSignedCookie: async (key, secret, prefix) => {
|
|
15711
|
+
const finalKey = getCookieKey2(key, prefix);
|
|
15712
|
+
if (!finalKey)
|
|
15713
|
+
return null;
|
|
15714
|
+
const value = parsedCookies?.get(finalKey);
|
|
15715
|
+
if (!value)
|
|
15716
|
+
return null;
|
|
15717
|
+
const signatureStartPos = value.lastIndexOf(".");
|
|
15718
|
+
if (signatureStartPos < 1)
|
|
15719
|
+
return null;
|
|
15720
|
+
const signedValue = value.substring(0, signatureStartPos);
|
|
15721
|
+
const signature = value.substring(signatureStartPos + 1);
|
|
15722
|
+
if (signature.length !== 44 || !signature.endsWith("="))
|
|
15723
|
+
return null;
|
|
15724
|
+
return await verifySignature2(signature, signedValue, await getCryptoKey2(secret)) ? signedValue : false;
|
|
15725
|
+
},
|
|
15726
|
+
setCookie: (key, value, options2) => {
|
|
15727
|
+
const cookie = serializeCookie2(key, value, options2);
|
|
15728
|
+
headers.append("set-cookie", cookie);
|
|
15729
|
+
return cookie;
|
|
15730
|
+
},
|
|
15731
|
+
setSignedCookie: async (key, value, secret, options2) => {
|
|
15732
|
+
const cookie = await serializeSignedCookie2(key, value, secret, options2);
|
|
15733
|
+
headers.append("set-cookie", cookie);
|
|
15734
|
+
return cookie;
|
|
15735
|
+
},
|
|
15736
|
+
redirect: (url) => {
|
|
15737
|
+
headers.set("location", url);
|
|
15738
|
+
return new APIError2("FOUND", undefined, headers);
|
|
15739
|
+
},
|
|
15740
|
+
error: (status, body, headers2) => {
|
|
15741
|
+
return new APIError2(status, body, headers2);
|
|
15742
|
+
},
|
|
15743
|
+
setStatus: (status) => {
|
|
15744
|
+
responseStatus = status;
|
|
15745
|
+
},
|
|
15746
|
+
json: (json, routerResponse) => {
|
|
15747
|
+
if (!context.asResponse)
|
|
15748
|
+
return json;
|
|
15749
|
+
return {
|
|
15750
|
+
body: routerResponse?.body || json,
|
|
15751
|
+
routerResponse,
|
|
15752
|
+
_flag: "json"
|
|
15753
|
+
};
|
|
15754
|
+
},
|
|
15755
|
+
responseHeaders: headers,
|
|
15756
|
+
get responseStatus() {
|
|
15757
|
+
return responseStatus;
|
|
15758
|
+
}
|
|
15759
|
+
};
|
|
15760
|
+
for (const middleware of options.use || []) {
|
|
15761
|
+
const response = await middleware({
|
|
15762
|
+
...internalContext,
|
|
15763
|
+
returnHeaders: true,
|
|
15764
|
+
asResponse: false
|
|
15765
|
+
});
|
|
15766
|
+
if (response.response)
|
|
15767
|
+
Object.assign(internalContext.context, response.response);
|
|
15768
|
+
if (response.headers)
|
|
15769
|
+
response.headers.forEach((value, key) => {
|
|
15770
|
+
internalContext.responseHeaders.set(key, value);
|
|
15771
|
+
});
|
|
15772
|
+
}
|
|
15773
|
+
return internalContext;
|
|
15774
|
+
};
|
|
15775
|
+
|
|
15776
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/endpoint.mjs
|
|
15777
|
+
function createEndpoint(pathOrOptions, handlerOrOptions, handlerOrNever) {
|
|
15778
|
+
const path = typeof pathOrOptions === "string" ? pathOrOptions : undefined;
|
|
15779
|
+
const options = typeof handlerOrOptions === "object" ? handlerOrOptions : pathOrOptions;
|
|
15780
|
+
const handler = typeof handlerOrOptions === "function" ? handlerOrOptions : handlerOrNever;
|
|
15781
|
+
if ((options.method === "GET" || options.method === "HEAD") && options.body)
|
|
15782
|
+
throw new BetterCallError("Body is not allowed with GET or HEAD methods");
|
|
15783
|
+
if (path && /\/{2,}/.test(path))
|
|
15784
|
+
throw new BetterCallError("Path cannot contain consecutive slashes");
|
|
15785
|
+
const internalHandler = async (...inputCtx) => {
|
|
15786
|
+
const context = inputCtx[0] || {};
|
|
15787
|
+
const { data: internalContext, error: validationError } = await tryCatch(createInternalContext2(context, {
|
|
15788
|
+
options,
|
|
15789
|
+
path
|
|
15790
|
+
}));
|
|
15791
|
+
if (validationError) {
|
|
15792
|
+
if (!(validationError instanceof ValidationError2))
|
|
15793
|
+
throw validationError;
|
|
15794
|
+
if (options.onValidationError)
|
|
15795
|
+
await options.onValidationError({
|
|
15796
|
+
message: validationError.message,
|
|
15797
|
+
issues: validationError.issues
|
|
15798
|
+
});
|
|
15799
|
+
throw new APIError2(400, {
|
|
15800
|
+
message: validationError.message,
|
|
15801
|
+
code: "VALIDATION_ERROR"
|
|
15802
|
+
});
|
|
15803
|
+
}
|
|
15804
|
+
const response = await handler(internalContext).catch(async (e) => {
|
|
15805
|
+
if (isAPIError2(e)) {
|
|
15806
|
+
const onAPIError = options.onAPIError;
|
|
15807
|
+
if (onAPIError)
|
|
15808
|
+
await onAPIError(e);
|
|
15809
|
+
if (context.asResponse)
|
|
15810
|
+
return e;
|
|
15811
|
+
}
|
|
15812
|
+
throw e;
|
|
15813
|
+
});
|
|
15814
|
+
const headers = internalContext.responseHeaders;
|
|
15815
|
+
const status = internalContext.responseStatus;
|
|
15816
|
+
return context.asResponse ? toResponse2(response, {
|
|
15817
|
+
headers,
|
|
15818
|
+
status
|
|
15819
|
+
}) : context.returnHeaders ? context.returnStatus ? {
|
|
15820
|
+
headers,
|
|
15821
|
+
response,
|
|
15822
|
+
status
|
|
15823
|
+
} : {
|
|
15824
|
+
headers,
|
|
15825
|
+
response
|
|
15826
|
+
} : context.returnStatus ? {
|
|
15827
|
+
response,
|
|
15828
|
+
status
|
|
15829
|
+
} : response;
|
|
15830
|
+
};
|
|
15831
|
+
internalHandler.options = options;
|
|
15832
|
+
internalHandler.path = path;
|
|
15833
|
+
return internalHandler;
|
|
15834
|
+
}
|
|
15835
|
+
createEndpoint.create = (opts) => {
|
|
15836
|
+
return (path, options, handler) => {
|
|
15837
|
+
return createEndpoint(path, {
|
|
15838
|
+
...options,
|
|
15839
|
+
use: [...options?.use || [], ...opts?.use || []]
|
|
15840
|
+
}, handler);
|
|
15841
|
+
};
|
|
15842
|
+
};
|
|
15843
|
+
|
|
15844
|
+
// ../../node_modules/.bun/better-call@1.3.5+3c5d820c62823f0b/node_modules/better-call/dist/middleware.mjs
|
|
15845
|
+
function createMiddleware2(optionsOrHandler, handler) {
|
|
15846
|
+
const internalHandler = async (inputCtx) => {
|
|
15847
|
+
const context = inputCtx;
|
|
15848
|
+
const _handler = typeof optionsOrHandler === "function" ? optionsOrHandler : handler;
|
|
15849
|
+
const internalContext = await createInternalContext2(context, {
|
|
15850
|
+
options: typeof optionsOrHandler === "function" ? {} : optionsOrHandler,
|
|
15851
|
+
path: "/"
|
|
15852
|
+
});
|
|
15853
|
+
if (!_handler)
|
|
15854
|
+
throw new Error("handler must be defined");
|
|
15855
|
+
try {
|
|
15856
|
+
const response = await _handler(internalContext);
|
|
15857
|
+
const headers = internalContext.responseHeaders;
|
|
15858
|
+
return context.returnHeaders ? {
|
|
15859
|
+
headers,
|
|
15860
|
+
response
|
|
15861
|
+
} : response;
|
|
15862
|
+
} catch (e) {
|
|
15863
|
+
if (isAPIError2(e))
|
|
15864
|
+
Object.defineProperty(e, kAPIErrorHeaderSymbol, {
|
|
15865
|
+
enumerable: false,
|
|
15866
|
+
configurable: true,
|
|
15867
|
+
get() {
|
|
15868
|
+
return internalContext.responseHeaders;
|
|
15869
|
+
}
|
|
15870
|
+
});
|
|
15871
|
+
throw e;
|
|
15872
|
+
}
|
|
15873
|
+
};
|
|
15874
|
+
internalHandler.options = typeof optionsOrHandler === "function" ? {} : optionsOrHandler;
|
|
15875
|
+
return internalHandler;
|
|
15876
|
+
}
|
|
15877
|
+
createMiddleware2.create = (opts) => {
|
|
15878
|
+
function fn(optionsOrHandler, handler) {
|
|
15879
|
+
if (typeof optionsOrHandler === "function")
|
|
15880
|
+
return createMiddleware2({ use: opts?.use }, optionsOrHandler);
|
|
15881
|
+
if (!handler)
|
|
15882
|
+
throw new Error("Middleware handler is required");
|
|
15883
|
+
return createMiddleware2({
|
|
15884
|
+
...optionsOrHandler,
|
|
15885
|
+
method: "*",
|
|
15886
|
+
use: [...opts?.use || [], ...optionsOrHandler.use || []]
|
|
15887
|
+
}, handler);
|
|
15888
|
+
}
|
|
15889
|
+
return fn;
|
|
15890
|
+
};
|
|
15891
|
+
|
|
15180
15892
|
// ../sdk/dist/server.js
|
|
15181
15893
|
import { existsSync, readdirSync, statSync } from "fs";
|
|
15182
15894
|
import { readFile } from "fs/promises";
|
|
@@ -15761,7 +16473,7 @@ async function hasValidSession(adapter, sessionToken, userId) {
|
|
|
15761
16473
|
}
|
|
15762
16474
|
async function buildCrossSiteCookie(options) {
|
|
15763
16475
|
const { cookieName, sessionToken, secret, maxAge, path, userAgent, domain } = options;
|
|
15764
|
-
const signed = await
|
|
16476
|
+
const signed = await serializeSignedCookie2(cookieName, sessionToken, secret);
|
|
15765
16477
|
const nameValue = signed.split(";")[0];
|
|
15766
16478
|
const parts = [nameValue, `Max-Age=${maxAge}`, `Path=${path}`];
|
|
15767
16479
|
if (domain) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcademy/better-auth",
|
|
3
|
-
"version": "0.0.14-beta.
|
|
3
|
+
"version": "0.0.14-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@inquirer/prompts": "^7.9.0",
|
|
34
34
|
"@playcademy/utils": "0.0.1",
|
|
35
|
-
"@types/bun": "
|
|
35
|
+
"@types/bun": "1.3.5",
|
|
36
36
|
"typescript": "^5.7.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|