@asgardeo/javascript 0.1.21 → 0.1.22

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/index.js CHANGED
@@ -1929,6 +1929,17 @@ var initializeEmbeddedSignInFlow = async ({
1929
1929
  payload,
1930
1930
  ...requestConfig
1931
1931
  }) => {
1932
+ try {
1933
+ new URL(url ?? baseUrl);
1934
+ } catch (error2) {
1935
+ throw new AsgardeoAPIError(
1936
+ `Invalid URL provided. ${error2?.toString()}`,
1937
+ "getSchemas-ValidationError-001",
1938
+ "javascript",
1939
+ 400,
1940
+ "The provided `url` or `baseUrl` path does not adhere to the URL schema."
1941
+ );
1942
+ }
1932
1943
  if (!payload) {
1933
1944
  throw new AsgardeoAPIError(
1934
1945
  "Authorization payload is required",
@@ -1944,27 +1955,40 @@ var initializeEmbeddedSignInFlow = async ({
1944
1955
  searchParams.append(key, String(value));
1945
1956
  }
1946
1957
  });
1947
- const response = await fetch(url ?? `${baseUrl}/oauth2/authorize`, {
1948
- ...requestConfig,
1949
- method: requestConfig.method || "POST",
1950
- headers: {
1951
- ...requestConfig.headers,
1952
- "Content-Type": "application/x-www-form-urlencoded",
1953
- Accept: "application/json"
1954
- },
1955
- body: searchParams.toString()
1956
- });
1957
- if (!response.ok) {
1958
- const errorText = await response.text();
1958
+ try {
1959
+ const response = await fetch(url ?? `${baseUrl}/oauth2/authorize`, {
1960
+ ...requestConfig,
1961
+ method: requestConfig.method || "POST",
1962
+ headers: {
1963
+ ...requestConfig.headers,
1964
+ "Content-Type": "application/x-www-form-urlencoded",
1965
+ Accept: "application/json"
1966
+ },
1967
+ body: searchParams.toString()
1968
+ });
1969
+ if (!response.ok) {
1970
+ const errorText = await response.text();
1971
+ throw new AsgardeoAPIError(
1972
+ `Authorization request failed: ${errorText}`,
1973
+ "initializeEmbeddedSignInFlow-ResponseError-001",
1974
+ "javascript",
1975
+ response.status,
1976
+ response.statusText
1977
+ );
1978
+ }
1979
+ return await response.json();
1980
+ } catch (error2) {
1981
+ if (error2 instanceof AsgardeoAPIError) {
1982
+ throw error2;
1983
+ }
1959
1984
  throw new AsgardeoAPIError(
1960
- `Authorization request failed: ${errorText}`,
1961
- "initializeEmbeddedSignInFlow-ResponseError-001",
1985
+ `Network or parsing error: ${error2 instanceof Error ? error2.message : "Unknown error"}`,
1986
+ "initializeEmbeddedSignInFlow-NetworkError-001",
1962
1987
  "javascript",
1963
- response.status,
1964
- response.statusText
1988
+ 0,
1989
+ "Network Error"
1965
1990
  );
1966
1991
  }
1967
- return await response.json();
1968
1992
  };
1969
1993
  var initializeEmbeddedSignInFlow_default = initializeEmbeddedSignInFlow;
1970
1994
 
@@ -1975,6 +1999,17 @@ var executeEmbeddedSignInFlow = async ({
1975
1999
  payload,
1976
2000
  ...requestConfig
1977
2001
  }) => {
2002
+ try {
2003
+ new URL(url ?? baseUrl);
2004
+ } catch (error2) {
2005
+ throw new AsgardeoAPIError(
2006
+ `Invalid URL provided. ${error2?.toString()}`,
2007
+ "executeEmbeddedSignInFlow-ValidationError-001",
2008
+ "javascript",
2009
+ 400,
2010
+ "The provided `url` or `baseUrl` path does not adhere to the URL schema."
2011
+ );
2012
+ }
1978
2013
  if (!payload) {
1979
2014
  throw new AsgardeoAPIError(
1980
2015
  "Authorization payload is required",
@@ -1984,27 +2019,40 @@ var executeEmbeddedSignInFlow = async ({
1984
2019
  "If an authorization payload is not provided, the request cannot be constructed correctly."
1985
2020
  );
1986
2021
  }
1987
- const response = await fetch(url ?? `${baseUrl}/oauth2/authn`, {
1988
- ...requestConfig,
1989
- method: requestConfig.method || "POST",
1990
- headers: {
1991
- "Content-Type": "application/json",
1992
- Accept: "application/json",
1993
- ...requestConfig.headers
1994
- },
1995
- body: JSON.stringify(payload)
1996
- });
1997
- if (!response.ok) {
1998
- const errorText = await response.text();
2022
+ try {
2023
+ const response = await fetch(url ?? `${baseUrl}/oauth2/authn`, {
2024
+ ...requestConfig,
2025
+ method: requestConfig.method || "POST",
2026
+ headers: {
2027
+ "Content-Type": "application/json",
2028
+ Accept: "application/json",
2029
+ ...requestConfig.headers
2030
+ },
2031
+ body: JSON.stringify(payload)
2032
+ });
2033
+ if (!response.ok) {
2034
+ const errorText = await response.text();
2035
+ throw new AsgardeoAPIError(
2036
+ `Authorization request failed: ${errorText}`,
2037
+ "initializeEmbeddedSignInFlow-ResponseError-001",
2038
+ "javascript",
2039
+ response.status,
2040
+ response.statusText
2041
+ );
2042
+ }
2043
+ return await response.json();
2044
+ } catch (error2) {
2045
+ if (error2 instanceof AsgardeoAPIError) {
2046
+ throw error2;
2047
+ }
1999
2048
  throw new AsgardeoAPIError(
2000
- `Authorization request failed: ${errorText}`,
2001
- "initializeEmbeddedSignInFlow-ResponseError-001",
2049
+ `Network or parsing error: ${error2 instanceof Error ? error2.message : "Unknown error"}`,
2050
+ "executeEmbeddedSignInFlow-NetworkError-001",
2002
2051
  "javascript",
2003
- response.status,
2004
- response.statusText
2052
+ 0,
2053
+ "Network Error"
2005
2054
  );
2006
2055
  }
2007
- return await response.json();
2008
2056
  };
2009
2057
  var executeEmbeddedSignInFlow_default = executeEmbeddedSignInFlow;
2010
2058
 
@@ -2053,30 +2101,54 @@ var executeEmbeddedSignUpFlow = async ({
2053
2101
  "At least one of the baseUrl or url must be provided to execute the embedded sign up flow."
2054
2102
  );
2055
2103
  }
2056
- const response = await fetch(url ?? `${baseUrl}/api/server/v1/flow/execute`, {
2057
- ...requestConfig,
2058
- method: requestConfig.method || "POST",
2059
- headers: {
2060
- "Content-Type": "application/json",
2061
- Accept: "application/json",
2062
- ...requestConfig.headers
2063
- },
2064
- body: JSON.stringify({
2065
- ...payload ?? {},
2066
- flowType: "REGISTRATION" /* Registration */
2067
- })
2068
- });
2069
- if (!response.ok) {
2070
- const errorText = await response.text();
2104
+ try {
2105
+ new URL(url ?? baseUrl);
2106
+ } catch (error2) {
2071
2107
  throw new AsgardeoAPIError(
2072
- `Embedded SignUp flow execution failed: ${errorText}`,
2073
- "javascript-executeEmbeddedSignUpFlow-ResponseError-100",
2108
+ `Invalid URL provided. ${error2?.toString()}`,
2109
+ "executeEmbeddedSignUpFlow-ValidationError-001",
2074
2110
  "javascript",
2075
- response.status,
2076
- response.statusText
2111
+ 400,
2112
+ "The provided `url` or `baseUrl` path does not adhere to the URL schema."
2113
+ );
2114
+ }
2115
+ try {
2116
+ const response = await fetch(url ?? `${baseUrl}/api/server/v1/flow/execute`, {
2117
+ ...requestConfig,
2118
+ method: requestConfig.method || "POST",
2119
+ headers: {
2120
+ "Content-Type": "application/json",
2121
+ Accept: "application/json",
2122
+ ...requestConfig.headers
2123
+ },
2124
+ body: JSON.stringify({
2125
+ ...payload ?? {},
2126
+ flowType: "REGISTRATION" /* Registration */
2127
+ })
2128
+ });
2129
+ if (!response.ok) {
2130
+ const errorText = await response.text();
2131
+ throw new AsgardeoAPIError(
2132
+ `Embedded SignUp flow execution failed: ${errorText}`,
2133
+ "javascript-executeEmbeddedSignUpFlow-ResponseError-100",
2134
+ "javascript",
2135
+ response.status,
2136
+ response.statusText
2137
+ );
2138
+ }
2139
+ return await response.json();
2140
+ } catch (error2) {
2141
+ if (error2 instanceof AsgardeoAPIError) {
2142
+ throw error2;
2143
+ }
2144
+ throw new AsgardeoAPIError(
2145
+ `Network or parsing error: ${error2 instanceof Error ? error2.message : "Unknown error"}`,
2146
+ "executeEmbeddedSignUpFlow-NetworkError-001",
2147
+ "javascript",
2148
+ 0,
2149
+ "Network Error"
2077
2150
  );
2078
2151
  }
2079
- return await response.json();
2080
2152
  };
2081
2153
  var executeEmbeddedSignUpFlow_default = executeEmbeddedSignUpFlow;
2082
2154
 
@@ -2093,26 +2165,39 @@ var getUserInfo = async ({ url, ...requestConfig }) => {
2093
2165
  "Invalid Request"
2094
2166
  );
2095
2167
  }
2096
- const response = await fetch(url, {
2097
- ...requestConfig,
2098
- method: "GET",
2099
- headers: {
2100
- "Content-Type": "application/json",
2101
- Accept: "application/json",
2102
- ...requestConfig.headers
2168
+ try {
2169
+ const response = await fetch(url, {
2170
+ ...requestConfig,
2171
+ method: "GET",
2172
+ headers: {
2173
+ "Content-Type": "application/json",
2174
+ Accept: "application/json",
2175
+ ...requestConfig.headers
2176
+ }
2177
+ });
2178
+ if (!response.ok) {
2179
+ const errorText = await response.text();
2180
+ throw new AsgardeoAPIError(
2181
+ `Failed to fetch user info: ${errorText}`,
2182
+ "getUserInfo-ResponseError-001",
2183
+ "javascript",
2184
+ response.status,
2185
+ response.statusText
2186
+ );
2187
+ }
2188
+ return await response.json();
2189
+ } catch (error2) {
2190
+ if (error2 instanceof AsgardeoAPIError) {
2191
+ throw error2;
2103
2192
  }
2104
- });
2105
- if (!response.ok) {
2106
- const errorText = await response.text();
2107
2193
  throw new AsgardeoAPIError(
2108
- `Failed to fetch user info: ${errorText}`,
2109
- "getUserInfo-ResponseError-001",
2194
+ `Network or parsing error: ${error2 instanceof Error ? error2.message : "Unknown error"}`,
2195
+ "getUserInfo-NetworkError-001",
2110
2196
  "javascript",
2111
- response.status,
2112
- response.statusText
2197
+ 0,
2198
+ "Network Error"
2113
2199
  );
2114
2200
  }
2115
- return await response.json();
2116
2201
  };
2117
2202
  var getUserInfo_default = getUserInfo;
2118
2203
 
@@ -3728,6 +3813,12 @@ var BROWSER_STYLES = {
3728
3813
  prefix: "color: #7c3aed; font-weight: bold;",
3729
3814
  timestamp: "color: #6b7280; font-size: 0.9em;"
3730
3815
  };
3816
+ var LOG_LEVEL_ORDER = {
3817
+ debug: 0,
3818
+ info: 1,
3819
+ warn: 2,
3820
+ error: 3
3821
+ };
3731
3822
  var Logger = class _Logger {
3732
3823
  constructor(config = {}) {
3733
3824
  __publicField(this, "config");
@@ -3749,7 +3840,7 @@ var Logger = class _Logger {
3749
3840
  * Check if a log level should be output
3750
3841
  */
3751
3842
  shouldLog(level) {
3752
- return level >= this.config.level;
3843
+ return LOG_LEVEL_ORDER[level] >= LOG_LEVEL_ORDER[this.config.level];
3753
3844
  }
3754
3845
  /**
3755
3846
  * Get timestamp string