@1sat/connect 0.0.14 → 0.0.15
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/connectWallet.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3701 -87
- package/dist/sigma-oauth.d.ts +962 -24
- package/dist/sigma-oauth.d.ts.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -259,7 +259,7 @@ __export(exports_buffer, {
|
|
|
259
259
|
default: () => buffer_default,
|
|
260
260
|
constants: () => constants,
|
|
261
261
|
btoa: () => btoa2,
|
|
262
|
-
atob: () =>
|
|
262
|
+
atob: () => atob2,
|
|
263
263
|
INSPECT_MAX_BYTES: () => INSPECT_MAX_BYTES,
|
|
264
264
|
File: () => File,
|
|
265
265
|
Buffer: () => Buffer2,
|
|
@@ -932,7 +932,7 @@ function notimpl(name) {
|
|
|
932
932
|
throw Error(name + " is not implemented for node:buffer browser polyfill");
|
|
933
933
|
};
|
|
934
934
|
}
|
|
935
|
-
var lookup, revLookup, code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i, len, customInspectSymbol, INSPECT_MAX_BYTES = 50, kMaxLength = 2147483647, kStringMaxLength = 536870888, btoa2,
|
|
935
|
+
var lookup, revLookup, code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i, len, customInspectSymbol, INSPECT_MAX_BYTES = 50, kMaxLength = 2147483647, kStringMaxLength = 536870888, btoa2, atob2, File, Blob2, constants, ERR_BUFFER_OUT_OF_BOUNDS, ERR_INVALID_ARG_TYPE, ERR_OUT_OF_RANGE, MAX_ARGUMENTS_LENGTH = 4096, INVALID_BASE64_RE, hexSliceLookupTable, resolveObjectURL, isUtf8, isAscii = (str) => {
|
|
936
936
|
for (let char of str)
|
|
937
937
|
if (char.charCodeAt(0) > 127)
|
|
938
938
|
return false;
|
|
@@ -947,7 +947,7 @@ var init_buffer = __esm(() => {
|
|
|
947
947
|
revLookup[95] = 63;
|
|
948
948
|
customInspectSymbol = typeof Symbol === "function" && typeof Symbol.for === "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
|
|
949
949
|
btoa2 = globalThis.btoa;
|
|
950
|
-
|
|
950
|
+
atob2 = globalThis.atob;
|
|
951
951
|
File = globalThis.File;
|
|
952
952
|
Blob2 = globalThis.Blob;
|
|
953
953
|
constants = { MAX_LENGTH: kMaxLength, MAX_STRING_LENGTH: kStringMaxLength };
|
|
@@ -114948,90 +114948,3699 @@ class GlobalKVStore5 {
|
|
|
114948
114948
|
return await this.topicBroadcaster.broadcast(transaction5);
|
|
114949
114949
|
}
|
|
114950
114950
|
}
|
|
114951
|
-
//
|
|
114952
|
-
|
|
114953
|
-
|
|
114954
|
-
|
|
114955
|
-
|
|
114956
|
-
|
|
114957
|
-
|
|
114958
|
-
|
|
114959
|
-
|
|
114960
|
-
|
|
114951
|
+
// ../../node_modules/@better-auth/core/dist/utils/error-codes.mjs
|
|
114952
|
+
function defineErrorCodes(codes) {
|
|
114953
|
+
return Object.fromEntries(Object.entries(codes).map(([key, value]) => [key, {
|
|
114954
|
+
code: key,
|
|
114955
|
+
message: value,
|
|
114956
|
+
toString: () => key
|
|
114957
|
+
}]));
|
|
114958
|
+
}
|
|
114959
|
+
|
|
114960
|
+
// ../../node_modules/better-auth/dist/plugins/admin/error-codes.mjs
|
|
114961
|
+
var ADMIN_ERROR_CODES = defineErrorCodes({
|
|
114962
|
+
FAILED_TO_CREATE_USER: "Failed to create user",
|
|
114963
|
+
USER_ALREADY_EXISTS: "User already exists.",
|
|
114964
|
+
USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.",
|
|
114965
|
+
YOU_CANNOT_BAN_YOURSELF: "You cannot ban yourself",
|
|
114966
|
+
YOU_ARE_NOT_ALLOWED_TO_CHANGE_USERS_ROLE: "You are not allowed to change users role",
|
|
114967
|
+
YOU_ARE_NOT_ALLOWED_TO_CREATE_USERS: "You are not allowed to create users",
|
|
114968
|
+
YOU_ARE_NOT_ALLOWED_TO_LIST_USERS: "You are not allowed to list users",
|
|
114969
|
+
YOU_ARE_NOT_ALLOWED_TO_LIST_USERS_SESSIONS: "You are not allowed to list users sessions",
|
|
114970
|
+
YOU_ARE_NOT_ALLOWED_TO_BAN_USERS: "You are not allowed to ban users",
|
|
114971
|
+
YOU_ARE_NOT_ALLOWED_TO_IMPERSONATE_USERS: "You are not allowed to impersonate users",
|
|
114972
|
+
YOU_ARE_NOT_ALLOWED_TO_REVOKE_USERS_SESSIONS: "You are not allowed to revoke users sessions",
|
|
114973
|
+
YOU_ARE_NOT_ALLOWED_TO_DELETE_USERS: "You are not allowed to delete users",
|
|
114974
|
+
YOU_ARE_NOT_ALLOWED_TO_SET_USERS_PASSWORD: "You are not allowed to set users password",
|
|
114975
|
+
BANNED_USER: "You have been banned from this application",
|
|
114976
|
+
YOU_ARE_NOT_ALLOWED_TO_GET_USER: "You are not allowed to get user",
|
|
114977
|
+
NO_DATA_TO_UPDATE: "No data to update",
|
|
114978
|
+
YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS: "You are not allowed to update users",
|
|
114979
|
+
YOU_CANNOT_REMOVE_YOURSELF: "You cannot remove yourself",
|
|
114980
|
+
YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE: "You are not allowed to set a non-existent role value",
|
|
114981
|
+
YOU_CANNOT_IMPERSONATE_ADMINS: "You cannot impersonate admins",
|
|
114982
|
+
INVALID_ROLE_TYPE: "Invalid role type"
|
|
114983
|
+
});
|
|
114984
|
+
|
|
114985
|
+
// ../../node_modules/@better-auth/core/dist/error/codes.mjs
|
|
114986
|
+
var BASE_ERROR_CODES = defineErrorCodes({
|
|
114987
|
+
USER_NOT_FOUND: "User not found",
|
|
114988
|
+
FAILED_TO_CREATE_USER: "Failed to create user",
|
|
114989
|
+
FAILED_TO_CREATE_SESSION: "Failed to create session",
|
|
114990
|
+
FAILED_TO_UPDATE_USER: "Failed to update user",
|
|
114991
|
+
FAILED_TO_GET_SESSION: "Failed to get session",
|
|
114992
|
+
INVALID_PASSWORD: "Invalid password",
|
|
114993
|
+
INVALID_EMAIL: "Invalid email",
|
|
114994
|
+
INVALID_EMAIL_OR_PASSWORD: "Invalid email or password",
|
|
114995
|
+
INVALID_USER: "Invalid user",
|
|
114996
|
+
SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked",
|
|
114997
|
+
PROVIDER_NOT_FOUND: "Provider not found",
|
|
114998
|
+
INVALID_TOKEN: "Invalid token",
|
|
114999
|
+
TOKEN_EXPIRED: "Token expired",
|
|
115000
|
+
ID_TOKEN_NOT_SUPPORTED: "id_token not supported",
|
|
115001
|
+
FAILED_TO_GET_USER_INFO: "Failed to get user info",
|
|
115002
|
+
USER_EMAIL_NOT_FOUND: "User email not found",
|
|
115003
|
+
EMAIL_NOT_VERIFIED: "Email not verified",
|
|
115004
|
+
PASSWORD_TOO_SHORT: "Password too short",
|
|
115005
|
+
PASSWORD_TOO_LONG: "Password too long",
|
|
115006
|
+
USER_ALREADY_EXISTS: "User already exists.",
|
|
115007
|
+
USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.",
|
|
115008
|
+
EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated",
|
|
115009
|
+
CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found",
|
|
115010
|
+
SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.",
|
|
115011
|
+
FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account",
|
|
115012
|
+
ACCOUNT_NOT_FOUND: "Account not found",
|
|
115013
|
+
USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.",
|
|
115014
|
+
CROSS_SITE_NAVIGATION_LOGIN_BLOCKED: "Cross-site navigation login blocked. This request appears to be a CSRF attack.",
|
|
115015
|
+
VERIFICATION_EMAIL_NOT_ENABLED: "Verification email isn't enabled",
|
|
115016
|
+
EMAIL_ALREADY_VERIFIED: "Email is already verified",
|
|
115017
|
+
EMAIL_MISMATCH: "Email mismatch",
|
|
115018
|
+
SESSION_NOT_FRESH: "Session is not fresh",
|
|
115019
|
+
LINKED_ACCOUNT_ALREADY_EXISTS: "Linked account already exists",
|
|
115020
|
+
INVALID_ORIGIN: "Invalid origin",
|
|
115021
|
+
INVALID_CALLBACK_URL: "Invalid callbackURL",
|
|
115022
|
+
INVALID_REDIRECT_URL: "Invalid redirectURL",
|
|
115023
|
+
INVALID_ERROR_CALLBACK_URL: "Invalid errorCallbackURL",
|
|
115024
|
+
INVALID_NEW_USER_CALLBACK_URL: "Invalid newUserCallbackURL",
|
|
115025
|
+
MISSING_OR_NULL_ORIGIN: "Missing or null Origin",
|
|
115026
|
+
CALLBACK_URL_REQUIRED: "callbackURL is required",
|
|
115027
|
+
FAILED_TO_CREATE_VERIFICATION: "Unable to create verification",
|
|
115028
|
+
FIELD_NOT_ALLOWED: "Field not allowed to be set",
|
|
115029
|
+
ASYNC_VALIDATION_NOT_SUPPORTED: "Async validation is not supported",
|
|
115030
|
+
VALIDATION_ERROR: "Validation Error",
|
|
115031
|
+
MISSING_FIELD: "Field is required",
|
|
115032
|
+
METHOD_NOT_ALLOWED_DEFER_SESSION_REQUIRED: "POST method requires deferSessionRefresh to be enabled in session config",
|
|
115033
|
+
BODY_MUST_BE_AN_OBJECT: "Body must be an object",
|
|
115034
|
+
PASSWORD_ALREADY_SET: "User already has a password set"
|
|
115035
|
+
});
|
|
115036
|
+
|
|
115037
|
+
// ../../node_modules/better-call/dist/error.mjs
|
|
115038
|
+
function isErrorStackTraceLimitWritable() {
|
|
115039
|
+
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
115040
|
+
if (desc === undefined)
|
|
115041
|
+
return Object.isExtensible(Error);
|
|
115042
|
+
return Object.prototype.hasOwnProperty.call(desc, "writable") ? desc.writable : desc.set !== undefined;
|
|
115043
|
+
}
|
|
115044
|
+
function hideInternalStackFrames(stack) {
|
|
115045
|
+
const lines = stack.split(`
|
|
115046
|
+
at `);
|
|
115047
|
+
if (lines.length <= 1)
|
|
115048
|
+
return stack;
|
|
115049
|
+
lines.splice(1, 1);
|
|
115050
|
+
return lines.join(`
|
|
115051
|
+
at `);
|
|
115052
|
+
}
|
|
115053
|
+
function makeErrorForHideStackFrame(Base, clazz) {
|
|
115054
|
+
|
|
115055
|
+
class HideStackFramesError extends Base {
|
|
115056
|
+
#hiddenStack;
|
|
115057
|
+
constructor(...args) {
|
|
115058
|
+
if (isErrorStackTraceLimitWritable()) {
|
|
115059
|
+
const limit = Error.stackTraceLimit;
|
|
115060
|
+
Error.stackTraceLimit = 0;
|
|
115061
|
+
super(...args);
|
|
115062
|
+
Error.stackTraceLimit = limit;
|
|
115063
|
+
} else
|
|
115064
|
+
super(...args);
|
|
115065
|
+
const stack = (/* @__PURE__ */ new Error()).stack;
|
|
115066
|
+
if (stack)
|
|
115067
|
+
this.#hiddenStack = hideInternalStackFrames(stack.replace(/^Error/, this.name));
|
|
115068
|
+
}
|
|
115069
|
+
get errorStack() {
|
|
115070
|
+
return this.#hiddenStack;
|
|
115071
|
+
}
|
|
115072
|
+
}
|
|
115073
|
+
Object.defineProperty(HideStackFramesError.prototype, "constructor", {
|
|
115074
|
+
get() {
|
|
115075
|
+
return clazz;
|
|
115076
|
+
},
|
|
115077
|
+
enumerable: false,
|
|
115078
|
+
configurable: true
|
|
115079
|
+
});
|
|
115080
|
+
return HideStackFramesError;
|
|
115081
|
+
}
|
|
115082
|
+
var statusCodes = {
|
|
115083
|
+
OK: 200,
|
|
115084
|
+
CREATED: 201,
|
|
115085
|
+
ACCEPTED: 202,
|
|
115086
|
+
NO_CONTENT: 204,
|
|
115087
|
+
MULTIPLE_CHOICES: 300,
|
|
115088
|
+
MOVED_PERMANENTLY: 301,
|
|
115089
|
+
FOUND: 302,
|
|
115090
|
+
SEE_OTHER: 303,
|
|
115091
|
+
NOT_MODIFIED: 304,
|
|
115092
|
+
TEMPORARY_REDIRECT: 307,
|
|
115093
|
+
BAD_REQUEST: 400,
|
|
115094
|
+
UNAUTHORIZED: 401,
|
|
115095
|
+
PAYMENT_REQUIRED: 402,
|
|
115096
|
+
FORBIDDEN: 403,
|
|
115097
|
+
NOT_FOUND: 404,
|
|
115098
|
+
METHOD_NOT_ALLOWED: 405,
|
|
115099
|
+
NOT_ACCEPTABLE: 406,
|
|
115100
|
+
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
115101
|
+
REQUEST_TIMEOUT: 408,
|
|
115102
|
+
CONFLICT: 409,
|
|
115103
|
+
GONE: 410,
|
|
115104
|
+
LENGTH_REQUIRED: 411,
|
|
115105
|
+
PRECONDITION_FAILED: 412,
|
|
115106
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
115107
|
+
URI_TOO_LONG: 414,
|
|
115108
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
115109
|
+
RANGE_NOT_SATISFIABLE: 416,
|
|
115110
|
+
EXPECTATION_FAILED: 417,
|
|
115111
|
+
"I'M_A_TEAPOT": 418,
|
|
115112
|
+
MISDIRECTED_REQUEST: 421,
|
|
115113
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
115114
|
+
LOCKED: 423,
|
|
115115
|
+
FAILED_DEPENDENCY: 424,
|
|
115116
|
+
TOO_EARLY: 425,
|
|
115117
|
+
UPGRADE_REQUIRED: 426,
|
|
115118
|
+
PRECONDITION_REQUIRED: 428,
|
|
115119
|
+
TOO_MANY_REQUESTS: 429,
|
|
115120
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
115121
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451,
|
|
115122
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
115123
|
+
NOT_IMPLEMENTED: 501,
|
|
115124
|
+
BAD_GATEWAY: 502,
|
|
115125
|
+
SERVICE_UNAVAILABLE: 503,
|
|
115126
|
+
GATEWAY_TIMEOUT: 504,
|
|
115127
|
+
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
115128
|
+
VARIANT_ALSO_NEGOTIATES: 506,
|
|
115129
|
+
INSUFFICIENT_STORAGE: 507,
|
|
115130
|
+
LOOP_DETECTED: 508,
|
|
115131
|
+
NOT_EXTENDED: 510,
|
|
115132
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511
|
|
115133
|
+
};
|
|
115134
|
+
var InternalAPIError = class extends Error {
|
|
115135
|
+
constructor(status = "INTERNAL_SERVER_ERROR", body = undefined, headers = {}, statusCode = typeof status === "number" ? status : statusCodes[status]) {
|
|
115136
|
+
super(body?.message, body?.cause ? { cause: body.cause } : undefined);
|
|
115137
|
+
this.status = status;
|
|
115138
|
+
this.body = body;
|
|
115139
|
+
this.headers = headers;
|
|
115140
|
+
this.statusCode = statusCode;
|
|
115141
|
+
this.name = "APIError";
|
|
115142
|
+
this.status = status;
|
|
115143
|
+
this.headers = headers;
|
|
115144
|
+
this.statusCode = statusCode;
|
|
115145
|
+
this.body = body;
|
|
115146
|
+
}
|
|
115147
|
+
};
|
|
115148
|
+
var kAPIErrorHeaderSymbol = Symbol.for("better-call:api-error-headers");
|
|
115149
|
+
var APIError = makeErrorForHideStackFrame(InternalAPIError, Error);
|
|
115150
|
+
|
|
115151
|
+
// ../../node_modules/@better-auth/core/dist/error/index.mjs
|
|
115152
|
+
var BetterAuthError = class extends Error {
|
|
115153
|
+
constructor(message, options) {
|
|
115154
|
+
super(message, options);
|
|
115155
|
+
this.name = "BetterAuthError";
|
|
115156
|
+
this.message = message;
|
|
115157
|
+
this.stack = "";
|
|
115158
|
+
}
|
|
115159
|
+
};
|
|
115160
|
+
|
|
115161
|
+
// ../../node_modules/better-auth/dist/plugins/access/access.mjs
|
|
115162
|
+
function role(statements) {
|
|
115163
|
+
return {
|
|
115164
|
+
authorize(request3, connector = "AND") {
|
|
115165
|
+
let success = false;
|
|
115166
|
+
for (const [requestedResource, requestedActions] of Object.entries(request3)) {
|
|
115167
|
+
const allowedActions = statements[requestedResource];
|
|
115168
|
+
if (!allowedActions)
|
|
115169
|
+
return {
|
|
115170
|
+
success: false,
|
|
115171
|
+
error: `You are not allowed to access resource: ${requestedResource}`
|
|
115172
|
+
};
|
|
115173
|
+
if (Array.isArray(requestedActions))
|
|
115174
|
+
success = requestedActions.every((requestedAction) => allowedActions.includes(requestedAction));
|
|
115175
|
+
else if (typeof requestedActions === "object") {
|
|
115176
|
+
const actions = requestedActions;
|
|
115177
|
+
if (actions.connector === "OR")
|
|
115178
|
+
success = actions.actions.some((requestedAction) => allowedActions.includes(requestedAction));
|
|
115179
|
+
else
|
|
115180
|
+
success = actions.actions.every((requestedAction) => allowedActions.includes(requestedAction));
|
|
115181
|
+
} else
|
|
115182
|
+
throw new BetterAuthError("Invalid access control request");
|
|
115183
|
+
if (success && connector === "OR")
|
|
115184
|
+
return { success };
|
|
115185
|
+
if (!success && connector === "AND")
|
|
115186
|
+
return {
|
|
115187
|
+
success: false,
|
|
115188
|
+
error: `unauthorized to access resource "${requestedResource}"`
|
|
115189
|
+
};
|
|
115190
|
+
}
|
|
115191
|
+
if (success)
|
|
115192
|
+
return { success };
|
|
115193
|
+
return {
|
|
115194
|
+
success: false,
|
|
115195
|
+
error: "Not authorized"
|
|
115196
|
+
};
|
|
115197
|
+
},
|
|
115198
|
+
statements
|
|
115199
|
+
};
|
|
114961
115200
|
}
|
|
114962
|
-
function
|
|
114963
|
-
|
|
114964
|
-
|
|
114965
|
-
|
|
115201
|
+
function createAccessControl(s6) {
|
|
115202
|
+
return {
|
|
115203
|
+
newRole(statements) {
|
|
115204
|
+
return role(statements);
|
|
115205
|
+
},
|
|
115206
|
+
statements: s6
|
|
115207
|
+
};
|
|
115208
|
+
}
|
|
115209
|
+
|
|
115210
|
+
// ../../node_modules/better-auth/dist/plugins/admin/access/statement.mjs
|
|
115211
|
+
var defaultStatements = {
|
|
115212
|
+
user: [
|
|
115213
|
+
"create",
|
|
115214
|
+
"list",
|
|
115215
|
+
"set-role",
|
|
115216
|
+
"ban",
|
|
115217
|
+
"impersonate",
|
|
115218
|
+
"impersonate-admins",
|
|
115219
|
+
"delete",
|
|
115220
|
+
"set-password",
|
|
115221
|
+
"get",
|
|
115222
|
+
"update"
|
|
115223
|
+
],
|
|
115224
|
+
session: [
|
|
115225
|
+
"list",
|
|
115226
|
+
"revoke",
|
|
115227
|
+
"delete"
|
|
115228
|
+
]
|
|
115229
|
+
};
|
|
115230
|
+
var defaultAc = createAccessControl(defaultStatements);
|
|
115231
|
+
var adminAc = defaultAc.newRole({
|
|
115232
|
+
user: [
|
|
115233
|
+
"create",
|
|
115234
|
+
"list",
|
|
115235
|
+
"set-role",
|
|
115236
|
+
"ban",
|
|
115237
|
+
"impersonate",
|
|
115238
|
+
"delete",
|
|
115239
|
+
"set-password",
|
|
115240
|
+
"get",
|
|
115241
|
+
"update"
|
|
115242
|
+
],
|
|
115243
|
+
session: [
|
|
115244
|
+
"list",
|
|
115245
|
+
"revoke",
|
|
115246
|
+
"delete"
|
|
115247
|
+
]
|
|
115248
|
+
});
|
|
115249
|
+
var userAc = defaultAc.newRole({
|
|
115250
|
+
user: [],
|
|
115251
|
+
session: []
|
|
115252
|
+
});
|
|
115253
|
+
|
|
115254
|
+
// ../../node_modules/better-auth/dist/plugins/anonymous/error-codes.mjs
|
|
115255
|
+
var ANONYMOUS_ERROR_CODES = defineErrorCodes({
|
|
115256
|
+
INVALID_EMAIL_FORMAT: "Email was not generated in a valid format",
|
|
115257
|
+
FAILED_TO_CREATE_USER: "Failed to create user",
|
|
115258
|
+
COULD_NOT_CREATE_SESSION: "Could not create session",
|
|
115259
|
+
ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY: "Anonymous users cannot sign in again anonymously",
|
|
115260
|
+
FAILED_TO_DELETE_ANONYMOUS_USER: "Failed to delete anonymous user",
|
|
115261
|
+
USER_IS_NOT_ANONYMOUS: "User is not anonymous",
|
|
115262
|
+
DELETE_ANONYMOUS_USER_DISABLED: "Deleting anonymous users is disabled"
|
|
115263
|
+
});
|
|
115264
|
+
|
|
115265
|
+
// ../../node_modules/better-auth/dist/plugins/email-otp/error-codes.mjs
|
|
115266
|
+
var EMAIL_OTP_ERROR_CODES = defineErrorCodes({
|
|
115267
|
+
OTP_EXPIRED: "OTP expired",
|
|
115268
|
+
INVALID_OTP: "Invalid OTP",
|
|
115269
|
+
TOO_MANY_ATTEMPTS: "Too many attempts"
|
|
115270
|
+
});
|
|
115271
|
+
|
|
115272
|
+
// ../../node_modules/better-auth/dist/plugins/generic-oauth/error-codes.mjs
|
|
115273
|
+
var GENERIC_OAUTH_ERROR_CODES = defineErrorCodes({
|
|
115274
|
+
INVALID_OAUTH_CONFIGURATION: "Invalid OAuth configuration",
|
|
115275
|
+
TOKEN_URL_NOT_FOUND: "Invalid OAuth configuration. Token URL not found.",
|
|
115276
|
+
PROVIDER_CONFIG_NOT_FOUND: "No config found for provider",
|
|
115277
|
+
PROVIDER_ID_REQUIRED: "Provider ID is required",
|
|
115278
|
+
INVALID_OAUTH_CONFIG: "Invalid OAuth configuration.",
|
|
115279
|
+
SESSION_REQUIRED: "Session is required",
|
|
115280
|
+
ISSUER_MISMATCH: "OAuth issuer mismatch. The authorization server issuer does not match the expected value (RFC 9207).",
|
|
115281
|
+
ISSUER_MISSING: "OAuth issuer parameter missing. The authorization server did not include the required iss parameter (RFC 9207)."
|
|
115282
|
+
});
|
|
115283
|
+
|
|
115284
|
+
// ../../node_modules/better-auth/dist/plugins/multi-session/error-codes.mjs
|
|
115285
|
+
var MULTI_SESSION_ERROR_CODES = defineErrorCodes({ INVALID_SESSION_TOKEN: "Invalid session token" });
|
|
115286
|
+
|
|
115287
|
+
// ../../node_modules/better-auth/dist/plugins/organization/error-codes.mjs
|
|
115288
|
+
var ORGANIZATION_ERROR_CODES = defineErrorCodes({
|
|
115289
|
+
YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION: "You are not allowed to create a new organization",
|
|
115290
|
+
YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS: "You have reached the maximum number of organizations",
|
|
115291
|
+
ORGANIZATION_ALREADY_EXISTS: "Organization already exists",
|
|
115292
|
+
ORGANIZATION_SLUG_ALREADY_TAKEN: "Organization slug already taken",
|
|
115293
|
+
ORGANIZATION_NOT_FOUND: "Organization not found",
|
|
115294
|
+
USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION: "User is not a member of the organization",
|
|
115295
|
+
YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_ORGANIZATION: "You are not allowed to update this organization",
|
|
115296
|
+
YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_ORGANIZATION: "You are not allowed to delete this organization",
|
|
115297
|
+
NO_ACTIVE_ORGANIZATION: "No active organization",
|
|
115298
|
+
USER_IS_ALREADY_A_MEMBER_OF_THIS_ORGANIZATION: "User is already a member of this organization",
|
|
115299
|
+
MEMBER_NOT_FOUND: "Member not found",
|
|
115300
|
+
ROLE_NOT_FOUND: "Role not found",
|
|
115301
|
+
YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM: "You are not allowed to create a new team",
|
|
115302
|
+
TEAM_ALREADY_EXISTS: "Team already exists",
|
|
115303
|
+
TEAM_NOT_FOUND: "Team not found",
|
|
115304
|
+
YOU_CANNOT_LEAVE_THE_ORGANIZATION_AS_THE_ONLY_OWNER: "You cannot leave the organization as the only owner",
|
|
115305
|
+
YOU_CANNOT_LEAVE_THE_ORGANIZATION_WITHOUT_AN_OWNER: "You cannot leave the organization without an owner",
|
|
115306
|
+
YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_MEMBER: "You are not allowed to delete this member",
|
|
115307
|
+
YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION: "You are not allowed to invite users to this organization",
|
|
115308
|
+
USER_IS_ALREADY_INVITED_TO_THIS_ORGANIZATION: "User is already invited to this organization",
|
|
115309
|
+
INVITATION_NOT_FOUND: "Invitation not found",
|
|
115310
|
+
YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION: "You are not the recipient of the invitation",
|
|
115311
|
+
EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION: "Email verification required before accepting or rejecting invitation",
|
|
115312
|
+
YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION: "You are not allowed to cancel this invitation",
|
|
115313
|
+
INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION: "Inviter is no longer a member of the organization",
|
|
115314
|
+
YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE: "You are not allowed to invite a user with this role",
|
|
115315
|
+
FAILED_TO_RETRIEVE_INVITATION: "Failed to retrieve invitation",
|
|
115316
|
+
YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS: "You have reached the maximum number of teams",
|
|
115317
|
+
UNABLE_TO_REMOVE_LAST_TEAM: "Unable to remove last team",
|
|
115318
|
+
YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_MEMBER: "You are not allowed to update this member",
|
|
115319
|
+
ORGANIZATION_MEMBERSHIP_LIMIT_REACHED: "Organization membership limit reached",
|
|
115320
|
+
YOU_ARE_NOT_ALLOWED_TO_CREATE_TEAMS_IN_THIS_ORGANIZATION: "You are not allowed to create teams in this organization",
|
|
115321
|
+
YOU_ARE_NOT_ALLOWED_TO_DELETE_TEAMS_IN_THIS_ORGANIZATION: "You are not allowed to delete teams in this organization",
|
|
115322
|
+
YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM: "You are not allowed to update this team",
|
|
115323
|
+
YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_TEAM: "You are not allowed to delete this team",
|
|
115324
|
+
INVITATION_LIMIT_REACHED: "Invitation limit reached",
|
|
115325
|
+
TEAM_MEMBER_LIMIT_REACHED: "Team member limit reached",
|
|
115326
|
+
USER_IS_NOT_A_MEMBER_OF_THE_TEAM: "User is not a member of the team",
|
|
115327
|
+
YOU_CAN_NOT_ACCESS_THE_MEMBERS_OF_THIS_TEAM: "You are not allowed to list the members of this team",
|
|
115328
|
+
YOU_DO_NOT_HAVE_AN_ACTIVE_TEAM: "You do not have an active team",
|
|
115329
|
+
YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM_MEMBER: "You are not allowed to create a new member",
|
|
115330
|
+
YOU_ARE_NOT_ALLOWED_TO_REMOVE_A_TEAM_MEMBER: "You are not allowed to remove a team member",
|
|
115331
|
+
YOU_ARE_NOT_ALLOWED_TO_ACCESS_THIS_ORGANIZATION: "You are not allowed to access this organization as an owner",
|
|
115332
|
+
YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION: "You are not a member of this organization",
|
|
115333
|
+
MISSING_AC_INSTANCE: "Dynamic Access Control requires a pre-defined ac instance on the server auth plugin. Read server logs for more information",
|
|
115334
|
+
YOU_MUST_BE_IN_AN_ORGANIZATION_TO_CREATE_A_ROLE: "You must be in an organization to create a role",
|
|
115335
|
+
YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE: "You are not allowed to create a role",
|
|
115336
|
+
YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE: "You are not allowed to update a role",
|
|
115337
|
+
YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE: "You are not allowed to delete a role",
|
|
115338
|
+
YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE: "You are not allowed to read a role",
|
|
115339
|
+
YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE: "You are not allowed to list a role",
|
|
115340
|
+
YOU_ARE_NOT_ALLOWED_TO_GET_A_ROLE: "You are not allowed to get a role",
|
|
115341
|
+
TOO_MANY_ROLES: "This organization has too many roles",
|
|
115342
|
+
INVALID_RESOURCE: "The provided permission includes an invalid resource",
|
|
115343
|
+
ROLE_NAME_IS_ALREADY_TAKEN: "That role name is already taken",
|
|
115344
|
+
CANNOT_DELETE_A_PRE_DEFINED_ROLE: "Cannot delete a pre-defined role",
|
|
115345
|
+
ROLE_IS_ASSIGNED_TO_MEMBERS: "Cannot delete a role that is assigned to members. Please reassign the members to a different role first"
|
|
115346
|
+
});
|
|
115347
|
+
|
|
115348
|
+
// ../../node_modules/nanostores/clean-stores/index.js
|
|
115349
|
+
var clean6 = Symbol("clean");
|
|
115350
|
+
|
|
115351
|
+
// ../../node_modules/nanostores/atom/index.js
|
|
115352
|
+
var listenerQueue = [];
|
|
115353
|
+
var lqIndex = 0;
|
|
115354
|
+
var QUEUE_ITEMS_PER_LISTENER = 4;
|
|
115355
|
+
var epoch = 0;
|
|
115356
|
+
var atom = (initialValue) => {
|
|
115357
|
+
let listeners = [];
|
|
115358
|
+
let $atom = {
|
|
115359
|
+
get() {
|
|
115360
|
+
if (!$atom.lc) {
|
|
115361
|
+
$atom.listen(() => {})();
|
|
115362
|
+
}
|
|
115363
|
+
return $atom.value;
|
|
115364
|
+
},
|
|
115365
|
+
init: initialValue,
|
|
115366
|
+
lc: 0,
|
|
115367
|
+
listen(listener) {
|
|
115368
|
+
$atom.lc = listeners.push(listener);
|
|
115369
|
+
return () => {
|
|
115370
|
+
for (let i2 = lqIndex + QUEUE_ITEMS_PER_LISTENER;i2 < listenerQueue.length; ) {
|
|
115371
|
+
if (listenerQueue[i2] === listener) {
|
|
115372
|
+
listenerQueue.splice(i2, QUEUE_ITEMS_PER_LISTENER);
|
|
115373
|
+
} else {
|
|
115374
|
+
i2 += QUEUE_ITEMS_PER_LISTENER;
|
|
115375
|
+
}
|
|
115376
|
+
}
|
|
115377
|
+
let index = listeners.indexOf(listener);
|
|
115378
|
+
if (~index) {
|
|
115379
|
+
listeners.splice(index, 1);
|
|
115380
|
+
if (!--$atom.lc)
|
|
115381
|
+
$atom.off();
|
|
115382
|
+
}
|
|
115383
|
+
};
|
|
115384
|
+
},
|
|
115385
|
+
notify(oldValue, changedKey) {
|
|
115386
|
+
epoch++;
|
|
115387
|
+
let runListenerQueue = !listenerQueue.length;
|
|
115388
|
+
for (let listener of listeners) {
|
|
115389
|
+
listenerQueue.push(listener, $atom.value, oldValue, changedKey);
|
|
115390
|
+
}
|
|
115391
|
+
if (runListenerQueue) {
|
|
115392
|
+
for (lqIndex = 0;lqIndex < listenerQueue.length; lqIndex += QUEUE_ITEMS_PER_LISTENER) {
|
|
115393
|
+
listenerQueue[lqIndex](listenerQueue[lqIndex + 1], listenerQueue[lqIndex + 2], listenerQueue[lqIndex + 3]);
|
|
115394
|
+
}
|
|
115395
|
+
listenerQueue.length = 0;
|
|
115396
|
+
}
|
|
115397
|
+
},
|
|
115398
|
+
off() {},
|
|
115399
|
+
set(newValue) {
|
|
115400
|
+
let oldValue = $atom.value;
|
|
115401
|
+
if (oldValue !== newValue) {
|
|
115402
|
+
$atom.value = newValue;
|
|
115403
|
+
$atom.notify(oldValue);
|
|
115404
|
+
}
|
|
115405
|
+
},
|
|
115406
|
+
subscribe(listener) {
|
|
115407
|
+
let unbind = $atom.listen(listener);
|
|
115408
|
+
listener($atom.value);
|
|
115409
|
+
return unbind;
|
|
115410
|
+
},
|
|
115411
|
+
value: initialValue
|
|
115412
|
+
};
|
|
115413
|
+
if (true) {
|
|
115414
|
+
$atom[clean6] = () => {
|
|
115415
|
+
listeners = [];
|
|
115416
|
+
$atom.lc = 0;
|
|
115417
|
+
$atom.off();
|
|
115418
|
+
};
|
|
115419
|
+
}
|
|
115420
|
+
return $atom;
|
|
115421
|
+
};
|
|
115422
|
+
// ../../node_modules/nanostores/lifecycle/index.js
|
|
115423
|
+
var MOUNT = 5;
|
|
115424
|
+
var UNMOUNT = 6;
|
|
115425
|
+
var REVERT_MUTATION = 10;
|
|
115426
|
+
var on = (object, listener, eventKey, mutateStore) => {
|
|
115427
|
+
object.events = object.events || {};
|
|
115428
|
+
if (!object.events[eventKey + REVERT_MUTATION]) {
|
|
115429
|
+
object.events[eventKey + REVERT_MUTATION] = mutateStore((eventProps) => {
|
|
115430
|
+
object.events[eventKey].reduceRight((event, l) => (l(event), event), {
|
|
115431
|
+
shared: {},
|
|
115432
|
+
...eventProps
|
|
115433
|
+
});
|
|
115434
|
+
});
|
|
115435
|
+
}
|
|
115436
|
+
object.events[eventKey] = object.events[eventKey] || [];
|
|
115437
|
+
object.events[eventKey].push(listener);
|
|
115438
|
+
return () => {
|
|
115439
|
+
let currentListeners = object.events[eventKey];
|
|
115440
|
+
let index = currentListeners.indexOf(listener);
|
|
115441
|
+
currentListeners.splice(index, 1);
|
|
115442
|
+
if (!currentListeners.length) {
|
|
115443
|
+
delete object.events[eventKey];
|
|
115444
|
+
object.events[eventKey + REVERT_MUTATION]();
|
|
115445
|
+
delete object.events[eventKey + REVERT_MUTATION];
|
|
115446
|
+
}
|
|
115447
|
+
};
|
|
115448
|
+
};
|
|
115449
|
+
var STORE_UNMOUNT_DELAY = 1000;
|
|
115450
|
+
var onMount = ($store, initialize) => {
|
|
115451
|
+
let listener = (payload) => {
|
|
115452
|
+
let destroy = initialize(payload);
|
|
115453
|
+
if (destroy)
|
|
115454
|
+
$store.events[UNMOUNT].push(destroy);
|
|
115455
|
+
};
|
|
115456
|
+
return on($store, listener, MOUNT, (runListeners) => {
|
|
115457
|
+
let originListen = $store.listen;
|
|
115458
|
+
$store.listen = (...args) => {
|
|
115459
|
+
if (!$store.lc && !$store.active) {
|
|
115460
|
+
$store.active = true;
|
|
115461
|
+
runListeners();
|
|
115462
|
+
}
|
|
115463
|
+
return originListen(...args);
|
|
115464
|
+
};
|
|
115465
|
+
let originOff = $store.off;
|
|
115466
|
+
$store.events[UNMOUNT] = [];
|
|
115467
|
+
$store.off = () => {
|
|
115468
|
+
originOff();
|
|
115469
|
+
setTimeout(() => {
|
|
115470
|
+
if ($store.active && !$store.lc) {
|
|
115471
|
+
$store.active = false;
|
|
115472
|
+
for (let destroy of $store.events[UNMOUNT])
|
|
115473
|
+
destroy();
|
|
115474
|
+
$store.events[UNMOUNT] = [];
|
|
115475
|
+
}
|
|
115476
|
+
}, STORE_UNMOUNT_DELAY);
|
|
115477
|
+
};
|
|
115478
|
+
if (true) {
|
|
115479
|
+
let originClean = $store[clean6];
|
|
115480
|
+
$store[clean6] = () => {
|
|
115481
|
+
for (let destroy of $store.events[UNMOUNT])
|
|
115482
|
+
destroy();
|
|
115483
|
+
$store.events[UNMOUNT] = [];
|
|
115484
|
+
$store.active = false;
|
|
115485
|
+
originClean();
|
|
115486
|
+
};
|
|
115487
|
+
}
|
|
115488
|
+
return () => {
|
|
115489
|
+
$store.listen = originListen;
|
|
115490
|
+
$store.off = originOff;
|
|
115491
|
+
};
|
|
115492
|
+
});
|
|
115493
|
+
};
|
|
115494
|
+
// ../../node_modules/better-auth/dist/client/query.mjs
|
|
115495
|
+
var isServer = () => typeof window === "undefined";
|
|
115496
|
+
var useAuthQuery = (initializedAtom, path, $fetch, options) => {
|
|
115497
|
+
const value = atom({
|
|
115498
|
+
data: null,
|
|
115499
|
+
error: null,
|
|
115500
|
+
isPending: true,
|
|
115501
|
+
isRefetching: false,
|
|
115502
|
+
refetch: (queryParams) => fn(queryParams)
|
|
115503
|
+
});
|
|
115504
|
+
const fn = async (queryParams) => {
|
|
115505
|
+
return new Promise((resolve) => {
|
|
115506
|
+
const opts = typeof options === "function" ? options({
|
|
115507
|
+
data: value.get().data,
|
|
115508
|
+
error: value.get().error,
|
|
115509
|
+
isPending: value.get().isPending
|
|
115510
|
+
}) : options;
|
|
115511
|
+
$fetch(path, {
|
|
115512
|
+
...opts,
|
|
115513
|
+
query: {
|
|
115514
|
+
...opts?.query,
|
|
115515
|
+
...queryParams?.query
|
|
115516
|
+
},
|
|
115517
|
+
async onSuccess(context) {
|
|
115518
|
+
value.set({
|
|
115519
|
+
data: context.data,
|
|
115520
|
+
error: null,
|
|
115521
|
+
isPending: false,
|
|
115522
|
+
isRefetching: false,
|
|
115523
|
+
refetch: value.value.refetch
|
|
115524
|
+
});
|
|
115525
|
+
await opts?.onSuccess?.(context);
|
|
115526
|
+
},
|
|
115527
|
+
async onError(context) {
|
|
115528
|
+
const { request: request3 } = context;
|
|
115529
|
+
const retryAttempts = typeof request3.retry === "number" ? request3.retry : request3.retry?.attempts;
|
|
115530
|
+
const retryAttempt = request3.retryAttempt || 0;
|
|
115531
|
+
if (retryAttempts && retryAttempt < retryAttempts)
|
|
115532
|
+
return;
|
|
115533
|
+
const isUnauthorized = context.error.status === 401;
|
|
115534
|
+
value.set({
|
|
115535
|
+
error: context.error,
|
|
115536
|
+
data: isUnauthorized ? null : value.get().data,
|
|
115537
|
+
isPending: false,
|
|
115538
|
+
isRefetching: false,
|
|
115539
|
+
refetch: value.value.refetch
|
|
115540
|
+
});
|
|
115541
|
+
await opts?.onError?.(context);
|
|
115542
|
+
},
|
|
115543
|
+
async onRequest(context) {
|
|
115544
|
+
const currentValue = value.get();
|
|
115545
|
+
value.set({
|
|
115546
|
+
isPending: currentValue.data === null,
|
|
115547
|
+
data: currentValue.data,
|
|
115548
|
+
error: null,
|
|
115549
|
+
isRefetching: true,
|
|
115550
|
+
refetch: value.value.refetch
|
|
115551
|
+
});
|
|
115552
|
+
await opts?.onRequest?.(context);
|
|
115553
|
+
}
|
|
115554
|
+
}).catch((error) => {
|
|
115555
|
+
value.set({
|
|
115556
|
+
error,
|
|
115557
|
+
data: value.get().data,
|
|
115558
|
+
isPending: false,
|
|
115559
|
+
isRefetching: false,
|
|
115560
|
+
refetch: value.value.refetch
|
|
115561
|
+
});
|
|
115562
|
+
}).finally(() => {
|
|
115563
|
+
resolve(undefined);
|
|
115564
|
+
});
|
|
115565
|
+
});
|
|
115566
|
+
};
|
|
115567
|
+
initializedAtom = Array.isArray(initializedAtom) ? initializedAtom : [initializedAtom];
|
|
115568
|
+
let isMounted = false;
|
|
115569
|
+
for (const initAtom of initializedAtom)
|
|
115570
|
+
initAtom.subscribe(async () => {
|
|
115571
|
+
if (isServer())
|
|
115572
|
+
return;
|
|
115573
|
+
if (isMounted)
|
|
115574
|
+
await fn();
|
|
115575
|
+
else
|
|
115576
|
+
onMount(value, () => {
|
|
115577
|
+
const timeoutId = setTimeout(async () => {
|
|
115578
|
+
if (!isMounted) {
|
|
115579
|
+
await fn();
|
|
115580
|
+
isMounted = true;
|
|
115581
|
+
}
|
|
115582
|
+
}, 0);
|
|
115583
|
+
return () => {
|
|
115584
|
+
value.off();
|
|
115585
|
+
initAtom.off();
|
|
115586
|
+
clearTimeout(timeoutId);
|
|
115587
|
+
};
|
|
115588
|
+
});
|
|
115589
|
+
});
|
|
115590
|
+
return value;
|
|
115591
|
+
};
|
|
115592
|
+
|
|
115593
|
+
// ../../node_modules/better-auth/dist/client/broadcast-channel.mjs
|
|
115594
|
+
var kBroadcastChannel = Symbol.for("better-auth:broadcast-channel");
|
|
115595
|
+
var now = () => Math.floor(Date.now() / 1000);
|
|
115596
|
+
var WindowBroadcastChannel = class {
|
|
115597
|
+
listeners = /* @__PURE__ */ new Set;
|
|
115598
|
+
name;
|
|
115599
|
+
constructor(name = "better-auth.message") {
|
|
115600
|
+
this.name = name;
|
|
115601
|
+
}
|
|
115602
|
+
subscribe(listener) {
|
|
115603
|
+
this.listeners.add(listener);
|
|
115604
|
+
return () => {
|
|
115605
|
+
this.listeners.delete(listener);
|
|
115606
|
+
};
|
|
115607
|
+
}
|
|
115608
|
+
post(message) {
|
|
115609
|
+
if (typeof window === "undefined")
|
|
115610
|
+
return;
|
|
115611
|
+
try {
|
|
115612
|
+
localStorage.setItem(this.name, JSON.stringify({
|
|
115613
|
+
...message,
|
|
115614
|
+
timestamp: now()
|
|
115615
|
+
}));
|
|
115616
|
+
} catch {}
|
|
115617
|
+
}
|
|
115618
|
+
setup() {
|
|
115619
|
+
if (typeof window === "undefined" || typeof window.addEventListener === "undefined")
|
|
115620
|
+
return () => {};
|
|
115621
|
+
const handler = (event) => {
|
|
115622
|
+
if (event.key !== this.name)
|
|
115623
|
+
return;
|
|
115624
|
+
const message = JSON.parse(event.newValue ?? "{}");
|
|
115625
|
+
if (message?.event !== "session" || !message?.data)
|
|
115626
|
+
return;
|
|
115627
|
+
this.listeners.forEach((listener) => listener(message));
|
|
115628
|
+
};
|
|
115629
|
+
window.addEventListener("storage", handler);
|
|
115630
|
+
return () => {
|
|
115631
|
+
window.removeEventListener("storage", handler);
|
|
115632
|
+
};
|
|
115633
|
+
}
|
|
115634
|
+
};
|
|
115635
|
+
function getGlobalBroadcastChannel(name = "better-auth.message") {
|
|
115636
|
+
if (!globalThis[kBroadcastChannel])
|
|
115637
|
+
globalThis[kBroadcastChannel] = new WindowBroadcastChannel(name);
|
|
115638
|
+
return globalThis[kBroadcastChannel];
|
|
115639
|
+
}
|
|
115640
|
+
|
|
115641
|
+
// ../../node_modules/better-auth/dist/client/focus-manager.mjs
|
|
115642
|
+
var kFocusManager = Symbol.for("better-auth:focus-manager");
|
|
115643
|
+
var WindowFocusManager = class {
|
|
115644
|
+
listeners = /* @__PURE__ */ new Set;
|
|
115645
|
+
subscribe(listener) {
|
|
115646
|
+
this.listeners.add(listener);
|
|
115647
|
+
return () => {
|
|
115648
|
+
this.listeners.delete(listener);
|
|
115649
|
+
};
|
|
115650
|
+
}
|
|
115651
|
+
setFocused(focused) {
|
|
115652
|
+
this.listeners.forEach((listener) => listener(focused));
|
|
115653
|
+
}
|
|
115654
|
+
setup() {
|
|
115655
|
+
if (typeof window === "undefined" || typeof document === "undefined" || typeof window.addEventListener === "undefined")
|
|
115656
|
+
return () => {};
|
|
115657
|
+
const visibilityHandler = () => {
|
|
115658
|
+
if (document.visibilityState === "visible")
|
|
115659
|
+
this.setFocused(true);
|
|
115660
|
+
};
|
|
115661
|
+
document.addEventListener("visibilitychange", visibilityHandler, false);
|
|
115662
|
+
return () => {
|
|
115663
|
+
document.removeEventListener("visibilitychange", visibilityHandler, false);
|
|
115664
|
+
};
|
|
115665
|
+
}
|
|
115666
|
+
};
|
|
115667
|
+
function getGlobalFocusManager() {
|
|
115668
|
+
if (!globalThis[kFocusManager])
|
|
115669
|
+
globalThis[kFocusManager] = new WindowFocusManager;
|
|
115670
|
+
return globalThis[kFocusManager];
|
|
115671
|
+
}
|
|
115672
|
+
|
|
115673
|
+
// ../../node_modules/better-auth/dist/client/online-manager.mjs
|
|
115674
|
+
var kOnlineManager = Symbol.for("better-auth:online-manager");
|
|
115675
|
+
var WindowOnlineManager = class {
|
|
115676
|
+
listeners = /* @__PURE__ */ new Set;
|
|
115677
|
+
isOnline = typeof navigator !== "undefined" ? navigator.onLine : true;
|
|
115678
|
+
subscribe(listener) {
|
|
115679
|
+
this.listeners.add(listener);
|
|
115680
|
+
return () => {
|
|
115681
|
+
this.listeners.delete(listener);
|
|
115682
|
+
};
|
|
115683
|
+
}
|
|
115684
|
+
setOnline(online) {
|
|
115685
|
+
this.isOnline = online;
|
|
115686
|
+
this.listeners.forEach((listener) => listener(online));
|
|
115687
|
+
}
|
|
115688
|
+
setup() {
|
|
115689
|
+
if (typeof window === "undefined" || typeof window.addEventListener === "undefined")
|
|
115690
|
+
return () => {};
|
|
115691
|
+
const onOnline = () => this.setOnline(true);
|
|
115692
|
+
const onOffline = () => this.setOnline(false);
|
|
115693
|
+
window.addEventListener("online", onOnline, false);
|
|
115694
|
+
window.addEventListener("offline", onOffline, false);
|
|
115695
|
+
return () => {
|
|
115696
|
+
window.removeEventListener("online", onOnline, false);
|
|
115697
|
+
window.removeEventListener("offline", onOffline, false);
|
|
115698
|
+
};
|
|
115699
|
+
}
|
|
115700
|
+
};
|
|
115701
|
+
function getGlobalOnlineManager() {
|
|
115702
|
+
if (!globalThis[kOnlineManager])
|
|
115703
|
+
globalThis[kOnlineManager] = new WindowOnlineManager;
|
|
115704
|
+
return globalThis[kOnlineManager];
|
|
115705
|
+
}
|
|
115706
|
+
|
|
115707
|
+
// ../../node_modules/better-auth/dist/client/parser.mjs
|
|
115708
|
+
var PROTO_POLLUTION_PATTERNS = {
|
|
115709
|
+
proto: /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,
|
|
115710
|
+
constructor: /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,
|
|
115711
|
+
protoShort: /"__proto__"\s*:/,
|
|
115712
|
+
constructorShort: /"constructor"\s*:/
|
|
115713
|
+
};
|
|
115714
|
+
var JSON_SIGNATURE = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
|
|
115715
|
+
var SPECIAL_VALUES = {
|
|
115716
|
+
true: true,
|
|
115717
|
+
false: false,
|
|
115718
|
+
null: null,
|
|
115719
|
+
undefined: undefined,
|
|
115720
|
+
nan: NaN,
|
|
115721
|
+
infinity: Number.POSITIVE_INFINITY,
|
|
115722
|
+
"-infinity": Number.NEGATIVE_INFINITY
|
|
115723
|
+
};
|
|
115724
|
+
var ISO_DATE_REGEX = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
|
|
115725
|
+
function isValidDate(date) {
|
|
115726
|
+
return date instanceof Date && !isNaN(date.getTime());
|
|
115727
|
+
}
|
|
115728
|
+
function parseISODate(value) {
|
|
115729
|
+
const match = ISO_DATE_REGEX.exec(value);
|
|
115730
|
+
if (!match)
|
|
115731
|
+
return null;
|
|
115732
|
+
const [, year, month, day, hour, minute, second, ms, offsetSign, offsetHour, offsetMinute] = match;
|
|
115733
|
+
const date = new Date(Date.UTC(parseInt(year, 10), parseInt(month, 10) - 1, parseInt(day, 10), parseInt(hour, 10), parseInt(minute, 10), parseInt(second, 10), ms ? parseInt(ms.padEnd(3, "0"), 10) : 0));
|
|
115734
|
+
if (offsetSign) {
|
|
115735
|
+
const offset = (parseInt(offsetHour, 10) * 60 + parseInt(offsetMinute, 10)) * (offsetSign === "+" ? -1 : 1);
|
|
115736
|
+
date.setUTCMinutes(date.getUTCMinutes() + offset);
|
|
115737
|
+
}
|
|
115738
|
+
return isValidDate(date) ? date : null;
|
|
115739
|
+
}
|
|
115740
|
+
function betterJSONParse(value, options = {}) {
|
|
115741
|
+
const { strict = false, warnings = false, reviver, parseDates = true } = options;
|
|
115742
|
+
if (typeof value !== "string")
|
|
115743
|
+
return value;
|
|
115744
|
+
const trimmed = value.trim();
|
|
115745
|
+
if (trimmed.length > 0 && trimmed[0] === '"' && trimmed.endsWith('"') && !trimmed.slice(1, -1).includes('"'))
|
|
115746
|
+
return trimmed.slice(1, -1);
|
|
115747
|
+
const lowerValue = trimmed.toLowerCase();
|
|
115748
|
+
if (lowerValue.length <= 9 && lowerValue in SPECIAL_VALUES)
|
|
115749
|
+
return SPECIAL_VALUES[lowerValue];
|
|
115750
|
+
if (!JSON_SIGNATURE.test(trimmed)) {
|
|
115751
|
+
if (strict)
|
|
115752
|
+
throw new SyntaxError("[better-json] Invalid JSON");
|
|
115753
|
+
return value;
|
|
115754
|
+
}
|
|
115755
|
+
if (Object.entries(PROTO_POLLUTION_PATTERNS).some(([key, pattern]) => {
|
|
115756
|
+
const matches = pattern.test(trimmed);
|
|
115757
|
+
if (matches && warnings)
|
|
115758
|
+
console.warn(`[better-json] Detected potential prototype pollution attempt using ${key} pattern`);
|
|
115759
|
+
return matches;
|
|
115760
|
+
}) && strict)
|
|
115761
|
+
throw new Error("[better-json] Potential prototype pollution attempt detected");
|
|
115762
|
+
try {
|
|
115763
|
+
const secureReviver = (key, value2) => {
|
|
115764
|
+
if (key === "__proto__" || key === "constructor" && value2 && typeof value2 === "object" && "prototype" in value2) {
|
|
115765
|
+
if (warnings)
|
|
115766
|
+
console.warn(`[better-json] Dropping "${key}" key to prevent prototype pollution`);
|
|
115767
|
+
return;
|
|
115768
|
+
}
|
|
115769
|
+
if (parseDates && typeof value2 === "string") {
|
|
115770
|
+
const date = parseISODate(value2);
|
|
115771
|
+
if (date)
|
|
115772
|
+
return date;
|
|
115773
|
+
}
|
|
115774
|
+
return reviver ? reviver(key, value2) : value2;
|
|
115775
|
+
};
|
|
115776
|
+
return JSON.parse(trimmed, secureReviver);
|
|
115777
|
+
} catch (error) {
|
|
115778
|
+
if (strict)
|
|
115779
|
+
throw error;
|
|
115780
|
+
return value;
|
|
115781
|
+
}
|
|
115782
|
+
}
|
|
115783
|
+
function parseJSON(value, options = { strict: true }) {
|
|
115784
|
+
return betterJSONParse(value, options);
|
|
115785
|
+
}
|
|
115786
|
+
|
|
115787
|
+
// ../../node_modules/better-auth/dist/client/session-refresh.mjs
|
|
115788
|
+
var now2 = () => Math.floor(Date.now() / 1000);
|
|
115789
|
+
var FOCUS_REFETCH_RATE_LIMIT_SECONDS = 5;
|
|
115790
|
+
function createSessionRefreshManager(opts) {
|
|
115791
|
+
const { sessionAtom, sessionSignal, $fetch, options = {} } = opts;
|
|
115792
|
+
const refetchInterval = options.sessionOptions?.refetchInterval ?? 0;
|
|
115793
|
+
const refetchOnWindowFocus = options.sessionOptions?.refetchOnWindowFocus ?? true;
|
|
115794
|
+
const refetchWhenOffline = options.sessionOptions?.refetchWhenOffline ?? false;
|
|
115795
|
+
const state = {
|
|
115796
|
+
lastSync: 0,
|
|
115797
|
+
lastSessionRequest: 0,
|
|
115798
|
+
cachedSession: undefined
|
|
115799
|
+
};
|
|
115800
|
+
const shouldRefetch = () => {
|
|
115801
|
+
return refetchWhenOffline || getGlobalOnlineManager().isOnline;
|
|
115802
|
+
};
|
|
115803
|
+
const triggerRefetch = (event) => {
|
|
115804
|
+
if (!shouldRefetch())
|
|
115805
|
+
return;
|
|
115806
|
+
if (event?.event === "storage") {
|
|
115807
|
+
state.lastSync = now2();
|
|
115808
|
+
sessionSignal.set(!sessionSignal.get());
|
|
115809
|
+
return;
|
|
115810
|
+
}
|
|
115811
|
+
const currentSession = sessionAtom.get();
|
|
115812
|
+
const fetchSessionWithRefresh = () => {
|
|
115813
|
+
state.lastSessionRequest = now2();
|
|
115814
|
+
$fetch("/get-session").then(async (res) => {
|
|
115815
|
+
let data = res.data;
|
|
115816
|
+
let error = res.error || null;
|
|
115817
|
+
if (data?.needsRefresh)
|
|
115818
|
+
try {
|
|
115819
|
+
const refreshRes = await $fetch("/get-session", { method: "POST" });
|
|
115820
|
+
data = refreshRes.data;
|
|
115821
|
+
error = refreshRes.error || null;
|
|
115822
|
+
} catch {}
|
|
115823
|
+
const sessionData = data?.session && data?.user ? data : null;
|
|
115824
|
+
sessionAtom.set({
|
|
115825
|
+
...currentSession,
|
|
115826
|
+
data: sessionData,
|
|
115827
|
+
error
|
|
115828
|
+
});
|
|
115829
|
+
state.lastSync = now2();
|
|
115830
|
+
sessionSignal.set(!sessionSignal.get());
|
|
115831
|
+
}).catch(() => {});
|
|
115832
|
+
};
|
|
115833
|
+
if (event?.event === "poll") {
|
|
115834
|
+
fetchSessionWithRefresh();
|
|
115835
|
+
return;
|
|
115836
|
+
}
|
|
115837
|
+
if (event?.event === "visibilitychange") {
|
|
115838
|
+
if (now2() - state.lastSessionRequest < FOCUS_REFETCH_RATE_LIMIT_SECONDS)
|
|
115839
|
+
return;
|
|
115840
|
+
state.lastSessionRequest = now2();
|
|
115841
|
+
}
|
|
115842
|
+
if (event?.event === "visibilitychange") {
|
|
115843
|
+
fetchSessionWithRefresh();
|
|
115844
|
+
return;
|
|
115845
|
+
}
|
|
115846
|
+
if (currentSession?.data === null || currentSession?.data === undefined) {
|
|
115847
|
+
state.lastSync = now2();
|
|
115848
|
+
sessionSignal.set(!sessionSignal.get());
|
|
115849
|
+
}
|
|
115850
|
+
};
|
|
115851
|
+
const broadcastSessionUpdate = (trigger) => {
|
|
115852
|
+
getGlobalBroadcastChannel().post({
|
|
115853
|
+
event: "session",
|
|
115854
|
+
data: { trigger },
|
|
115855
|
+
clientId: Math.random().toString(36).substring(7)
|
|
115856
|
+
});
|
|
115857
|
+
};
|
|
115858
|
+
const setupPolling = () => {
|
|
115859
|
+
if (refetchInterval && refetchInterval > 0)
|
|
115860
|
+
state.pollInterval = setInterval(() => {
|
|
115861
|
+
if (sessionAtom.get()?.data)
|
|
115862
|
+
triggerRefetch({ event: "poll" });
|
|
115863
|
+
}, refetchInterval * 1000);
|
|
115864
|
+
};
|
|
115865
|
+
const setupBroadcast = () => {
|
|
115866
|
+
state.unsubscribeBroadcast = getGlobalBroadcastChannel().subscribe(() => {
|
|
115867
|
+
triggerRefetch({ event: "storage" });
|
|
115868
|
+
});
|
|
115869
|
+
};
|
|
115870
|
+
const setupFocusRefetch = () => {
|
|
115871
|
+
if (!refetchOnWindowFocus)
|
|
115872
|
+
return;
|
|
115873
|
+
state.unsubscribeFocus = getGlobalFocusManager().subscribe(() => {
|
|
115874
|
+
triggerRefetch({ event: "visibilitychange" });
|
|
115875
|
+
});
|
|
115876
|
+
};
|
|
115877
|
+
const setupOnlineRefetch = () => {
|
|
115878
|
+
state.unsubscribeOnline = getGlobalOnlineManager().subscribe((online) => {
|
|
115879
|
+
if (online)
|
|
115880
|
+
triggerRefetch({ event: "visibilitychange" });
|
|
115881
|
+
});
|
|
115882
|
+
};
|
|
115883
|
+
const init = () => {
|
|
115884
|
+
setupPolling();
|
|
115885
|
+
setupBroadcast();
|
|
115886
|
+
setupFocusRefetch();
|
|
115887
|
+
setupOnlineRefetch();
|
|
115888
|
+
getGlobalBroadcastChannel().setup();
|
|
115889
|
+
getGlobalFocusManager().setup();
|
|
115890
|
+
getGlobalOnlineManager().setup();
|
|
115891
|
+
};
|
|
115892
|
+
const cleanup = () => {
|
|
115893
|
+
if (state.pollInterval) {
|
|
115894
|
+
clearInterval(state.pollInterval);
|
|
115895
|
+
state.pollInterval = undefined;
|
|
115896
|
+
}
|
|
115897
|
+
if (state.unsubscribeBroadcast) {
|
|
115898
|
+
state.unsubscribeBroadcast();
|
|
115899
|
+
state.unsubscribeBroadcast = undefined;
|
|
115900
|
+
}
|
|
115901
|
+
if (state.unsubscribeFocus) {
|
|
115902
|
+
state.unsubscribeFocus();
|
|
115903
|
+
state.unsubscribeFocus = undefined;
|
|
115904
|
+
}
|
|
115905
|
+
if (state.unsubscribeOnline) {
|
|
115906
|
+
state.unsubscribeOnline();
|
|
115907
|
+
state.unsubscribeOnline = undefined;
|
|
115908
|
+
}
|
|
115909
|
+
state.lastSync = 0;
|
|
115910
|
+
state.lastSessionRequest = 0;
|
|
115911
|
+
state.cachedSession = undefined;
|
|
115912
|
+
};
|
|
115913
|
+
return {
|
|
115914
|
+
init,
|
|
115915
|
+
cleanup,
|
|
115916
|
+
triggerRefetch,
|
|
115917
|
+
broadcastSessionUpdate
|
|
115918
|
+
};
|
|
115919
|
+
}
|
|
115920
|
+
|
|
115921
|
+
// ../../node_modules/@better-auth/core/dist/env/env-impl.mjs
|
|
115922
|
+
var _envShim = Object.create(null);
|
|
115923
|
+
var _getEnv = (useShim) => globalThis.process?.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (useShim ? _envShim : globalThis);
|
|
115924
|
+
var env = new Proxy(_envShim, {
|
|
115925
|
+
get(_, prop) {
|
|
115926
|
+
return _getEnv()[prop] ?? _envShim[prop];
|
|
115927
|
+
},
|
|
115928
|
+
has(_, prop) {
|
|
115929
|
+
return prop in _getEnv() || prop in _envShim;
|
|
115930
|
+
},
|
|
115931
|
+
set(_, prop, value) {
|
|
115932
|
+
const env2 = _getEnv(true);
|
|
115933
|
+
env2[prop] = value;
|
|
115934
|
+
return true;
|
|
115935
|
+
},
|
|
115936
|
+
deleteProperty(_, prop) {
|
|
115937
|
+
if (!prop)
|
|
115938
|
+
return false;
|
|
115939
|
+
const env2 = _getEnv(true);
|
|
115940
|
+
delete env2[prop];
|
|
115941
|
+
return true;
|
|
115942
|
+
},
|
|
115943
|
+
ownKeys() {
|
|
115944
|
+
const env2 = _getEnv(true);
|
|
115945
|
+
return Object.keys(env2);
|
|
115946
|
+
}
|
|
115947
|
+
});
|
|
115948
|
+
var nodeENV = typeof process !== "undefined" && process.env && "development" || "";
|
|
115949
|
+
function getEnvVar(key, fallback) {
|
|
115950
|
+
if (typeof process !== "undefined" && process.env)
|
|
115951
|
+
return process.env[key] ?? fallback;
|
|
115952
|
+
if (typeof Deno !== "undefined")
|
|
115953
|
+
return Deno.env.get(key) ?? fallback;
|
|
115954
|
+
if (typeof Bun !== "undefined")
|
|
115955
|
+
return Bun.env[key] ?? fallback;
|
|
115956
|
+
return fallback;
|
|
115957
|
+
}
|
|
115958
|
+
var ENV = Object.freeze({
|
|
115959
|
+
get BETTER_AUTH_SECRET() {
|
|
115960
|
+
return getEnvVar("BETTER_AUTH_SECRET");
|
|
115961
|
+
},
|
|
115962
|
+
get AUTH_SECRET() {
|
|
115963
|
+
return getEnvVar("AUTH_SECRET");
|
|
115964
|
+
},
|
|
115965
|
+
get BETTER_AUTH_TELEMETRY() {
|
|
115966
|
+
return getEnvVar("BETTER_AUTH_TELEMETRY");
|
|
115967
|
+
},
|
|
115968
|
+
get BETTER_AUTH_TELEMETRY_ID() {
|
|
115969
|
+
return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
|
|
115970
|
+
},
|
|
115971
|
+
get NODE_ENV() {
|
|
115972
|
+
return getEnvVar("NODE_ENV", "development");
|
|
115973
|
+
},
|
|
115974
|
+
get PACKAGE_VERSION() {
|
|
115975
|
+
return getEnvVar("PACKAGE_VERSION", "0.0.0");
|
|
115976
|
+
},
|
|
115977
|
+
get BETTER_AUTH_TELEMETRY_ENDPOINT() {
|
|
115978
|
+
return getEnvVar("BETTER_AUTH_TELEMETRY_ENDPOINT", "");
|
|
115979
|
+
}
|
|
115980
|
+
});
|
|
115981
|
+
|
|
115982
|
+
// ../../node_modules/@better-auth/core/dist/env/color-depth.mjs
|
|
115983
|
+
var COLORS_2 = 1;
|
|
115984
|
+
var COLORS_16 = 4;
|
|
115985
|
+
var COLORS_256 = 8;
|
|
115986
|
+
var COLORS_16m = 24;
|
|
115987
|
+
var TERM_ENVS = {
|
|
115988
|
+
eterm: COLORS_16,
|
|
115989
|
+
cons25: COLORS_16,
|
|
115990
|
+
console: COLORS_16,
|
|
115991
|
+
cygwin: COLORS_16,
|
|
115992
|
+
dtterm: COLORS_16,
|
|
115993
|
+
gnome: COLORS_16,
|
|
115994
|
+
hurd: COLORS_16,
|
|
115995
|
+
jfbterm: COLORS_16,
|
|
115996
|
+
konsole: COLORS_16,
|
|
115997
|
+
kterm: COLORS_16,
|
|
115998
|
+
mlterm: COLORS_16,
|
|
115999
|
+
mosh: COLORS_16m,
|
|
116000
|
+
putty: COLORS_16,
|
|
116001
|
+
st: COLORS_16,
|
|
116002
|
+
"rxvt-unicode-24bit": COLORS_16m,
|
|
116003
|
+
terminator: COLORS_16m,
|
|
116004
|
+
"xterm-kitty": COLORS_16m
|
|
116005
|
+
};
|
|
116006
|
+
var CI_ENVS_MAP = new Map(Object.entries({
|
|
116007
|
+
APPVEYOR: COLORS_256,
|
|
116008
|
+
BUILDKITE: COLORS_256,
|
|
116009
|
+
CIRCLECI: COLORS_16m,
|
|
116010
|
+
DRONE: COLORS_256,
|
|
116011
|
+
GITEA_ACTIONS: COLORS_16m,
|
|
116012
|
+
GITHUB_ACTIONS: COLORS_16m,
|
|
116013
|
+
GITLAB_CI: COLORS_256,
|
|
116014
|
+
TRAVIS: COLORS_256
|
|
116015
|
+
}));
|
|
116016
|
+
var TERM_ENVS_REG_EXP = [
|
|
116017
|
+
/ansi/,
|
|
116018
|
+
/color/,
|
|
116019
|
+
/linux/,
|
|
116020
|
+
/direct/,
|
|
116021
|
+
/^con[0-9]*x[0-9]/,
|
|
116022
|
+
/^rxvt/,
|
|
116023
|
+
/^screen/,
|
|
116024
|
+
/^xterm/,
|
|
116025
|
+
/^vt100/,
|
|
116026
|
+
/^vt220/
|
|
116027
|
+
];
|
|
116028
|
+
function getColorDepth() {
|
|
116029
|
+
if (getEnvVar("FORCE_COLOR") !== undefined)
|
|
116030
|
+
switch (getEnvVar("FORCE_COLOR")) {
|
|
116031
|
+
case "":
|
|
116032
|
+
case "1":
|
|
116033
|
+
case "true":
|
|
116034
|
+
return COLORS_16;
|
|
116035
|
+
case "2":
|
|
116036
|
+
return COLORS_256;
|
|
116037
|
+
case "3":
|
|
116038
|
+
return COLORS_16m;
|
|
116039
|
+
default:
|
|
116040
|
+
return COLORS_2;
|
|
116041
|
+
}
|
|
116042
|
+
if (getEnvVar("NODE_DISABLE_COLORS") !== undefined && getEnvVar("NODE_DISABLE_COLORS") !== "" || getEnvVar("NO_COLOR") !== undefined && getEnvVar("NO_COLOR") !== "" || getEnvVar("TERM") === "dumb")
|
|
116043
|
+
return COLORS_2;
|
|
116044
|
+
if (getEnvVar("TMUX"))
|
|
116045
|
+
return COLORS_16m;
|
|
116046
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env)
|
|
116047
|
+
return COLORS_16;
|
|
116048
|
+
if ("CI" in env) {
|
|
116049
|
+
for (const { 0: envName, 1: colors } of CI_ENVS_MAP)
|
|
116050
|
+
if (envName in env)
|
|
116051
|
+
return colors;
|
|
116052
|
+
if (getEnvVar("CI_NAME") === "codeship")
|
|
116053
|
+
return COLORS_256;
|
|
116054
|
+
return COLORS_2;
|
|
116055
|
+
}
|
|
116056
|
+
if ("TEAMCITY_VERSION" in env)
|
|
116057
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(getEnvVar("TEAMCITY_VERSION")) !== null ? COLORS_16 : COLORS_2;
|
|
116058
|
+
switch (getEnvVar("TERM_PROGRAM")) {
|
|
116059
|
+
case "iTerm.app":
|
|
116060
|
+
if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null)
|
|
116061
|
+
return COLORS_256;
|
|
116062
|
+
return COLORS_16m;
|
|
116063
|
+
case "HyperTerm":
|
|
116064
|
+
case "MacTerm":
|
|
116065
|
+
return COLORS_16m;
|
|
116066
|
+
case "Apple_Terminal":
|
|
116067
|
+
return COLORS_256;
|
|
116068
|
+
}
|
|
116069
|
+
if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit")
|
|
116070
|
+
return COLORS_16m;
|
|
116071
|
+
if (getEnvVar("TERM")) {
|
|
116072
|
+
if (/truecolor/.exec(getEnvVar("TERM")) !== null)
|
|
116073
|
+
return COLORS_16m;
|
|
116074
|
+
if (/^xterm-256/.exec(getEnvVar("TERM")) !== null)
|
|
116075
|
+
return COLORS_256;
|
|
116076
|
+
const termEnv = getEnvVar("TERM").toLowerCase();
|
|
116077
|
+
if (TERM_ENVS[termEnv])
|
|
116078
|
+
return TERM_ENVS[termEnv];
|
|
116079
|
+
if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null))
|
|
116080
|
+
return COLORS_16;
|
|
116081
|
+
}
|
|
116082
|
+
if (getEnvVar("COLORTERM"))
|
|
116083
|
+
return COLORS_16;
|
|
116084
|
+
return COLORS_2;
|
|
116085
|
+
}
|
|
116086
|
+
|
|
116087
|
+
// ../../node_modules/@better-auth/core/dist/env/logger.mjs
|
|
116088
|
+
var TTY_COLORS = {
|
|
116089
|
+
reset: "\x1B[0m",
|
|
116090
|
+
bright: "\x1B[1m",
|
|
116091
|
+
dim: "\x1B[2m",
|
|
116092
|
+
undim: "\x1B[22m",
|
|
116093
|
+
underscore: "\x1B[4m",
|
|
116094
|
+
blink: "\x1B[5m",
|
|
116095
|
+
reverse: "\x1B[7m",
|
|
116096
|
+
hidden: "\x1B[8m",
|
|
116097
|
+
fg: {
|
|
116098
|
+
black: "\x1B[30m",
|
|
116099
|
+
red: "\x1B[31m",
|
|
116100
|
+
green: "\x1B[32m",
|
|
116101
|
+
yellow: "\x1B[33m",
|
|
116102
|
+
blue: "\x1B[34m",
|
|
116103
|
+
magenta: "\x1B[35m",
|
|
116104
|
+
cyan: "\x1B[36m",
|
|
116105
|
+
white: "\x1B[37m"
|
|
116106
|
+
},
|
|
116107
|
+
bg: {
|
|
116108
|
+
black: "\x1B[40m",
|
|
116109
|
+
red: "\x1B[41m",
|
|
116110
|
+
green: "\x1B[42m",
|
|
116111
|
+
yellow: "\x1B[43m",
|
|
116112
|
+
blue: "\x1B[44m",
|
|
116113
|
+
magenta: "\x1B[45m",
|
|
116114
|
+
cyan: "\x1B[46m",
|
|
116115
|
+
white: "\x1B[47m"
|
|
116116
|
+
}
|
|
116117
|
+
};
|
|
116118
|
+
var levels = [
|
|
116119
|
+
"debug",
|
|
116120
|
+
"info",
|
|
116121
|
+
"success",
|
|
116122
|
+
"warn",
|
|
116123
|
+
"error"
|
|
116124
|
+
];
|
|
116125
|
+
function shouldPublishLog(currentLogLevel, logLevel) {
|
|
116126
|
+
return levels.indexOf(logLevel) >= levels.indexOf(currentLogLevel);
|
|
116127
|
+
}
|
|
116128
|
+
var levelColors = {
|
|
116129
|
+
info: TTY_COLORS.fg.blue,
|
|
116130
|
+
success: TTY_COLORS.fg.green,
|
|
116131
|
+
warn: TTY_COLORS.fg.yellow,
|
|
116132
|
+
error: TTY_COLORS.fg.red,
|
|
116133
|
+
debug: TTY_COLORS.fg.magenta
|
|
116134
|
+
};
|
|
116135
|
+
var formatMessage = (level, message, colorsEnabled) => {
|
|
116136
|
+
const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
116137
|
+
if (colorsEnabled)
|
|
116138
|
+
return `${TTY_COLORS.dim}${timestamp2}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
|
|
116139
|
+
return `${timestamp2} ${level.toUpperCase()} [Better Auth]: ${message}`;
|
|
116140
|
+
};
|
|
116141
|
+
var createLogger = (options) => {
|
|
116142
|
+
const enabled = options?.disabled !== true;
|
|
116143
|
+
const logLevel = options?.level ?? "warn";
|
|
116144
|
+
const colorsEnabled = options?.disableColors !== undefined ? !options.disableColors : getColorDepth() !== 1;
|
|
116145
|
+
const LogFunc = (level, message, args = []) => {
|
|
116146
|
+
if (!enabled || !shouldPublishLog(logLevel, level))
|
|
116147
|
+
return;
|
|
116148
|
+
const formattedMessage = formatMessage(level, message, colorsEnabled);
|
|
116149
|
+
if (!options || typeof options.log !== "function") {
|
|
116150
|
+
if (level === "error")
|
|
116151
|
+
console.error(formattedMessage, ...args);
|
|
116152
|
+
else if (level === "warn")
|
|
116153
|
+
console.warn(formattedMessage, ...args);
|
|
116154
|
+
else
|
|
116155
|
+
console.log(formattedMessage, ...args);
|
|
116156
|
+
return;
|
|
116157
|
+
}
|
|
116158
|
+
options.log(level === "success" ? "info" : level, message, ...args);
|
|
116159
|
+
};
|
|
116160
|
+
return {
|
|
116161
|
+
...Object.fromEntries(levels.map((level) => [level, (...[message, ...args]) => LogFunc(level, message, args)])),
|
|
116162
|
+
get level() {
|
|
116163
|
+
return logLevel;
|
|
116164
|
+
}
|
|
116165
|
+
};
|
|
116166
|
+
};
|
|
116167
|
+
var logger = createLogger();
|
|
116168
|
+
|
|
116169
|
+
// ../../node_modules/better-auth/dist/utils/url.mjs
|
|
116170
|
+
function checkHasPath(url) {
|
|
116171
|
+
try {
|
|
116172
|
+
return (new URL(url).pathname.replace(/\/+$/, "") || "/") !== "/";
|
|
116173
|
+
} catch {
|
|
116174
|
+
throw new BetterAuthError(`Invalid base URL: ${url}. Please provide a valid base URL.`);
|
|
116175
|
+
}
|
|
116176
|
+
}
|
|
116177
|
+
function assertHasProtocol(url) {
|
|
116178
|
+
try {
|
|
116179
|
+
const parsedUrl = new URL(url);
|
|
116180
|
+
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:")
|
|
116181
|
+
throw new BetterAuthError(`Invalid base URL: ${url}. URL must include 'http://' or 'https://'`);
|
|
116182
|
+
} catch (error) {
|
|
116183
|
+
if (error instanceof BetterAuthError)
|
|
116184
|
+
throw error;
|
|
116185
|
+
throw new BetterAuthError(`Invalid base URL: ${url}. Please provide a valid base URL.`, { cause: error });
|
|
116186
|
+
}
|
|
116187
|
+
}
|
|
116188
|
+
function withPath(url, path = "/api/auth") {
|
|
116189
|
+
assertHasProtocol(url);
|
|
116190
|
+
if (checkHasPath(url))
|
|
116191
|
+
return url;
|
|
116192
|
+
const trimmedUrl = url.replace(/\/+$/, "");
|
|
116193
|
+
if (!path || path === "/")
|
|
116194
|
+
return trimmedUrl;
|
|
116195
|
+
path = path.startsWith("/") ? path : `/${path}`;
|
|
116196
|
+
return `${trimmedUrl}${path}`;
|
|
116197
|
+
}
|
|
116198
|
+
function validateProxyHeader(header, type) {
|
|
116199
|
+
if (!header || header.trim() === "")
|
|
116200
|
+
return false;
|
|
116201
|
+
if (type === "proto")
|
|
116202
|
+
return header === "http" || header === "https";
|
|
116203
|
+
if (type === "host") {
|
|
116204
|
+
if ([
|
|
116205
|
+
/\.\./,
|
|
116206
|
+
/\0/,
|
|
116207
|
+
/[\s]/,
|
|
116208
|
+
/^[.]/,
|
|
116209
|
+
/[<>'"]/,
|
|
116210
|
+
/javascript:/i,
|
|
116211
|
+
/file:/i,
|
|
116212
|
+
/data:/i
|
|
116213
|
+
].some((pattern) => pattern.test(header)))
|
|
116214
|
+
return false;
|
|
116215
|
+
return /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(:[0-9]{1,5})?$/.test(header) || /^(\d{1,3}\.){3}\d{1,3}(:[0-9]{1,5})?$/.test(header) || /^\[[0-9a-fA-F:]+\](:[0-9]{1,5})?$/.test(header) || /^localhost(:[0-9]{1,5})?$/i.test(header);
|
|
116216
|
+
}
|
|
116217
|
+
return false;
|
|
116218
|
+
}
|
|
116219
|
+
function getBaseURL(url, path, request3, loadEnv, trustedProxyHeaders) {
|
|
116220
|
+
if (url)
|
|
116221
|
+
return withPath(url, path);
|
|
116222
|
+
if (loadEnv !== false) {
|
|
116223
|
+
const fromEnv = env.BETTER_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL || (env.BASE_URL !== "/" ? env.BASE_URL : undefined);
|
|
116224
|
+
if (fromEnv)
|
|
116225
|
+
return withPath(fromEnv, path);
|
|
116226
|
+
}
|
|
116227
|
+
const fromRequest = request3?.headers.get("x-forwarded-host");
|
|
116228
|
+
const fromRequestProto = request3?.headers.get("x-forwarded-proto");
|
|
116229
|
+
if (fromRequest && fromRequestProto && trustedProxyHeaders) {
|
|
116230
|
+
if (validateProxyHeader(fromRequestProto, "proto") && validateProxyHeader(fromRequest, "host"))
|
|
116231
|
+
try {
|
|
116232
|
+
return withPath(`${fromRequestProto}://${fromRequest}`, path);
|
|
116233
|
+
} catch (_error) {}
|
|
116234
|
+
}
|
|
116235
|
+
if (request3) {
|
|
116236
|
+
const url2 = getOrigin(request3.url);
|
|
116237
|
+
if (!url2)
|
|
116238
|
+
throw new BetterAuthError("Could not get origin from request. Please provide a valid base URL.");
|
|
116239
|
+
return withPath(url2, path);
|
|
116240
|
+
}
|
|
116241
|
+
if (typeof window !== "undefined" && window.location)
|
|
116242
|
+
return withPath(window.location.origin, path);
|
|
116243
|
+
}
|
|
116244
|
+
function getOrigin(url) {
|
|
116245
|
+
try {
|
|
116246
|
+
const parsedUrl = new URL(url);
|
|
116247
|
+
return parsedUrl.origin === "null" ? null : parsedUrl.origin;
|
|
116248
|
+
} catch {
|
|
116249
|
+
return null;
|
|
116250
|
+
}
|
|
116251
|
+
}
|
|
116252
|
+
|
|
116253
|
+
// ../../node_modules/better-auth/dist/client/fetch-plugins.mjs
|
|
116254
|
+
var redirectPlugin = {
|
|
116255
|
+
id: "redirect",
|
|
116256
|
+
name: "Redirect",
|
|
116257
|
+
hooks: { onSuccess(context) {
|
|
116258
|
+
if (context.data?.url && context.data?.redirect) {
|
|
116259
|
+
if (typeof window !== "undefined" && window.location) {
|
|
116260
|
+
if (window.location)
|
|
116261
|
+
try {
|
|
116262
|
+
window.location.href = context.data.url;
|
|
116263
|
+
} catch {}
|
|
116264
|
+
}
|
|
116265
|
+
}
|
|
116266
|
+
} }
|
|
116267
|
+
};
|
|
116268
|
+
|
|
116269
|
+
// ../../node_modules/better-auth/dist/client/session-atom.mjs
|
|
116270
|
+
function getSessionAtom($fetch, options) {
|
|
116271
|
+
const $signal = atom(false);
|
|
116272
|
+
const session = useAuthQuery($signal, "/get-session", $fetch, { method: "GET" });
|
|
116273
|
+
let broadcastSessionUpdate = () => {};
|
|
116274
|
+
onMount(session, () => {
|
|
116275
|
+
const refreshManager = createSessionRefreshManager({
|
|
116276
|
+
sessionAtom: session,
|
|
116277
|
+
sessionSignal: $signal,
|
|
116278
|
+
$fetch,
|
|
116279
|
+
options
|
|
116280
|
+
});
|
|
116281
|
+
refreshManager.init();
|
|
116282
|
+
broadcastSessionUpdate = refreshManager.broadcastSessionUpdate;
|
|
116283
|
+
return () => {
|
|
116284
|
+
refreshManager.cleanup();
|
|
116285
|
+
};
|
|
116286
|
+
});
|
|
116287
|
+
return {
|
|
116288
|
+
session,
|
|
116289
|
+
$sessionSignal: $signal,
|
|
116290
|
+
broadcastSessionUpdate: (trigger) => broadcastSessionUpdate(trigger)
|
|
116291
|
+
};
|
|
116292
|
+
}
|
|
116293
|
+
|
|
116294
|
+
// ../../node_modules/defu/dist/defu.mjs
|
|
116295
|
+
function isPlainObject(value) {
|
|
116296
|
+
if (value === null || typeof value !== "object") {
|
|
116297
|
+
return false;
|
|
116298
|
+
}
|
|
116299
|
+
const prototype = Object.getPrototypeOf(value);
|
|
116300
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
116301
|
+
return false;
|
|
116302
|
+
}
|
|
116303
|
+
if (Symbol.iterator in value) {
|
|
116304
|
+
return false;
|
|
116305
|
+
}
|
|
116306
|
+
if (Symbol.toStringTag in value) {
|
|
116307
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
116308
|
+
}
|
|
116309
|
+
return true;
|
|
116310
|
+
}
|
|
116311
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
116312
|
+
if (!isPlainObject(defaults)) {
|
|
116313
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
116314
|
+
}
|
|
116315
|
+
const object = Object.assign({}, defaults);
|
|
116316
|
+
for (const key in baseObject) {
|
|
116317
|
+
if (key === "__proto__" || key === "constructor") {
|
|
116318
|
+
continue;
|
|
116319
|
+
}
|
|
116320
|
+
const value = baseObject[key];
|
|
116321
|
+
if (value === null || value === undefined) {
|
|
116322
|
+
continue;
|
|
116323
|
+
}
|
|
116324
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
116325
|
+
continue;
|
|
116326
|
+
}
|
|
116327
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
116328
|
+
object[key] = [...value, ...object[key]];
|
|
116329
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
116330
|
+
object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
116331
|
+
} else {
|
|
116332
|
+
object[key] = value;
|
|
116333
|
+
}
|
|
116334
|
+
}
|
|
116335
|
+
return object;
|
|
116336
|
+
}
|
|
116337
|
+
function createDefu(merger) {
|
|
116338
|
+
return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
116339
|
+
}
|
|
116340
|
+
var defu = createDefu();
|
|
116341
|
+
var defuFn = createDefu((object, key, currentValue) => {
|
|
116342
|
+
if (object[key] !== undefined && typeof currentValue === "function") {
|
|
116343
|
+
object[key] = currentValue(object[key]);
|
|
116344
|
+
return true;
|
|
116345
|
+
}
|
|
116346
|
+
});
|
|
116347
|
+
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
116348
|
+
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
116349
|
+
object[key] = currentValue(object[key]);
|
|
116350
|
+
return true;
|
|
116351
|
+
}
|
|
116352
|
+
});
|
|
116353
|
+
|
|
116354
|
+
// ../../node_modules/@better-fetch/fetch/dist/index.js
|
|
116355
|
+
var __defProp5 = Object.defineProperty;
|
|
116356
|
+
var __defProps = Object.defineProperties;
|
|
116357
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
116358
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
116359
|
+
var __hasOwnProp5 = Object.prototype.hasOwnProperty;
|
|
116360
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
116361
|
+
var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
116362
|
+
var __spreadValues = (a, b) => {
|
|
116363
|
+
for (var prop in b || (b = {}))
|
|
116364
|
+
if (__hasOwnProp5.call(b, prop))
|
|
116365
|
+
__defNormalProp(a, prop, b[prop]);
|
|
116366
|
+
if (__getOwnPropSymbols)
|
|
116367
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
116368
|
+
if (__propIsEnum.call(b, prop))
|
|
116369
|
+
__defNormalProp(a, prop, b[prop]);
|
|
116370
|
+
}
|
|
116371
|
+
return a;
|
|
116372
|
+
};
|
|
116373
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
116374
|
+
var BetterFetchError = class extends Error {
|
|
116375
|
+
constructor(status, statusText, error) {
|
|
116376
|
+
super(statusText || status.toString(), {
|
|
116377
|
+
cause: error
|
|
116378
|
+
});
|
|
116379
|
+
this.status = status;
|
|
116380
|
+
this.statusText = statusText;
|
|
116381
|
+
this.error = error;
|
|
116382
|
+
Error.captureStackTrace(this, this.constructor);
|
|
116383
|
+
}
|
|
116384
|
+
};
|
|
116385
|
+
var initializePlugins = async (url, options) => {
|
|
116386
|
+
var _a, _b, _c, _d, _e, _f;
|
|
116387
|
+
let opts = options || {};
|
|
116388
|
+
const hooks = {
|
|
116389
|
+
onRequest: [options == null ? undefined : options.onRequest],
|
|
116390
|
+
onResponse: [options == null ? undefined : options.onResponse],
|
|
116391
|
+
onSuccess: [options == null ? undefined : options.onSuccess],
|
|
116392
|
+
onError: [options == null ? undefined : options.onError],
|
|
116393
|
+
onRetry: [options == null ? undefined : options.onRetry]
|
|
116394
|
+
};
|
|
116395
|
+
if (!options || !(options == null ? undefined : options.plugins)) {
|
|
116396
|
+
return {
|
|
116397
|
+
url,
|
|
116398
|
+
options: opts,
|
|
116399
|
+
hooks
|
|
116400
|
+
};
|
|
116401
|
+
}
|
|
116402
|
+
for (const plugin of (options == null ? undefined : options.plugins) || []) {
|
|
116403
|
+
if (plugin.init) {
|
|
116404
|
+
const pluginRes = await ((_a = plugin.init) == null ? undefined : _a.call(plugin, url.toString(), options));
|
|
116405
|
+
opts = pluginRes.options || opts;
|
|
116406
|
+
url = pluginRes.url;
|
|
116407
|
+
}
|
|
116408
|
+
hooks.onRequest.push((_b = plugin.hooks) == null ? undefined : _b.onRequest);
|
|
116409
|
+
hooks.onResponse.push((_c = plugin.hooks) == null ? undefined : _c.onResponse);
|
|
116410
|
+
hooks.onSuccess.push((_d = plugin.hooks) == null ? undefined : _d.onSuccess);
|
|
116411
|
+
hooks.onError.push((_e = plugin.hooks) == null ? undefined : _e.onError);
|
|
116412
|
+
hooks.onRetry.push((_f = plugin.hooks) == null ? undefined : _f.onRetry);
|
|
116413
|
+
}
|
|
116414
|
+
return {
|
|
116415
|
+
url,
|
|
116416
|
+
options: opts,
|
|
116417
|
+
hooks
|
|
116418
|
+
};
|
|
116419
|
+
};
|
|
116420
|
+
var LinearRetryStrategy = class {
|
|
116421
|
+
constructor(options) {
|
|
116422
|
+
this.options = options;
|
|
116423
|
+
}
|
|
116424
|
+
shouldAttemptRetry(attempt, response) {
|
|
116425
|
+
if (this.options.shouldRetry) {
|
|
116426
|
+
return Promise.resolve(attempt < this.options.attempts && this.options.shouldRetry(response));
|
|
116427
|
+
}
|
|
116428
|
+
return Promise.resolve(attempt < this.options.attempts);
|
|
116429
|
+
}
|
|
116430
|
+
getDelay() {
|
|
116431
|
+
return this.options.delay;
|
|
116432
|
+
}
|
|
116433
|
+
};
|
|
116434
|
+
var ExponentialRetryStrategy = class {
|
|
116435
|
+
constructor(options) {
|
|
116436
|
+
this.options = options;
|
|
116437
|
+
}
|
|
116438
|
+
shouldAttemptRetry(attempt, response) {
|
|
116439
|
+
if (this.options.shouldRetry) {
|
|
116440
|
+
return Promise.resolve(attempt < this.options.attempts && this.options.shouldRetry(response));
|
|
116441
|
+
}
|
|
116442
|
+
return Promise.resolve(attempt < this.options.attempts);
|
|
116443
|
+
}
|
|
116444
|
+
getDelay(attempt) {
|
|
116445
|
+
const delay = Math.min(this.options.maxDelay, this.options.baseDelay * 2 ** attempt);
|
|
116446
|
+
return delay;
|
|
116447
|
+
}
|
|
116448
|
+
};
|
|
116449
|
+
function createRetryStrategy(options) {
|
|
116450
|
+
if (typeof options === "number") {
|
|
116451
|
+
return new LinearRetryStrategy({
|
|
116452
|
+
type: "linear",
|
|
116453
|
+
attempts: options,
|
|
116454
|
+
delay: 1000
|
|
116455
|
+
});
|
|
116456
|
+
}
|
|
116457
|
+
switch (options.type) {
|
|
116458
|
+
case "linear":
|
|
116459
|
+
return new LinearRetryStrategy(options);
|
|
116460
|
+
case "exponential":
|
|
116461
|
+
return new ExponentialRetryStrategy(options);
|
|
116462
|
+
default:
|
|
116463
|
+
throw new Error("Invalid retry strategy");
|
|
116464
|
+
}
|
|
116465
|
+
}
|
|
116466
|
+
var getAuthHeader = async (options) => {
|
|
116467
|
+
const headers = {};
|
|
116468
|
+
const getValue = async (value) => typeof value === "function" ? await value() : value;
|
|
116469
|
+
if (options == null ? undefined : options.auth) {
|
|
116470
|
+
if (options.auth.type === "Bearer") {
|
|
116471
|
+
const token = await getValue(options.auth.token);
|
|
116472
|
+
if (!token) {
|
|
116473
|
+
return headers;
|
|
116474
|
+
}
|
|
116475
|
+
headers["authorization"] = `Bearer ${token}`;
|
|
116476
|
+
} else if (options.auth.type === "Basic") {
|
|
116477
|
+
const [username, password] = await Promise.all([
|
|
116478
|
+
getValue(options.auth.username),
|
|
116479
|
+
getValue(options.auth.password)
|
|
116480
|
+
]);
|
|
116481
|
+
if (!username || !password) {
|
|
116482
|
+
return headers;
|
|
116483
|
+
}
|
|
116484
|
+
headers["authorization"] = `Basic ${btoa(`${username}:${password}`)}`;
|
|
116485
|
+
} else if (options.auth.type === "Custom") {
|
|
116486
|
+
const [prefix2, value] = await Promise.all([
|
|
116487
|
+
getValue(options.auth.prefix),
|
|
116488
|
+
getValue(options.auth.value)
|
|
116489
|
+
]);
|
|
116490
|
+
if (!value) {
|
|
116491
|
+
return headers;
|
|
116492
|
+
}
|
|
116493
|
+
headers["authorization"] = `${prefix2 != null ? prefix2 : ""} ${value}`;
|
|
116494
|
+
}
|
|
116495
|
+
}
|
|
116496
|
+
return headers;
|
|
116497
|
+
};
|
|
116498
|
+
var JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
|
|
116499
|
+
function detectResponseType(request3) {
|
|
116500
|
+
const _contentType = request3.headers.get("content-type");
|
|
116501
|
+
const textTypes = /* @__PURE__ */ new Set([
|
|
116502
|
+
"image/svg",
|
|
116503
|
+
"application/xml",
|
|
116504
|
+
"application/xhtml",
|
|
116505
|
+
"application/html"
|
|
116506
|
+
]);
|
|
116507
|
+
if (!_contentType) {
|
|
116508
|
+
return "json";
|
|
116509
|
+
}
|
|
116510
|
+
const contentType = _contentType.split(";").shift() || "";
|
|
116511
|
+
if (JSON_RE.test(contentType)) {
|
|
116512
|
+
return "json";
|
|
116513
|
+
}
|
|
116514
|
+
if (textTypes.has(contentType) || contentType.startsWith("text/")) {
|
|
116515
|
+
return "text";
|
|
116516
|
+
}
|
|
116517
|
+
return "blob";
|
|
116518
|
+
}
|
|
116519
|
+
function isJSONParsable(value) {
|
|
116520
|
+
try {
|
|
116521
|
+
JSON.parse(value);
|
|
116522
|
+
return true;
|
|
116523
|
+
} catch (error) {
|
|
116524
|
+
return false;
|
|
116525
|
+
}
|
|
116526
|
+
}
|
|
116527
|
+
function isJSONSerializable(value) {
|
|
116528
|
+
if (value === undefined) {
|
|
116529
|
+
return false;
|
|
116530
|
+
}
|
|
116531
|
+
const t = typeof value;
|
|
116532
|
+
if (t === "string" || t === "number" || t === "boolean" || t === null) {
|
|
116533
|
+
return true;
|
|
116534
|
+
}
|
|
116535
|
+
if (t !== "object") {
|
|
116536
|
+
return false;
|
|
116537
|
+
}
|
|
116538
|
+
if (Array.isArray(value)) {
|
|
116539
|
+
return true;
|
|
116540
|
+
}
|
|
116541
|
+
if (value.buffer) {
|
|
116542
|
+
return false;
|
|
116543
|
+
}
|
|
116544
|
+
return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
|
|
116545
|
+
}
|
|
116546
|
+
function jsonParse(text) {
|
|
116547
|
+
try {
|
|
116548
|
+
return JSON.parse(text);
|
|
116549
|
+
} catch (error) {
|
|
116550
|
+
return text;
|
|
116551
|
+
}
|
|
116552
|
+
}
|
|
116553
|
+
function isFunction2(value) {
|
|
116554
|
+
return typeof value === "function";
|
|
116555
|
+
}
|
|
116556
|
+
function getFetch(options) {
|
|
116557
|
+
if (options == null ? undefined : options.customFetchImpl) {
|
|
116558
|
+
return options.customFetchImpl;
|
|
116559
|
+
}
|
|
116560
|
+
if (typeof globalThis !== "undefined" && isFunction2(globalThis.fetch)) {
|
|
116561
|
+
return globalThis.fetch;
|
|
116562
|
+
}
|
|
116563
|
+
if (typeof window !== "undefined" && isFunction2(window.fetch)) {
|
|
116564
|
+
return window.fetch;
|
|
116565
|
+
}
|
|
116566
|
+
throw new Error("No fetch implementation found");
|
|
116567
|
+
}
|
|
116568
|
+
async function getHeaders(opts) {
|
|
116569
|
+
const headers = new Headers(opts == null ? undefined : opts.headers);
|
|
116570
|
+
const authHeader = await getAuthHeader(opts);
|
|
116571
|
+
for (const [key, value] of Object.entries(authHeader || {})) {
|
|
116572
|
+
headers.set(key, value);
|
|
116573
|
+
}
|
|
116574
|
+
if (!headers.has("content-type")) {
|
|
116575
|
+
const t = detectContentType(opts == null ? undefined : opts.body);
|
|
116576
|
+
if (t) {
|
|
116577
|
+
headers.set("content-type", t);
|
|
116578
|
+
}
|
|
116579
|
+
}
|
|
116580
|
+
return headers;
|
|
116581
|
+
}
|
|
116582
|
+
function detectContentType(body) {
|
|
116583
|
+
if (isJSONSerializable(body)) {
|
|
116584
|
+
return "application/json";
|
|
116585
|
+
}
|
|
116586
|
+
return null;
|
|
116587
|
+
}
|
|
116588
|
+
function getBody(options) {
|
|
116589
|
+
if (!(options == null ? undefined : options.body)) {
|
|
116590
|
+
return null;
|
|
116591
|
+
}
|
|
116592
|
+
const headers = new Headers(options == null ? undefined : options.headers);
|
|
116593
|
+
if (isJSONSerializable(options.body) && !headers.has("content-type")) {
|
|
116594
|
+
for (const [key, value] of Object.entries(options == null ? undefined : options.body)) {
|
|
116595
|
+
if (value instanceof Date) {
|
|
116596
|
+
options.body[key] = value.toISOString();
|
|
116597
|
+
}
|
|
116598
|
+
}
|
|
116599
|
+
return JSON.stringify(options.body);
|
|
116600
|
+
}
|
|
116601
|
+
if (headers.has("content-type") && headers.get("content-type") === "application/x-www-form-urlencoded") {
|
|
116602
|
+
if (isJSONSerializable(options.body)) {
|
|
116603
|
+
return new URLSearchParams(options.body).toString();
|
|
116604
|
+
}
|
|
116605
|
+
return options.body;
|
|
116606
|
+
}
|
|
116607
|
+
return options.body;
|
|
116608
|
+
}
|
|
116609
|
+
function getMethod(url, options) {
|
|
116610
|
+
var _a;
|
|
116611
|
+
if (options == null ? undefined : options.method) {
|
|
116612
|
+
return options.method.toUpperCase();
|
|
116613
|
+
}
|
|
116614
|
+
if (url.startsWith("@")) {
|
|
116615
|
+
const pMethod = (_a = url.split("@")[1]) == null ? undefined : _a.split("/")[0];
|
|
116616
|
+
if (!methods.includes(pMethod)) {
|
|
116617
|
+
return (options == null ? undefined : options.body) ? "POST" : "GET";
|
|
116618
|
+
}
|
|
116619
|
+
return pMethod.toUpperCase();
|
|
114966
116620
|
}
|
|
114967
|
-
return
|
|
116621
|
+
return (options == null ? undefined : options.body) ? "POST" : "GET";
|
|
114968
116622
|
}
|
|
114969
|
-
function
|
|
114970
|
-
|
|
116623
|
+
function getTimeout(options, controller) {
|
|
116624
|
+
let abortTimeout;
|
|
116625
|
+
if (!(options == null ? undefined : options.signal) && (options == null ? undefined : options.timeout)) {
|
|
116626
|
+
abortTimeout = setTimeout(() => controller == null ? undefined : controller.abort(), options == null ? undefined : options.timeout);
|
|
116627
|
+
}
|
|
116628
|
+
return {
|
|
116629
|
+
abortTimeout,
|
|
116630
|
+
clearTimeout: () => {
|
|
116631
|
+
if (abortTimeout) {
|
|
116632
|
+
clearTimeout(abortTimeout);
|
|
116633
|
+
}
|
|
116634
|
+
}
|
|
116635
|
+
};
|
|
114971
116636
|
}
|
|
114972
|
-
|
|
114973
|
-
|
|
116637
|
+
var ValidationError = class _ValidationError extends Error {
|
|
116638
|
+
constructor(issues, message) {
|
|
116639
|
+
super(message || JSON.stringify(issues, null, 2));
|
|
116640
|
+
this.issues = issues;
|
|
116641
|
+
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
116642
|
+
}
|
|
116643
|
+
};
|
|
116644
|
+
async function parseStandardSchema(schema, input) {
|
|
116645
|
+
const result = await schema["~standard"].validate(input);
|
|
116646
|
+
if (result.issues) {
|
|
116647
|
+
throw new ValidationError(result.issues);
|
|
116648
|
+
}
|
|
116649
|
+
return result.value;
|
|
116650
|
+
}
|
|
116651
|
+
var methods = ["get", "post", "put", "patch", "delete"];
|
|
116652
|
+
var applySchemaPlugin = (config) => ({
|
|
116653
|
+
id: "apply-schema",
|
|
116654
|
+
name: "Apply Schema",
|
|
116655
|
+
version: "1.0.0",
|
|
116656
|
+
async init(url, options) {
|
|
116657
|
+
var _a, _b, _c, _d;
|
|
116658
|
+
const schema = ((_b = (_a = config.plugins) == null ? undefined : _a.find((plugin) => {
|
|
116659
|
+
var _a2;
|
|
116660
|
+
return ((_a2 = plugin.schema) == null ? undefined : _a2.config) ? url.startsWith(plugin.schema.config.baseURL || "") || url.startsWith(plugin.schema.config.prefix || "") : false;
|
|
116661
|
+
})) == null ? undefined : _b.schema) || config.schema;
|
|
116662
|
+
if (schema) {
|
|
116663
|
+
let urlKey = url;
|
|
116664
|
+
if ((_c = schema.config) == null ? undefined : _c.prefix) {
|
|
116665
|
+
if (urlKey.startsWith(schema.config.prefix)) {
|
|
116666
|
+
urlKey = urlKey.replace(schema.config.prefix, "");
|
|
116667
|
+
if (schema.config.baseURL) {
|
|
116668
|
+
url = url.replace(schema.config.prefix, schema.config.baseURL);
|
|
116669
|
+
}
|
|
116670
|
+
}
|
|
116671
|
+
}
|
|
116672
|
+
if ((_d = schema.config) == null ? undefined : _d.baseURL) {
|
|
116673
|
+
if (urlKey.startsWith(schema.config.baseURL)) {
|
|
116674
|
+
urlKey = urlKey.replace(schema.config.baseURL, "");
|
|
116675
|
+
}
|
|
116676
|
+
}
|
|
116677
|
+
const keySchema = schema.schema[urlKey];
|
|
116678
|
+
if (keySchema) {
|
|
116679
|
+
let opts = __spreadProps(__spreadValues({}, options), {
|
|
116680
|
+
method: keySchema.method,
|
|
116681
|
+
output: keySchema.output
|
|
116682
|
+
});
|
|
116683
|
+
if (!(options == null ? undefined : options.disableValidation)) {
|
|
116684
|
+
opts = __spreadProps(__spreadValues({}, opts), {
|
|
116685
|
+
body: keySchema.input ? await parseStandardSchema(keySchema.input, options == null ? undefined : options.body) : options == null ? undefined : options.body,
|
|
116686
|
+
params: keySchema.params ? await parseStandardSchema(keySchema.params, options == null ? undefined : options.params) : options == null ? undefined : options.params,
|
|
116687
|
+
query: keySchema.query ? await parseStandardSchema(keySchema.query, options == null ? undefined : options.query) : options == null ? undefined : options.query
|
|
116688
|
+
});
|
|
116689
|
+
}
|
|
116690
|
+
return {
|
|
116691
|
+
url,
|
|
116692
|
+
options: opts
|
|
116693
|
+
};
|
|
116694
|
+
}
|
|
116695
|
+
}
|
|
116696
|
+
return {
|
|
116697
|
+
url,
|
|
116698
|
+
options
|
|
116699
|
+
};
|
|
116700
|
+
}
|
|
116701
|
+
});
|
|
116702
|
+
var createFetch = (config) => {
|
|
116703
|
+
async function $fetch(url, options) {
|
|
116704
|
+
const opts = __spreadProps(__spreadValues(__spreadValues({}, config), options), {
|
|
116705
|
+
plugins: [...(config == null ? undefined : config.plugins) || [], applySchemaPlugin(config || {}), ...(options == null ? undefined : options.plugins) || []]
|
|
116706
|
+
});
|
|
116707
|
+
if (config == null ? undefined : config.catchAllError) {
|
|
116708
|
+
try {
|
|
116709
|
+
return await betterFetch(url, opts);
|
|
116710
|
+
} catch (error) {
|
|
116711
|
+
return {
|
|
116712
|
+
data: null,
|
|
116713
|
+
error: {
|
|
116714
|
+
status: 500,
|
|
116715
|
+
statusText: "Fetch Error",
|
|
116716
|
+
message: "Fetch related error. Captured by catchAllError option. See error property for more details.",
|
|
116717
|
+
error
|
|
116718
|
+
}
|
|
116719
|
+
};
|
|
116720
|
+
}
|
|
116721
|
+
}
|
|
116722
|
+
return await betterFetch(url, opts);
|
|
116723
|
+
}
|
|
116724
|
+
return $fetch;
|
|
116725
|
+
};
|
|
116726
|
+
function getURL2(url, option) {
|
|
116727
|
+
const { baseURL, params, query } = option || {
|
|
116728
|
+
query: {},
|
|
116729
|
+
params: {},
|
|
116730
|
+
baseURL: ""
|
|
116731
|
+
};
|
|
116732
|
+
let basePath = url.startsWith("http") ? url.split("/").slice(0, 3).join("/") : baseURL || "";
|
|
116733
|
+
if (url.startsWith("@")) {
|
|
116734
|
+
const m = url.toString().split("@")[1].split("/")[0];
|
|
116735
|
+
if (methods.includes(m)) {
|
|
116736
|
+
url = url.replace(`@${m}/`, "/");
|
|
116737
|
+
}
|
|
116738
|
+
}
|
|
116739
|
+
if (!basePath.endsWith("/"))
|
|
116740
|
+
basePath += "/";
|
|
116741
|
+
let [path, urlQuery] = url.replace(basePath, "").split("?");
|
|
116742
|
+
const queryParams = new URLSearchParams(urlQuery);
|
|
116743
|
+
for (const [key, value] of Object.entries(query || {})) {
|
|
116744
|
+
if (value == null)
|
|
116745
|
+
continue;
|
|
116746
|
+
let serializedValue;
|
|
116747
|
+
if (typeof value === "string") {
|
|
116748
|
+
serializedValue = value;
|
|
116749
|
+
} else if (Array.isArray(value)) {
|
|
116750
|
+
for (const val of value) {
|
|
116751
|
+
queryParams.append(key, val);
|
|
116752
|
+
}
|
|
116753
|
+
continue;
|
|
116754
|
+
} else {
|
|
116755
|
+
serializedValue = JSON.stringify(value);
|
|
116756
|
+
}
|
|
116757
|
+
queryParams.set(key, serializedValue);
|
|
116758
|
+
}
|
|
116759
|
+
if (params) {
|
|
116760
|
+
if (Array.isArray(params)) {
|
|
116761
|
+
const paramPaths = path.split("/").filter((p) => p.startsWith(":"));
|
|
116762
|
+
for (const [index, key] of paramPaths.entries()) {
|
|
116763
|
+
const value = params[index];
|
|
116764
|
+
path = path.replace(key, value);
|
|
116765
|
+
}
|
|
116766
|
+
} else {
|
|
116767
|
+
for (const [key, value] of Object.entries(params)) {
|
|
116768
|
+
path = path.replace(`:${key}`, String(value));
|
|
116769
|
+
}
|
|
116770
|
+
}
|
|
116771
|
+
}
|
|
116772
|
+
path = path.split("/").map(encodeURIComponent).join("/");
|
|
116773
|
+
if (path.startsWith("/"))
|
|
116774
|
+
path = path.slice(1);
|
|
116775
|
+
let queryParamString = queryParams.toString();
|
|
116776
|
+
queryParamString = queryParamString.length > 0 ? `?${queryParamString}`.replace(/\+/g, "%20") : "";
|
|
116777
|
+
if (!basePath.startsWith("http")) {
|
|
116778
|
+
return `${basePath}${path}${queryParamString}`;
|
|
116779
|
+
}
|
|
116780
|
+
const _url = new URL(`${path}${queryParamString}`, basePath);
|
|
116781
|
+
return _url;
|
|
114974
116782
|
}
|
|
114975
|
-
async
|
|
116783
|
+
var betterFetch = async (url, options) => {
|
|
116784
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
116785
|
+
const {
|
|
116786
|
+
hooks,
|
|
116787
|
+
url: __url,
|
|
116788
|
+
options: opts
|
|
116789
|
+
} = await initializePlugins(url, options);
|
|
116790
|
+
const fetch2 = getFetch(opts);
|
|
116791
|
+
const controller = new AbortController;
|
|
116792
|
+
const signal = (_a = opts.signal) != null ? _a : controller.signal;
|
|
116793
|
+
const _url = getURL2(__url, opts);
|
|
116794
|
+
const body = getBody(opts);
|
|
116795
|
+
const headers = await getHeaders(opts);
|
|
116796
|
+
const method = getMethod(__url, opts);
|
|
116797
|
+
let context = __spreadProps(__spreadValues({}, opts), {
|
|
116798
|
+
url: _url,
|
|
116799
|
+
headers,
|
|
116800
|
+
body,
|
|
116801
|
+
method,
|
|
116802
|
+
signal
|
|
116803
|
+
});
|
|
116804
|
+
for (const onRequest of hooks.onRequest) {
|
|
116805
|
+
if (onRequest) {
|
|
116806
|
+
const res = await onRequest(context);
|
|
116807
|
+
if (typeof res === "object" && res !== null) {
|
|
116808
|
+
context = res;
|
|
116809
|
+
}
|
|
116810
|
+
}
|
|
116811
|
+
}
|
|
116812
|
+
if ("pipeTo" in context && typeof context.pipeTo === "function" || typeof ((_b = options == null ? undefined : options.body) == null ? undefined : _b.pipe) === "function") {
|
|
116813
|
+
if (!("duplex" in context)) {
|
|
116814
|
+
context.duplex = "half";
|
|
116815
|
+
}
|
|
116816
|
+
}
|
|
116817
|
+
const { clearTimeout: clearTimeout2 } = getTimeout(opts, controller);
|
|
116818
|
+
let response = await fetch2(context.url, context);
|
|
116819
|
+
clearTimeout2();
|
|
116820
|
+
const responseContext = {
|
|
116821
|
+
response,
|
|
116822
|
+
request: context
|
|
116823
|
+
};
|
|
116824
|
+
for (const onResponse of hooks.onResponse) {
|
|
116825
|
+
if (onResponse) {
|
|
116826
|
+
const r6 = await onResponse(__spreadProps(__spreadValues({}, responseContext), {
|
|
116827
|
+
response: ((_c = options == null ? undefined : options.hookOptions) == null ? undefined : _c.cloneResponse) ? response.clone() : response
|
|
116828
|
+
}));
|
|
116829
|
+
if (r6 instanceof Response) {
|
|
116830
|
+
response = r6;
|
|
116831
|
+
} else if (typeof r6 === "object" && r6 !== null) {
|
|
116832
|
+
response = r6.response;
|
|
116833
|
+
}
|
|
116834
|
+
}
|
|
116835
|
+
}
|
|
116836
|
+
if (response.ok) {
|
|
116837
|
+
const hasBody = context.method !== "HEAD";
|
|
116838
|
+
if (!hasBody) {
|
|
116839
|
+
return {
|
|
116840
|
+
data: "",
|
|
116841
|
+
error: null
|
|
116842
|
+
};
|
|
116843
|
+
}
|
|
116844
|
+
const responseType = detectResponseType(response);
|
|
116845
|
+
const successContext = {
|
|
116846
|
+
data: null,
|
|
116847
|
+
response,
|
|
116848
|
+
request: context
|
|
116849
|
+
};
|
|
116850
|
+
if (responseType === "json" || responseType === "text") {
|
|
116851
|
+
const text = await response.text();
|
|
116852
|
+
const parser2 = (_d = context.jsonParser) != null ? _d : jsonParse;
|
|
116853
|
+
successContext.data = await parser2(text);
|
|
116854
|
+
} else {
|
|
116855
|
+
successContext.data = await response[responseType]();
|
|
116856
|
+
}
|
|
116857
|
+
if (context == null ? undefined : context.output) {
|
|
116858
|
+
if (context.output && !context.disableValidation) {
|
|
116859
|
+
successContext.data = await parseStandardSchema(context.output, successContext.data);
|
|
116860
|
+
}
|
|
116861
|
+
}
|
|
116862
|
+
for (const onSuccess of hooks.onSuccess) {
|
|
116863
|
+
if (onSuccess) {
|
|
116864
|
+
await onSuccess(__spreadProps(__spreadValues({}, successContext), {
|
|
116865
|
+
response: ((_e = options == null ? undefined : options.hookOptions) == null ? undefined : _e.cloneResponse) ? response.clone() : response
|
|
116866
|
+
}));
|
|
116867
|
+
}
|
|
116868
|
+
}
|
|
116869
|
+
if (options == null ? undefined : options.throw) {
|
|
116870
|
+
return successContext.data;
|
|
116871
|
+
}
|
|
116872
|
+
return {
|
|
116873
|
+
data: successContext.data,
|
|
116874
|
+
error: null
|
|
116875
|
+
};
|
|
116876
|
+
}
|
|
116877
|
+
const parser = (_f = options == null ? undefined : options.jsonParser) != null ? _f : jsonParse;
|
|
116878
|
+
const responseText = await response.text();
|
|
116879
|
+
const isJSONResponse = isJSONParsable(responseText);
|
|
116880
|
+
const errorObject = isJSONResponse ? await parser(responseText) : null;
|
|
116881
|
+
const errorContext = {
|
|
116882
|
+
response,
|
|
116883
|
+
responseText,
|
|
116884
|
+
request: context,
|
|
116885
|
+
error: __spreadProps(__spreadValues({}, errorObject), {
|
|
116886
|
+
status: response.status,
|
|
116887
|
+
statusText: response.statusText
|
|
116888
|
+
})
|
|
116889
|
+
};
|
|
116890
|
+
for (const onError of hooks.onError) {
|
|
116891
|
+
if (onError) {
|
|
116892
|
+
await onError(__spreadProps(__spreadValues({}, errorContext), {
|
|
116893
|
+
response: ((_g = options == null ? undefined : options.hookOptions) == null ? undefined : _g.cloneResponse) ? response.clone() : response
|
|
116894
|
+
}));
|
|
116895
|
+
}
|
|
116896
|
+
}
|
|
116897
|
+
if (options == null ? undefined : options.retry) {
|
|
116898
|
+
const retryStrategy = createRetryStrategy(options.retry);
|
|
116899
|
+
const _retryAttempt = (_h = options.retryAttempt) != null ? _h : 0;
|
|
116900
|
+
if (await retryStrategy.shouldAttemptRetry(_retryAttempt, response)) {
|
|
116901
|
+
for (const onRetry of hooks.onRetry) {
|
|
116902
|
+
if (onRetry) {
|
|
116903
|
+
await onRetry(responseContext);
|
|
116904
|
+
}
|
|
116905
|
+
}
|
|
116906
|
+
const delay = retryStrategy.getDelay(_retryAttempt);
|
|
116907
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
116908
|
+
return await betterFetch(url, __spreadProps(__spreadValues({}, options), {
|
|
116909
|
+
retryAttempt: _retryAttempt + 1
|
|
116910
|
+
}));
|
|
116911
|
+
}
|
|
116912
|
+
}
|
|
116913
|
+
if (options == null ? undefined : options.throw) {
|
|
116914
|
+
throw new BetterFetchError(response.status, response.statusText, isJSONResponse ? errorObject : responseText);
|
|
116915
|
+
}
|
|
116916
|
+
return {
|
|
116917
|
+
data: null,
|
|
116918
|
+
error: __spreadProps(__spreadValues({}, errorObject), {
|
|
116919
|
+
status: response.status,
|
|
116920
|
+
statusText: response.statusText
|
|
116921
|
+
})
|
|
116922
|
+
};
|
|
116923
|
+
};
|
|
116924
|
+
|
|
116925
|
+
// ../../node_modules/better-auth/dist/client/config.mjs
|
|
116926
|
+
var resolvePublicAuthUrl = (basePath) => {
|
|
116927
|
+
if (typeof process === "undefined")
|
|
116928
|
+
return;
|
|
116929
|
+
const path = basePath ?? "/api/auth";
|
|
116930
|
+
if (process.env.NEXT_PUBLIC_AUTH_URL)
|
|
116931
|
+
return process.env.NEXT_PUBLIC_AUTH_URL;
|
|
116932
|
+
if (typeof window === "undefined") {
|
|
116933
|
+
if (process.env.NEXTAUTH_URL)
|
|
116934
|
+
try {
|
|
116935
|
+
return process.env.NEXTAUTH_URL;
|
|
116936
|
+
} catch {}
|
|
116937
|
+
if (process.env.VERCEL_URL)
|
|
116938
|
+
try {
|
|
116939
|
+
const protocol = process.env.VERCEL_URL.startsWith("http") ? "" : "https://";
|
|
116940
|
+
return `${new URL(`${protocol}${process.env.VERCEL_URL}`).origin}${path}`;
|
|
116941
|
+
} catch {}
|
|
116942
|
+
}
|
|
116943
|
+
};
|
|
116944
|
+
var getClientConfig = (options, loadEnv) => {
|
|
116945
|
+
const isCredentialsSupported = "credentials" in Request.prototype;
|
|
116946
|
+
const baseURL = getBaseURL(options?.baseURL, options?.basePath, undefined, loadEnv) ?? resolvePublicAuthUrl(options?.basePath) ?? "/api/auth";
|
|
116947
|
+
const pluginsFetchPlugins = options?.plugins?.flatMap((plugin) => plugin.fetchPlugins).filter((pl) => pl !== undefined) || [];
|
|
116948
|
+
const lifeCyclePlugin = {
|
|
116949
|
+
id: "lifecycle-hooks",
|
|
116950
|
+
name: "lifecycle-hooks",
|
|
116951
|
+
hooks: {
|
|
116952
|
+
onSuccess: options?.fetchOptions?.onSuccess,
|
|
116953
|
+
onError: options?.fetchOptions?.onError,
|
|
116954
|
+
onRequest: options?.fetchOptions?.onRequest,
|
|
116955
|
+
onResponse: options?.fetchOptions?.onResponse
|
|
116956
|
+
}
|
|
116957
|
+
};
|
|
116958
|
+
const { onSuccess: _onSuccess, onError: _onError, onRequest: _onRequest, onResponse: _onResponse, ...restOfFetchOptions } = options?.fetchOptions || {};
|
|
116959
|
+
const $fetch = createFetch({
|
|
116960
|
+
baseURL,
|
|
116961
|
+
...isCredentialsSupported ? { credentials: "include" } : {},
|
|
116962
|
+
method: "GET",
|
|
116963
|
+
jsonParser(text) {
|
|
116964
|
+
if (!text)
|
|
116965
|
+
return null;
|
|
116966
|
+
return parseJSON(text, { strict: false });
|
|
116967
|
+
},
|
|
116968
|
+
customFetchImpl: fetch,
|
|
116969
|
+
...restOfFetchOptions,
|
|
116970
|
+
plugins: [
|
|
116971
|
+
lifeCyclePlugin,
|
|
116972
|
+
...restOfFetchOptions.plugins || [],
|
|
116973
|
+
...options?.disableDefaultFetchPlugins ? [] : [redirectPlugin],
|
|
116974
|
+
...pluginsFetchPlugins
|
|
116975
|
+
]
|
|
116976
|
+
});
|
|
116977
|
+
const { $sessionSignal, session, broadcastSessionUpdate } = getSessionAtom($fetch, options);
|
|
116978
|
+
const plugins = options?.plugins || [];
|
|
116979
|
+
let pluginsActions = {};
|
|
116980
|
+
const pluginsAtoms = {
|
|
116981
|
+
$sessionSignal,
|
|
116982
|
+
session
|
|
116983
|
+
};
|
|
116984
|
+
const pluginPathMethods = {
|
|
116985
|
+
"/sign-out": "POST",
|
|
116986
|
+
"/revoke-sessions": "POST",
|
|
116987
|
+
"/revoke-other-sessions": "POST",
|
|
116988
|
+
"/delete-user": "POST"
|
|
116989
|
+
};
|
|
116990
|
+
const atomListeners = [{
|
|
116991
|
+
signal: "$sessionSignal",
|
|
116992
|
+
matcher(path) {
|
|
116993
|
+
return path === "/sign-out" || path === "/update-user" || path === "/update-session" || path === "/sign-up/email" || path === "/sign-in/email" || path === "/delete-user" || path === "/verify-email" || path === "/revoke-sessions" || path === "/revoke-session" || path === "/change-email";
|
|
116994
|
+
},
|
|
116995
|
+
callback(path) {
|
|
116996
|
+
if (path === "/sign-out")
|
|
116997
|
+
broadcastSessionUpdate("signout");
|
|
116998
|
+
else if (path === "/update-user" || path === "/update-session")
|
|
116999
|
+
broadcastSessionUpdate("updateUser");
|
|
117000
|
+
}
|
|
117001
|
+
}];
|
|
117002
|
+
for (const plugin of plugins) {
|
|
117003
|
+
if (plugin.getAtoms)
|
|
117004
|
+
Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
|
|
117005
|
+
if (plugin.pathMethods)
|
|
117006
|
+
Object.assign(pluginPathMethods, plugin.pathMethods);
|
|
117007
|
+
if (plugin.atomListeners)
|
|
117008
|
+
atomListeners.push(...plugin.atomListeners);
|
|
117009
|
+
}
|
|
117010
|
+
const $store = {
|
|
117011
|
+
notify: (signal) => {
|
|
117012
|
+
pluginsAtoms[signal].set(!pluginsAtoms[signal].get());
|
|
117013
|
+
},
|
|
117014
|
+
listen: (signal, listener) => {
|
|
117015
|
+
pluginsAtoms[signal].subscribe(listener);
|
|
117016
|
+
},
|
|
117017
|
+
atoms: pluginsAtoms
|
|
117018
|
+
};
|
|
117019
|
+
for (const plugin of plugins)
|
|
117020
|
+
if (plugin.getActions)
|
|
117021
|
+
pluginsActions = defu(plugin.getActions?.($fetch, $store, options) ?? {}, pluginsActions);
|
|
117022
|
+
return {
|
|
117023
|
+
get baseURL() {
|
|
117024
|
+
return baseURL;
|
|
117025
|
+
},
|
|
117026
|
+
pluginsActions,
|
|
117027
|
+
pluginsAtoms,
|
|
117028
|
+
pluginPathMethods,
|
|
117029
|
+
atomListeners,
|
|
117030
|
+
$fetch,
|
|
117031
|
+
$store
|
|
117032
|
+
};
|
|
117033
|
+
};
|
|
117034
|
+
|
|
117035
|
+
// ../../node_modules/better-auth/dist/utils/is-atom.mjs
|
|
117036
|
+
function isAtom(value) {
|
|
117037
|
+
return typeof value === "object" && value !== null && "get" in value && typeof value.get === "function" && "lc" in value && typeof value.lc === "number";
|
|
117038
|
+
}
|
|
117039
|
+
|
|
117040
|
+
// ../../node_modules/better-auth/dist/client/proxy.mjs
|
|
117041
|
+
function getMethod2(path, knownPathMethods, args) {
|
|
117042
|
+
const method = knownPathMethods[path];
|
|
117043
|
+
const { fetchOptions, query: _query, ...body } = args || {};
|
|
117044
|
+
if (method)
|
|
117045
|
+
return method;
|
|
117046
|
+
if (fetchOptions?.method)
|
|
117047
|
+
return fetchOptions.method;
|
|
117048
|
+
if (body && Object.keys(body).length > 0)
|
|
117049
|
+
return "POST";
|
|
117050
|
+
return "GET";
|
|
117051
|
+
}
|
|
117052
|
+
function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
|
|
117053
|
+
function createProxy(path = []) {
|
|
117054
|
+
return new Proxy(function() {}, {
|
|
117055
|
+
get(_, prop) {
|
|
117056
|
+
if (typeof prop !== "string")
|
|
117057
|
+
return;
|
|
117058
|
+
if (prop === "then" || prop === "catch" || prop === "finally")
|
|
117059
|
+
return;
|
|
117060
|
+
const fullPath = [...path, prop];
|
|
117061
|
+
let current = routes;
|
|
117062
|
+
for (const segment of fullPath)
|
|
117063
|
+
if (current && typeof current === "object" && segment in current)
|
|
117064
|
+
current = current[segment];
|
|
117065
|
+
else {
|
|
117066
|
+
current = undefined;
|
|
117067
|
+
break;
|
|
117068
|
+
}
|
|
117069
|
+
if (typeof current === "function")
|
|
117070
|
+
return current;
|
|
117071
|
+
if (isAtom(current))
|
|
117072
|
+
return current;
|
|
117073
|
+
return createProxy(fullPath);
|
|
117074
|
+
},
|
|
117075
|
+
apply: async (_, __, args) => {
|
|
117076
|
+
const routePath = "/" + path.map((segment) => segment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)).join("/");
|
|
117077
|
+
const arg = args[0] || {};
|
|
117078
|
+
const fetchOptions = args[1] || {};
|
|
117079
|
+
const { query, fetchOptions: argFetchOptions, ...body } = arg;
|
|
117080
|
+
const options = {
|
|
117081
|
+
...fetchOptions,
|
|
117082
|
+
...argFetchOptions
|
|
117083
|
+
};
|
|
117084
|
+
const method = getMethod2(routePath, knownPathMethods, arg);
|
|
117085
|
+
return await client(routePath, {
|
|
117086
|
+
...options,
|
|
117087
|
+
body: method === "GET" ? undefined : {
|
|
117088
|
+
...body,
|
|
117089
|
+
...options?.body || {}
|
|
117090
|
+
},
|
|
117091
|
+
query: query || options?.query,
|
|
117092
|
+
method,
|
|
117093
|
+
async onSuccess(context) {
|
|
117094
|
+
await options?.onSuccess?.(context);
|
|
117095
|
+
if (!atomListeners || options.disableSignal)
|
|
117096
|
+
return;
|
|
117097
|
+
const matches = atomListeners.filter((s6) => s6.matcher(routePath));
|
|
117098
|
+
if (!matches.length)
|
|
117099
|
+
return;
|
|
117100
|
+
const visited = /* @__PURE__ */ new Set;
|
|
117101
|
+
for (const match of matches) {
|
|
117102
|
+
const signal = atoms[match.signal];
|
|
117103
|
+
if (!signal)
|
|
117104
|
+
return;
|
|
117105
|
+
if (visited.has(match.signal))
|
|
117106
|
+
continue;
|
|
117107
|
+
visited.add(match.signal);
|
|
117108
|
+
const val = signal.get();
|
|
117109
|
+
setTimeout(() => {
|
|
117110
|
+
signal.set(!val);
|
|
117111
|
+
}, 10);
|
|
117112
|
+
match.callback?.(routePath);
|
|
117113
|
+
}
|
|
117114
|
+
}
|
|
117115
|
+
});
|
|
117116
|
+
}
|
|
117117
|
+
});
|
|
117118
|
+
}
|
|
117119
|
+
return createProxy();
|
|
117120
|
+
}
|
|
117121
|
+
|
|
117122
|
+
// ../../node_modules/@better-auth/core/dist/utils/string.mjs
|
|
117123
|
+
function capitalizeFirstLetter(str) {
|
|
117124
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
117125
|
+
}
|
|
117126
|
+
|
|
117127
|
+
// ../../node_modules/better-auth/dist/client/vanilla.mjs
|
|
117128
|
+
function createAuthClient(options) {
|
|
117129
|
+
const { pluginPathMethods, pluginsActions, pluginsAtoms, $fetch, atomListeners, $store } = getClientConfig(options);
|
|
117130
|
+
const resolvedHooks = {};
|
|
117131
|
+
for (const [key, value] of Object.entries(pluginsAtoms))
|
|
117132
|
+
resolvedHooks[`use${capitalizeFirstLetter(key)}`] = value;
|
|
117133
|
+
return createDynamicPathProxy({
|
|
117134
|
+
...pluginsActions,
|
|
117135
|
+
...resolvedHooks,
|
|
117136
|
+
$fetch,
|
|
117137
|
+
$store
|
|
117138
|
+
}, $fetch, pluginPathMethods, pluginsAtoms, atomListeners);
|
|
117139
|
+
}
|
|
117140
|
+
|
|
117141
|
+
// ../../node_modules/better-auth/dist/plugins/organization/access/statement.mjs
|
|
117142
|
+
var defaultStatements2 = {
|
|
117143
|
+
organization: ["update", "delete"],
|
|
117144
|
+
member: [
|
|
117145
|
+
"create",
|
|
117146
|
+
"update",
|
|
117147
|
+
"delete"
|
|
117148
|
+
],
|
|
117149
|
+
invitation: ["create", "cancel"],
|
|
117150
|
+
team: [
|
|
117151
|
+
"create",
|
|
117152
|
+
"update",
|
|
117153
|
+
"delete"
|
|
117154
|
+
],
|
|
117155
|
+
ac: [
|
|
117156
|
+
"create",
|
|
117157
|
+
"read",
|
|
117158
|
+
"update",
|
|
117159
|
+
"delete"
|
|
117160
|
+
]
|
|
117161
|
+
};
|
|
117162
|
+
var defaultAc2 = createAccessControl(defaultStatements2);
|
|
117163
|
+
var adminAc2 = defaultAc2.newRole({
|
|
117164
|
+
organization: ["update"],
|
|
117165
|
+
invitation: ["create", "cancel"],
|
|
117166
|
+
member: [
|
|
117167
|
+
"create",
|
|
117168
|
+
"update",
|
|
117169
|
+
"delete"
|
|
117170
|
+
],
|
|
117171
|
+
team: [
|
|
117172
|
+
"create",
|
|
117173
|
+
"update",
|
|
117174
|
+
"delete"
|
|
117175
|
+
],
|
|
117176
|
+
ac: [
|
|
117177
|
+
"create",
|
|
117178
|
+
"read",
|
|
117179
|
+
"update",
|
|
117180
|
+
"delete"
|
|
117181
|
+
]
|
|
117182
|
+
});
|
|
117183
|
+
var ownerAc = defaultAc2.newRole({
|
|
117184
|
+
organization: ["update", "delete"],
|
|
117185
|
+
member: [
|
|
117186
|
+
"create",
|
|
117187
|
+
"update",
|
|
117188
|
+
"delete"
|
|
117189
|
+
],
|
|
117190
|
+
invitation: ["create", "cancel"],
|
|
117191
|
+
team: [
|
|
117192
|
+
"create",
|
|
117193
|
+
"update",
|
|
117194
|
+
"delete"
|
|
117195
|
+
],
|
|
117196
|
+
ac: [
|
|
117197
|
+
"create",
|
|
117198
|
+
"read",
|
|
117199
|
+
"update",
|
|
117200
|
+
"delete"
|
|
117201
|
+
]
|
|
117202
|
+
});
|
|
117203
|
+
var memberAc = defaultAc2.newRole({
|
|
117204
|
+
organization: [],
|
|
117205
|
+
member: [],
|
|
117206
|
+
invitation: [],
|
|
117207
|
+
team: [],
|
|
117208
|
+
ac: ["read"]
|
|
117209
|
+
});
|
|
117210
|
+
|
|
117211
|
+
// ../../node_modules/better-auth/dist/plugins/phone-number/error-codes.mjs
|
|
117212
|
+
var PHONE_NUMBER_ERROR_CODES = defineErrorCodes({
|
|
117213
|
+
INVALID_PHONE_NUMBER: "Invalid phone number",
|
|
117214
|
+
PHONE_NUMBER_EXIST: "Phone number already exists",
|
|
117215
|
+
PHONE_NUMBER_NOT_EXIST: "phone number isn't registered",
|
|
117216
|
+
INVALID_PHONE_NUMBER_OR_PASSWORD: "Invalid phone number or password",
|
|
117217
|
+
UNEXPECTED_ERROR: "Unexpected error",
|
|
117218
|
+
OTP_NOT_FOUND: "OTP not found",
|
|
117219
|
+
OTP_EXPIRED: "OTP expired",
|
|
117220
|
+
INVALID_OTP: "Invalid OTP",
|
|
117221
|
+
PHONE_NUMBER_NOT_VERIFIED: "Phone number not verified",
|
|
117222
|
+
PHONE_NUMBER_CANNOT_BE_UPDATED: "Phone number cannot be updated",
|
|
117223
|
+
SEND_OTP_NOT_IMPLEMENTED: "sendOTP not implemented",
|
|
117224
|
+
TOO_MANY_ATTEMPTS: "Too many attempts"
|
|
117225
|
+
});
|
|
117226
|
+
|
|
117227
|
+
// ../../node_modules/better-auth/dist/plugins/two-factor/error-code.mjs
|
|
117228
|
+
var TWO_FACTOR_ERROR_CODES = defineErrorCodes({
|
|
117229
|
+
OTP_NOT_ENABLED: "OTP not enabled",
|
|
117230
|
+
OTP_HAS_EXPIRED: "OTP has expired",
|
|
117231
|
+
TOTP_NOT_ENABLED: "TOTP not enabled",
|
|
117232
|
+
TWO_FACTOR_NOT_ENABLED: "Two factor isn't enabled",
|
|
117233
|
+
BACKUP_CODES_NOT_ENABLED: "Backup codes aren't enabled",
|
|
117234
|
+
INVALID_BACKUP_CODE: "Invalid backup code",
|
|
117235
|
+
INVALID_CODE: "Invalid code",
|
|
117236
|
+
TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE: "Too many attempts. Please request a new code.",
|
|
117237
|
+
INVALID_TWO_FACTOR_COOKIE: "Invalid two factor cookie"
|
|
117238
|
+
});
|
|
117239
|
+
|
|
117240
|
+
// ../../node_modules/better-auth/dist/plugins/username/error-codes.mjs
|
|
117241
|
+
var USERNAME_ERROR_CODES = defineErrorCodes({
|
|
117242
|
+
INVALID_USERNAME_OR_PASSWORD: "Invalid username or password",
|
|
117243
|
+
EMAIL_NOT_VERIFIED: "Email not verified",
|
|
117244
|
+
UNEXPECTED_ERROR: "Unexpected error",
|
|
117245
|
+
USERNAME_IS_ALREADY_TAKEN: "Username is already taken. Please try another.",
|
|
117246
|
+
USERNAME_TOO_SHORT: "Username is too short",
|
|
117247
|
+
USERNAME_TOO_LONG: "Username is too long",
|
|
117248
|
+
INVALID_USERNAME: "Username is invalid",
|
|
117249
|
+
INVALID_DISPLAY_USERNAME: "Display username is invalid"
|
|
117250
|
+
});
|
|
117251
|
+
|
|
117252
|
+
// ../../node_modules/@sigma-auth/better-auth-plugin/dist/client/local-signer.js
|
|
117253
|
+
class LocalServerSigner {
|
|
117254
|
+
baseUrl;
|
|
117255
|
+
timeout;
|
|
117256
|
+
accessToken = null;
|
|
117257
|
+
currentBapId = null;
|
|
117258
|
+
constructor(options = {}) {
|
|
117259
|
+
this.baseUrl = options.baseUrl || "http://localhost:21000";
|
|
117260
|
+
this.timeout = options.timeout || 5000;
|
|
117261
|
+
}
|
|
117262
|
+
async probe() {
|
|
117263
|
+
try {
|
|
117264
|
+
const controller = new AbortController;
|
|
117265
|
+
const timeoutId = setTimeout(() => controller.abort(), 500);
|
|
117266
|
+
const res = await fetch(`${this.baseUrl}/api/status`, {
|
|
117267
|
+
signal: controller.signal
|
|
117268
|
+
});
|
|
117269
|
+
clearTimeout(timeoutId);
|
|
117270
|
+
return res.ok;
|
|
117271
|
+
} catch {
|
|
117272
|
+
return false;
|
|
117273
|
+
}
|
|
117274
|
+
}
|
|
117275
|
+
async getStatus() {
|
|
117276
|
+
try {
|
|
117277
|
+
const controller = new AbortController;
|
|
117278
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
117279
|
+
const res = await fetch(`${this.baseUrl}/api/status`, {
|
|
117280
|
+
signal: controller.signal
|
|
117281
|
+
});
|
|
117282
|
+
clearTimeout(timeoutId);
|
|
117283
|
+
if (!res.ok)
|
|
117284
|
+
return null;
|
|
117285
|
+
return await res.json();
|
|
117286
|
+
} catch {
|
|
117287
|
+
return null;
|
|
117288
|
+
}
|
|
117289
|
+
}
|
|
117290
|
+
async authenticate(host, scopes = ["sign", "encrypt", "decrypt"], expiry = "1h") {
|
|
117291
|
+
try {
|
|
117292
|
+
const controller = new AbortController;
|
|
117293
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
117294
|
+
const res = await fetch(`${this.baseUrl}/api/auth`, {
|
|
117295
|
+
method: "POST",
|
|
117296
|
+
headers: { "Content-Type": "application/json" },
|
|
117297
|
+
body: JSON.stringify({ host, scopes, expiry }),
|
|
117298
|
+
signal: controller.signal
|
|
117299
|
+
});
|
|
117300
|
+
clearTimeout(timeoutId);
|
|
117301
|
+
if (!res.ok)
|
|
117302
|
+
return false;
|
|
117303
|
+
const data = await res.json();
|
|
117304
|
+
this.accessToken = data.accessToken;
|
|
117305
|
+
return true;
|
|
117306
|
+
} catch {
|
|
117307
|
+
return false;
|
|
117308
|
+
}
|
|
117309
|
+
}
|
|
117310
|
+
isReady() {
|
|
117311
|
+
return this.accessToken !== null;
|
|
117312
|
+
}
|
|
117313
|
+
setIdentity(bapId) {
|
|
117314
|
+
this.currentBapId = bapId;
|
|
117315
|
+
}
|
|
117316
|
+
getIdentity() {
|
|
117317
|
+
return this.currentBapId;
|
|
117318
|
+
}
|
|
117319
|
+
async sign(path, body, signatureType = "brc77") {
|
|
117320
|
+
if (!this.accessToken) {
|
|
117321
|
+
throw new Error("Not authenticated. Call authenticate() first.");
|
|
117322
|
+
}
|
|
117323
|
+
const controller = new AbortController;
|
|
117324
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
117325
|
+
try {
|
|
117326
|
+
const res = await fetch(`${this.baseUrl}/api/sign`, {
|
|
117327
|
+
method: "POST",
|
|
117328
|
+
headers: {
|
|
117329
|
+
"Content-Type": "application/json",
|
|
117330
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
117331
|
+
},
|
|
117332
|
+
body: JSON.stringify({
|
|
117333
|
+
path,
|
|
117334
|
+
body,
|
|
117335
|
+
signatureType
|
|
117336
|
+
}),
|
|
117337
|
+
signal: controller.signal
|
|
117338
|
+
});
|
|
117339
|
+
clearTimeout(timeoutId);
|
|
117340
|
+
if (!res.ok) {
|
|
117341
|
+
const error = await res.text();
|
|
117342
|
+
throw new Error(`Sign request failed: ${error}`);
|
|
117343
|
+
}
|
|
117344
|
+
const data = await res.json();
|
|
117345
|
+
return data.token;
|
|
117346
|
+
} catch (err) {
|
|
117347
|
+
clearTimeout(timeoutId);
|
|
117348
|
+
throw err;
|
|
117349
|
+
}
|
|
117350
|
+
}
|
|
117351
|
+
async signAIP(hexArray) {
|
|
117352
|
+
if (!this.accessToken) {
|
|
117353
|
+
throw new Error("Not authenticated. Call authenticate() first.");
|
|
117354
|
+
}
|
|
117355
|
+
const controller = new AbortController;
|
|
117356
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
117357
|
+
try {
|
|
117358
|
+
const res = await fetch(`${this.baseUrl}/api/sign-aip`, {
|
|
117359
|
+
method: "POST",
|
|
117360
|
+
headers: {
|
|
117361
|
+
"Content-Type": "application/json",
|
|
117362
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
117363
|
+
},
|
|
117364
|
+
body: JSON.stringify({ data: hexArray }),
|
|
117365
|
+
signal: controller.signal
|
|
117366
|
+
});
|
|
117367
|
+
clearTimeout(timeoutId);
|
|
117368
|
+
if (!res.ok) {
|
|
117369
|
+
const error = await res.text();
|
|
117370
|
+
throw new Error(`AIP sign request failed: ${error}`);
|
|
117371
|
+
}
|
|
117372
|
+
const data = await res.json();
|
|
117373
|
+
return data.signedOps;
|
|
117374
|
+
} catch (err) {
|
|
117375
|
+
clearTimeout(timeoutId);
|
|
117376
|
+
throw err;
|
|
117377
|
+
}
|
|
117378
|
+
}
|
|
117379
|
+
async encrypt(data, friendBapId, theirPublicKey) {
|
|
117380
|
+
if (!this.accessToken) {
|
|
117381
|
+
throw new Error("Not authenticated. Call authenticate() first.");
|
|
117382
|
+
}
|
|
117383
|
+
const controller = new AbortController;
|
|
117384
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
117385
|
+
try {
|
|
117386
|
+
const res = await fetch(`${this.baseUrl}/api/encrypt`, {
|
|
117387
|
+
method: "POST",
|
|
117388
|
+
headers: {
|
|
117389
|
+
"Content-Type": "application/json",
|
|
117390
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
117391
|
+
},
|
|
117392
|
+
body: JSON.stringify({
|
|
117393
|
+
data,
|
|
117394
|
+
friendBapId,
|
|
117395
|
+
theirPublicKey
|
|
117396
|
+
}),
|
|
117397
|
+
signal: controller.signal
|
|
117398
|
+
});
|
|
117399
|
+
clearTimeout(timeoutId);
|
|
117400
|
+
if (!res.ok) {
|
|
117401
|
+
const error = await res.text();
|
|
117402
|
+
throw new Error(`Encrypt request failed: ${error}`);
|
|
117403
|
+
}
|
|
117404
|
+
const result = await res.json();
|
|
117405
|
+
return result.ciphertext;
|
|
117406
|
+
} catch (err) {
|
|
117407
|
+
clearTimeout(timeoutId);
|
|
117408
|
+
throw err;
|
|
117409
|
+
}
|
|
117410
|
+
}
|
|
117411
|
+
async decrypt(ciphertext, friendBapId, theirPublicKey) {
|
|
117412
|
+
if (!this.accessToken) {
|
|
117413
|
+
throw new Error("Not authenticated. Call authenticate() first.");
|
|
117414
|
+
}
|
|
117415
|
+
const controller = new AbortController;
|
|
117416
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
117417
|
+
try {
|
|
117418
|
+
const res = await fetch(`${this.baseUrl}/api/decrypt`, {
|
|
117419
|
+
method: "POST",
|
|
117420
|
+
headers: {
|
|
117421
|
+
"Content-Type": "application/json",
|
|
117422
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
117423
|
+
},
|
|
117424
|
+
body: JSON.stringify({
|
|
117425
|
+
ciphertext,
|
|
117426
|
+
friendBapId,
|
|
117427
|
+
theirPublicKey
|
|
117428
|
+
}),
|
|
117429
|
+
signal: controller.signal
|
|
117430
|
+
});
|
|
117431
|
+
clearTimeout(timeoutId);
|
|
117432
|
+
if (!res.ok) {
|
|
117433
|
+
const error = await res.text();
|
|
117434
|
+
throw new Error(`Decrypt request failed: ${error}`);
|
|
117435
|
+
}
|
|
117436
|
+
const result = await res.json();
|
|
117437
|
+
return result.data;
|
|
117438
|
+
} catch (err) {
|
|
117439
|
+
clearTimeout(timeoutId);
|
|
117440
|
+
throw err;
|
|
117441
|
+
}
|
|
117442
|
+
}
|
|
117443
|
+
async getFriendPublicKey(friendBapId) {
|
|
117444
|
+
if (!this.accessToken) {
|
|
117445
|
+
throw new Error("Not authenticated. Call authenticate() first.");
|
|
117446
|
+
}
|
|
117447
|
+
const controller = new AbortController;
|
|
117448
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
117449
|
+
try {
|
|
117450
|
+
const res = await fetch(`${this.baseUrl}/api/friend-pubkey`, {
|
|
117451
|
+
method: "POST",
|
|
117452
|
+
headers: {
|
|
117453
|
+
"Content-Type": "application/json",
|
|
117454
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
117455
|
+
},
|
|
117456
|
+
body: JSON.stringify({ friendBapId }),
|
|
117457
|
+
signal: controller.signal
|
|
117458
|
+
});
|
|
117459
|
+
clearTimeout(timeoutId);
|
|
117460
|
+
if (!res.ok) {
|
|
117461
|
+
const error = await res.text();
|
|
117462
|
+
throw new Error(`Get friend public key failed: ${error}`);
|
|
117463
|
+
}
|
|
117464
|
+
const result = await res.json();
|
|
117465
|
+
return result.publicKey;
|
|
117466
|
+
} catch (err) {
|
|
117467
|
+
clearTimeout(timeoutId);
|
|
117468
|
+
throw err;
|
|
117469
|
+
}
|
|
117470
|
+
}
|
|
117471
|
+
getBaseUrl() {
|
|
117472
|
+
return this.baseUrl;
|
|
117473
|
+
}
|
|
117474
|
+
destroy() {
|
|
117475
|
+
this.accessToken = null;
|
|
117476
|
+
this.currentBapId = null;
|
|
117477
|
+
}
|
|
117478
|
+
}
|
|
117479
|
+
|
|
117480
|
+
// ../../node_modules/@sigma-auth/better-auth-plugin/dist/client/sigma-cwi.js
|
|
117481
|
+
var isRecord3 = (v) => typeof v === "object" && v !== null;
|
|
117482
|
+
var isResponse4 = (v) => isRecord3(v) && v.type === "CWI" && v.isInvocation === false && typeof v.id === "string";
|
|
117483
|
+
var isState3 = (v) => isRecord3(v) && v.type === "CWI" && isRecord3(v.cwiState);
|
|
117484
|
+
var createId3 = () => typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2, 14)}`;
|
|
117485
|
+
var DEFAULT_TIMEOUT_MS = 30000;
|
|
117486
|
+
var HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
117487
|
+
|
|
117488
|
+
class SigmaCWISigner {
|
|
117489
|
+
iframe = null;
|
|
117490
|
+
pending = new Map;
|
|
117491
|
+
initialized = false;
|
|
117492
|
+
destroyed = false;
|
|
117493
|
+
currentBapId = null;
|
|
117494
|
+
sigmaUrl;
|
|
117495
|
+
sigmaOrigin;
|
|
117496
|
+
handshakeResolve = null;
|
|
117497
|
+
handshakeReject = null;
|
|
117498
|
+
handshakeComplete = false;
|
|
117499
|
+
boundMessageHandler = null;
|
|
117500
|
+
constructor(sigmaUrl) {
|
|
117501
|
+
this.sigmaUrl = sigmaUrl;
|
|
117502
|
+
this.sigmaOrigin = new URL(sigmaUrl).origin;
|
|
117503
|
+
}
|
|
117504
|
+
async init() {
|
|
117505
|
+
if (typeof window === "undefined") {
|
|
117506
|
+
throw new Error("SigmaCWISigner can only be used in browser");
|
|
117507
|
+
}
|
|
117508
|
+
if (this.initialized)
|
|
117509
|
+
return;
|
|
117510
|
+
this.iframe = document.createElement("iframe");
|
|
117511
|
+
this.iframe.src = `${this.sigmaUrl}/signer`;
|
|
117512
|
+
this.iframe.setAttribute("aria-hidden", "true");
|
|
117513
|
+
this.iframe.style.cssText = `
|
|
117514
|
+
position: fixed;
|
|
117515
|
+
top: 0;
|
|
117516
|
+
left: 0;
|
|
117517
|
+
width: 0;
|
|
117518
|
+
height: 0;
|
|
117519
|
+
border: 0;
|
|
117520
|
+
opacity: 0;
|
|
117521
|
+
pointer-events: none;
|
|
117522
|
+
z-index: 2147483647;
|
|
117523
|
+
`;
|
|
117524
|
+
document.body.appendChild(this.iframe);
|
|
117525
|
+
this.boundMessageHandler = this.handleMessage.bind(this);
|
|
117526
|
+
window.addEventListener("message", this.boundMessageHandler);
|
|
117527
|
+
await this.waitForHandshake();
|
|
117528
|
+
this.initialized = true;
|
|
117529
|
+
}
|
|
117530
|
+
waitForHandshake() {
|
|
117531
|
+
if (this.handshakeComplete)
|
|
117532
|
+
return Promise.resolve();
|
|
117533
|
+
return new Promise((resolve, reject) => {
|
|
117534
|
+
this.handshakeResolve = resolve;
|
|
117535
|
+
this.handshakeReject = reject;
|
|
117536
|
+
setTimeout(() => {
|
|
117537
|
+
if (!this.handshakeComplete) {
|
|
117538
|
+
this.handshakeReject?.(new Error("Sigma signer handshake timed out"));
|
|
117539
|
+
this.handshakeResolve = null;
|
|
117540
|
+
this.handshakeReject = null;
|
|
117541
|
+
}
|
|
117542
|
+
}, HANDSHAKE_TIMEOUT_MS);
|
|
117543
|
+
});
|
|
117544
|
+
}
|
|
117545
|
+
handleMessage(event) {
|
|
117546
|
+
if (this.destroyed)
|
|
117547
|
+
return;
|
|
117548
|
+
if (event.origin !== this.sigmaOrigin)
|
|
117549
|
+
return;
|
|
117550
|
+
const data = event.data;
|
|
117551
|
+
if (isState3(data)) {
|
|
117552
|
+
const { status, hasPermission: hasPermission2 } = data.cwiState;
|
|
117553
|
+
if (status === "need_password" || hasPermission2) {
|
|
117554
|
+
this.showIframe();
|
|
117555
|
+
} else {
|
|
117556
|
+
this.hideIframe();
|
|
117557
|
+
}
|
|
117558
|
+
if (!this.handshakeComplete) {
|
|
117559
|
+
this.handshakeComplete = true;
|
|
117560
|
+
this.handshakeResolve?.();
|
|
117561
|
+
this.handshakeResolve = null;
|
|
117562
|
+
this.handshakeReject = null;
|
|
117563
|
+
}
|
|
117564
|
+
if (status === "error") {
|
|
117565
|
+
this.rejectAllPending(new Error("Signer error. Please sign in to Sigma Identity."));
|
|
117566
|
+
}
|
|
117567
|
+
return;
|
|
117568
|
+
}
|
|
117569
|
+
if (!isResponse4(data))
|
|
117570
|
+
return;
|
|
117571
|
+
const req = this.pending.get(data.id);
|
|
117572
|
+
if (!req)
|
|
117573
|
+
return;
|
|
117574
|
+
this.pending.delete(data.id);
|
|
117575
|
+
clearTimeout(req.timeout);
|
|
117576
|
+
if (data.status === "error") {
|
|
117577
|
+
req.reject(new Error(data.description ?? "CWI request failed"));
|
|
117578
|
+
} else {
|
|
117579
|
+
req.resolve(data.result);
|
|
117580
|
+
}
|
|
117581
|
+
}
|
|
117582
|
+
showIframe() {
|
|
117583
|
+
if (!this.iframe)
|
|
117584
|
+
return;
|
|
117585
|
+
this.iframe.style.width = "100%";
|
|
117586
|
+
this.iframe.style.height = "100%";
|
|
117587
|
+
this.iframe.style.opacity = "1";
|
|
117588
|
+
this.iframe.style.pointerEvents = "auto";
|
|
117589
|
+
}
|
|
117590
|
+
hideIframe() {
|
|
117591
|
+
if (!this.iframe)
|
|
117592
|
+
return;
|
|
117593
|
+
this.iframe.style.width = "0";
|
|
117594
|
+
this.iframe.style.height = "0";
|
|
117595
|
+
this.iframe.style.opacity = "0";
|
|
117596
|
+
this.iframe.style.pointerEvents = "none";
|
|
117597
|
+
}
|
|
117598
|
+
sendCWI(call, args) {
|
|
117599
|
+
if (this.destroyed) {
|
|
117600
|
+
return Promise.reject(new Error("SigmaCWISigner has been destroyed"));
|
|
117601
|
+
}
|
|
117602
|
+
const contentWindow = this.iframe?.contentWindow;
|
|
117603
|
+
if (!contentWindow) {
|
|
117604
|
+
return Promise.reject(new Error("Sigma iframe not accessible"));
|
|
117605
|
+
}
|
|
117606
|
+
const id = createId3();
|
|
117607
|
+
const request3 = {
|
|
117608
|
+
type: "CWI",
|
|
117609
|
+
isInvocation: true,
|
|
117610
|
+
id,
|
|
117611
|
+
call,
|
|
117612
|
+
args
|
|
117613
|
+
};
|
|
117614
|
+
return new Promise((resolve, reject) => {
|
|
117615
|
+
const timeout = setTimeout(() => {
|
|
117616
|
+
this.pending.delete(id);
|
|
117617
|
+
reject(new Error(`CWI request timed out: ${call}`));
|
|
117618
|
+
}, DEFAULT_TIMEOUT_MS);
|
|
117619
|
+
this.pending.set(id, {
|
|
117620
|
+
resolve,
|
|
117621
|
+
reject,
|
|
117622
|
+
timeout
|
|
117623
|
+
});
|
|
117624
|
+
contentWindow.postMessage(request3, this.sigmaOrigin);
|
|
117625
|
+
});
|
|
117626
|
+
}
|
|
117627
|
+
sendCustomMessage(type, payload) {
|
|
117628
|
+
const contentWindow = this.iframe?.contentWindow;
|
|
117629
|
+
if (!contentWindow)
|
|
117630
|
+
return;
|
|
117631
|
+
contentWindow.postMessage({ type, payload }, this.sigmaOrigin);
|
|
117632
|
+
}
|
|
117633
|
+
ensureIdentity() {
|
|
117634
|
+
if (!this.currentBapId) {
|
|
117635
|
+
throw new Error("No identity set. Call setIdentity() first.");
|
|
117636
|
+
}
|
|
117637
|
+
}
|
|
117638
|
+
async ensureReady() {
|
|
117639
|
+
if (!this.initialized) {
|
|
117640
|
+
await this.init();
|
|
117641
|
+
}
|
|
117642
|
+
this.ensureIdentity();
|
|
117643
|
+
this.sendCustomMessage("SET_IDENTITY", { bapId: this.currentBapId });
|
|
117644
|
+
}
|
|
117645
|
+
setIdentity(bapId) {
|
|
117646
|
+
this.currentBapId = bapId;
|
|
117647
|
+
if (this.initialized && this.iframe?.contentWindow) {
|
|
117648
|
+
this.sendCustomMessage("SET_IDENTITY", { bapId });
|
|
117649
|
+
}
|
|
117650
|
+
}
|
|
117651
|
+
getIdentity() {
|
|
117652
|
+
return this.currentBapId;
|
|
117653
|
+
}
|
|
117654
|
+
async sign(requestPath, body, signatureType = "brc77") {
|
|
117655
|
+
await this.ensureReady();
|
|
117656
|
+
return this.sendCWI("signAuthToken", {
|
|
117657
|
+
requestPath,
|
|
117658
|
+
body,
|
|
117659
|
+
signatureType
|
|
117660
|
+
});
|
|
117661
|
+
}
|
|
117662
|
+
async signAIP(hexArray) {
|
|
117663
|
+
await this.ensureReady();
|
|
117664
|
+
return this.sendCWI("signAIP", { hexArray });
|
|
117665
|
+
}
|
|
117666
|
+
async encrypt(data, friendBapId, theirPublicKey) {
|
|
117667
|
+
await this.ensureReady();
|
|
117668
|
+
const result = await this.sendCWI("encrypt", {
|
|
117669
|
+
plaintext: new TextEncoder().encode(data),
|
|
117670
|
+
protocolID: [2, "sigma-encrypt"],
|
|
117671
|
+
keyID: friendBapId,
|
|
117672
|
+
counterparty: theirPublicKey
|
|
117673
|
+
});
|
|
117674
|
+
return btoa(String.fromCharCode(...new Uint8Array(Object.values(result.ciphertext))));
|
|
117675
|
+
}
|
|
117676
|
+
async decrypt(ciphertext, friendBapId, theirPublicKey) {
|
|
117677
|
+
await this.ensureReady();
|
|
117678
|
+
const ciphertextBytes = Uint8Array.from(atob(ciphertext), (c) => c.charCodeAt(0));
|
|
117679
|
+
const result = await this.sendCWI("decrypt", {
|
|
117680
|
+
ciphertext: ciphertextBytes,
|
|
117681
|
+
protocolID: [2, "sigma-encrypt"],
|
|
117682
|
+
keyID: friendBapId,
|
|
117683
|
+
counterparty: theirPublicKey
|
|
117684
|
+
});
|
|
117685
|
+
return new TextDecoder().decode(new Uint8Array(Object.values(result.plaintext)));
|
|
117686
|
+
}
|
|
117687
|
+
async getFriendPublicKey(friendBapId) {
|
|
117688
|
+
await this.ensureReady();
|
|
117689
|
+
const result = await this.sendCWI("getPublicKey", {
|
|
117690
|
+
protocolID: [2, "sigma-encrypt"],
|
|
117691
|
+
keyID: friendBapId
|
|
117692
|
+
});
|
|
117693
|
+
return result.publicKey;
|
|
117694
|
+
}
|
|
117695
|
+
isReady() {
|
|
117696
|
+
return this.initialized && !this.destroyed && this.iframe !== null;
|
|
117697
|
+
}
|
|
117698
|
+
destroy() {
|
|
117699
|
+
if (this.destroyed)
|
|
117700
|
+
return;
|
|
117701
|
+
this.destroyed = true;
|
|
117702
|
+
if (this.boundMessageHandler) {
|
|
117703
|
+
window.removeEventListener("message", this.boundMessageHandler);
|
|
117704
|
+
this.boundMessageHandler = null;
|
|
117705
|
+
}
|
|
117706
|
+
this.rejectAllPending(new Error("Signer destroyed"));
|
|
117707
|
+
if (this.iframe?.parentNode) {
|
|
117708
|
+
this.iframe.parentNode.removeChild(this.iframe);
|
|
117709
|
+
}
|
|
117710
|
+
this.iframe = null;
|
|
117711
|
+
this.initialized = false;
|
|
117712
|
+
}
|
|
117713
|
+
rejectAllPending(error) {
|
|
117714
|
+
for (const [, req] of this.pending) {
|
|
117715
|
+
clearTimeout(req.timeout);
|
|
117716
|
+
req.reject(error);
|
|
117717
|
+
}
|
|
117718
|
+
this.pending.clear();
|
|
117719
|
+
}
|
|
117720
|
+
}
|
|
117721
|
+
// ../../node_modules/@sigma-auth/better-auth-plugin/dist/client/signer.js
|
|
117722
|
+
class SigmaIframeSigner {
|
|
117723
|
+
iframe = null;
|
|
117724
|
+
pendingRequests = new Map;
|
|
117725
|
+
pendingAIPRequests = new Map;
|
|
117726
|
+
pendingEncryptRequests = new Map;
|
|
117727
|
+
pendingDecryptRequests = new Map;
|
|
117728
|
+
pendingGetFriendPubkeyRequests = new Map;
|
|
117729
|
+
pendingWalletKeyRequests = new Map;
|
|
117730
|
+
initialized = false;
|
|
117731
|
+
boundMessageHandler = null;
|
|
117732
|
+
currentBapId = null;
|
|
117733
|
+
sigmaUrl;
|
|
117734
|
+
constructor(sigmaUrl) {
|
|
117735
|
+
this.sigmaUrl = sigmaUrl;
|
|
117736
|
+
}
|
|
117737
|
+
async init() {
|
|
117738
|
+
if (typeof window === "undefined") {
|
|
117739
|
+
throw new Error("SigmaIframeSigner can only be used in browser");
|
|
117740
|
+
}
|
|
117741
|
+
if (this.initialized)
|
|
117742
|
+
return;
|
|
117743
|
+
this.iframe = document.createElement("iframe");
|
|
117744
|
+
this.iframe.src = `${this.sigmaUrl}/signer`;
|
|
117745
|
+
this.iframe.style.cssText = `
|
|
117746
|
+
position: fixed;
|
|
117747
|
+
inset: 0;
|
|
117748
|
+
width: 100vw;
|
|
117749
|
+
height: 100vh;
|
|
117750
|
+
border: none;
|
|
117751
|
+
background: transparent;
|
|
117752
|
+
z-index: 10000;
|
|
117753
|
+
display: none;
|
|
117754
|
+
pointer-events: auto;
|
|
117755
|
+
`;
|
|
117756
|
+
document.body.appendChild(this.iframe);
|
|
117757
|
+
this.boundMessageHandler = this.handleMessage.bind(this);
|
|
117758
|
+
window.addEventListener("message", this.boundMessageHandler);
|
|
117759
|
+
const iframe = this.iframe;
|
|
117760
|
+
await new Promise((resolve, reject) => {
|
|
117761
|
+
const timeout = setTimeout(() => reject(new Error("Sigma iframe load timeout")), 1e4);
|
|
117762
|
+
iframe.addEventListener("load", () => {
|
|
117763
|
+
clearTimeout(timeout);
|
|
117764
|
+
this.initialized = true;
|
|
117765
|
+
resolve();
|
|
117766
|
+
});
|
|
117767
|
+
iframe.addEventListener("error", () => {
|
|
117768
|
+
clearTimeout(timeout);
|
|
117769
|
+
reject(new Error("Failed to load Sigma iframe"));
|
|
117770
|
+
});
|
|
117771
|
+
});
|
|
117772
|
+
}
|
|
117773
|
+
setIdentity(bapId) {
|
|
117774
|
+
this.currentBapId = bapId;
|
|
117775
|
+
if (this.initialized && this.iframe?.contentWindow) {
|
|
117776
|
+
this.iframe.contentWindow.postMessage({ type: "SET_IDENTITY", payload: { bapId } }, this.sigmaUrl);
|
|
117777
|
+
}
|
|
117778
|
+
}
|
|
117779
|
+
async sign(requestPath, body, signatureType = "brc77") {
|
|
117780
|
+
if (!this.initialized) {
|
|
117781
|
+
await this.init();
|
|
117782
|
+
}
|
|
117783
|
+
if (!this.currentBapId) {
|
|
117784
|
+
throw new Error("No identity set. Call setIdentity() first.");
|
|
117785
|
+
}
|
|
117786
|
+
const contentWindow = this.iframe?.contentWindow;
|
|
117787
|
+
if (!contentWindow) {
|
|
117788
|
+
throw new Error("Sigma iframe not accessible");
|
|
117789
|
+
}
|
|
117790
|
+
contentWindow.postMessage({ type: "SET_IDENTITY", payload: { bapId: this.currentBapId } }, this.sigmaUrl);
|
|
117791
|
+
const requestId = `req_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
117792
|
+
const request3 = {
|
|
117793
|
+
requestId,
|
|
117794
|
+
requestPath,
|
|
117795
|
+
signatureType
|
|
117796
|
+
};
|
|
117797
|
+
if (body) {
|
|
117798
|
+
request3.body = body;
|
|
117799
|
+
request3.bodyEncoding = "utf8";
|
|
117800
|
+
}
|
|
117801
|
+
return new Promise((resolve, reject) => {
|
|
117802
|
+
const timeout = setTimeout(() => {
|
|
117803
|
+
this.pendingRequests.delete(requestId);
|
|
117804
|
+
reject(new Error("Signature request timeout"));
|
|
117805
|
+
}, 30000);
|
|
117806
|
+
this.pendingRequests.set(requestId, { resolve, reject, timeout });
|
|
117807
|
+
contentWindow.postMessage({ type: "SIGN_REQUEST", payload: request3 }, this.sigmaUrl);
|
|
117808
|
+
});
|
|
117809
|
+
}
|
|
117810
|
+
async signAIP(hexArray) {
|
|
117811
|
+
if (!this.initialized) {
|
|
117812
|
+
await this.init();
|
|
117813
|
+
}
|
|
117814
|
+
if (!this.currentBapId) {
|
|
117815
|
+
throw new Error("No identity set. Call setIdentity() first.");
|
|
117816
|
+
}
|
|
117817
|
+
const contentWindow = this.iframe?.contentWindow;
|
|
117818
|
+
if (!contentWindow) {
|
|
117819
|
+
throw new Error("Sigma iframe not accessible");
|
|
117820
|
+
}
|
|
117821
|
+
contentWindow.postMessage({ type: "SET_IDENTITY", payload: { bapId: this.currentBapId } }, this.sigmaUrl);
|
|
117822
|
+
const requestId = `aip_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
117823
|
+
const request3 = {
|
|
117824
|
+
requestId,
|
|
117825
|
+
hexArray
|
|
117826
|
+
};
|
|
117827
|
+
return new Promise((resolve, reject) => {
|
|
117828
|
+
const timeout = setTimeout(() => {
|
|
117829
|
+
this.pendingAIPRequests.delete(requestId);
|
|
117830
|
+
reject(new Error("AIP signature request timeout"));
|
|
117831
|
+
}, 30000);
|
|
117832
|
+
this.pendingAIPRequests.set(requestId, { resolve, reject, timeout });
|
|
117833
|
+
contentWindow.postMessage({ type: "SIGN_AIP_REQUEST", payload: request3 }, this.sigmaUrl);
|
|
117834
|
+
});
|
|
117835
|
+
}
|
|
117836
|
+
async encrypt(data, friendBapId, counterPartyPublicKey) {
|
|
117837
|
+
if (!this.initialized) {
|
|
117838
|
+
await this.init();
|
|
117839
|
+
}
|
|
117840
|
+
if (!this.currentBapId) {
|
|
117841
|
+
throw new Error("No identity set. Call setIdentity() first.");
|
|
117842
|
+
}
|
|
117843
|
+
const contentWindow = this.iframe?.contentWindow;
|
|
117844
|
+
if (!contentWindow) {
|
|
117845
|
+
throw new Error("Sigma iframe not accessible");
|
|
117846
|
+
}
|
|
117847
|
+
contentWindow.postMessage({ type: "SET_IDENTITY", payload: { bapId: this.currentBapId } }, this.sigmaUrl);
|
|
117848
|
+
const requestId = `enc_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
117849
|
+
const request3 = {
|
|
117850
|
+
requestId,
|
|
117851
|
+
data,
|
|
117852
|
+
friendBapId,
|
|
117853
|
+
counterPartyPublicKey
|
|
117854
|
+
};
|
|
117855
|
+
return new Promise((resolve, reject) => {
|
|
117856
|
+
const timeout = setTimeout(() => {
|
|
117857
|
+
this.pendingEncryptRequests.delete(requestId);
|
|
117858
|
+
reject(new Error("Encryption request timeout"));
|
|
117859
|
+
}, 30000);
|
|
117860
|
+
this.pendingEncryptRequests.set(requestId, { resolve, reject, timeout });
|
|
117861
|
+
contentWindow.postMessage({ type: "ENCRYPT_REQUEST", payload: request3 }, this.sigmaUrl);
|
|
117862
|
+
});
|
|
117863
|
+
}
|
|
117864
|
+
async decrypt(ciphertext, friendBapId, counterPartyPublicKey) {
|
|
117865
|
+
if (!this.initialized) {
|
|
117866
|
+
await this.init();
|
|
117867
|
+
}
|
|
117868
|
+
if (!this.currentBapId) {
|
|
117869
|
+
throw new Error("No identity set. Call setIdentity() first.");
|
|
117870
|
+
}
|
|
117871
|
+
const contentWindow = this.iframe?.contentWindow;
|
|
117872
|
+
if (!contentWindow) {
|
|
117873
|
+
throw new Error("Sigma iframe not accessible");
|
|
117874
|
+
}
|
|
117875
|
+
contentWindow.postMessage({ type: "SET_IDENTITY", payload: { bapId: this.currentBapId } }, this.sigmaUrl);
|
|
117876
|
+
const requestId = `dec_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
117877
|
+
const request3 = {
|
|
117878
|
+
requestId,
|
|
117879
|
+
ciphertext,
|
|
117880
|
+
friendBapId,
|
|
117881
|
+
counterPartyPublicKey
|
|
117882
|
+
};
|
|
117883
|
+
return new Promise((resolve, reject) => {
|
|
117884
|
+
const timeout = setTimeout(() => {
|
|
117885
|
+
this.pendingDecryptRequests.delete(requestId);
|
|
117886
|
+
reject(new Error("Decryption request timeout"));
|
|
117887
|
+
}, 30000);
|
|
117888
|
+
this.pendingDecryptRequests.set(requestId, { resolve, reject, timeout });
|
|
117889
|
+
contentWindow.postMessage({ type: "DECRYPT_REQUEST", payload: request3 }, this.sigmaUrl);
|
|
117890
|
+
});
|
|
117891
|
+
}
|
|
117892
|
+
async getFriendPublicKey(friendBapId) {
|
|
117893
|
+
if (!this.initialized) {
|
|
117894
|
+
await this.init();
|
|
117895
|
+
}
|
|
117896
|
+
if (!this.currentBapId) {
|
|
117897
|
+
throw new Error("No identity set. Call setIdentity() first.");
|
|
117898
|
+
}
|
|
117899
|
+
const contentWindow = this.iframe?.contentWindow;
|
|
117900
|
+
if (!contentWindow) {
|
|
117901
|
+
throw new Error("Sigma iframe not accessible");
|
|
117902
|
+
}
|
|
117903
|
+
contentWindow.postMessage({ type: "SET_IDENTITY", payload: { bapId: this.currentBapId } }, this.sigmaUrl);
|
|
117904
|
+
const requestId = `pubkey_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
117905
|
+
const request3 = {
|
|
117906
|
+
requestId,
|
|
117907
|
+
friendBapId
|
|
117908
|
+
};
|
|
117909
|
+
return new Promise((resolve, reject) => {
|
|
117910
|
+
const timeout = setTimeout(() => {
|
|
117911
|
+
this.pendingGetFriendPubkeyRequests.delete(requestId);
|
|
117912
|
+
reject(new Error("Get friend public key request timeout"));
|
|
117913
|
+
}, 30000);
|
|
117914
|
+
this.pendingGetFriendPubkeyRequests.set(requestId, {
|
|
117915
|
+
resolve,
|
|
117916
|
+
reject,
|
|
117917
|
+
timeout
|
|
117918
|
+
});
|
|
117919
|
+
contentWindow.postMessage({ type: "GET_FRIEND_PUBKEY_REQUEST", payload: request3 }, this.sigmaUrl);
|
|
117920
|
+
});
|
|
117921
|
+
}
|
|
117922
|
+
async getWalletKey() {
|
|
117923
|
+
if (!this.initialized) {
|
|
117924
|
+
await this.init();
|
|
117925
|
+
}
|
|
117926
|
+
if (!this.currentBapId) {
|
|
117927
|
+
throw new Error("No identity set. Call setIdentity() first.");
|
|
117928
|
+
}
|
|
117929
|
+
const contentWindow = this.iframe?.contentWindow;
|
|
117930
|
+
if (!contentWindow) {
|
|
117931
|
+
throw new Error("Sigma iframe not accessible");
|
|
117932
|
+
}
|
|
117933
|
+
contentWindow.postMessage({ type: "SET_IDENTITY", payload: { bapId: this.currentBapId } }, this.sigmaUrl);
|
|
117934
|
+
const requestId = `wkey_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
117935
|
+
return new Promise((resolve, reject) => {
|
|
117936
|
+
const timeout = setTimeout(() => {
|
|
117937
|
+
this.pendingWalletKeyRequests.delete(requestId);
|
|
117938
|
+
reject(new Error("Wallet key request timeout"));
|
|
117939
|
+
}, 30000);
|
|
117940
|
+
this.pendingWalletKeyRequests.set(requestId, {
|
|
117941
|
+
resolve,
|
|
117942
|
+
reject,
|
|
117943
|
+
timeout
|
|
117944
|
+
});
|
|
117945
|
+
contentWindow.postMessage({ type: "GET_WALLET_KEY_REQUEST", payload: { requestId } }, this.sigmaUrl);
|
|
117946
|
+
});
|
|
117947
|
+
}
|
|
117948
|
+
handleMessage(event) {
|
|
117949
|
+
if (event.origin !== this.sigmaUrl) {
|
|
117950
|
+
return;
|
|
117951
|
+
}
|
|
117952
|
+
const { type, payload } = event.data || {};
|
|
117953
|
+
switch (type) {
|
|
117954
|
+
case "WALLET_LOCKED":
|
|
117955
|
+
if (this.iframe) {
|
|
117956
|
+
this.iframe.style.display = "block";
|
|
117957
|
+
}
|
|
117958
|
+
break;
|
|
117959
|
+
case "WALLET_UNLOCKED":
|
|
117960
|
+
if (this.iframe) {
|
|
117961
|
+
this.iframe.style.display = "none";
|
|
117962
|
+
}
|
|
117963
|
+
break;
|
|
117964
|
+
case "SIGNER_ERROR": {
|
|
117965
|
+
if (this.iframe) {
|
|
117966
|
+
this.iframe.style.display = "none";
|
|
117967
|
+
}
|
|
117968
|
+
const errorMsg = event.data.error || "Signer error";
|
|
117969
|
+
this.rejectAllPending(new Error(`Signer error: ${errorMsg}. Please sign in to Sigma Identity.`));
|
|
117970
|
+
break;
|
|
117971
|
+
}
|
|
117972
|
+
case "SIGN_RESPONSE": {
|
|
117973
|
+
const response = payload;
|
|
117974
|
+
const pending = this.pendingRequests.get(response.requestId);
|
|
117975
|
+
if (pending) {
|
|
117976
|
+
clearTimeout(pending.timeout);
|
|
117977
|
+
this.pendingRequests.delete(response.requestId);
|
|
117978
|
+
if (response.error) {
|
|
117979
|
+
pending.reject(new Error(response.error));
|
|
117980
|
+
} else {
|
|
117981
|
+
pending.resolve(response.authToken);
|
|
117982
|
+
}
|
|
117983
|
+
}
|
|
117984
|
+
break;
|
|
117985
|
+
}
|
|
117986
|
+
case "SIGN_AIP_RESPONSE": {
|
|
117987
|
+
const response = payload;
|
|
117988
|
+
const pending = this.pendingAIPRequests.get(response.requestId);
|
|
117989
|
+
if (pending) {
|
|
117990
|
+
clearTimeout(pending.timeout);
|
|
117991
|
+
this.pendingAIPRequests.delete(response.requestId);
|
|
117992
|
+
if (response.error) {
|
|
117993
|
+
pending.reject(new Error(response.error));
|
|
117994
|
+
} else if (response.signedOps) {
|
|
117995
|
+
pending.resolve(response.signedOps);
|
|
117996
|
+
} else {
|
|
117997
|
+
pending.reject(new Error("No signed ops returned"));
|
|
117998
|
+
}
|
|
117999
|
+
}
|
|
118000
|
+
break;
|
|
118001
|
+
}
|
|
118002
|
+
case "ENCRYPT_RESPONSE": {
|
|
118003
|
+
const response = payload;
|
|
118004
|
+
const pending = this.pendingEncryptRequests.get(response.requestId);
|
|
118005
|
+
if (pending) {
|
|
118006
|
+
clearTimeout(pending.timeout);
|
|
118007
|
+
this.pendingEncryptRequests.delete(response.requestId);
|
|
118008
|
+
if (response.error) {
|
|
118009
|
+
pending.reject(new Error(response.error));
|
|
118010
|
+
} else if (response.encrypted) {
|
|
118011
|
+
pending.resolve(response.encrypted);
|
|
118012
|
+
} else {
|
|
118013
|
+
pending.reject(new Error("No encrypted data returned"));
|
|
118014
|
+
}
|
|
118015
|
+
}
|
|
118016
|
+
break;
|
|
118017
|
+
}
|
|
118018
|
+
case "DECRYPT_RESPONSE": {
|
|
118019
|
+
const response = payload;
|
|
118020
|
+
const pending = this.pendingDecryptRequests.get(response.requestId);
|
|
118021
|
+
if (pending) {
|
|
118022
|
+
clearTimeout(pending.timeout);
|
|
118023
|
+
this.pendingDecryptRequests.delete(response.requestId);
|
|
118024
|
+
if (response.error) {
|
|
118025
|
+
pending.reject(new Error(response.error));
|
|
118026
|
+
} else if (response.decrypted !== undefined) {
|
|
118027
|
+
pending.resolve(response.decrypted);
|
|
118028
|
+
} else {
|
|
118029
|
+
pending.reject(new Error("No decrypted data returned"));
|
|
118030
|
+
}
|
|
118031
|
+
}
|
|
118032
|
+
break;
|
|
118033
|
+
}
|
|
118034
|
+
case "GET_FRIEND_PUBKEY_RESPONSE": {
|
|
118035
|
+
const response = payload;
|
|
118036
|
+
const pending = this.pendingGetFriendPubkeyRequests.get(response.requestId);
|
|
118037
|
+
if (pending) {
|
|
118038
|
+
clearTimeout(pending.timeout);
|
|
118039
|
+
this.pendingGetFriendPubkeyRequests.delete(response.requestId);
|
|
118040
|
+
if (response.error) {
|
|
118041
|
+
pending.reject(new Error(response.error));
|
|
118042
|
+
} else if (response.publicKey) {
|
|
118043
|
+
pending.resolve(response.publicKey);
|
|
118044
|
+
} else {
|
|
118045
|
+
pending.reject(new Error("No public key returned"));
|
|
118046
|
+
}
|
|
118047
|
+
}
|
|
118048
|
+
break;
|
|
118049
|
+
}
|
|
118050
|
+
case "GET_WALLET_KEY_RESPONSE": {
|
|
118051
|
+
const response = payload;
|
|
118052
|
+
const pending = this.pendingWalletKeyRequests.get(response.requestId);
|
|
118053
|
+
if (pending) {
|
|
118054
|
+
clearTimeout(pending.timeout);
|
|
118055
|
+
this.pendingWalletKeyRequests.delete(response.requestId);
|
|
118056
|
+
if (response.error) {
|
|
118057
|
+
pending.reject(new Error(response.error));
|
|
118058
|
+
} else if (response.encryptedWalletKey) {
|
|
118059
|
+
pending.resolve(response.encryptedWalletKey);
|
|
118060
|
+
} else {
|
|
118061
|
+
pending.reject(new Error("No wallet key returned"));
|
|
118062
|
+
}
|
|
118063
|
+
}
|
|
118064
|
+
break;
|
|
118065
|
+
}
|
|
118066
|
+
}
|
|
118067
|
+
}
|
|
118068
|
+
rejectAllPending(error) {
|
|
118069
|
+
for (const [, pending] of this.pendingRequests) {
|
|
118070
|
+
clearTimeout(pending.timeout);
|
|
118071
|
+
pending.reject(error);
|
|
118072
|
+
}
|
|
118073
|
+
this.pendingRequests.clear();
|
|
118074
|
+
for (const [, pending] of this.pendingAIPRequests) {
|
|
118075
|
+
clearTimeout(pending.timeout);
|
|
118076
|
+
pending.reject(error);
|
|
118077
|
+
}
|
|
118078
|
+
this.pendingAIPRequests.clear();
|
|
118079
|
+
for (const [, pending] of this.pendingEncryptRequests) {
|
|
118080
|
+
clearTimeout(pending.timeout);
|
|
118081
|
+
pending.reject(error);
|
|
118082
|
+
}
|
|
118083
|
+
this.pendingEncryptRequests.clear();
|
|
118084
|
+
for (const [, pending] of this.pendingDecryptRequests) {
|
|
118085
|
+
clearTimeout(pending.timeout);
|
|
118086
|
+
pending.reject(error);
|
|
118087
|
+
}
|
|
118088
|
+
this.pendingDecryptRequests.clear();
|
|
118089
|
+
for (const [, pending] of this.pendingGetFriendPubkeyRequests) {
|
|
118090
|
+
clearTimeout(pending.timeout);
|
|
118091
|
+
pending.reject(error);
|
|
118092
|
+
}
|
|
118093
|
+
this.pendingGetFriendPubkeyRequests.clear();
|
|
118094
|
+
for (const [, pending] of this.pendingWalletKeyRequests) {
|
|
118095
|
+
clearTimeout(pending.timeout);
|
|
118096
|
+
pending.reject(error);
|
|
118097
|
+
}
|
|
118098
|
+
this.pendingWalletKeyRequests.clear();
|
|
118099
|
+
}
|
|
118100
|
+
isReady() {
|
|
118101
|
+
return this.initialized && this.iframe !== null;
|
|
118102
|
+
}
|
|
118103
|
+
getIdentity() {
|
|
118104
|
+
return this.currentBapId;
|
|
118105
|
+
}
|
|
118106
|
+
destroy() {
|
|
118107
|
+
if (this.iframe) {
|
|
118108
|
+
document.body.removeChild(this.iframe);
|
|
118109
|
+
this.iframe = null;
|
|
118110
|
+
}
|
|
118111
|
+
if (this.boundMessageHandler) {
|
|
118112
|
+
window.removeEventListener("message", this.boundMessageHandler);
|
|
118113
|
+
this.boundMessageHandler = null;
|
|
118114
|
+
}
|
|
118115
|
+
this.initialized = false;
|
|
118116
|
+
this.rejectAllPending(new Error("Signer destroyed"));
|
|
118117
|
+
}
|
|
118118
|
+
}
|
|
118119
|
+
// ../../node_modules/@sigma-auth/better-auth-plugin/dist/client/index.js
|
|
118120
|
+
var signer = null;
|
|
118121
|
+
var signerType = null;
|
|
118122
|
+
var storedBapId = null;
|
|
118123
|
+
var hasSessionListener = false;
|
|
118124
|
+
var BAP_ID_STORAGE_KEY = "sigma_bap_id";
|
|
118125
|
+
var getSigmaUrl = () => {
|
|
118126
|
+
if (typeof process !== "undefined" && process.env.NEXT_PUBLIC_SIGMA_AUTH_URL) {
|
|
118127
|
+
return process.env.NEXT_PUBLIC_SIGMA_AUTH_URL;
|
|
118128
|
+
}
|
|
118129
|
+
return "https://auth.sigmaidentity.com";
|
|
118130
|
+
};
|
|
118131
|
+
var getLocalServerUrl = () => {
|
|
118132
|
+
if (typeof process !== "undefined" && process.env.NEXT_PUBLIC_TOKENPASS_URL) {
|
|
118133
|
+
return process.env.NEXT_PUBLIC_TOKENPASS_URL;
|
|
118134
|
+
}
|
|
118135
|
+
return "http://localhost:21000";
|
|
118136
|
+
};
|
|
118137
|
+
var preferLocalServer = false;
|
|
118138
|
+
var localServerOptions = {};
|
|
118139
|
+
var serverDetectedCallback;
|
|
118140
|
+
var getOrCreateSigner = async () => {
|
|
118141
|
+
if (signer?.isReady()) {
|
|
118142
|
+
return signer;
|
|
118143
|
+
}
|
|
118144
|
+
if (preferLocalServer && signerType !== "iframe") {
|
|
118145
|
+
const localSigner = new LocalServerSigner({
|
|
118146
|
+
baseUrl: localServerOptions.baseUrl || getLocalServerUrl(),
|
|
118147
|
+
timeout: localServerOptions.timeout
|
|
118148
|
+
});
|
|
118149
|
+
if (await localSigner.probe()) {
|
|
118150
|
+
signer = localSigner;
|
|
118151
|
+
signerType = "local";
|
|
118152
|
+
serverDetectedCallback?.(localSigner.getBaseUrl(), true);
|
|
118153
|
+
const host = typeof window !== "undefined" ? window.location.host : "localhost";
|
|
118154
|
+
await localSigner.authenticate(host);
|
|
118155
|
+
return signer;
|
|
118156
|
+
}
|
|
118157
|
+
}
|
|
118158
|
+
if (!signer || signerType !== "iframe") {
|
|
118159
|
+
const cwiSigner = new SigmaCWISigner(getSigmaUrl());
|
|
118160
|
+
signer = cwiSigner;
|
|
118161
|
+
signerType = "iframe";
|
|
118162
|
+
serverDetectedCallback?.(getSigmaUrl(), false);
|
|
118163
|
+
}
|
|
118164
|
+
if (!signer.isReady()) {
|
|
118165
|
+
await signer.init();
|
|
118166
|
+
}
|
|
118167
|
+
return signer;
|
|
118168
|
+
};
|
|
118169
|
+
var loadStoredBapId = () => {
|
|
118170
|
+
if (typeof window === "undefined")
|
|
118171
|
+
return null;
|
|
118172
|
+
if (storedBapId)
|
|
118173
|
+
return storedBapId;
|
|
118174
|
+
const stored = localStorage.getItem(BAP_ID_STORAGE_KEY);
|
|
118175
|
+
if (stored) {
|
|
118176
|
+
storedBapId = stored;
|
|
118177
|
+
}
|
|
118178
|
+
return storedBapId;
|
|
118179
|
+
};
|
|
118180
|
+
var clearStoredIdentity = () => {
|
|
118181
|
+
storedBapId = null;
|
|
118182
|
+
if (typeof window !== "undefined") {
|
|
118183
|
+
localStorage.removeItem(BAP_ID_STORAGE_KEY);
|
|
118184
|
+
}
|
|
118185
|
+
if (signer) {
|
|
118186
|
+
signer.destroy();
|
|
118187
|
+
signer = null;
|
|
118188
|
+
signerType = null;
|
|
118189
|
+
}
|
|
118190
|
+
};
|
|
118191
|
+
var generateCodeVerifier = () => {
|
|
118192
|
+
const array = new Uint8Array(32);
|
|
118193
|
+
crypto.getRandomValues(array);
|
|
118194
|
+
return btoa(String.fromCharCode(...array)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
118195
|
+
};
|
|
118196
|
+
var generateCodeChallenge = async (verifier) => {
|
|
114976
118197
|
const encoder = new TextEncoder;
|
|
114977
118198
|
const data = encoder.encode(verifier);
|
|
114978
118199
|
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
114979
|
-
return
|
|
114980
|
-
}
|
|
114981
|
-
|
|
114982
|
-
|
|
114983
|
-
|
|
114984
|
-
|
|
114985
|
-
|
|
114986
|
-
|
|
114987
|
-
|
|
114988
|
-
|
|
114989
|
-
|
|
114990
|
-
|
|
114991
|
-
|
|
114992
|
-
|
|
114993
|
-
|
|
114994
|
-
|
|
114995
|
-
|
|
114996
|
-
|
|
114997
|
-
|
|
118200
|
+
return btoa(String.fromCharCode(...new Uint8Array(hash))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
118201
|
+
};
|
|
118202
|
+
var sigmaClient = (options = {}) => {
|
|
118203
|
+
preferLocalServer = options.preferLocal ?? false;
|
|
118204
|
+
localServerOptions = {
|
|
118205
|
+
baseUrl: options.localServerUrl,
|
|
118206
|
+
timeout: options.localServerTimeout
|
|
118207
|
+
};
|
|
118208
|
+
serverDetectedCallback = options.onServerDetected;
|
|
118209
|
+
return {
|
|
118210
|
+
id: "sigma",
|
|
118211
|
+
getActions: ($fetch, $store) => {
|
|
118212
|
+
if (typeof window !== "undefined" && (options.clearIdentityOnSignOut ?? true) && !hasSessionListener) {
|
|
118213
|
+
const store = $store;
|
|
118214
|
+
const sessionAtom = store.atoms?.session;
|
|
118215
|
+
if (sessionAtom?.get && sessionAtom.listen) {
|
|
118216
|
+
hasSessionListener = true;
|
|
118217
|
+
let hadSession = !!sessionAtom.get()?.data;
|
|
118218
|
+
sessionAtom.listen((value) => {
|
|
118219
|
+
const hasSession = !!value?.data;
|
|
118220
|
+
if (hadSession && !hasSession) {
|
|
118221
|
+
clearStoredIdentity();
|
|
118222
|
+
}
|
|
118223
|
+
hadSession = hasSession;
|
|
118224
|
+
});
|
|
118225
|
+
}
|
|
118226
|
+
}
|
|
118227
|
+
return {
|
|
118228
|
+
subscription: {
|
|
118229
|
+
getStatus: async () => {
|
|
118230
|
+
const res = await $fetch("/subscription/status", {
|
|
118231
|
+
method: "GET"
|
|
118232
|
+
});
|
|
118233
|
+
if (res.error) {
|
|
118234
|
+
throw new Error(res.error.message || "Failed to fetch subscription status");
|
|
118235
|
+
}
|
|
118236
|
+
return res.data;
|
|
118237
|
+
},
|
|
118238
|
+
hasTier: (currentTier, requiredTier) => {
|
|
118239
|
+
const tierPriority = {
|
|
118240
|
+
free: 0,
|
|
118241
|
+
plus: 1,
|
|
118242
|
+
pro: 2,
|
|
118243
|
+
premium: 3,
|
|
118244
|
+
enterprise: 4
|
|
118245
|
+
};
|
|
118246
|
+
return tierPriority[currentTier] >= tierPriority[requiredTier];
|
|
118247
|
+
}
|
|
118248
|
+
},
|
|
118249
|
+
wallet: {
|
|
118250
|
+
getConnected: async (bapId) => {
|
|
118251
|
+
const url = bapId ? `/wallet/connect?bapId=${encodeURIComponent(bapId)}` : "/wallet/connect";
|
|
118252
|
+
const res = await $fetch(url, {
|
|
118253
|
+
method: "GET"
|
|
118254
|
+
});
|
|
118255
|
+
if (res.error) {
|
|
118256
|
+
throw new Error(res.error.message || "Failed to fetch connected wallets");
|
|
118257
|
+
}
|
|
118258
|
+
return res.data;
|
|
118259
|
+
},
|
|
118260
|
+
connect: async (bapId, authToken, provider = "yours") => {
|
|
118261
|
+
const res = await $fetch("/wallet/connect", {
|
|
118262
|
+
method: "POST",
|
|
118263
|
+
body: {
|
|
118264
|
+
bapId,
|
|
118265
|
+
authToken,
|
|
118266
|
+
provider
|
|
118267
|
+
}
|
|
118268
|
+
});
|
|
118269
|
+
if (res.error) {
|
|
118270
|
+
throw new Error(res.error.message || "Failed to connect wallet");
|
|
118271
|
+
}
|
|
118272
|
+
return res.data;
|
|
118273
|
+
},
|
|
118274
|
+
disconnect: async (bapId, address) => {
|
|
118275
|
+
const res = await $fetch(`/wallet/connect?bapId=${encodeURIComponent(bapId)}&address=${encodeURIComponent(address)}`, {
|
|
118276
|
+
method: "DELETE"
|
|
118277
|
+
});
|
|
118278
|
+
if (res.error) {
|
|
118279
|
+
throw new Error(res.error.message || "Failed to disconnect wallet");
|
|
118280
|
+
}
|
|
118281
|
+
return res.data;
|
|
118282
|
+
},
|
|
118283
|
+
setPrimary: async (bapId, walletAddress) => {
|
|
118284
|
+
const res = await $fetch("/wallet/set-primary", {
|
|
118285
|
+
method: "POST",
|
|
118286
|
+
body: {
|
|
118287
|
+
bapId,
|
|
118288
|
+
walletAddress
|
|
118289
|
+
}
|
|
118290
|
+
});
|
|
118291
|
+
if (res.error) {
|
|
118292
|
+
throw new Error(res.error.message || "Failed to set primary wallet");
|
|
118293
|
+
}
|
|
118294
|
+
return res.data;
|
|
118295
|
+
}
|
|
118296
|
+
},
|
|
118297
|
+
nft: {
|
|
118298
|
+
list: async (refresh = false) => {
|
|
118299
|
+
const url = refresh ? "/wallet/nfts?refresh=true" : "/wallet/nfts";
|
|
118300
|
+
const res = await $fetch(url, {
|
|
118301
|
+
method: "GET"
|
|
118302
|
+
});
|
|
118303
|
+
if (res.error) {
|
|
118304
|
+
throw new Error(res.error.message || "Failed to fetch NFTs");
|
|
118305
|
+
}
|
|
118306
|
+
return res.data;
|
|
118307
|
+
},
|
|
118308
|
+
verifyOwnership: async (params) => {
|
|
118309
|
+
const res = await $fetch("/wallet/verify-ownership", {
|
|
118310
|
+
method: "POST",
|
|
118311
|
+
body: params
|
|
118312
|
+
});
|
|
118313
|
+
if (res.error) {
|
|
118314
|
+
throw new Error(res.error.message || "Failed to verify NFT ownership");
|
|
118315
|
+
}
|
|
118316
|
+
return res.data;
|
|
118317
|
+
}
|
|
118318
|
+
},
|
|
118319
|
+
signIn: {
|
|
118320
|
+
sigma: async (signInOptions, fetchOptions) => {
|
|
118321
|
+
if (signInOptions?.authToken) {
|
|
118322
|
+
const res = await $fetch("/sign-in/sigma", {
|
|
118323
|
+
...fetchOptions,
|
|
118324
|
+
method: "POST",
|
|
118325
|
+
body: {},
|
|
118326
|
+
headers: {
|
|
118327
|
+
...fetchOptions?.headers,
|
|
118328
|
+
"X-Auth-Token": signInOptions.authToken
|
|
118329
|
+
}
|
|
118330
|
+
});
|
|
118331
|
+
return res;
|
|
118332
|
+
}
|
|
118333
|
+
if ($store && !signInOptions?.forceLogin) {
|
|
118334
|
+
const sessionAtom = $store.session;
|
|
118335
|
+
if (sessionAtom) {
|
|
118336
|
+
const currentSession = sessionAtom.get();
|
|
118337
|
+
if (currentSession.data) {
|
|
118338
|
+
return { data: currentSession, error: null };
|
|
118339
|
+
}
|
|
118340
|
+
}
|
|
118341
|
+
}
|
|
118342
|
+
if (!signInOptions?.clientId) {
|
|
118343
|
+
throw new Error("[Sigma Auth] clientId is required for OAuth flow. " + "Pass clientId in signIn.sigma({ clientId: 'your-app', ... }) or set NEXT_PUBLIC_SIGMA_CLIENT_ID environment variable.");
|
|
118344
|
+
}
|
|
118345
|
+
const state = Math.random().toString(36).substring(7);
|
|
118346
|
+
const codeVerifier = generateCodeVerifier();
|
|
118347
|
+
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
118348
|
+
if (typeof window !== "undefined") {
|
|
118349
|
+
sessionStorage.setItem("sigma_oauth_state", state);
|
|
118350
|
+
sessionStorage.setItem("sigma_code_verifier", codeVerifier);
|
|
118351
|
+
if (signInOptions?.errorCallbackURL) {
|
|
118352
|
+
sessionStorage.setItem("sigma_error_callback", signInOptions.errorCallbackURL);
|
|
118353
|
+
} else {
|
|
118354
|
+
sessionStorage.removeItem("sigma_error_callback");
|
|
118355
|
+
}
|
|
118356
|
+
}
|
|
118357
|
+
const authUrl = getSigmaUrl();
|
|
118358
|
+
const origin = typeof window !== "undefined" ? window.location.origin : "";
|
|
118359
|
+
const callbackPath = signInOptions?.callbackURL || "/auth/sigma/callback";
|
|
118360
|
+
const redirectUri = callbackPath.startsWith("http") ? callbackPath : `${origin}${callbackPath.startsWith("/") ? callbackPath : `/${callbackPath}`}`;
|
|
118361
|
+
if (typeof window !== "undefined") {
|
|
118362
|
+
sessionStorage.setItem("sigma_redirect_uri", redirectUri);
|
|
118363
|
+
}
|
|
118364
|
+
const params = new URLSearchParams({
|
|
118365
|
+
client_id: signInOptions.clientId,
|
|
118366
|
+
redirect_uri: redirectUri,
|
|
118367
|
+
response_type: "code",
|
|
118368
|
+
state,
|
|
118369
|
+
scope: "openid profile",
|
|
118370
|
+
code_challenge: codeChallenge,
|
|
118371
|
+
code_challenge_method: "S256"
|
|
118372
|
+
});
|
|
118373
|
+
if (signInOptions?.provider) {
|
|
118374
|
+
params.append("provider", signInOptions.provider);
|
|
118375
|
+
}
|
|
118376
|
+
if (signInOptions?.prompt) {
|
|
118377
|
+
params.append("prompt", signInOptions.prompt);
|
|
118378
|
+
}
|
|
118379
|
+
if (signInOptions?.bapId) {
|
|
118380
|
+
params.append("bapId", signInOptions.bapId);
|
|
118381
|
+
params.append("bap_id", signInOptions.bapId);
|
|
118382
|
+
}
|
|
118383
|
+
const fullAuthUrl = `${authUrl}/oauth2/authorize?${params.toString()}`;
|
|
118384
|
+
if (typeof window !== "undefined") {
|
|
118385
|
+
window.location.href = fullAuthUrl;
|
|
118386
|
+
}
|
|
118387
|
+
return new Promise(() => {});
|
|
118388
|
+
}
|
|
118389
|
+
},
|
|
118390
|
+
sigma: {
|
|
118391
|
+
handleCallback: async (searchParams) => {
|
|
118392
|
+
const error = searchParams.get("error");
|
|
118393
|
+
if (error) {
|
|
118394
|
+
const errorDescription = searchParams.get("error_description");
|
|
118395
|
+
throw {
|
|
118396
|
+
title: "Authentication Error",
|
|
118397
|
+
message: errorDescription || error || "An unknown error occurred during authentication."
|
|
118398
|
+
};
|
|
118399
|
+
}
|
|
118400
|
+
const code2 = searchParams.get("code");
|
|
118401
|
+
const state = searchParams.get("state");
|
|
118402
|
+
if (!code2) {
|
|
118403
|
+
throw {
|
|
118404
|
+
title: "Missing Authorization Code",
|
|
118405
|
+
message: "The authorization code was not received from the authentication server."
|
|
118406
|
+
};
|
|
118407
|
+
}
|
|
118408
|
+
const savedState = typeof window !== "undefined" ? sessionStorage.getItem("sigma_oauth_state") : null;
|
|
118409
|
+
if (state !== savedState) {
|
|
118410
|
+
if (typeof window !== "undefined") {
|
|
118411
|
+
sessionStorage.removeItem("sigma_oauth_state");
|
|
118412
|
+
}
|
|
118413
|
+
throw {
|
|
118414
|
+
title: "Security Error",
|
|
118415
|
+
message: "Invalid state parameter. Please try signing in again."
|
|
118416
|
+
};
|
|
118417
|
+
}
|
|
118418
|
+
if (typeof window !== "undefined") {
|
|
118419
|
+
sessionStorage.removeItem("sigma_oauth_state");
|
|
118420
|
+
}
|
|
118421
|
+
const codeVerifier = typeof window !== "undefined" ? sessionStorage.getItem("sigma_code_verifier") || undefined : undefined;
|
|
118422
|
+
const storedRedirectUri = typeof window !== "undefined" ? sessionStorage.getItem("sigma_redirect_uri") || undefined : undefined;
|
|
118423
|
+
const isCrossDomain = typeof window !== "undefined" && new URL(getSigmaUrl()).host !== window.location.host;
|
|
118424
|
+
try {
|
|
118425
|
+
let data;
|
|
118426
|
+
if (isCrossDomain) {
|
|
118427
|
+
const response = await fetch("/api/auth/sigma/callback", {
|
|
118428
|
+
method: "POST",
|
|
118429
|
+
headers: { "Content-Type": "application/json" },
|
|
118430
|
+
body: JSON.stringify({
|
|
118431
|
+
code: code2,
|
|
118432
|
+
state,
|
|
118433
|
+
code_verifier: codeVerifier,
|
|
118434
|
+
redirect_uri: storedRedirectUri
|
|
118435
|
+
})
|
|
118436
|
+
});
|
|
118437
|
+
if (!response.ok) {
|
|
118438
|
+
const errorData = await response.json().catch(() => ({}));
|
|
118439
|
+
throw {
|
|
118440
|
+
title: errorData.error || "Token Exchange Failed",
|
|
118441
|
+
message: errorData.details || `Server returned ${response.status}`
|
|
118442
|
+
};
|
|
118443
|
+
}
|
|
118444
|
+
data = await response.json();
|
|
118445
|
+
} else {
|
|
118446
|
+
const res = await $fetch("/sigma/callback", {
|
|
118447
|
+
method: "POST",
|
|
118448
|
+
body: {
|
|
118449
|
+
code: code2,
|
|
118450
|
+
state,
|
|
118451
|
+
code_verifier: codeVerifier,
|
|
118452
|
+
redirect_uri: storedRedirectUri
|
|
118453
|
+
}
|
|
118454
|
+
});
|
|
118455
|
+
if (res.error) {
|
|
118456
|
+
let errorMessage = "Failed to exchange authorization code for access token.";
|
|
118457
|
+
let errorTitle = "Token Exchange Failed";
|
|
118458
|
+
const errorData = res.error;
|
|
118459
|
+
const endpoint = errorData.endpoint || "unknown";
|
|
118460
|
+
const status = errorData.status || 500;
|
|
118461
|
+
if (errorData.details) {
|
|
118462
|
+
try {
|
|
118463
|
+
const nestedError = JSON.parse(errorData.details);
|
|
118464
|
+
if (nestedError.error_description) {
|
|
118465
|
+
errorMessage = nestedError.error_description;
|
|
118466
|
+
}
|
|
118467
|
+
if (nestedError.error === "invalid_client") {
|
|
118468
|
+
errorTitle = "Platform Not Registered";
|
|
118469
|
+
errorMessage = "This platform is not registered with the authentication server.";
|
|
118470
|
+
}
|
|
118471
|
+
} catch {
|
|
118472
|
+
errorMessage = errorData.details;
|
|
118473
|
+
}
|
|
118474
|
+
} else if (errorData.error) {
|
|
118475
|
+
errorMessage = errorData.error;
|
|
118476
|
+
}
|
|
118477
|
+
errorMessage += `
|
|
118478
|
+
|
|
118479
|
+
Backend: ${status} (${endpoint})`;
|
|
118480
|
+
throw {
|
|
118481
|
+
title: errorTitle,
|
|
118482
|
+
message: errorMessage
|
|
118483
|
+
};
|
|
118484
|
+
}
|
|
118485
|
+
data = res.data;
|
|
118486
|
+
}
|
|
118487
|
+
const bapId = data.user?.bap_id;
|
|
118488
|
+
if (bapId) {
|
|
118489
|
+
storedBapId = bapId;
|
|
118490
|
+
if (typeof window !== "undefined") {
|
|
118491
|
+
localStorage.setItem(BAP_ID_STORAGE_KEY, bapId);
|
|
118492
|
+
}
|
|
118493
|
+
}
|
|
118494
|
+
if (typeof window !== "undefined") {
|
|
118495
|
+
sessionStorage.removeItem("sigma_redirect_uri");
|
|
118496
|
+
sessionStorage.removeItem("sigma_code_verifier");
|
|
118497
|
+
}
|
|
118498
|
+
return {
|
|
118499
|
+
user: data.user,
|
|
118500
|
+
access_token: data.access_token,
|
|
118501
|
+
id_token: data.id_token,
|
|
118502
|
+
refresh_token: data.refresh_token
|
|
118503
|
+
};
|
|
118504
|
+
} catch (err) {
|
|
118505
|
+
if (typeof err === "object" && err !== null && "title" in err && "message" in err) {
|
|
118506
|
+
throw err;
|
|
118507
|
+
}
|
|
118508
|
+
throw {
|
|
118509
|
+
title: "Authentication Failed",
|
|
118510
|
+
message: err instanceof Error ? err.message : "An unknown error occurred."
|
|
118511
|
+
};
|
|
118512
|
+
}
|
|
118513
|
+
},
|
|
118514
|
+
sign: async (requestPath, body, signatureType = "brc77") => {
|
|
118515
|
+
const bapId = storedBapId || loadStoredBapId();
|
|
118516
|
+
if (!bapId) {
|
|
118517
|
+
throw new Error("No identity set. Complete OAuth login first or call setIdentity().");
|
|
118518
|
+
}
|
|
118519
|
+
const signerInstance = await getOrCreateSigner();
|
|
118520
|
+
signerInstance.setIdentity(bapId);
|
|
118521
|
+
const bodyString = body && typeof body === "object" ? JSON.stringify(body) : body;
|
|
118522
|
+
return signerInstance.sign(requestPath, bodyString, signatureType);
|
|
118523
|
+
},
|
|
118524
|
+
signAIP: async (hexArray) => {
|
|
118525
|
+
const bapId = storedBapId || loadStoredBapId();
|
|
118526
|
+
if (!bapId) {
|
|
118527
|
+
throw new Error("No identity set. Complete OAuth login first or call setIdentity().");
|
|
118528
|
+
}
|
|
118529
|
+
const signerInstance = await getOrCreateSigner();
|
|
118530
|
+
signerInstance.setIdentity(bapId);
|
|
118531
|
+
return signerInstance.signAIP(hexArray);
|
|
118532
|
+
},
|
|
118533
|
+
encrypt: async (data, friendBapId, theirPublicKey) => {
|
|
118534
|
+
const bapId = storedBapId || loadStoredBapId();
|
|
118535
|
+
if (!bapId) {
|
|
118536
|
+
throw new Error("No identity set. Complete OAuth login first or call setIdentity().");
|
|
118537
|
+
}
|
|
118538
|
+
const signerInstance = await getOrCreateSigner();
|
|
118539
|
+
signerInstance.setIdentity(bapId);
|
|
118540
|
+
return signerInstance.encrypt(data, friendBapId, theirPublicKey);
|
|
118541
|
+
},
|
|
118542
|
+
decrypt: async (ciphertext, friendBapId, theirPublicKey) => {
|
|
118543
|
+
const bapId = storedBapId || loadStoredBapId();
|
|
118544
|
+
if (!bapId) {
|
|
118545
|
+
throw new Error("No identity set. Complete OAuth login first or call setIdentity().");
|
|
118546
|
+
}
|
|
118547
|
+
const signerInstance = await getOrCreateSigner();
|
|
118548
|
+
signerInstance.setIdentity(bapId);
|
|
118549
|
+
return signerInstance.decrypt(ciphertext, friendBapId, theirPublicKey);
|
|
118550
|
+
},
|
|
118551
|
+
getFriendPublicKey: async (friendBapId) => {
|
|
118552
|
+
const bapId = storedBapId || loadStoredBapId();
|
|
118553
|
+
if (!bapId) {
|
|
118554
|
+
throw new Error("No identity set. Complete OAuth login first or call setIdentity().");
|
|
118555
|
+
}
|
|
118556
|
+
const signerInstance = await getOrCreateSigner();
|
|
118557
|
+
signerInstance.setIdentity(bapId);
|
|
118558
|
+
return signerInstance.getFriendPublicKey(friendBapId);
|
|
118559
|
+
},
|
|
118560
|
+
getIdentity: () => {
|
|
118561
|
+
return storedBapId || loadStoredBapId();
|
|
118562
|
+
},
|
|
118563
|
+
setIdentity: (bapId) => {
|
|
118564
|
+
storedBapId = bapId;
|
|
118565
|
+
if (typeof window !== "undefined") {
|
|
118566
|
+
localStorage.setItem(BAP_ID_STORAGE_KEY, bapId);
|
|
118567
|
+
}
|
|
118568
|
+
if (signer) {
|
|
118569
|
+
signer.setIdentity(bapId);
|
|
118570
|
+
}
|
|
118571
|
+
},
|
|
118572
|
+
clearIdentity: () => {
|
|
118573
|
+
clearStoredIdentity();
|
|
118574
|
+
},
|
|
118575
|
+
detectServer: async () => {
|
|
118576
|
+
const localSigner = new LocalServerSigner({
|
|
118577
|
+
baseUrl: localServerOptions.baseUrl || getLocalServerUrl(),
|
|
118578
|
+
timeout: localServerOptions.timeout
|
|
118579
|
+
});
|
|
118580
|
+
if (await localSigner.probe()) {
|
|
118581
|
+
return { url: localSigner.getBaseUrl(), isLocal: true };
|
|
118582
|
+
}
|
|
118583
|
+
return { url: getSigmaUrl(), isLocal: false };
|
|
118584
|
+
},
|
|
118585
|
+
getSignerType: () => {
|
|
118586
|
+
return signerType;
|
|
118587
|
+
},
|
|
118588
|
+
getSigner: async () => {
|
|
118589
|
+
return getOrCreateSigner();
|
|
118590
|
+
},
|
|
118591
|
+
isReady: () => {
|
|
118592
|
+
const bapId = storedBapId || loadStoredBapId();
|
|
118593
|
+
return !!bapId;
|
|
118594
|
+
},
|
|
118595
|
+
getErrorCallbackURL: () => {
|
|
118596
|
+
if (typeof window === "undefined")
|
|
118597
|
+
return "/auth/sigma/error";
|
|
118598
|
+
return sessionStorage.getItem("sigma_error_callback") || "/auth/sigma/error";
|
|
118599
|
+
},
|
|
118600
|
+
redirectToError: (error) => {
|
|
118601
|
+
if (typeof window === "undefined")
|
|
118602
|
+
return;
|
|
118603
|
+
const errorCallbackURL = sessionStorage.getItem("sigma_error_callback") || "/auth/sigma/error";
|
|
118604
|
+
sessionStorage.removeItem("sigma_error_callback");
|
|
118605
|
+
sessionStorage.removeItem("sigma_oauth_state");
|
|
118606
|
+
sessionStorage.removeItem("sigma_code_verifier");
|
|
118607
|
+
const errorUrl = new URL(errorCallbackURL, window.location.origin);
|
|
118608
|
+
if (error && typeof error === "object" && "title" in error && "message" in error) {
|
|
118609
|
+
const oauthError = error;
|
|
118610
|
+
errorUrl.searchParams.set("error", oauthError.title);
|
|
118611
|
+
errorUrl.searchParams.set("error_description", oauthError.message);
|
|
118612
|
+
} else if (error instanceof Error) {
|
|
118613
|
+
errorUrl.searchParams.set("error", "callback_error");
|
|
118614
|
+
errorUrl.searchParams.set("error_description", error.message);
|
|
118615
|
+
} else {
|
|
118616
|
+
errorUrl.searchParams.set("error", "unknown_error");
|
|
118617
|
+
errorUrl.searchParams.set("error_description", "An unknown error occurred");
|
|
118618
|
+
}
|
|
118619
|
+
window.location.href = errorUrl.toString();
|
|
118620
|
+
}
|
|
118621
|
+
}
|
|
118622
|
+
};
|
|
118623
|
+
}
|
|
118624
|
+
};
|
|
118625
|
+
};
|
|
118626
|
+
|
|
118627
|
+
// src/sigma-oauth.ts
|
|
118628
|
+
var SIGMA_URL = "https://auth.sigmaidentity.com";
|
|
118629
|
+
var baseAuthClient = createAuthClient({
|
|
118630
|
+
baseURL: SIGMA_URL,
|
|
118631
|
+
plugins: [sigmaClient()]
|
|
118632
|
+
});
|
|
118633
|
+
var sigmaAuthClient = baseAuthClient;
|
|
118634
|
+
async function initiateSigmaOAuth(config, options) {
|
|
118635
|
+
await sigmaAuthClient.signIn.sigma({
|
|
118636
|
+
clientId: config.clientId,
|
|
118637
|
+
callbackURL: config.callbackURL ?? "/auth/sigma/callback",
|
|
118638
|
+
...options
|
|
114998
118639
|
});
|
|
114999
|
-
const authorizeUrl = `${SIGMA_URL}${SIGMA_AUTHORIZE_PATH}?${params.toString()}`;
|
|
115000
|
-
window.location.href = authorizeUrl;
|
|
115001
118640
|
return new Promise(() => {});
|
|
115002
118641
|
}
|
|
115003
|
-
function
|
|
115004
|
-
const
|
|
115005
|
-
const state = searchParams.get("state");
|
|
115006
|
-
const storedState = sessionStorage.getItem(STATE_KEY);
|
|
115007
|
-
return !!(code2 && state && storedState && state === storedState);
|
|
115008
|
-
}
|
|
115009
|
-
async function completeSigmaOAuth(searchParams, serverCallbackUrl = "/api/auth/sigma/callback") {
|
|
115010
|
-
const code2 = searchParams.get("code");
|
|
115011
|
-
const state = searchParams.get("state");
|
|
115012
|
-
const storedState = sessionStorage.getItem(STATE_KEY);
|
|
115013
|
-
const verifier = sessionStorage.getItem(VERIFIER_KEY);
|
|
115014
|
-
if (!code2 || !state) {
|
|
115015
|
-
throw new Error("Missing OAuth callback parameters (code or state)");
|
|
115016
|
-
}
|
|
115017
|
-
if (!storedState || state !== storedState) {
|
|
115018
|
-
throw new Error("OAuth state mismatch — possible CSRF attack");
|
|
115019
|
-
}
|
|
115020
|
-
if (!verifier) {
|
|
115021
|
-
throw new Error("Missing PKCE verifier — OAuth flow was not initiated");
|
|
115022
|
-
}
|
|
115023
|
-
sessionStorage.removeItem(STATE_KEY);
|
|
115024
|
-
sessionStorage.removeItem(VERIFIER_KEY);
|
|
115025
|
-
const response = await fetch(serverCallbackUrl, {
|
|
115026
|
-
method: "POST",
|
|
115027
|
-
headers: { "Content-Type": "application/json" },
|
|
115028
|
-
body: JSON.stringify({ code: code2, state, code_verifier: verifier })
|
|
115029
|
-
});
|
|
115030
|
-
if (!response.ok) {
|
|
115031
|
-
const text = await response.text().catch(() => "");
|
|
115032
|
-
throw new Error(`Sigma OAuth token exchange failed (${response.status}): ${text}`);
|
|
115033
|
-
}
|
|
115034
|
-
const result = await response.json();
|
|
118642
|
+
async function completeSigmaOAuth(searchParams) {
|
|
118643
|
+
const result = await sigmaAuthClient.sigma.handleCallback(searchParams);
|
|
115035
118644
|
const bapId = result.user?.bap_id;
|
|
115036
118645
|
if (!bapId) {
|
|
115037
118646
|
throw new Error("Sigma callback response missing bap_id");
|
|
@@ -115047,6 +118656,9 @@ async function completeSigmaOAuth(searchParams, serverCallbackUrl = "/api/auth/s
|
|
|
115047
118656
|
accessToken: result.access_token ?? ""
|
|
115048
118657
|
};
|
|
115049
118658
|
}
|
|
118659
|
+
function setSigmaIdentity(bapId) {
|
|
118660
|
+
sigmaAuthClient.sigma.setIdentity(bapId);
|
|
118661
|
+
}
|
|
115050
118662
|
|
|
115051
118663
|
// src/connectWallet.ts
|
|
115052
118664
|
var DEFAULT_ONESAT_URL = "https://1sat.market";
|
|
@@ -115054,6 +118666,7 @@ async function reconnectSigma(config, bapId) {
|
|
|
115054
118666
|
const sigmaUrl = config.url ?? SIGMA_URL;
|
|
115055
118667
|
const cwiConfig = { sigmaUrl };
|
|
115056
118668
|
const { wallet: wallet6, destroy, sendCustomMessage } = createSigmaCWI(cwiConfig);
|
|
118669
|
+
setSigmaIdentity(bapId);
|
|
115057
118670
|
sendCustomMessage("SET_IDENTITY", { bapId });
|
|
115058
118671
|
await wallet6.waitForAuthentication({});
|
|
115059
118672
|
const { publicKey } = await wallet6.getPublicKey({ identityKey: true });
|
|
@@ -115178,7 +118791,7 @@ var DEFAULT_MOBILE_HANDSHAKE_TIMEOUT_MS = 900;
|
|
|
115178
118791
|
var DEFAULT_DESKTOP_MAX_RETRIES = 2;
|
|
115179
118792
|
var DEFAULT_MOBILE_MAX_RETRIES = 1;
|
|
115180
118793
|
var REDIRECT_PENDING_KEY = "onesat:cwi:redirect:pending";
|
|
115181
|
-
var
|
|
118794
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null;
|
|
115182
118795
|
var isLikelyMobileRuntime = () => {
|
|
115183
118796
|
if (typeof navigator === "undefined")
|
|
115184
118797
|
return false;
|
|
@@ -115191,7 +118804,7 @@ var isLikelyMobileRuntime = () => {
|
|
|
115191
118804
|
const userAgent = navigator.userAgent ?? "";
|
|
115192
118805
|
return /Android|iPhone|iPad|iPod|Mobile/i.test(userAgent);
|
|
115193
118806
|
};
|
|
115194
|
-
var
|
|
118807
|
+
var createId4 = () => {
|
|
115195
118808
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
115196
118809
|
return crypto.randomUUID();
|
|
115197
118810
|
}
|
|
@@ -115250,16 +118863,16 @@ var normalizeState = (state) => ({
|
|
|
115250
118863
|
reason: normalizeReason(state.reason)
|
|
115251
118864
|
});
|
|
115252
118865
|
var isCWIStateMessage = (value) => {
|
|
115253
|
-
if (!
|
|
118866
|
+
if (!isRecord4(value))
|
|
115254
118867
|
return false;
|
|
115255
118868
|
if (value.type !== "CWI")
|
|
115256
118869
|
return false;
|
|
115257
|
-
if (!
|
|
118870
|
+
if (!isRecord4(value.cwiState))
|
|
115258
118871
|
return false;
|
|
115259
118872
|
return true;
|
|
115260
118873
|
};
|
|
115261
118874
|
var isCWIResponseMessage = (value) => {
|
|
115262
|
-
if (!
|
|
118875
|
+
if (!isRecord4(value))
|
|
115263
118876
|
return false;
|
|
115264
118877
|
if (value.type !== "CWI")
|
|
115265
118878
|
return false;
|
|
@@ -115271,7 +118884,7 @@ var isCWIResponseMessage = (value) => {
|
|
|
115271
118884
|
};
|
|
115272
118885
|
var toCWIError = (message) => new OneSatError(ErrorCodes.INTERNAL_ERROR, message.description ?? "Wallet request failed", { code: message.code });
|
|
115273
118886
|
var extractErrorDescription = (value) => {
|
|
115274
|
-
if (!
|
|
118887
|
+
if (!isRecord4(value))
|
|
115275
118888
|
return;
|
|
115276
118889
|
const description = value.error_description;
|
|
115277
118890
|
if (typeof description === "string" && description.length > 0) {
|
|
@@ -115469,7 +119082,7 @@ class EmbedTransport {
|
|
|
115469
119082
|
if (!target) {
|
|
115470
119083
|
throw new TransportUnavailableError("CWI iframe is not reachable");
|
|
115471
119084
|
}
|
|
115472
|
-
const requestId =
|
|
119085
|
+
const requestId = createId4();
|
|
115473
119086
|
const request3 = {
|
|
115474
119087
|
type: "CWI",
|
|
115475
119088
|
isInvocation: true,
|
|
@@ -115628,7 +119241,7 @@ class RedirectTransport {
|
|
|
115628
119241
|
credentials: "omit"
|
|
115629
119242
|
}, this.timeoutMs, () => new AuthorizationTimeoutError("authorize/init timed out"));
|
|
115630
119243
|
const payload = await response.json().catch(() => ({}));
|
|
115631
|
-
if (!response.ok || !
|
|
119244
|
+
if (!response.ok || !isRecord4(payload)) {
|
|
115632
119245
|
const description = extractErrorDescription(payload) ?? "Failed to initialize redirect authorization";
|
|
115633
119246
|
throw new OneSatError(ErrorCodes.INVALID_REQUEST, description, payload);
|
|
115634
119247
|
}
|
|
@@ -115674,7 +119287,7 @@ class RedirectTransport {
|
|
|
115674
119287
|
credentials: "omit"
|
|
115675
119288
|
}, this.timeoutMs, () => new AuthorizationTimeoutError("token exchange timed out"));
|
|
115676
119289
|
const payload = await response.json().catch(() => ({}));
|
|
115677
|
-
if (!response.ok || !
|
|
119290
|
+
if (!response.ok || !isRecord4(payload)) {
|
|
115678
119291
|
const description = extractErrorDescription(payload) ?? "Authorization code exchange failed";
|
|
115679
119292
|
if (/already_consumed|replay|consumed/i.test(description)) {
|
|
115680
119293
|
throw new CodeReplayError(description);
|
|
@@ -115784,7 +119397,7 @@ class AutoTransport {
|
|
|
115784
119397
|
toFallbackReason(error) {
|
|
115785
119398
|
if (error instanceof FallbackRequiredError) {
|
|
115786
119399
|
const data = error.data;
|
|
115787
|
-
if (
|
|
119400
|
+
if (isRecord4(data)) {
|
|
115788
119401
|
const reason = normalizeReason(data.reason);
|
|
115789
119402
|
if (reason) {
|
|
115790
119403
|
return reason;
|
|
@@ -115975,6 +119588,8 @@ export {
|
|
|
115975
119588
|
walletLockedError,
|
|
115976
119589
|
waitForOneSat,
|
|
115977
119590
|
signRequest,
|
|
119591
|
+
sigmaAuthClient,
|
|
119592
|
+
setSigmaIdentity,
|
|
115978
119593
|
sendResponse,
|
|
115979
119594
|
sendErrorResponse,
|
|
115980
119595
|
saveConnection,
|
|
@@ -115983,7 +119598,6 @@ export {
|
|
|
115983
119598
|
parsePopupParams,
|
|
115984
119599
|
loadConnection,
|
|
115985
119600
|
isValidMessage,
|
|
115986
|
-
isSigmaCallback,
|
|
115987
119601
|
isResponse,
|
|
115988
119602
|
isPopupContext,
|
|
115989
119603
|
isOneSatInjected,
|