@asgardeo/javascript 0.20.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -952,6 +952,16 @@ var StorageManager = class _StorageManager {
952
952
  };
953
953
  var StorageManager_default = StorageManager;
954
954
 
955
+ // src/utils/base64Encode.ts
956
+ import * as jose from "jose";
957
+ var base64Encode = (value) => {
958
+ const b64url = jose.base64url.encode(new TextEncoder().encode(value));
959
+ const rem = b64url.length % 4;
960
+ const padded = rem === 0 ? b64url : b64url + "=".repeat(4 - rem);
961
+ return padded.replace(/-/g, "+").replace(/_/g, "/");
962
+ };
963
+ var base64Encode_default = base64Encode;
964
+
955
965
  // src/utils/deepMerge.ts
956
966
  var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof RegExp) && Object.prototype.toString.call(value) === "[object Object]";
957
967
  var deepMerge = (target, ...sources) => {
@@ -1318,7 +1328,9 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
1318
1328
  }
1319
1329
  const body = new URLSearchParams();
1320
1330
  body.set("client_id", configData.clientId);
1321
- if (configData.clientSecret && configData.clientSecret.trim().length > 0) {
1331
+ const hasSecret = Boolean(configData.clientSecret && configData.clientSecret.trim().length > 0);
1332
+ const tokenEndpointAuthMethod = configData.tokenRequest?.authMethod ?? (configData.platform === "AsgardeoV2" /* AsgardeoV2 */ ? "client_secret_basic" : "client_secret_post");
1333
+ if (hasSecret && tokenEndpointAuthMethod === "client_secret_post") {
1322
1334
  body.set("client_secret", configData.clientSecret);
1323
1335
  }
1324
1336
  const code = authorizationCode;
@@ -1337,15 +1349,22 @@ var _AsgardeoAuthClient = class _AsgardeoAuthClient {
1337
1349
  );
1338
1350
  await this.storageManager.removeTemporaryDataParameter(extractPkceStorageKeyFromState_default(state), userId);
1339
1351
  }
1352
+ const tokenRequestHeaders = {
1353
+ Accept: "application/json",
1354
+ "Content-Type": "application/x-www-form-urlencoded"
1355
+ };
1356
+ if (hasSecret && tokenEndpointAuthMethod === "client_secret_basic") {
1357
+ const credential = `${encodeURIComponent(configData.clientId)}:${encodeURIComponent(
1358
+ configData.clientSecret
1359
+ )}`;
1360
+ tokenRequestHeaders["Authorization"] = `Basic ${base64Encode_default(credential)}`;
1361
+ }
1340
1362
  let tokenResponse;
1341
1363
  try {
1342
1364
  tokenResponse = await fetch(tokenEndpoint, {
1343
1365
  body,
1344
1366
  credentials: configData.sendCookiesInRequests ? "include" : "same-origin",
1345
- headers: {
1346
- Accept: "application/json",
1347
- "Content-Type": "application/x-www-form-urlencoded"
1348
- },
1367
+ headers: tokenRequestHeaders,
1349
1368
  method: "POST"
1350
1369
  });
1351
1370
  } catch (error2) {
@@ -2957,171 +2976,533 @@ var updateMeProfile = async ({
2957
2976
  };
2958
2977
  var updateMeProfile_default = updateMeProfile;
2959
2978
 
2960
- // src/api/getBrandingPreference.ts
2961
- var getBrandingPreference = async ({
2962
- baseUrl,
2963
- locale,
2964
- name,
2965
- type,
2966
- fetcher,
2967
- ...requestConfig
2968
- }) => {
2969
- try {
2970
- new URL(baseUrl);
2971
- } catch (error2) {
2972
- throw new AsgardeoAPIError(
2973
- `Invalid base URL provided. ${error2?.toString()}`,
2974
- "getBrandingPreference-ValidationError-001",
2975
- "javascript",
2976
- 400,
2977
- "The provided `baseUrl` does not adhere to the URL schema."
2978
- );
2979
+ // src/utils/logger.ts
2980
+ var PREFIX = "\u{1F6E1}\uFE0F Asgardeo";
2981
+ var DEFAULT_CONFIG = {
2982
+ level: "info",
2983
+ prefix: `${PREFIX}`,
2984
+ showLevel: true,
2985
+ timestamps: true
2986
+ };
2987
+ var isBrowser = () => (
2988
+ /* @ts-ignore */
2989
+ typeof window !== "undefined" && typeof window.document !== "undefined"
2990
+ );
2991
+ var isNode = () => (
2992
+ /* @ts-ignore */
2993
+ typeof process !== "undefined" && void 0
2994
+ );
2995
+ var COLORS = {
2996
+ blue: "\x1B[34m",
2997
+ bright: "\x1B[1m",
2998
+ cyan: "\x1B[36m",
2999
+ dim: "\x1B[2m",
3000
+ gray: "\x1B[90m",
3001
+ green: "\x1B[32m",
3002
+ magenta: "\x1B[35m",
3003
+ red: "\x1B[31m",
3004
+ reset: "\x1B[0m",
3005
+ white: "\x1B[37m",
3006
+ yellow: "\x1B[33m"
3007
+ };
3008
+ var BROWSER_STYLES = {
3009
+ debug: "color: #6b7280; font-weight: normal;",
3010
+ error: "color: #dc2626; font-weight: bold;",
3011
+ info: "color: #2563eb; font-weight: bold;",
3012
+ prefix: "color: #7c3aed; font-weight: bold;",
3013
+ timestamp: "color: #6b7280; font-size: 0.9em;",
3014
+ warn: "color: #d97706; font-weight: bold;"
3015
+ };
3016
+ var LOG_LEVEL_ORDER = {
3017
+ debug: 0,
3018
+ error: 3,
3019
+ info: 1,
3020
+ warn: 2
3021
+ };
3022
+ var Logger = class _Logger {
3023
+ constructor(config = {}) {
3024
+ __publicField(this, "config");
3025
+ this.config = { ...DEFAULT_CONFIG, ...config };
2979
3026
  }
2980
- const queryParams = new URLSearchParams(
2981
- Object.fromEntries(
2982
- Object.entries({
2983
- locale: locale || "",
2984
- name: name || "",
2985
- type: type || ""
2986
- }).filter(([, value]) => Boolean(value))
2987
- )
2988
- );
2989
- const fetchFn = fetcher || fetch;
2990
- const resolvedUrl = `${baseUrl}/api/server/v1/branding-preference/resolve${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
2991
- const requestInit = {
2992
- ...requestConfig,
2993
- headers: {
2994
- Accept: "application/json",
2995
- "Content-Type": "application/json",
2996
- ...requestConfig.headers
2997
- },
2998
- method: "GET"
2999
- };
3000
- try {
3001
- const response = await fetchFn(resolvedUrl, requestInit);
3002
- if (!response?.ok) {
3003
- const errorText = await response.text();
3004
- throw new AsgardeoAPIError(
3005
- errorText,
3006
- "getBrandingPreference-ResponseError-001",
3007
- "javascript",
3008
- response.status,
3009
- response.statusText,
3010
- "Failed to get branding preference"
3011
- );
3012
- }
3013
- const data = await response.json();
3014
- return data;
3015
- } catch (error2) {
3016
- if (error2 instanceof AsgardeoAPIError) {
3017
- throw error2;
3018
- }
3019
- throw new AsgardeoAPIError(
3020
- `Network or parsing error: ${error2 instanceof Error ? error2.message : "Unknown error"}`,
3021
- "getBrandingPreference-NetworkError-001",
3022
- "javascript",
3023
- 0,
3024
- "Network Error"
3025
- );
3027
+ /**
3028
+ * Update logger configuration
3029
+ */
3030
+ configure(config) {
3031
+ this.config = { ...this.config, ...config };
3026
3032
  }
3027
- };
3028
- var getBrandingPreference_default = getBrandingPreference;
3029
-
3030
- // src/models/v2/embedded-signin-flow-v2.ts
3031
- var EmbeddedSignInFlowStatus = /* @__PURE__ */ ((EmbeddedSignInFlowStatus3) => {
3032
- EmbeddedSignInFlowStatus3["Complete"] = "COMPLETE";
3033
- EmbeddedSignInFlowStatus3["Error"] = "ERROR";
3034
- EmbeddedSignInFlowStatus3["Incomplete"] = "INCOMPLETE";
3035
- return EmbeddedSignInFlowStatus3;
3036
- })(EmbeddedSignInFlowStatus || {});
3037
- var EmbeddedSignInFlowType = /* @__PURE__ */ ((EmbeddedSignInFlowType3) => {
3038
- EmbeddedSignInFlowType3["Redirection"] = "REDIRECTION";
3039
- EmbeddedSignInFlowType3["View"] = "VIEW";
3040
- return EmbeddedSignInFlowType3;
3041
- })(EmbeddedSignInFlowType || {});
3042
-
3043
- // src/api/v2/executeEmbeddedSignInFlowV2.ts
3044
- var executeEmbeddedSignInFlowV2 = async ({
3045
- url,
3046
- baseUrl,
3047
- payload,
3048
- authId,
3049
- ...requestConfig
3050
- }) => {
3051
- if (!payload) {
3052
- throw new AsgardeoAPIError(
3053
- "Authorization payload is required",
3054
- "executeEmbeddedSignInFlow-ValidationError-002",
3055
- "javascript",
3056
- 400,
3057
- "If an authorization payload is not provided, the request cannot be constructed correctly."
3058
- );
3033
+ /**
3034
+ * Get current configuration
3035
+ */
3036
+ getConfig() {
3037
+ return { ...this.config };
3059
3038
  }
3060
- const endpoint = url ?? `${baseUrl}/flow/execute`;
3061
- const cleanPayload = typeof payload === "object" && payload !== null ? Object.fromEntries(Object.entries(payload).filter(([key]) => key !== "verbose")) : payload;
3062
- const hasOnlyAppIdAndFlowType = typeof cleanPayload === "object" && cleanPayload !== null && "applicationId" in cleanPayload && "flowType" in cleanPayload && Object.keys(cleanPayload).length === 2;
3063
- const hasOnlyFlowId = typeof cleanPayload === "object" && cleanPayload !== null && "executionId" in cleanPayload && Object.keys(cleanPayload).length === 1;
3064
- const requestPayload = hasOnlyAppIdAndFlowType || hasOnlyFlowId ? { ...cleanPayload, verbose: true } : cleanPayload;
3065
- const response = await fetch(endpoint, {
3066
- ...requestConfig,
3067
- body: JSON.stringify(requestPayload),
3068
- headers: {
3069
- Accept: "application/json",
3070
- "Content-Type": "application/json",
3071
- ...requestConfig.headers
3072
- },
3073
- method: requestConfig.method || "POST"
3074
- });
3075
- if (!response.ok) {
3076
- const errorText = await response.text();
3077
- throw new AsgardeoAPIError(
3078
- errorText,
3079
- "executeEmbeddedSignInFlow-ResponseError-001",
3080
- "javascript",
3081
- response.status,
3082
- response.statusText,
3083
- "Authorization request failed"
3084
- );
3039
+ /**
3040
+ * Check if a log level should be output
3041
+ */
3042
+ shouldLog(level) {
3043
+ return LOG_LEVEL_ORDER[level] >= LOG_LEVEL_ORDER[this.config.level];
3085
3044
  }
3086
- const flowResponse = await response.json();
3087
- if (flowResponse.flowStatus === "COMPLETE" /* Complete */ && flowResponse.assertion && authId) {
3088
- try {
3089
- const oauth2Response = await fetch(`${baseUrl}/oauth2/auth/callback`, {
3090
- body: JSON.stringify({
3091
- assertion: flowResponse.assertion,
3092
- authId
3093
- }),
3094
- credentials: "include",
3095
- headers: {
3096
- Accept: "application/json",
3097
- "Content-Type": "application/json",
3098
- ...requestConfig.headers
3099
- },
3100
- method: "POST"
3101
- });
3102
- if (!oauth2Response.ok) {
3103
- const oauth2ErrorText = await oauth2Response.text();
3104
- throw new AsgardeoAPIError(
3105
- `OAuth2 authorization failed: ${oauth2ErrorText}`,
3106
- "executeEmbeddedSignInFlow-OAuth2Error-002",
3107
- "javascript",
3108
- oauth2Response.status,
3109
- oauth2Response.statusText
3110
- );
3111
- }
3112
- const oauth2Result = await oauth2Response.json();
3113
- return {
3114
- flowStatus: flowResponse.flowStatus,
3115
- redirectUrl: oauth2Result["redirect_uri"]
3116
- };
3117
- } catch (authError) {
3118
- throw new AsgardeoAPIError(
3119
- `OAuth2 authorization failed: ${authError instanceof Error ? authError.message : "Unknown error"}`,
3120
- "executeEmbeddedSignInFlow-OAuth2Error-001",
3121
- "javascript",
3122
- 500,
3123
- "Failed to complete OAuth2 authorization after successful embedded sign-in flow."
3124
- );
3045
+ /**
3046
+ * Get timestamp string
3047
+ */
3048
+ static getTimestamp() {
3049
+ return (/* @__PURE__ */ new Date()).toISOString();
3050
+ }
3051
+ /**
3052
+ * Get log level string
3053
+ */
3054
+ static getLevelString(level) {
3055
+ switch (level) {
3056
+ case "debug":
3057
+ return "DEBUG";
3058
+ case "info":
3059
+ return "INFO";
3060
+ case "warn":
3061
+ return "WARN";
3062
+ case "error":
3063
+ return "ERROR";
3064
+ default:
3065
+ return "UNKNOWN";
3066
+ }
3067
+ }
3068
+ /**
3069
+ * Format message for Node.js terminal
3070
+ */
3071
+ formatForNode(level, message) {
3072
+ const parts = [];
3073
+ if (this.config.timestamps) {
3074
+ parts.push(`${COLORS.gray}[${_Logger.getTimestamp()}]${COLORS.reset}`);
3075
+ }
3076
+ if (this.config.prefix) {
3077
+ parts.push(`${COLORS.magenta}${this.config.prefix}${COLORS.reset}`);
3078
+ }
3079
+ if (this.config.showLevel) {
3080
+ const levelStr = _Logger.getLevelString(level);
3081
+ let coloredLevel;
3082
+ switch (level) {
3083
+ case "debug":
3084
+ coloredLevel = `${COLORS.gray}[${levelStr}]${COLORS.reset}`;
3085
+ break;
3086
+ case "info":
3087
+ coloredLevel = `${COLORS.blue}[${levelStr}]${COLORS.reset}`;
3088
+ break;
3089
+ case "warn":
3090
+ coloredLevel = `${COLORS.yellow}[${levelStr}]${COLORS.reset}`;
3091
+ break;
3092
+ case "error":
3093
+ coloredLevel = `${COLORS.red}[${levelStr}]${COLORS.reset}`;
3094
+ break;
3095
+ default:
3096
+ coloredLevel = `[${levelStr}]`;
3097
+ }
3098
+ parts.push(coloredLevel);
3099
+ }
3100
+ parts.push(message);
3101
+ return parts.join(" ");
3102
+ }
3103
+ /**
3104
+ * Log message using appropriate method
3105
+ */
3106
+ logMessage(level, message, ...args) {
3107
+ if (!this.shouldLog(level)) {
3108
+ return;
3109
+ }
3110
+ if (this.config.formatter) {
3111
+ this.config.formatter(level, message, ...args);
3112
+ return;
3113
+ }
3114
+ if (isBrowser()) {
3115
+ this.logToBrowser(level, message, ...args);
3116
+ } else if (isNode()) {
3117
+ this.logToNode(level, message, ...args);
3118
+ } else {
3119
+ console.log(message, ...args);
3120
+ }
3121
+ }
3122
+ /**
3123
+ * Log to browser console with styling
3124
+ */
3125
+ logToBrowser(level, message, ...args) {
3126
+ const parts = [];
3127
+ const styles = [];
3128
+ if (this.config.timestamps) {
3129
+ parts.push(`%c[${_Logger.getTimestamp()}]`);
3130
+ styles.push(BROWSER_STYLES.timestamp);
3131
+ }
3132
+ if (this.config.prefix) {
3133
+ parts.push(`%c${this.config.prefix}`);
3134
+ styles.push(BROWSER_STYLES.prefix);
3135
+ }
3136
+ if (this.config.showLevel) {
3137
+ const levelStr = _Logger.getLevelString(level);
3138
+ parts.push(`%c[${levelStr}]`);
3139
+ switch (level) {
3140
+ case "debug":
3141
+ styles.push(BROWSER_STYLES.debug);
3142
+ break;
3143
+ case "info":
3144
+ styles.push(BROWSER_STYLES.info);
3145
+ break;
3146
+ case "warn":
3147
+ styles.push(BROWSER_STYLES.warn);
3148
+ break;
3149
+ case "error":
3150
+ styles.push(BROWSER_STYLES.error);
3151
+ break;
3152
+ default:
3153
+ styles.push("");
3154
+ }
3155
+ }
3156
+ parts.push(`%c${message}`);
3157
+ styles.push("color: inherit; font-weight: normal;");
3158
+ const formattedMessage = parts.join(" ");
3159
+ switch (level) {
3160
+ case "debug":
3161
+ console.debug(formattedMessage, ...styles, ...args);
3162
+ break;
3163
+ case "info":
3164
+ console.info(formattedMessage, ...styles, ...args);
3165
+ break;
3166
+ case "warn":
3167
+ console.warn(formattedMessage, ...styles, ...args);
3168
+ break;
3169
+ case "error":
3170
+ console.error(formattedMessage, ...styles, ...args);
3171
+ break;
3172
+ default:
3173
+ console.log(formattedMessage, ...styles, ...args);
3174
+ }
3175
+ }
3176
+ /**
3177
+ * Log to Node.js console
3178
+ */
3179
+ logToNode(level, message, ...args) {
3180
+ const formattedMessage = this.formatForNode(level, message);
3181
+ switch (level) {
3182
+ case "debug":
3183
+ console.debug(formattedMessage, ...args);
3184
+ break;
3185
+ case "info":
3186
+ console.info(formattedMessage, ...args);
3187
+ break;
3188
+ case "warn":
3189
+ console.warn(formattedMessage, ...args);
3190
+ break;
3191
+ case "error":
3192
+ console.error(formattedMessage, ...args);
3193
+ break;
3194
+ default:
3195
+ console.log(formattedMessage, ...args);
3196
+ }
3197
+ }
3198
+ /**
3199
+ * Log debug message
3200
+ */
3201
+ debug(message, ...args) {
3202
+ this.logMessage("debug", message, ...args);
3203
+ }
3204
+ /**
3205
+ * Log info message
3206
+ */
3207
+ info(message, ...args) {
3208
+ this.logMessage("info", message, ...args);
3209
+ }
3210
+ /**
3211
+ * Log warning message
3212
+ */
3213
+ warn(message, ...args) {
3214
+ this.logMessage("warn", message, ...args);
3215
+ }
3216
+ /**
3217
+ * Log error message
3218
+ */
3219
+ error(message, ...args) {
3220
+ this.logMessage("error", message, ...args);
3221
+ }
3222
+ /**
3223
+ * Create a child logger with additional prefix
3224
+ */
3225
+ child(prefix) {
3226
+ const childPrefix = this.config.prefix ? `${this.config.prefix} - ${prefix}` : prefix;
3227
+ return new _Logger({
3228
+ ...this.config,
3229
+ prefix: childPrefix
3230
+ });
3231
+ }
3232
+ /**
3233
+ * Set log level
3234
+ */
3235
+ setLevel(level) {
3236
+ this.config.level = level;
3237
+ }
3238
+ /**
3239
+ * Get current log level
3240
+ */
3241
+ getLevel() {
3242
+ return this.config.level;
3243
+ }
3244
+ };
3245
+ var logger = new Logger();
3246
+ var createLogger = (config) => new Logger(config);
3247
+ var logger_default = logger;
3248
+ var debug = (message, ...args) => logger.debug(message, ...args);
3249
+ var info = (message, ...args) => logger.info(message, ...args);
3250
+ var warn = (message, ...args) => logger.warn(message, ...args);
3251
+ var error = (message, ...args) => logger.error(message, ...args);
3252
+ var configure = (config) => logger.configure(config);
3253
+ var createComponentLogger = (component) => logger.child(component);
3254
+ var createPackageLogger = (packageName) => createLogger({
3255
+ level: "info",
3256
+ prefix: `${PREFIX} - ${packageName}`,
3257
+ showLevel: true,
3258
+ timestamps: true
3259
+ });
3260
+ var createPackageComponentLogger = (packageName, component) => {
3261
+ const packageLogger = createPackageLogger(packageName);
3262
+ return packageLogger.child(component);
3263
+ };
3264
+
3265
+ // src/utils/isRecognizedBaseUrlPattern.ts
3266
+ var isRecognizedBaseUrlPattern = (baseUrl) => {
3267
+ if (!baseUrl) {
3268
+ throw new AsgardeoRuntimeError(
3269
+ "Base URL is required to derive if the `baseUrl` is recognized.",
3270
+ "isRecognizedBaseUrlPattern-ValidationError-001",
3271
+ "javascript",
3272
+ "A valid base URL must be provided to derive if the `baseUrl` is recognized to use the sensible fallbacks."
3273
+ );
3274
+ }
3275
+ let parsedUrl;
3276
+ try {
3277
+ parsedUrl = new URL(baseUrl);
3278
+ } catch (error2) {
3279
+ throw new AsgardeoRuntimeError(
3280
+ `Invalid base URL format: ${baseUrl}`,
3281
+ "isRecognizedBaseUrlPattern-ValidationError-002",
3282
+ "javascript",
3283
+ "The provided base URL does not conform to valid URL syntax."
3284
+ );
3285
+ }
3286
+ const pathSegments = parsedUrl.pathname?.split("/")?.filter((segment) => segment?.length > 0);
3287
+ if (pathSegments.length < 2 || pathSegments[0] !== "t") {
3288
+ logger_default.warn(
3289
+ "[isRecognizedBaseUrlPattern] The provided base URL does not follow the expected URL pattern (/t/{orgHandle})."
3290
+ );
3291
+ return false;
3292
+ }
3293
+ return true;
3294
+ };
3295
+ var isRecognizedBaseUrlPattern_default = isRecognizedBaseUrlPattern;
3296
+
3297
+ // src/utils/identifyPlatform.ts
3298
+ var identifyPlatform = (config) => {
3299
+ const { baseUrl } = config;
3300
+ try {
3301
+ if (isRecognizedBaseUrlPattern_default(baseUrl)) {
3302
+ try {
3303
+ const url = new URL(baseUrl);
3304
+ if (/\.asgardeo\.io$/i.test(url.hostname) || /asgardeo\.io$/i.test(url.hostname)) {
3305
+ return "ASGARDEO" /* Asgardeo */;
3306
+ }
3307
+ } catch {
3308
+ logger_default.debug(
3309
+ `[identifyPlatform] Could not identify platform from the base URL: ${baseUrl}. Defaulting to WSO2 Identity Server as the platform.`
3310
+ );
3311
+ }
3312
+ return "IDENTITY_SERVER" /* IdentityServer */;
3313
+ }
3314
+ return "UNKNOWN" /* Unknown */;
3315
+ } catch (error2) {
3316
+ logger_default.debug(`[identifyPlatform] Error identifying platform from base URL: ${baseUrl}. Error: ${error2.message}`);
3317
+ return "UNKNOWN" /* Unknown */;
3318
+ }
3319
+ };
3320
+ var identifyPlatform_default = identifyPlatform;
3321
+
3322
+ // src/api/getBrandingPreference.ts
3323
+ var getBrandingPreference = async ({
3324
+ baseUrl,
3325
+ locale,
3326
+ name,
3327
+ type,
3328
+ fetcher,
3329
+ ...requestConfig
3330
+ }) => {
3331
+ try {
3332
+ new URL(baseUrl);
3333
+ } catch (error2) {
3334
+ throw new AsgardeoAPIError(
3335
+ `Invalid base URL provided. ${error2?.toString()}`,
3336
+ "getBrandingPreference-ValidationError-001",
3337
+ "javascript",
3338
+ 400,
3339
+ "The provided `baseUrl` does not adhere to the URL schema."
3340
+ );
3341
+ }
3342
+ const queryParams = new URLSearchParams(
3343
+ Object.fromEntries(
3344
+ Object.entries({
3345
+ locale: locale || "",
3346
+ name: name || "",
3347
+ type: type || ""
3348
+ }).filter(([, value]) => Boolean(value))
3349
+ )
3350
+ );
3351
+ const fetchFn = fetcher || fetch;
3352
+ const resolvedUrl = `${baseUrl}/api/server/v1/branding-preference/resolve${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
3353
+ const requestInit = {
3354
+ ...requestConfig,
3355
+ headers: {
3356
+ Accept: "application/json",
3357
+ "Content-Type": "application/json",
3358
+ ...requestConfig.headers
3359
+ },
3360
+ method: "GET"
3361
+ };
3362
+ try {
3363
+ const response = await fetchFn(resolvedUrl, requestInit);
3364
+ if (!response?.ok) {
3365
+ const errorText = await response.text();
3366
+ const platform = identifyPlatform_default({ baseUrl });
3367
+ let errorDescription;
3368
+ try {
3369
+ const errorBody = JSON.parse(errorText);
3370
+ errorDescription = errorBody?.description || errorBody?.message || errorText;
3371
+ } catch {
3372
+ errorDescription = errorText;
3373
+ }
3374
+ let platformConsoleGuidance;
3375
+ if (platform === "ASGARDEO" /* Asgardeo */) {
3376
+ platformConsoleGuidance = "configure branding preferences in the Asgardeo console";
3377
+ } else if (platform === "IDENTITY_SERVER" /* IdentityServer */) {
3378
+ platformConsoleGuidance = "configure branding preferences in the WSO2 Identity Server console";
3379
+ } else {
3380
+ platformConsoleGuidance = "configure branding preferences in the platform console";
3381
+ }
3382
+ logger_default.warn(
3383
+ `[BrandingError] ${errorDescription} To resolve this issue, please ${platformConsoleGuidance}. If you want to suppress this warning and stop fetching branding preferences, set \`<AsgardeoProvider>\` -> \`preferences\` -> \`theme\` -> \`inheritFromBranding\` to false.`
3384
+ );
3385
+ throw new AsgardeoAPIError(
3386
+ errorText,
3387
+ "getBrandingPreference-ResponseError-001",
3388
+ "javascript",
3389
+ response.status,
3390
+ response.statusText,
3391
+ "Failed to get branding preference"
3392
+ );
3393
+ }
3394
+ const data = await response.json();
3395
+ return data;
3396
+ } catch (error2) {
3397
+ if (error2 instanceof AsgardeoAPIError) {
3398
+ throw error2;
3399
+ }
3400
+ throw new AsgardeoAPIError(
3401
+ `Network or parsing error: ${error2 instanceof Error ? error2.message : "Unknown error"}`,
3402
+ "getBrandingPreference-NetworkError-001",
3403
+ "javascript",
3404
+ 0,
3405
+ "Network Error"
3406
+ );
3407
+ }
3408
+ };
3409
+ var getBrandingPreference_default = getBrandingPreference;
3410
+
3411
+ // src/models/v2/embedded-signin-flow-v2.ts
3412
+ var EmbeddedSignInFlowStatus = /* @__PURE__ */ ((EmbeddedSignInFlowStatus3) => {
3413
+ EmbeddedSignInFlowStatus3["Complete"] = "COMPLETE";
3414
+ EmbeddedSignInFlowStatus3["Error"] = "ERROR";
3415
+ EmbeddedSignInFlowStatus3["Incomplete"] = "INCOMPLETE";
3416
+ return EmbeddedSignInFlowStatus3;
3417
+ })(EmbeddedSignInFlowStatus || {});
3418
+ var EmbeddedSignInFlowType = /* @__PURE__ */ ((EmbeddedSignInFlowType3) => {
3419
+ EmbeddedSignInFlowType3["Redirection"] = "REDIRECTION";
3420
+ EmbeddedSignInFlowType3["View"] = "VIEW";
3421
+ return EmbeddedSignInFlowType3;
3422
+ })(EmbeddedSignInFlowType || {});
3423
+
3424
+ // src/api/v2/executeEmbeddedSignInFlowV2.ts
3425
+ var executeEmbeddedSignInFlowV2 = async ({
3426
+ url,
3427
+ baseUrl,
3428
+ payload,
3429
+ authId,
3430
+ ...requestConfig
3431
+ }) => {
3432
+ if (!payload) {
3433
+ throw new AsgardeoAPIError(
3434
+ "Authorization payload is required",
3435
+ "executeEmbeddedSignInFlow-ValidationError-002",
3436
+ "javascript",
3437
+ 400,
3438
+ "If an authorization payload is not provided, the request cannot be constructed correctly."
3439
+ );
3440
+ }
3441
+ const endpoint = url ?? `${baseUrl}/flow/execute`;
3442
+ const cleanPayload = typeof payload === "object" && payload !== null ? Object.fromEntries(Object.entries(payload).filter(([key]) => key !== "verbose")) : payload;
3443
+ const hasOnlyAppIdAndFlowType = typeof cleanPayload === "object" && cleanPayload !== null && "applicationId" in cleanPayload && "flowType" in cleanPayload && Object.keys(cleanPayload).length === 2;
3444
+ const hasOnlyFlowId = typeof cleanPayload === "object" && cleanPayload !== null && "executionId" in cleanPayload && Object.keys(cleanPayload).length === 1;
3445
+ const requestPayload = hasOnlyAppIdAndFlowType || hasOnlyFlowId ? { ...cleanPayload, verbose: true } : cleanPayload;
3446
+ const response = await fetch(endpoint, {
3447
+ ...requestConfig,
3448
+ body: JSON.stringify(requestPayload),
3449
+ headers: {
3450
+ Accept: "application/json",
3451
+ "Content-Type": "application/json",
3452
+ ...requestConfig.headers
3453
+ },
3454
+ method: requestConfig.method || "POST"
3455
+ });
3456
+ if (!response.ok) {
3457
+ const errorText = await response.text();
3458
+ throw new AsgardeoAPIError(
3459
+ errorText,
3460
+ "executeEmbeddedSignInFlow-ResponseError-001",
3461
+ "javascript",
3462
+ response.status,
3463
+ response.statusText,
3464
+ "Authorization request failed"
3465
+ );
3466
+ }
3467
+ const flowResponse = await response.json();
3468
+ if (flowResponse.flowStatus === "COMPLETE" /* Complete */ && flowResponse.assertion && authId) {
3469
+ try {
3470
+ const oauth2Response = await fetch(`${baseUrl}/oauth2/auth/callback`, {
3471
+ body: JSON.stringify({
3472
+ assertion: flowResponse.assertion,
3473
+ authId
3474
+ }),
3475
+ credentials: "include",
3476
+ headers: {
3477
+ Accept: "application/json",
3478
+ "Content-Type": "application/json",
3479
+ ...requestConfig.headers
3480
+ },
3481
+ method: "POST"
3482
+ });
3483
+ if (!oauth2Response.ok) {
3484
+ const oauth2ErrorText = await oauth2Response.text();
3485
+ throw new AsgardeoAPIError(
3486
+ `OAuth2 authorization failed: ${oauth2ErrorText}`,
3487
+ "executeEmbeddedSignInFlow-OAuth2Error-002",
3488
+ "javascript",
3489
+ oauth2Response.status,
3490
+ oauth2Response.statusText
3491
+ );
3492
+ }
3493
+ const oauth2Result = await oauth2Response.json();
3494
+ return {
3495
+ flowStatus: flowResponse.flowStatus,
3496
+ redirectUrl: oauth2Result["redirect_uri"]
3497
+ };
3498
+ } catch (authError) {
3499
+ throw new AsgardeoAPIError(
3500
+ `OAuth2 authorization failed: ${authError instanceof Error ? authError.message : "Unknown error"}`,
3501
+ "executeEmbeddedSignInFlow-OAuth2Error-001",
3502
+ "javascript",
3503
+ 500,
3504
+ "Failed to complete OAuth2 authorization after successful embedded sign-in flow."
3505
+ );
3125
3506
  }
3126
3507
  }
3127
3508
  return flowResponse;
@@ -3569,12 +3950,6 @@ var FlowMode = /* @__PURE__ */ ((FlowMode2) => {
3569
3950
  return FlowMode2;
3570
3951
  })(FlowMode || {});
3571
3952
 
3572
- // src/models/agent.ts
3573
- var AgentConfig;
3574
- ((AgentConfig2) => {
3575
- AgentConfig2.DEFAULT_AUTHENTICATOR_NAME = "Username & Password";
3576
- })(AgentConfig || (AgentConfig = {}));
3577
-
3578
3953
  // src/models/scim2-schema.ts
3579
3954
  var WellKnownSchemaIds = /* @__PURE__ */ ((WellKnownSchemaIds2) => {
3580
3955
  WellKnownSchemaIds2["Core"] = "urn:ietf:params:scim:schemas:core:2.0";
@@ -3639,16 +4014,16 @@ var DefaultCacheStore = class {
3639
4014
  };
3640
4015
 
3641
4016
  // src/DefaultCrypto.ts
3642
- import * as jose from "jose";
4017
+ import * as jose2 from "jose";
3643
4018
  var DefaultCrypto = class {
3644
4019
  // eslint-disable-next-line class-methods-use-this
3645
4020
  base64URLDecode(value) {
3646
- const decodedArray = jose.base64url.decode(value);
4021
+ const decodedArray = jose2.base64url.decode(value);
3647
4022
  return new TextDecoder().decode(decodedArray);
3648
4023
  }
3649
4024
  // eslint-disable-next-line class-methods-use-this
3650
4025
  base64URLEncode(value) {
3651
- return jose.base64url.encode(value);
4026
+ return jose2.base64url.encode(value);
3652
4027
  }
3653
4028
  // eslint-disable-next-line class-methods-use-this
3654
4029
  generateRandomBytes(length) {
@@ -3663,8 +4038,8 @@ var DefaultCrypto = class {
3663
4038
  }
3664
4039
  // eslint-disable-next-line class-methods-use-this
3665
4040
  async verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance, validateJwtIssuer = true) {
3666
- const key = await jose.importJWK(jwk);
3667
- await jose.jwtVerify(idToken, key, {
4041
+ const key = await jose2.importJWK(jwk);
4042
+ await jose2.jwtVerify(idToken, key, {
3668
4043
  algorithms,
3669
4044
  audience: [clientId],
3670
4045
  clockTolerance,
@@ -3675,24 +4050,54 @@ var DefaultCrypto = class {
3675
4050
  }
3676
4051
  };
3677
4052
 
4053
+ // src/models/agent.ts
4054
+ var AgentConfig;
4055
+ ((AgentConfig2) => {
4056
+ AgentConfig2.DEFAULT_AUTHENTICATOR_NAME = "Username & Password";
4057
+ })(AgentConfig || (AgentConfig = {}));
4058
+
3678
4059
  // src/AsgardeoJavaScriptClient.ts
3679
- var AsgardeoJavaScriptClient = class {
4060
+ var RESERVED_AUTH_KEYS = /* @__PURE__ */ new Set([
4061
+ "client_id",
4062
+ "redirect_uri",
4063
+ "scope",
4064
+ "state",
4065
+ "response_type",
4066
+ "resource",
4067
+ "fidp",
4068
+ "requested_actor",
4069
+ "orgId",
4070
+ "orgHandle",
4071
+ "org",
4072
+ "login_hint",
4073
+ "orgDiscoveryType",
4074
+ "code_challenge",
4075
+ "code_challenge_method"
4076
+ ]);
4077
+ var AsgardeoJavaScriptClient = class _AsgardeoJavaScriptClient {
3680
4078
  constructor(config, cacheStore, cryptoUtils) {
3681
4079
  __publicField(this, "cacheStore");
3682
4080
  __publicField(this, "cryptoUtils");
3683
4081
  __publicField(this, "auth");
3684
4082
  __publicField(this, "storageManager");
3685
4083
  __publicField(this, "baseURL");
4084
+ __publicField(this, "initPromise");
3686
4085
  this.cacheStore = cacheStore ?? new DefaultCacheStore();
3687
4086
  this.cryptoUtils = cryptoUtils ?? new DefaultCrypto();
3688
4087
  this.auth = new AsgardeoAuthClient();
3689
4088
  if (config) {
3690
- this.auth.initialize(config, this.cacheStore, this.cryptoUtils);
4089
+ this.initPromise = this.auth.initialize(config, this.cacheStore, this.cryptoUtils);
3691
4090
  this.storageManager = this.auth.getStorageManager();
3692
4091
  }
3693
4092
  this.baseURL = config?.baseUrl ?? "";
3694
4093
  }
4094
+ async ensureInitialized() {
4095
+ if (this.initPromise) {
4096
+ await this.initPromise;
4097
+ }
4098
+ }
3695
4099
  async getDiscoveryResponse() {
4100
+ await this.ensureInitialized();
3696
4101
  if (!this.storageManager) {
3697
4102
  return null;
3698
4103
  }
@@ -3767,6 +4172,15 @@ var AsgardeoJavaScriptClient = class {
3767
4172
  }
3768
4173
  /* eslint-enable class-methods-use-this, @typescript-eslint/no-unused-vars */
3769
4174
  async getAgentToken(agentConfig) {
4175
+ await this.ensureInitialized();
4176
+ if (!agentConfig?.agentID) {
4177
+ throw new Error("agentConfig.agentID is required for getAgentToken().");
4178
+ }
4179
+ if (!agentConfig.agentSecret) {
4180
+ throw new Error(
4181
+ "agentConfig.agentSecret is required for getAgentToken(). The agent must authenticate against the token endpoint."
4182
+ );
4183
+ }
3770
4184
  const customParam = {
3771
4185
  response_mode: "direct"
3772
4186
  };
@@ -3806,6 +4220,7 @@ var AsgardeoJavaScriptClient = class {
3806
4220
  );
3807
4221
  }
3808
4222
  async getOBOSignInURL(agentConfig) {
4223
+ await this.ensureInitialized();
3809
4224
  const customParam = {
3810
4225
  requested_actor: agentConfig.agentID
3811
4226
  };
@@ -3830,6 +4245,200 @@ var AsgardeoJavaScriptClient = class {
3830
4245
  tokenRequestConfig
3831
4246
  );
3832
4247
  }
4248
+ /**
4249
+ * Builds a `/oauth2/authorize` URL targeting a specific child organization.
4250
+ *
4251
+ * The target organization can be identified by its UUID (`orgID`), handle
4252
+ * (`orgHandle`), display name (`org`) or via email-domain based discovery
4253
+ * (`emailDomain`).
4254
+ *
4255
+ * @param orgDiscoveryType - The organization discovery strategy to use.
4256
+ * @param discoveryInput - The identifier whose meaning depends on
4257
+ * `orgDiscoveryType` (UUID, handle, name or email).
4258
+ * @param options - Optional state, resource, agent delegation and
4259
+ * additional query parameters.
4260
+ * @returns The fully-built authorization URL.
4261
+ */
4262
+ async getOrgAuthorizationUrl(orgDiscoveryType, discoveryInput, options = {}) {
4263
+ await this.ensureInitialized();
4264
+ const customParam = _AsgardeoJavaScriptClient.buildOrgAuthorizationParams(
4265
+ orgDiscoveryType,
4266
+ discoveryInput,
4267
+ options
4268
+ );
4269
+ const authURL = await this.auth.getSignInUrl(customParam);
4270
+ if (!authURL) {
4271
+ throw new Error("Could not build organization authorization URL");
4272
+ }
4273
+ return authURL.toString();
4274
+ }
4275
+ /**
4276
+ * Exchanges an existing access token for one scoped to a target organization,
4277
+ * using the `organization_switch` grant type.
4278
+ *
4279
+ * Unlike {@link AsgardeoJavaScriptClient.exchangeToken} this method does
4280
+ * not require an active SDK session — the caller supplies the source
4281
+ * access token directly. This makes it safe to use from server-side agent
4282
+ * flows where there is no user session yet.
4283
+ *
4284
+ * @param token - The current access token to be switched.
4285
+ * @param switchingOrganization - The ID/UUID of the target organization.
4286
+ * @param scopes - Optional list of scopes to request for the switched token.
4287
+ * @returns A normalized {@link TokenResponse} for the switched organization.
4288
+ */
4289
+ async switchTokenToOrganization(token, switchingOrganization, scopes) {
4290
+ await this.ensureInitialized();
4291
+ if (!token) {
4292
+ throw new Error("Token is required for organization switch.");
4293
+ }
4294
+ if (!switchingOrganization) {
4295
+ throw new Error("switchingOrganization is required.");
4296
+ }
4297
+ if (!this.storageManager) {
4298
+ throw new Error("Client is not initialized. Call initialize() before switching organizations.");
4299
+ }
4300
+ const configData = await this.storageManager.getConfigData();
4301
+ if (!configData) {
4302
+ throw new Error("Client configuration is unavailable. Initialize the client before switching organizations.");
4303
+ }
4304
+ const tokenEndpoint = await this.resolveTokenEndpoint();
4305
+ const body = new URLSearchParams();
4306
+ const { clientId, clientSecret } = configData;
4307
+ if (!clientId || clientId.trim().length === 0) {
4308
+ throw new Error("clientId is required in the client configuration for organization switch.");
4309
+ }
4310
+ const hasSecret = Boolean(clientSecret && clientSecret.trim().length > 0);
4311
+ body.set("grant_type", "organization_switch");
4312
+ body.set("token", token);
4313
+ body.set("switching_organization", switchingOrganization);
4314
+ body.set("client_id", clientId);
4315
+ if (hasSecret) {
4316
+ body.set("client_secret", clientSecret);
4317
+ }
4318
+ if (scopes && scopes.length > 0) {
4319
+ body.set("scope", scopes.join(" "));
4320
+ }
4321
+ let response;
4322
+ try {
4323
+ response = await fetch(tokenEndpoint, {
4324
+ body,
4325
+ headers: {
4326
+ Accept: "application/json",
4327
+ "Content-Type": "application/x-www-form-urlencoded"
4328
+ },
4329
+ method: "POST"
4330
+ });
4331
+ } catch (error2) {
4332
+ throw new Error(`Organization switch request failed: ${error2?.message ?? String(error2)}`);
4333
+ }
4334
+ if (!response.ok) {
4335
+ let errorBody;
4336
+ try {
4337
+ errorBody = JSON.stringify(await response.json());
4338
+ } catch {
4339
+ errorBody = response.statusText;
4340
+ }
4341
+ throw new Error(`Organization switch failed (${response.status}): ${errorBody}`);
4342
+ }
4343
+ const parsed = await response.json();
4344
+ return {
4345
+ accessToken: parsed.access_token,
4346
+ createdAt: parsed.created_at ?? Date.now(),
4347
+ expiresIn: parsed.expires_in,
4348
+ idToken: parsed.id_token,
4349
+ refreshToken: parsed.refresh_token,
4350
+ scope: parsed.scope,
4351
+ tokenType: parsed.token_type
4352
+ };
4353
+ }
4354
+ /**
4355
+ * Resolves the OAuth2 token endpoint URL.
4356
+ *
4357
+ * Prefers the value advertised by the OIDC well-known document (when it
4358
+ * has already been loaded into the storage manager) and falls back to
4359
+ * `${baseURL}/oauth2/token` derived from the SDK configuration.
4360
+ */
4361
+ async resolveTokenEndpoint() {
4362
+ const discovery = this.storageManager ? await this.storageManager.loadOpenIDProviderConfiguration() : null;
4363
+ const discovered = discovery?.token_endpoint;
4364
+ if (discovered && discovered.trim().length > 0) {
4365
+ return discovered;
4366
+ }
4367
+ if (this.baseURL && this.baseURL.trim().length > 0) {
4368
+ return `${this.baseURL.replace(/\/$/, "")}/oauth2/token`;
4369
+ }
4370
+ throw new Error(
4371
+ "Unable to resolve the token endpoint. Provide a baseUrl in the client configuration or ensure OIDC discovery has been performed."
4372
+ );
4373
+ }
4374
+ /**
4375
+ * Authenticates as the agent and switches the issued agent token into a
4376
+ * target child organization in a single call.
4377
+ *
4378
+ * @param agentConfig - Agent credentials used to obtain the parent-org agent token.
4379
+ * @param switchingOrganization - The ID/UUID of the target organization.
4380
+ * @param orgScopes - Optional scopes to request for the organization-scoped token.
4381
+ * @returns A normalized {@link TokenResponse} scoped to the target organization.
4382
+ */
4383
+ async getOrganizationAgentToken(agentConfig, switchingOrganization, orgScopes) {
4384
+ if (!switchingOrganization) {
4385
+ throw new Error("switchingOrganization is required.");
4386
+ }
4387
+ const agentToken = await this.getAgentToken(agentConfig);
4388
+ return this.switchTokenToOrganization(agentToken.accessToken, switchingOrganization, orgScopes);
4389
+ }
4390
+ /**
4391
+ * Builds the custom query-parameter map for an organization-scoped authorization request.
4392
+ */
4393
+ static buildOrgAuthorizationParams(orgDiscoveryType, discoveryInput, options) {
4394
+ const trimmedValue = (discoveryInput ?? "").trim();
4395
+ if (!trimmedValue) {
4396
+ throw new Error("discoveryInput is required.");
4397
+ }
4398
+ const customParam = {};
4399
+ if (!options.isEnhancedOrgAuth) {
4400
+ customParam["fidp"] = "OrganizationSSO";
4401
+ }
4402
+ switch (orgDiscoveryType) {
4403
+ case "orgID":
4404
+ customParam["orgId"] = trimmedValue;
4405
+ break;
4406
+ case "orgHandle":
4407
+ customParam["orgHandle"] = trimmedValue;
4408
+ break;
4409
+ case "org":
4410
+ customParam["org"] = trimmedValue;
4411
+ break;
4412
+ case "emailDomain":
4413
+ customParam["login_hint"] = trimmedValue;
4414
+ customParam["orgDiscoveryType"] = "emailDomain";
4415
+ break;
4416
+ default:
4417
+ throw new Error(`Unsupported orgDiscoveryType: ${orgDiscoveryType}`);
4418
+ }
4419
+ if (options.resource) {
4420
+ customParam["resource"] = options.resource;
4421
+ }
4422
+ if (options.state) {
4423
+ customParam["state"] = options.state;
4424
+ }
4425
+ if (options.agentConfig) {
4426
+ if (!options.agentConfig.agentID || options.agentConfig.agentID.trim().length === 0) {
4427
+ throw new Error("agentConfig.agentID is required when agentConfig is provided.");
4428
+ }
4429
+ customParam["requested_actor"] = options.agentConfig.agentID;
4430
+ }
4431
+ if (options.additionalParams) {
4432
+ const conflicts = Object.keys(options.additionalParams).filter(
4433
+ (key) => RESERVED_AUTH_KEYS.has(key)
4434
+ );
4435
+ if (conflicts.length > 0) {
4436
+ throw new Error(`Reserved authorization parameters cannot be overridden: ${conflicts.sort().join(", ")}`);
4437
+ }
4438
+ Object.assign(customParam, options.additionalParams);
4439
+ }
4440
+ return customParam;
4441
+ }
3833
4442
  };
3834
4443
  var AsgardeoJavaScriptClient_default = AsgardeoJavaScriptClient;
3835
4444
 
@@ -4119,660 +4728,374 @@ var toCssVariables = (theme) => {
4119
4728
  if (theme.colors?.background?.disabled) {
4120
4729
  cssVars[`--${prefix}-color-background-disabled`] = theme.colors.background.disabled;
4121
4730
  }
4122
- if (theme.colors?.background?.body?.main) {
4123
- cssVars[`--${prefix}-color-background-body-main`] = theme.colors.background.body.main;
4124
- }
4125
- if (theme.colors?.error?.main) {
4126
- cssVars[`--${prefix}-color-error-main`] = theme.colors.error.main;
4127
- }
4128
- if (theme.colors?.error?.contrastText) {
4129
- cssVars[`--${prefix}-color-error-contrastText`] = theme.colors.error.contrastText;
4130
- }
4131
- if (theme.colors?.error?.light) {
4132
- cssVars[`--${prefix}-color-error-light`] = theme.colors.error.light;
4133
- }
4134
- if (theme.colors?.success?.main) {
4135
- cssVars[`--${prefix}-color-success-main`] = theme.colors.success.main;
4136
- }
4137
- if (theme.colors?.success?.contrastText) {
4138
- cssVars[`--${prefix}-color-success-contrastText`] = theme.colors.success.contrastText;
4139
- }
4140
- if (theme.colors?.success?.light) {
4141
- cssVars[`--${prefix}-color-success-light`] = theme.colors.success.light;
4142
- }
4143
- if (theme.colors?.warning?.main) {
4144
- cssVars[`--${prefix}-color-warning-main`] = theme.colors.warning.main;
4145
- }
4146
- if (theme.colors?.warning?.contrastText) {
4147
- cssVars[`--${prefix}-color-warning-contrastText`] = theme.colors.warning.contrastText;
4148
- }
4149
- if (theme.colors?.warning?.light) {
4150
- cssVars[`--${prefix}-color-warning-light`] = theme.colors.warning.light;
4151
- }
4152
- if (theme.colors?.info?.main) {
4153
- cssVars[`--${prefix}-color-info-main`] = theme.colors.info.main;
4154
- }
4155
- if (theme.colors?.info?.contrastText) {
4156
- cssVars[`--${prefix}-color-info-contrastText`] = theme.colors.info.contrastText;
4157
- }
4158
- if (theme.colors?.info?.light) {
4159
- cssVars[`--${prefix}-color-info-light`] = theme.colors.info.light;
4160
- }
4161
- if (theme.colors?.text?.primary) {
4162
- cssVars[`--${prefix}-color-text-primary`] = theme.colors.text.primary;
4163
- }
4164
- if (theme.colors?.text?.secondary) {
4165
- cssVars[`--${prefix}-color-text-secondary`] = theme.colors.text.secondary;
4166
- }
4167
- if (theme.colors?.border) {
4168
- cssVars[`--${prefix}-color-border`] = theme.colors.border;
4169
- }
4170
- if (theme.spacing?.unit !== void 0) {
4171
- cssVars[`--${prefix}-spacing-unit`] = `${theme.spacing.unit}px`;
4172
- }
4173
- if (theme.borderRadius?.small) {
4174
- cssVars[`--${prefix}-border-radius-small`] = theme.borderRadius.small;
4175
- }
4176
- if (theme.borderRadius?.medium) {
4177
- cssVars[`--${prefix}-border-radius-medium`] = theme.borderRadius.medium;
4178
- }
4179
- if (theme.borderRadius?.large) {
4180
- cssVars[`--${prefix}-border-radius-large`] = theme.borderRadius.large;
4181
- }
4182
- if (theme.shadows?.small) {
4183
- cssVars[`--${prefix}-shadow-small`] = theme.shadows.small;
4184
- }
4185
- if (theme.shadows?.medium) {
4186
- cssVars[`--${prefix}-shadow-medium`] = theme.shadows.medium;
4187
- }
4188
- if (theme.shadows?.large) {
4189
- cssVars[`--${prefix}-shadow-large`] = theme.shadows.large;
4190
- }
4191
- if (theme.typography?.fontFamily) {
4192
- cssVars[`--${prefix}-typography-fontFamily`] = theme.typography.fontFamily;
4193
- }
4194
- if (theme.typography?.fontSizes?.xs) {
4195
- cssVars[`--${prefix}-typography-fontSize-xs`] = theme.typography.fontSizes.xs;
4196
- }
4197
- if (theme.typography?.fontSizes?.sm) {
4198
- cssVars[`--${prefix}-typography-fontSize-sm`] = theme.typography.fontSizes.sm;
4199
- }
4200
- if (theme.typography?.fontSizes?.md) {
4201
- cssVars[`--${prefix}-typography-fontSize-md`] = theme.typography.fontSizes.md;
4202
- }
4203
- if (theme.typography?.fontSizes?.lg) {
4204
- cssVars[`--${prefix}-typography-fontSize-lg`] = theme.typography.fontSizes.lg;
4205
- }
4206
- if (theme.typography?.fontSizes?.xl) {
4207
- cssVars[`--${prefix}-typography-fontSize-xl`] = theme.typography.fontSizes.xl;
4208
- }
4209
- if (theme.typography?.fontSizes?.["2xl"]) {
4210
- cssVars[`--${prefix}-typography-fontSize-2xl`] = theme.typography.fontSizes["2xl"];
4211
- }
4212
- if (theme.typography?.fontSizes?.["3xl"]) {
4213
- cssVars[`--${prefix}-typography-fontSize-3xl`] = theme.typography.fontSizes["3xl"];
4214
- }
4215
- if (theme.typography?.fontWeights?.normal !== void 0) {
4216
- cssVars[`--${prefix}-typography-fontWeight-normal`] = theme.typography.fontWeights.normal.toString();
4217
- }
4218
- if (theme.typography?.fontWeights?.medium !== void 0) {
4219
- cssVars[`--${prefix}-typography-fontWeight-medium`] = theme.typography.fontWeights.medium.toString();
4220
- }
4221
- if (theme.typography?.fontWeights?.semibold !== void 0) {
4222
- cssVars[`--${prefix}-typography-fontWeight-semibold`] = theme.typography.fontWeights.semibold.toString();
4223
- }
4224
- if (theme.typography?.fontWeights?.bold !== void 0) {
4225
- cssVars[`--${prefix}-typography-fontWeight-bold`] = theme.typography.fontWeights.bold.toString();
4226
- }
4227
- if (theme.typography?.lineHeights?.tight !== void 0) {
4228
- cssVars[`--${prefix}-typography-lineHeight-tight`] = theme.typography.lineHeights.tight.toString();
4229
- }
4230
- if (theme.typography?.lineHeights?.normal !== void 0) {
4231
- cssVars[`--${prefix}-typography-lineHeight-normal`] = theme.typography.lineHeights.normal.toString();
4232
- }
4233
- if (theme.typography?.lineHeights?.relaxed !== void 0) {
4234
- cssVars[`--${prefix}-typography-lineHeight-relaxed`] = theme.typography.lineHeights.relaxed.toString();
4235
- }
4236
- if (theme.images) {
4237
- Object.keys(theme.images).forEach((imageKey) => {
4238
- const imageConfig = theme.images[imageKey];
4239
- if (imageConfig?.url) {
4240
- cssVars[`--${prefix}-image-${imageKey}-url`] = imageConfig.url;
4241
- }
4242
- if (imageConfig?.title) {
4243
- cssVars[`--${prefix}-image-${imageKey}-title`] = imageConfig.title;
4244
- }
4245
- if (imageConfig?.alt) {
4246
- cssVars[`--${prefix}-image-${imageKey}-alt`] = imageConfig.alt;
4247
- }
4248
- });
4249
- }
4250
- if (theme.components?.Button?.styleOverrides?.root?.borderRadius) {
4251
- cssVars[`--${prefix}-component-button-root-borderRadius`] = theme.components.Button.styleOverrides.root.borderRadius;
4252
- }
4253
- if (theme.components?.Field?.styleOverrides?.root?.borderRadius) {
4254
- cssVars[`--${prefix}-component-field-root-borderRadius`] = theme.components.Field.styleOverrides.root.borderRadius;
4255
- }
4256
- return cssVars;
4257
- };
4258
- var toThemeVars = (theme) => {
4259
- const prefix = theme.cssVarPrefix || VendorConstants_default.VENDOR_PREFIX;
4260
- const componentVars = {};
4261
- if (theme.components?.Button?.styleOverrides?.root?.borderRadius) {
4262
- componentVars.Button = {
4263
- root: {
4264
- borderRadius: `var(--${prefix}-component-button-root-borderRadius)`
4265
- }
4266
- };
4267
- }
4268
- if (theme.components?.Field?.styleOverrides?.root?.borderRadius) {
4269
- componentVars.Field = {
4270
- root: {
4271
- borderRadius: `var(--${prefix}-component-field-root-borderRadius)`
4272
- }
4273
- };
4274
- }
4275
- const themeVars = {
4276
- borderRadius: {
4277
- large: `var(--${prefix}-border-radius-large)`,
4278
- medium: `var(--${prefix}-border-radius-medium)`,
4279
- small: `var(--${prefix}-border-radius-small)`
4280
- },
4281
- colors: {
4282
- action: {
4283
- activatedOpacity: `var(--${prefix}-color-action-activatedOpacity)`,
4284
- active: `var(--${prefix}-color-action-active)`,
4285
- disabled: `var(--${prefix}-color-action-disabled)`,
4286
- disabledBackground: `var(--${prefix}-color-action-disabledBackground)`,
4287
- disabledOpacity: `var(--${prefix}-color-action-disabledOpacity)`,
4288
- focus: `var(--${prefix}-color-action-focus)`,
4289
- focusOpacity: `var(--${prefix}-color-action-focusOpacity)`,
4290
- hover: `var(--${prefix}-color-action-hover)`,
4291
- hoverOpacity: `var(--${prefix}-color-action-hoverOpacity)`,
4292
- selected: `var(--${prefix}-color-action-selected)`,
4293
- selectedOpacity: `var(--${prefix}-color-action-selectedOpacity)`
4294
- },
4295
- background: {
4296
- body: {
4297
- main: `var(--${prefix}-color-background-body-main)`
4298
- },
4299
- disabled: `var(--${prefix}-color-background-disabled)`,
4300
- surface: `var(--${prefix}-color-background-surface)`
4301
- },
4302
- border: `var(--${prefix}-color-border)`,
4303
- error: {
4304
- contrastText: `var(--${prefix}-color-error-contrastText)`,
4305
- main: `var(--${prefix}-color-error-main)`
4306
- },
4307
- info: {
4308
- contrastText: `var(--${prefix}-color-info-contrastText)`,
4309
- main: `var(--${prefix}-color-info-main)`
4310
- },
4311
- primary: {
4312
- contrastText: `var(--${prefix}-color-primary-contrastText)`,
4313
- main: `var(--${prefix}-color-primary-main)`
4314
- },
4315
- secondary: {
4316
- contrastText: `var(--${prefix}-color-secondary-contrastText)`,
4317
- main: `var(--${prefix}-color-secondary-main)`
4318
- },
4319
- success: {
4320
- contrastText: `var(--${prefix}-color-success-contrastText)`,
4321
- main: `var(--${prefix}-color-success-main)`
4322
- },
4323
- text: {
4324
- primary: `var(--${prefix}-color-text-primary)`,
4325
- secondary: `var(--${prefix}-color-text-secondary)`
4326
- },
4327
- warning: {
4328
- contrastText: `var(--${prefix}-color-warning-contrastText)`,
4329
- main: `var(--${prefix}-color-warning-main)`
4330
- }
4331
- },
4332
- shadows: {
4333
- large: `var(--${prefix}-shadow-large)`,
4334
- medium: `var(--${prefix}-shadow-medium)`,
4335
- small: `var(--${prefix}-shadow-small)`
4336
- },
4337
- spacing: {
4338
- unit: `var(--${prefix}-spacing-unit)`
4339
- },
4340
- typography: {
4341
- fontFamily: `var(--${prefix}-typography-fontFamily)`,
4342
- fontSizes: {
4343
- "2xl": `var(--${prefix}-typography-fontSize-2xl)`,
4344
- "3xl": `var(--${prefix}-typography-fontSize-3xl)`,
4345
- lg: `var(--${prefix}-typography-fontSize-lg)`,
4346
- md: `var(--${prefix}-typography-fontSize-md)`,
4347
- sm: `var(--${prefix}-typography-fontSize-sm)`,
4348
- xl: `var(--${prefix}-typography-fontSize-xl)`,
4349
- xs: `var(--${prefix}-typography-fontSize-xs)`
4350
- },
4351
- fontWeights: {
4352
- bold: `var(--${prefix}-typography-fontWeight-bold)`,
4353
- medium: `var(--${prefix}-typography-fontWeight-medium)`,
4354
- normal: `var(--${prefix}-typography-fontWeight-normal)`,
4355
- semibold: `var(--${prefix}-typography-fontWeight-semibold)`
4356
- },
4357
- lineHeights: {
4358
- normal: `var(--${prefix}-typography-lineHeight-normal)`,
4359
- relaxed: `var(--${prefix}-typography-lineHeight-relaxed)`,
4360
- tight: `var(--${prefix}-typography-lineHeight-tight)`
4361
- }
4362
- }
4363
- };
4364
- if (theme.images) {
4365
- themeVars.images = {};
4366
- Object.keys(theme.images).forEach((imageKey) => {
4367
- const imageConfig = theme.images[imageKey];
4368
- themeVars.images[imageKey] = {
4369
- alt: imageConfig?.alt ? `var(--${prefix}-image-${imageKey}-alt)` : void 0,
4370
- title: imageConfig?.title ? `var(--${prefix}-image-${imageKey}-title)` : void 0,
4371
- url: imageConfig?.url ? `var(--${prefix}-image-${imageKey}-url)` : void 0
4372
- };
4373
- });
4374
- }
4375
- if (Object.keys(componentVars).length > 0) {
4376
- themeVars.components = componentVars;
4731
+ if (theme.colors?.background?.body?.main) {
4732
+ cssVars[`--${prefix}-color-background-body-main`] = theme.colors.background.body.main;
4377
4733
  }
4378
- return themeVars;
4379
- };
4380
- var createTheme = (config = {}, isDark = false) => {
4381
- const baseTheme = isDark ? darkTheme : lightTheme;
4382
- const mergedConfig = {
4383
- ...baseTheme,
4384
- ...config,
4385
- borderRadius: {
4386
- ...baseTheme.borderRadius,
4387
- ...config.borderRadius
4388
- },
4389
- colors: {
4390
- ...baseTheme.colors,
4391
- ...config.colors,
4392
- action: {
4393
- ...baseTheme.colors.action,
4394
- ...config.colors?.action || {}
4395
- },
4396
- secondary: {
4397
- ...baseTheme.colors.secondary,
4398
- ...config.colors?.secondary || {}
4399
- }
4400
- },
4401
- images: {
4402
- ...baseTheme.images,
4403
- ...config.images
4404
- },
4405
- shadows: {
4406
- ...baseTheme.shadows,
4407
- ...config.shadows
4408
- },
4409
- spacing: {
4410
- ...baseTheme.spacing,
4411
- ...config.spacing
4412
- },
4413
- typography: {
4414
- ...baseTheme.typography,
4415
- ...config.typography,
4416
- fontSizes: {
4417
- ...baseTheme.typography.fontSizes,
4418
- ...config.typography?.fontSizes || {}
4419
- },
4420
- fontWeights: {
4421
- ...baseTheme.typography.fontWeights,
4422
- ...config.typography?.fontWeights || {}
4423
- },
4424
- lineHeights: {
4425
- ...baseTheme.typography.lineHeights,
4426
- ...config.typography?.lineHeights || {}
4427
- }
4428
- }
4429
- };
4430
- return {
4431
- ...mergedConfig,
4432
- cssVariables: toCssVariables(mergedConfig),
4433
- vars: toThemeVars(mergedConfig)
4434
- };
4435
- };
4436
- var DEFAULT_THEME = "light";
4437
- var createTheme_default = createTheme;
4438
-
4439
- // src/utils/arrayBufferToBase64url.ts
4440
- var arrayBufferToBase64url = (buffer) => {
4441
- const bytes = new Uint8Array(buffer);
4442
- let binary = "";
4443
- for (let i = 0; i < bytes.byteLength; i += 1) {
4444
- binary += String.fromCharCode(bytes[i]);
4734
+ if (theme.colors?.error?.main) {
4735
+ cssVars[`--${prefix}-color-error-main`] = theme.colors.error.main;
4445
4736
  }
4446
- return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
4447
- };
4448
- var arrayBufferToBase64url_default = arrayBufferToBase64url;
4449
-
4450
- // src/utils/base64urlToArrayBuffer.ts
4451
- var base64urlToArrayBuffer = (base64url2) => {
4452
- const padding = "=".repeat((4 - base64url2.length % 4) % 4);
4453
- const base64 = base64url2.replace(/-/g, "+").replace(/_/g, "/") + padding;
4454
- const binaryString = atob(base64);
4455
- const bytes = new Uint8Array(binaryString.length);
4456
- for (let i = 0; i < binaryString.length; i += 1) {
4457
- bytes[i] = binaryString.charCodeAt(i);
4737
+ if (theme.colors?.error?.contrastText) {
4738
+ cssVars[`--${prefix}-color-error-contrastText`] = theme.colors.error.contrastText;
4458
4739
  }
4459
- return bytes.buffer;
4460
- };
4461
- var base64urlToArrayBuffer_default = base64urlToArrayBuffer;
4462
-
4463
- // src/utils/bem.ts
4464
- var bem = (baseClass, element, modifier) => {
4465
- let className = baseClass;
4466
- if (element) {
4467
- className += `__${element}`;
4740
+ if (theme.colors?.error?.light) {
4741
+ cssVars[`--${prefix}-color-error-light`] = theme.colors.error.light;
4468
4742
  }
4469
- if (modifier) {
4470
- className += `--${modifier}`;
4743
+ if (theme.colors?.success?.main) {
4744
+ cssVars[`--${prefix}-color-success-main`] = theme.colors.success.main;
4471
4745
  }
4472
- return className;
4473
- };
4474
- var bem_default = bem;
4475
-
4476
- // src/utils/formatDate.ts
4477
- var formatDate = (dateString) => {
4478
- if (!dateString) return "-";
4479
- try {
4480
- return new Date(dateString).toLocaleDateString("en-US", {
4481
- day: "numeric",
4482
- month: "long",
4483
- year: "numeric"
4484
- });
4485
- } catch {
4486
- return dateString;
4746
+ if (theme.colors?.success?.contrastText) {
4747
+ cssVars[`--${prefix}-color-success-contrastText`] = theme.colors.success.contrastText;
4487
4748
  }
4488
- };
4489
- var formatDate_default = formatDate;
4490
-
4491
- // src/utils/logger.ts
4492
- var PREFIX = "\u{1F6E1}\uFE0F Asgardeo";
4493
- var DEFAULT_CONFIG = {
4494
- level: "info",
4495
- prefix: `${PREFIX}`,
4496
- showLevel: true,
4497
- timestamps: true
4498
- };
4499
- var isBrowser = () => (
4500
- /* @ts-ignore */
4501
- typeof window !== "undefined" && typeof window.document !== "undefined"
4502
- );
4503
- var isNode = () => (
4504
- /* @ts-ignore */
4505
- typeof process !== "undefined" && void 0
4506
- );
4507
- var COLORS = {
4508
- blue: "\x1B[34m",
4509
- bright: "\x1B[1m",
4510
- cyan: "\x1B[36m",
4511
- dim: "\x1B[2m",
4512
- gray: "\x1B[90m",
4513
- green: "\x1B[32m",
4514
- magenta: "\x1B[35m",
4515
- red: "\x1B[31m",
4516
- reset: "\x1B[0m",
4517
- white: "\x1B[37m",
4518
- yellow: "\x1B[33m"
4519
- };
4520
- var BROWSER_STYLES = {
4521
- debug: "color: #6b7280; font-weight: normal;",
4522
- error: "color: #dc2626; font-weight: bold;",
4523
- info: "color: #2563eb; font-weight: bold;",
4524
- prefix: "color: #7c3aed; font-weight: bold;",
4525
- timestamp: "color: #6b7280; font-size: 0.9em;",
4526
- warn: "color: #d97706; font-weight: bold;"
4527
- };
4528
- var LOG_LEVEL_ORDER = {
4529
- debug: 0,
4530
- error: 3,
4531
- info: 1,
4532
- warn: 2
4533
- };
4534
- var Logger = class _Logger {
4535
- constructor(config = {}) {
4536
- __publicField(this, "config");
4537
- this.config = { ...DEFAULT_CONFIG, ...config };
4749
+ if (theme.colors?.success?.light) {
4750
+ cssVars[`--${prefix}-color-success-light`] = theme.colors.success.light;
4538
4751
  }
4539
- /**
4540
- * Update logger configuration
4541
- */
4542
- configure(config) {
4543
- this.config = { ...this.config, ...config };
4752
+ if (theme.colors?.warning?.main) {
4753
+ cssVars[`--${prefix}-color-warning-main`] = theme.colors.warning.main;
4754
+ }
4755
+ if (theme.colors?.warning?.contrastText) {
4756
+ cssVars[`--${prefix}-color-warning-contrastText`] = theme.colors.warning.contrastText;
4757
+ }
4758
+ if (theme.colors?.warning?.light) {
4759
+ cssVars[`--${prefix}-color-warning-light`] = theme.colors.warning.light;
4760
+ }
4761
+ if (theme.colors?.info?.main) {
4762
+ cssVars[`--${prefix}-color-info-main`] = theme.colors.info.main;
4763
+ }
4764
+ if (theme.colors?.info?.contrastText) {
4765
+ cssVars[`--${prefix}-color-info-contrastText`] = theme.colors.info.contrastText;
4766
+ }
4767
+ if (theme.colors?.info?.light) {
4768
+ cssVars[`--${prefix}-color-info-light`] = theme.colors.info.light;
4769
+ }
4770
+ if (theme.colors?.text?.primary) {
4771
+ cssVars[`--${prefix}-color-text-primary`] = theme.colors.text.primary;
4772
+ }
4773
+ if (theme.colors?.text?.secondary) {
4774
+ cssVars[`--${prefix}-color-text-secondary`] = theme.colors.text.secondary;
4775
+ }
4776
+ if (theme.colors?.border) {
4777
+ cssVars[`--${prefix}-color-border`] = theme.colors.border;
4778
+ }
4779
+ if (theme.spacing?.unit !== void 0) {
4780
+ cssVars[`--${prefix}-spacing-unit`] = `${theme.spacing.unit}px`;
4781
+ }
4782
+ if (theme.borderRadius?.small) {
4783
+ cssVars[`--${prefix}-border-radius-small`] = theme.borderRadius.small;
4784
+ }
4785
+ if (theme.borderRadius?.medium) {
4786
+ cssVars[`--${prefix}-border-radius-medium`] = theme.borderRadius.medium;
4787
+ }
4788
+ if (theme.borderRadius?.large) {
4789
+ cssVars[`--${prefix}-border-radius-large`] = theme.borderRadius.large;
4790
+ }
4791
+ if (theme.shadows?.small) {
4792
+ cssVars[`--${prefix}-shadow-small`] = theme.shadows.small;
4793
+ }
4794
+ if (theme.shadows?.medium) {
4795
+ cssVars[`--${prefix}-shadow-medium`] = theme.shadows.medium;
4796
+ }
4797
+ if (theme.shadows?.large) {
4798
+ cssVars[`--${prefix}-shadow-large`] = theme.shadows.large;
4799
+ }
4800
+ if (theme.typography?.fontFamily) {
4801
+ cssVars[`--${prefix}-typography-fontFamily`] = theme.typography.fontFamily;
4802
+ }
4803
+ if (theme.typography?.fontSizes?.xs) {
4804
+ cssVars[`--${prefix}-typography-fontSize-xs`] = theme.typography.fontSizes.xs;
4805
+ }
4806
+ if (theme.typography?.fontSizes?.sm) {
4807
+ cssVars[`--${prefix}-typography-fontSize-sm`] = theme.typography.fontSizes.sm;
4808
+ }
4809
+ if (theme.typography?.fontSizes?.md) {
4810
+ cssVars[`--${prefix}-typography-fontSize-md`] = theme.typography.fontSizes.md;
4811
+ }
4812
+ if (theme.typography?.fontSizes?.lg) {
4813
+ cssVars[`--${prefix}-typography-fontSize-lg`] = theme.typography.fontSizes.lg;
4814
+ }
4815
+ if (theme.typography?.fontSizes?.xl) {
4816
+ cssVars[`--${prefix}-typography-fontSize-xl`] = theme.typography.fontSizes.xl;
4817
+ }
4818
+ if (theme.typography?.fontSizes?.["2xl"]) {
4819
+ cssVars[`--${prefix}-typography-fontSize-2xl`] = theme.typography.fontSizes["2xl"];
4820
+ }
4821
+ if (theme.typography?.fontSizes?.["3xl"]) {
4822
+ cssVars[`--${prefix}-typography-fontSize-3xl`] = theme.typography.fontSizes["3xl"];
4823
+ }
4824
+ if (theme.typography?.fontWeights?.normal !== void 0) {
4825
+ cssVars[`--${prefix}-typography-fontWeight-normal`] = theme.typography.fontWeights.normal.toString();
4826
+ }
4827
+ if (theme.typography?.fontWeights?.medium !== void 0) {
4828
+ cssVars[`--${prefix}-typography-fontWeight-medium`] = theme.typography.fontWeights.medium.toString();
4829
+ }
4830
+ if (theme.typography?.fontWeights?.semibold !== void 0) {
4831
+ cssVars[`--${prefix}-typography-fontWeight-semibold`] = theme.typography.fontWeights.semibold.toString();
4832
+ }
4833
+ if (theme.typography?.fontWeights?.bold !== void 0) {
4834
+ cssVars[`--${prefix}-typography-fontWeight-bold`] = theme.typography.fontWeights.bold.toString();
4544
4835
  }
4545
- /**
4546
- * Get current configuration
4547
- */
4548
- getConfig() {
4549
- return { ...this.config };
4836
+ if (theme.typography?.lineHeights?.tight !== void 0) {
4837
+ cssVars[`--${prefix}-typography-lineHeight-tight`] = theme.typography.lineHeights.tight.toString();
4550
4838
  }
4551
- /**
4552
- * Check if a log level should be output
4553
- */
4554
- shouldLog(level) {
4555
- return LOG_LEVEL_ORDER[level] >= LOG_LEVEL_ORDER[this.config.level];
4839
+ if (theme.typography?.lineHeights?.normal !== void 0) {
4840
+ cssVars[`--${prefix}-typography-lineHeight-normal`] = theme.typography.lineHeights.normal.toString();
4556
4841
  }
4557
- /**
4558
- * Get timestamp string
4559
- */
4560
- static getTimestamp() {
4561
- return (/* @__PURE__ */ new Date()).toISOString();
4842
+ if (theme.typography?.lineHeights?.relaxed !== void 0) {
4843
+ cssVars[`--${prefix}-typography-lineHeight-relaxed`] = theme.typography.lineHeights.relaxed.toString();
4562
4844
  }
4563
- /**
4564
- * Get log level string
4565
- */
4566
- static getLevelString(level) {
4567
- switch (level) {
4568
- case "debug":
4569
- return "DEBUG";
4570
- case "info":
4571
- return "INFO";
4572
- case "warn":
4573
- return "WARN";
4574
- case "error":
4575
- return "ERROR";
4576
- default:
4577
- return "UNKNOWN";
4578
- }
4845
+ if (theme.images) {
4846
+ Object.keys(theme.images).forEach((imageKey) => {
4847
+ const imageConfig = theme.images[imageKey];
4848
+ if (imageConfig?.url) {
4849
+ cssVars[`--${prefix}-image-${imageKey}-url`] = imageConfig.url;
4850
+ }
4851
+ if (imageConfig?.title) {
4852
+ cssVars[`--${prefix}-image-${imageKey}-title`] = imageConfig.title;
4853
+ }
4854
+ if (imageConfig?.alt) {
4855
+ cssVars[`--${prefix}-image-${imageKey}-alt`] = imageConfig.alt;
4856
+ }
4857
+ });
4579
4858
  }
4580
- /**
4581
- * Format message for Node.js terminal
4582
- */
4583
- formatForNode(level, message) {
4584
- const parts = [];
4585
- if (this.config.timestamps) {
4586
- parts.push(`${COLORS.gray}[${_Logger.getTimestamp()}]${COLORS.reset}`);
4587
- }
4588
- if (this.config.prefix) {
4589
- parts.push(`${COLORS.magenta}${this.config.prefix}${COLORS.reset}`);
4590
- }
4591
- if (this.config.showLevel) {
4592
- const levelStr = _Logger.getLevelString(level);
4593
- let coloredLevel;
4594
- switch (level) {
4595
- case "debug":
4596
- coloredLevel = `${COLORS.gray}[${levelStr}]${COLORS.reset}`;
4597
- break;
4598
- case "info":
4599
- coloredLevel = `${COLORS.blue}[${levelStr}]${COLORS.reset}`;
4600
- break;
4601
- case "warn":
4602
- coloredLevel = `${COLORS.yellow}[${levelStr}]${COLORS.reset}`;
4603
- break;
4604
- case "error":
4605
- coloredLevel = `${COLORS.red}[${levelStr}]${COLORS.reset}`;
4606
- break;
4607
- default:
4608
- coloredLevel = `[${levelStr}]`;
4859
+ if (theme.components?.Button?.styleOverrides?.root?.borderRadius) {
4860
+ cssVars[`--${prefix}-component-button-root-borderRadius`] = theme.components.Button.styleOverrides.root.borderRadius;
4861
+ }
4862
+ if (theme.components?.Field?.styleOverrides?.root?.borderRadius) {
4863
+ cssVars[`--${prefix}-component-field-root-borderRadius`] = theme.components.Field.styleOverrides.root.borderRadius;
4864
+ }
4865
+ return cssVars;
4866
+ };
4867
+ var toThemeVars = (theme) => {
4868
+ const prefix = theme.cssVarPrefix || VendorConstants_default.VENDOR_PREFIX;
4869
+ const componentVars = {};
4870
+ if (theme.components?.Button?.styleOverrides?.root?.borderRadius) {
4871
+ componentVars.Button = {
4872
+ root: {
4873
+ borderRadius: `var(--${prefix}-component-button-root-borderRadius)`
4609
4874
  }
4610
- parts.push(coloredLevel);
4611
- }
4612
- parts.push(message);
4613
- return parts.join(" ");
4875
+ };
4614
4876
  }
4615
- /**
4616
- * Log message using appropriate method
4617
- */
4618
- logMessage(level, message, ...args) {
4619
- if (!this.shouldLog(level)) {
4620
- return;
4621
- }
4622
- if (this.config.formatter) {
4623
- this.config.formatter(level, message, ...args);
4624
- return;
4625
- }
4626
- if (isBrowser()) {
4627
- this.logToBrowser(level, message, ...args);
4628
- } else if (isNode()) {
4629
- this.logToNode(level, message, ...args);
4630
- } else {
4631
- console.log(message, ...args);
4632
- }
4877
+ if (theme.components?.Field?.styleOverrides?.root?.borderRadius) {
4878
+ componentVars.Field = {
4879
+ root: {
4880
+ borderRadius: `var(--${prefix}-component-field-root-borderRadius)`
4881
+ }
4882
+ };
4633
4883
  }
4634
- /**
4635
- * Log to browser console with styling
4636
- */
4637
- logToBrowser(level, message, ...args) {
4638
- const parts = [];
4639
- const styles = [];
4640
- if (this.config.timestamps) {
4641
- parts.push(`%c[${_Logger.getTimestamp()}]`);
4642
- styles.push(BROWSER_STYLES.timestamp);
4643
- }
4644
- if (this.config.prefix) {
4645
- parts.push(`%c${this.config.prefix}`);
4646
- styles.push(BROWSER_STYLES.prefix);
4647
- }
4648
- if (this.config.showLevel) {
4649
- const levelStr = _Logger.getLevelString(level);
4650
- parts.push(`%c[${levelStr}]`);
4651
- switch (level) {
4652
- case "debug":
4653
- styles.push(BROWSER_STYLES.debug);
4654
- break;
4655
- case "info":
4656
- styles.push(BROWSER_STYLES.info);
4657
- break;
4658
- case "warn":
4659
- styles.push(BROWSER_STYLES.warn);
4660
- break;
4661
- case "error":
4662
- styles.push(BROWSER_STYLES.error);
4663
- break;
4664
- default:
4665
- styles.push("");
4884
+ const themeVars = {
4885
+ borderRadius: {
4886
+ large: `var(--${prefix}-border-radius-large)`,
4887
+ medium: `var(--${prefix}-border-radius-medium)`,
4888
+ small: `var(--${prefix}-border-radius-small)`
4889
+ },
4890
+ colors: {
4891
+ action: {
4892
+ activatedOpacity: `var(--${prefix}-color-action-activatedOpacity)`,
4893
+ active: `var(--${prefix}-color-action-active)`,
4894
+ disabled: `var(--${prefix}-color-action-disabled)`,
4895
+ disabledBackground: `var(--${prefix}-color-action-disabledBackground)`,
4896
+ disabledOpacity: `var(--${prefix}-color-action-disabledOpacity)`,
4897
+ focus: `var(--${prefix}-color-action-focus)`,
4898
+ focusOpacity: `var(--${prefix}-color-action-focusOpacity)`,
4899
+ hover: `var(--${prefix}-color-action-hover)`,
4900
+ hoverOpacity: `var(--${prefix}-color-action-hoverOpacity)`,
4901
+ selected: `var(--${prefix}-color-action-selected)`,
4902
+ selectedOpacity: `var(--${prefix}-color-action-selectedOpacity)`
4903
+ },
4904
+ background: {
4905
+ body: {
4906
+ main: `var(--${prefix}-color-background-body-main)`
4907
+ },
4908
+ disabled: `var(--${prefix}-color-background-disabled)`,
4909
+ surface: `var(--${prefix}-color-background-surface)`
4910
+ },
4911
+ border: `var(--${prefix}-color-border)`,
4912
+ error: {
4913
+ contrastText: `var(--${prefix}-color-error-contrastText)`,
4914
+ main: `var(--${prefix}-color-error-main)`
4915
+ },
4916
+ info: {
4917
+ contrastText: `var(--${prefix}-color-info-contrastText)`,
4918
+ main: `var(--${prefix}-color-info-main)`
4919
+ },
4920
+ primary: {
4921
+ contrastText: `var(--${prefix}-color-primary-contrastText)`,
4922
+ main: `var(--${prefix}-color-primary-main)`
4923
+ },
4924
+ secondary: {
4925
+ contrastText: `var(--${prefix}-color-secondary-contrastText)`,
4926
+ main: `var(--${prefix}-color-secondary-main)`
4927
+ },
4928
+ success: {
4929
+ contrastText: `var(--${prefix}-color-success-contrastText)`,
4930
+ main: `var(--${prefix}-color-success-main)`
4931
+ },
4932
+ text: {
4933
+ primary: `var(--${prefix}-color-text-primary)`,
4934
+ secondary: `var(--${prefix}-color-text-secondary)`
4935
+ },
4936
+ warning: {
4937
+ contrastText: `var(--${prefix}-color-warning-contrastText)`,
4938
+ main: `var(--${prefix}-color-warning-main)`
4939
+ }
4940
+ },
4941
+ shadows: {
4942
+ large: `var(--${prefix}-shadow-large)`,
4943
+ medium: `var(--${prefix}-shadow-medium)`,
4944
+ small: `var(--${prefix}-shadow-small)`
4945
+ },
4946
+ spacing: {
4947
+ unit: `var(--${prefix}-spacing-unit)`
4948
+ },
4949
+ typography: {
4950
+ fontFamily: `var(--${prefix}-typography-fontFamily)`,
4951
+ fontSizes: {
4952
+ "2xl": `var(--${prefix}-typography-fontSize-2xl)`,
4953
+ "3xl": `var(--${prefix}-typography-fontSize-3xl)`,
4954
+ lg: `var(--${prefix}-typography-fontSize-lg)`,
4955
+ md: `var(--${prefix}-typography-fontSize-md)`,
4956
+ sm: `var(--${prefix}-typography-fontSize-sm)`,
4957
+ xl: `var(--${prefix}-typography-fontSize-xl)`,
4958
+ xs: `var(--${prefix}-typography-fontSize-xs)`
4959
+ },
4960
+ fontWeights: {
4961
+ bold: `var(--${prefix}-typography-fontWeight-bold)`,
4962
+ medium: `var(--${prefix}-typography-fontWeight-medium)`,
4963
+ normal: `var(--${prefix}-typography-fontWeight-normal)`,
4964
+ semibold: `var(--${prefix}-typography-fontWeight-semibold)`
4965
+ },
4966
+ lineHeights: {
4967
+ normal: `var(--${prefix}-typography-lineHeight-normal)`,
4968
+ relaxed: `var(--${prefix}-typography-lineHeight-relaxed)`,
4969
+ tight: `var(--${prefix}-typography-lineHeight-tight)`
4666
4970
  }
4667
4971
  }
4668
- parts.push(`%c${message}`);
4669
- styles.push("color: inherit; font-weight: normal;");
4670
- const formattedMessage = parts.join(" ");
4671
- switch (level) {
4672
- case "debug":
4673
- console.debug(formattedMessage, ...styles, ...args);
4674
- break;
4675
- case "info":
4676
- console.info(formattedMessage, ...styles, ...args);
4677
- break;
4678
- case "warn":
4679
- console.warn(formattedMessage, ...styles, ...args);
4680
- break;
4681
- case "error":
4682
- console.error(formattedMessage, ...styles, ...args);
4683
- break;
4684
- default:
4685
- console.log(formattedMessage, ...styles, ...args);
4686
- }
4972
+ };
4973
+ if (theme.images) {
4974
+ themeVars.images = {};
4975
+ Object.keys(theme.images).forEach((imageKey) => {
4976
+ const imageConfig = theme.images[imageKey];
4977
+ themeVars.images[imageKey] = {
4978
+ alt: imageConfig?.alt ? `var(--${prefix}-image-${imageKey}-alt)` : void 0,
4979
+ title: imageConfig?.title ? `var(--${prefix}-image-${imageKey}-title)` : void 0,
4980
+ url: imageConfig?.url ? `var(--${prefix}-image-${imageKey}-url)` : void 0
4981
+ };
4982
+ });
4687
4983
  }
4688
- /**
4689
- * Log to Node.js console
4690
- */
4691
- logToNode(level, message, ...args) {
4692
- const formattedMessage = this.formatForNode(level, message);
4693
- switch (level) {
4694
- case "debug":
4695
- console.debug(formattedMessage, ...args);
4696
- break;
4697
- case "info":
4698
- console.info(formattedMessage, ...args);
4699
- break;
4700
- case "warn":
4701
- console.warn(formattedMessage, ...args);
4702
- break;
4703
- case "error":
4704
- console.error(formattedMessage, ...args);
4705
- break;
4706
- default:
4707
- console.log(formattedMessage, ...args);
4708
- }
4984
+ if (Object.keys(componentVars).length > 0) {
4985
+ themeVars.components = componentVars;
4709
4986
  }
4710
- /**
4711
- * Log debug message
4712
- */
4713
- debug(message, ...args) {
4714
- this.logMessage("debug", message, ...args);
4987
+ return themeVars;
4988
+ };
4989
+ var createTheme = (config = {}, isDark = false) => {
4990
+ const baseTheme = isDark ? darkTheme : lightTheme;
4991
+ const mergedConfig = {
4992
+ ...baseTheme,
4993
+ ...config,
4994
+ borderRadius: {
4995
+ ...baseTheme.borderRadius,
4996
+ ...config.borderRadius
4997
+ },
4998
+ colors: {
4999
+ ...baseTheme.colors,
5000
+ ...config.colors,
5001
+ action: {
5002
+ ...baseTheme.colors.action,
5003
+ ...config.colors?.action || {}
5004
+ },
5005
+ secondary: {
5006
+ ...baseTheme.colors.secondary,
5007
+ ...config.colors?.secondary || {}
5008
+ }
5009
+ },
5010
+ images: {
5011
+ ...baseTheme.images,
5012
+ ...config.images
5013
+ },
5014
+ shadows: {
5015
+ ...baseTheme.shadows,
5016
+ ...config.shadows
5017
+ },
5018
+ spacing: {
5019
+ ...baseTheme.spacing,
5020
+ ...config.spacing
5021
+ },
5022
+ typography: {
5023
+ ...baseTheme.typography,
5024
+ ...config.typography,
5025
+ fontSizes: {
5026
+ ...baseTheme.typography.fontSizes,
5027
+ ...config.typography?.fontSizes || {}
5028
+ },
5029
+ fontWeights: {
5030
+ ...baseTheme.typography.fontWeights,
5031
+ ...config.typography?.fontWeights || {}
5032
+ },
5033
+ lineHeights: {
5034
+ ...baseTheme.typography.lineHeights,
5035
+ ...config.typography?.lineHeights || {}
5036
+ }
5037
+ }
5038
+ };
5039
+ return {
5040
+ ...mergedConfig,
5041
+ cssVariables: toCssVariables(mergedConfig),
5042
+ vars: toThemeVars(mergedConfig)
5043
+ };
5044
+ };
5045
+ var DEFAULT_THEME = "light";
5046
+ var createTheme_default = createTheme;
5047
+
5048
+ // src/utils/arrayBufferToBase64url.ts
5049
+ var arrayBufferToBase64url = (buffer) => {
5050
+ const bytes = new Uint8Array(buffer);
5051
+ let binary = "";
5052
+ for (let i = 0; i < bytes.byteLength; i += 1) {
5053
+ binary += String.fromCharCode(bytes[i]);
4715
5054
  }
4716
- /**
4717
- * Log info message
4718
- */
4719
- info(message, ...args) {
4720
- this.logMessage("info", message, ...args);
5055
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
5056
+ };
5057
+ var arrayBufferToBase64url_default = arrayBufferToBase64url;
5058
+
5059
+ // src/utils/base64urlToArrayBuffer.ts
5060
+ var base64urlToArrayBuffer = (base64url3) => {
5061
+ const padding = "=".repeat((4 - base64url3.length % 4) % 4);
5062
+ const base64 = base64url3.replace(/-/g, "+").replace(/_/g, "/") + padding;
5063
+ const binaryString = atob(base64);
5064
+ const bytes = new Uint8Array(binaryString.length);
5065
+ for (let i = 0; i < binaryString.length; i += 1) {
5066
+ bytes[i] = binaryString.charCodeAt(i);
4721
5067
  }
4722
- /**
4723
- * Log warning message
4724
- */
4725
- warn(message, ...args) {
4726
- this.logMessage("warn", message, ...args);
5068
+ return bytes.buffer;
5069
+ };
5070
+ var base64urlToArrayBuffer_default = base64urlToArrayBuffer;
5071
+
5072
+ // src/utils/bem.ts
5073
+ var bem = (baseClass, element, modifier) => {
5074
+ let className = baseClass;
5075
+ if (element) {
5076
+ className += `__${element}`;
4727
5077
  }
4728
- /**
4729
- * Log error message
4730
- */
4731
- error(message, ...args) {
4732
- this.logMessage("error", message, ...args);
5078
+ if (modifier) {
5079
+ className += `--${modifier}`;
4733
5080
  }
4734
- /**
4735
- * Create a child logger with additional prefix
4736
- */
4737
- child(prefix) {
4738
- const childPrefix = this.config.prefix ? `${this.config.prefix} - ${prefix}` : prefix;
4739
- return new _Logger({
4740
- ...this.config,
4741
- prefix: childPrefix
5081
+ return className;
5082
+ };
5083
+ var bem_default = bem;
5084
+
5085
+ // src/utils/formatDate.ts
5086
+ var formatDate = (dateString) => {
5087
+ if (!dateString) return "-";
5088
+ try {
5089
+ return new Date(dateString).toLocaleDateString("en-US", {
5090
+ day: "numeric",
5091
+ month: "long",
5092
+ year: "numeric"
4742
5093
  });
5094
+ } catch {
5095
+ return dateString;
4743
5096
  }
4744
- /**
4745
- * Set log level
4746
- */
4747
- setLevel(level) {
4748
- this.config.level = level;
4749
- }
4750
- /**
4751
- * Get current log level
4752
- */
4753
- getLevel() {
4754
- return this.config.level;
4755
- }
4756
- };
4757
- var logger = new Logger();
4758
- var createLogger = (config) => new Logger(config);
4759
- var logger_default = logger;
4760
- var debug = (message, ...args) => logger.debug(message, ...args);
4761
- var info = (message, ...args) => logger.info(message, ...args);
4762
- var warn = (message, ...args) => logger.warn(message, ...args);
4763
- var error = (message, ...args) => logger.error(message, ...args);
4764
- var configure = (config) => logger.configure(config);
4765
- var createComponentLogger = (component) => logger.child(component);
4766
- var createPackageLogger = (packageName) => createLogger({
4767
- level: "info",
4768
- prefix: `${PREFIX} - ${packageName}`,
4769
- showLevel: true,
4770
- timestamps: true
4771
- });
4772
- var createPackageComponentLogger = (packageName, component) => {
4773
- const packageLogger = createPackageLogger(packageName);
4774
- return packageLogger.child(component);
4775
5097
  };
5098
+ var formatDate_default = formatDate;
4776
5099
 
4777
5100
  // src/utils/deriveOrganizationHandleFromBaseUrl.ts
4778
5101
  var deriveOrganizationHandleFromBaseUrl = (baseUrl) => {
@@ -4823,38 +5146,6 @@ var deriveOrganizationHandleFromBaseUrl = (baseUrl) => {
4823
5146
  };
4824
5147
  var deriveOrganizationHandleFromBaseUrl_default = deriveOrganizationHandleFromBaseUrl;
4825
5148
 
4826
- // src/utils/isRecognizedBaseUrlPattern.ts
4827
- var isRecognizedBaseUrlPattern = (baseUrl) => {
4828
- if (!baseUrl) {
4829
- throw new AsgardeoRuntimeError(
4830
- "Base URL is required to derive if the `baseUrl` is recognized.",
4831
- "isRecognizedBaseUrlPattern-ValidationError-001",
4832
- "javascript",
4833
- "A valid base URL must be provided to derive if the `baseUrl` is recognized to use the sensible fallbacks."
4834
- );
4835
- }
4836
- let parsedUrl;
4837
- try {
4838
- parsedUrl = new URL(baseUrl);
4839
- } catch (error2) {
4840
- throw new AsgardeoRuntimeError(
4841
- `Invalid base URL format: ${baseUrl}`,
4842
- "isRecognizedBaseUrlPattern-ValidationError-002",
4843
- "javascript",
4844
- "The provided base URL does not conform to valid URL syntax."
4845
- );
4846
- }
4847
- const pathSegments = parsedUrl.pathname?.split("/")?.filter((segment) => segment?.length > 0);
4848
- if (pathSegments.length < 2 || pathSegments[0] !== "t") {
4849
- logger_default.warn(
4850
- "[isRecognizedBaseUrlPattern] The provided base URL does not follow the expected URL pattern (/t/{orgHandle})."
4851
- );
4852
- return false;
4853
- }
4854
- return true;
4855
- };
4856
- var isRecognizedBaseUrlPattern_default = isRecognizedBaseUrlPattern;
4857
-
4858
5149
  // src/utils/flattenUserSchema.ts
4859
5150
  var flattenUserSchema = (schemas) => {
4860
5151
  const flattenedAttributes = [];
@@ -5040,31 +5331,6 @@ var generateFlattenedUserProfile = (meResponse, processedSchemas) => {
5040
5331
  };
5041
5332
  var generateFlattenedUserProfile_default = generateFlattenedUserProfile;
5042
5333
 
5043
- // src/utils/identifyPlatform.ts
5044
- var identifyPlatform = (config) => {
5045
- const { baseUrl } = config;
5046
- try {
5047
- if (isRecognizedBaseUrlPattern_default(baseUrl)) {
5048
- try {
5049
- const url = new URL(baseUrl);
5050
- if (/\.asgardeo\.io$/i.test(url.hostname) || /asgardeo\.io$/i.test(url.hostname)) {
5051
- return "ASGARDEO" /* Asgardeo */;
5052
- }
5053
- } catch {
5054
- logger_default.debug(
5055
- `[identifyPlatform] Could not identify platform from the base URL: ${baseUrl}. Defaulting to WSO2 Identity Server as the platform.`
5056
- );
5057
- }
5058
- return "IDENTITY_SERVER" /* IdentityServer */;
5059
- }
5060
- return "UNKNOWN" /* Unknown */;
5061
- } catch (error2) {
5062
- logger_default.debug(`[identifyPlatform] Error identifying platform from base URL: ${baseUrl}. Error: ${error2.message}`);
5063
- return "UNKNOWN" /* Unknown */;
5064
- }
5065
- };
5066
- var identifyPlatform_default = identifyPlatform;
5067
-
5068
5334
  // src/utils/getRedirectBasedSignUpUrl.ts
5069
5335
  var getRedirectBasedSignUpUrl = (config) => {
5070
5336
  const { baseUrl } = config;
@@ -5506,7 +5772,6 @@ var _HttpClient = class _HttpClient {
5506
5772
  __publicField(_HttpClient, "DEFAULT_HANDLER_DISABLE_TIMEOUT", 1e3);
5507
5773
  var HttpClient = _HttpClient;
5508
5774
  export {
5509
- AgentConfig,
5510
5775
  ApplicationNativeAuthenticationConstants_default as ApplicationNativeAuthenticationConstants,
5511
5776
  AsgardeoAPIError,
5512
5777
  AsgardeoAuthClient,