@asgardeo/javascript 0.1.1 → 0.1.2

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.d.ts CHANGED
@@ -30,6 +30,7 @@ export { default as getMeOrganizations, GetMeOrganizationsConfig } from './api/g
30
30
  export { default as getOrganization, OrganizationDetails, GetOrganizationConfig } from './api/getOrganization';
31
31
  export { default as updateOrganization, createPatchOperations, UpdateOrganizationConfig } from './api/updateOrganization';
32
32
  export { default as updateMeProfile, UpdateMeProfileConfig } from './api/updateMeProfile';
33
+ export { default as getBrandingPreference, GetBrandingPreferenceConfig } from './api/getBrandingPreference';
33
34
  export { default as ApplicationNativeAuthenticationConstants } from './constants/ApplicationNativeAuthenticationConstants';
34
35
  export { default as TokenConstants } from './constants/TokenConstants';
35
36
  export { default as OIDCRequestConstants } from './constants/OIDCRequestConstants';
@@ -52,14 +53,16 @@ export { Storage, TemporaryStore } from './models/store';
52
53
  export { User, UserProfile } from './models/user';
53
54
  export { SessionData } from './models/session';
54
55
  export { Organization } from './models/organization';
56
+ export { BrandingPreference, BrandingPreferenceConfig, BrandingLayout, BrandingTheme, ThemeVariant, ButtonsConfig, ColorsConfig, ColorVariants, BrandingOrganizationDetails, UrlsConfig, } from './models/branding-preference';
55
57
  export { Schema, SchemaAttribute, WellKnownSchemaIds, FlattenedSchema } from './models/scim2-schema';
56
58
  export { RecursivePartial } from './models/utility-types';
57
59
  export { FieldType } from './models/field';
58
60
  export { I18nBundle, I18nTranslations, I18nMetadata } from './models/i18n';
59
61
  export { default as AsgardeoJavaScriptClient } from './AsgardeoJavaScriptClient';
60
62
  export { default as createTheme } from './theme/createTheme';
61
- export { ThemeColors, ThemeConfig, Theme, ThemeMode } from './theme/types';
63
+ export { ThemeColors, ThemeConfig, Theme, ThemeMode, ThemeDetection } from './theme/types';
62
64
  export { default as deepMerge } from './utils/deepMerge';
65
+ export { default as deriveOrganizationHandleFromBaseUrl } from './utils/deriveOrganizationHandleFromBaseUrl';
63
66
  export { default as extractUserClaimsFromIdToken } from './utils/extractUserClaimsFromIdToken';
64
67
  export { default as extractPkceStorageKeyFromState } from './utils/extractPkceStorageKeyFromState';
65
68
  export { default as flattenUserSchema } from './utils/flattenUserSchema';
package/dist/index.js CHANGED
@@ -1949,16 +1949,15 @@ var initializeEmbeddedSignInFlow = async ({
1949
1949
  searchParams.append(key, String(value));
1950
1950
  }
1951
1951
  });
1952
- const { headers: customHeaders, ...otherConfig } = requestConfig;
1953
1952
  const response = await fetch(url ?? `${baseUrl}/oauth2/authorize`, {
1953
+ ...requestConfig,
1954
1954
  method: requestConfig.method || "POST",
1955
1955
  headers: {
1956
1956
  "Content-Type": "application/x-www-form-urlencoded",
1957
1957
  Accept: "application/json",
1958
- ...customHeaders
1958
+ ...requestConfig.headers
1959
1959
  },
1960
- body: searchParams.toString(),
1961
- ...otherConfig
1960
+ body: searchParams.toString()
1962
1961
  });
1963
1962
  if (!response.ok) {
1964
1963
  const errorText = await response.text();
@@ -1990,16 +1989,15 @@ var executeEmbeddedSignInFlow = async ({
1990
1989
  "If an authorization payload is not provided, the request cannot be constructed correctly."
1991
1990
  );
1992
1991
  }
1993
- const { headers: customHeaders, ...otherConfig } = requestConfig;
1994
1992
  const response = await fetch(url ?? `${baseUrl}/oauth2/authn`, {
1993
+ ...requestConfig,
1995
1994
  method: requestConfig.method || "POST",
1996
1995
  headers: {
1997
1996
  "Content-Type": "application/json",
1998
1997
  Accept: "application/json",
1999
- ...customHeaders
1998
+ ...requestConfig.headers
2000
1999
  },
2001
- body: JSON.stringify(payload),
2002
- ...otherConfig
2000
+ body: JSON.stringify(payload)
2003
2001
  });
2004
2002
  if (!response.ok) {
2005
2003
  const errorText = await response.text();
@@ -2059,19 +2057,18 @@ var executeEmbeddedSignUpFlow = async ({
2059
2057
  "At least one of the baseUrl or url must be provided to execute the embedded sign up flow."
2060
2058
  );
2061
2059
  }
2062
- const { headers: customHeaders, ...otherConfig } = requestConfig;
2063
2060
  const response = await fetch(url ?? `${baseUrl}/api/server/v1/flow/execute`, {
2061
+ ...requestConfig,
2064
2062
  method: requestConfig.method || "POST",
2065
2063
  headers: {
2066
2064
  "Content-Type": "application/json",
2067
2065
  Accept: "application/json",
2068
- ...customHeaders
2066
+ ...requestConfig.headers
2069
2067
  },
2070
2068
  body: JSON.stringify({
2071
2069
  ...payload ?? {},
2072
2070
  flowType: "REGISTRATION" /* Registration */
2073
- }),
2074
- ...otherConfig
2071
+ })
2075
2072
  });
2076
2073
  if (!response.ok) {
2077
2074
  const errorText = await response.text();
@@ -2101,12 +2098,13 @@ var getUserInfo = async ({ url, ...requestConfig }) => {
2101
2098
  );
2102
2099
  }
2103
2100
  const response = await fetch(url, {
2101
+ ...requestConfig,
2104
2102
  method: "GET",
2105
2103
  headers: {
2106
2104
  "Content-Type": "application/json",
2107
- Accept: "application/json"
2108
- },
2109
- ...requestConfig
2105
+ Accept: "application/json",
2106
+ ...requestConfig.headers
2107
+ }
2110
2108
  });
2111
2109
  if (!response.ok) {
2112
2110
  const errorText = await response.text();
@@ -2138,13 +2136,13 @@ var getScim2Me = async ({ url, baseUrl, fetcher, ...requestConfig }) => {
2138
2136
  const fetchFn = fetcher || fetch;
2139
2137
  const resolvedUrl = url ?? `${baseUrl}/scim2/Me`;
2140
2138
  const requestInit = {
2139
+ ...requestConfig,
2141
2140
  method: "GET",
2142
2141
  headers: {
2143
2142
  "Content-Type": "application/scim+json",
2144
2143
  Accept: "application/json",
2145
2144
  ...requestConfig.headers
2146
- },
2147
- ...requestConfig
2145
+ }
2148
2146
  };
2149
2147
  try {
2150
2148
  const response = await fetchFn(resolvedUrl, requestInit);
@@ -2190,13 +2188,13 @@ var getSchemas = async ({ url, baseUrl, fetcher, ...requestConfig }) => {
2190
2188
  const fetchFn = fetcher || fetch;
2191
2189
  const resolvedUrl = url ?? `${baseUrl}/scim2/Schemas`;
2192
2190
  const requestInit = {
2191
+ ...requestConfig,
2193
2192
  method: "GET",
2194
2193
  headers: {
2195
2194
  "Content-Type": "application/json",
2196
2195
  Accept: "application/json",
2197
2196
  ...requestConfig.headers
2198
- },
2199
- ...requestConfig
2197
+ }
2200
2198
  };
2201
2199
  try {
2202
2200
  const response = await fetchFn(resolvedUrl, requestInit);
@@ -2258,13 +2256,13 @@ var getAllOrganizations = async ({
2258
2256
  const fetchFn = fetcher || fetch;
2259
2257
  const resolvedUrl = `${baseUrl}/api/server/v1/organizations?${queryParams.toString()}`;
2260
2258
  const requestInit = {
2259
+ ...requestConfig,
2261
2260
  method: "GET",
2262
2261
  headers: {
2263
2262
  "Content-Type": "application/json",
2264
2263
  Accept: "application/json",
2265
2264
  ...requestConfig.headers
2266
- },
2267
- ...requestConfig
2265
+ }
2268
2266
  };
2269
2267
  try {
2270
2268
  const response = await fetchFn(resolvedUrl, requestInit);
@@ -2334,14 +2332,14 @@ var createOrganization = async ({
2334
2332
  const fetchFn = fetcher || fetch;
2335
2333
  const resolvedUrl = `${baseUrl}/api/server/v1/organizations`;
2336
2334
  const requestInit = {
2335
+ ...requestConfig,
2337
2336
  method: "POST",
2338
2337
  headers: {
2339
2338
  "Content-Type": "application/json",
2340
2339
  Accept: "application/json",
2341
2340
  ...requestConfig.headers
2342
2341
  },
2343
- body: JSON.stringify(organizationPayload),
2344
- ...requestConfig
2342
+ body: JSON.stringify(organizationPayload)
2345
2343
  };
2346
2344
  try {
2347
2345
  const response = await fetchFn(resolvedUrl, requestInit);
@@ -2409,13 +2407,13 @@ var getMeOrganizations = async ({
2409
2407
  const fetchFn = fetcher || fetch;
2410
2408
  const resolvedUrl = `${baseUrl}/api/users/v1/me/organizations?${queryParams.toString()}`;
2411
2409
  const requestInit = {
2410
+ ...requestConfig,
2412
2411
  method: "GET",
2413
2412
  headers: {
2414
2413
  "Content-Type": "application/json",
2415
2414
  Accept: "application/json",
2416
2415
  ...requestConfig.headers
2417
- },
2418
- ...requestConfig
2416
+ }
2419
2417
  };
2420
2418
  try {
2421
2419
  const response = await fetchFn(resolvedUrl, requestInit);
@@ -2476,13 +2474,13 @@ var getOrganization = async ({
2476
2474
  const fetchFn = fetcher || fetch;
2477
2475
  const resolvedUrl = `${baseUrl}/api/server/v1/organizations/${organizationId}`;
2478
2476
  const requestInit = {
2477
+ ...requestConfig,
2479
2478
  method: "GET",
2480
2479
  headers: {
2481
2480
  "Content-Type": "application/json",
2482
2481
  Accept: "application/json",
2483
2482
  ...requestConfig.headers
2484
- },
2485
- ...requestConfig
2483
+ }
2486
2484
  };
2487
2485
  try {
2488
2486
  const response = await fetchFn(resolvedUrl, requestInit);
@@ -2570,14 +2568,14 @@ var updateOrganization = async ({
2570
2568
  const fetchFn = fetcher || fetch;
2571
2569
  const resolvedUrl = `${baseUrl}/api/server/v1/organizations/${organizationId}`;
2572
2570
  const requestInit = {
2571
+ ...requestConfig,
2573
2572
  method: "PATCH",
2574
2573
  headers: {
2575
2574
  "Content-Type": "application/json",
2576
2575
  Accept: "application/json",
2577
2576
  ...requestConfig.headers
2578
2577
  },
2579
- body: JSON.stringify(operations),
2580
- ...requestConfig
2578
+ body: JSON.stringify(operations)
2581
2579
  };
2582
2580
  try {
2583
2581
  const response = await fetchFn(resolvedUrl, requestInit);
@@ -2654,13 +2652,13 @@ var updateMeProfile = async ({
2654
2652
  const resolvedUrl = url ?? `${baseUrl}/scim2/Me`;
2655
2653
  const requestInit = {
2656
2654
  method: "PATCH",
2655
+ ...requestConfig,
2657
2656
  headers: {
2657
+ ...requestConfig.headers,
2658
2658
  "Content-Type": "application/scim+json",
2659
- Accept: "application/json",
2660
- ...requestConfig.headers
2659
+ Accept: "application/json"
2661
2660
  },
2662
- body: JSON.stringify(data),
2663
- ...requestConfig
2661
+ body: JSON.stringify(data)
2664
2662
  };
2665
2663
  try {
2666
2664
  const response = await fetchFn(resolvedUrl, requestInit);
@@ -2690,6 +2688,75 @@ var updateMeProfile = async ({
2690
2688
  };
2691
2689
  var updateMeProfile_default = updateMeProfile;
2692
2690
 
2691
+ // src/api/getBrandingPreference.ts
2692
+ var getBrandingPreference = async ({
2693
+ baseUrl,
2694
+ locale,
2695
+ name,
2696
+ type,
2697
+ fetcher,
2698
+ ...requestConfig
2699
+ }) => {
2700
+ try {
2701
+ new URL(baseUrl);
2702
+ } catch (error) {
2703
+ throw new AsgardeoAPIError(
2704
+ `Invalid base URL provided. ${error?.toString()}`,
2705
+ "getBrandingPreference-ValidationError-001",
2706
+ "javascript",
2707
+ 400,
2708
+ "The provided `baseUrl` does not adhere to the URL schema."
2709
+ );
2710
+ }
2711
+ const queryParams = new URLSearchParams(
2712
+ Object.fromEntries(
2713
+ Object.entries({
2714
+ locale: locale || "",
2715
+ name: name || "",
2716
+ type: type || ""
2717
+ }).filter(([, value]) => Boolean(value))
2718
+ )
2719
+ );
2720
+ const fetchFn = fetcher || fetch;
2721
+ const resolvedUrl = `${baseUrl}/api/server/v1/branding-preference${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
2722
+ const requestInit = {
2723
+ ...requestConfig,
2724
+ method: "GET",
2725
+ headers: {
2726
+ "Content-Type": "application/json",
2727
+ Accept: "application/json",
2728
+ ...requestConfig.headers
2729
+ }
2730
+ };
2731
+ try {
2732
+ const response = await fetchFn(resolvedUrl, requestInit);
2733
+ if (!response?.ok) {
2734
+ const errorText = await response.text();
2735
+ throw new AsgardeoAPIError(
2736
+ `Failed to get branding preference: ${errorText}`,
2737
+ "getBrandingPreference-ResponseError-001",
2738
+ "javascript",
2739
+ response.status,
2740
+ response.statusText
2741
+ );
2742
+ }
2743
+ const data = await response.json();
2744
+ return data;
2745
+ } catch (error) {
2746
+ if (error instanceof AsgardeoAPIError) {
2747
+ throw error;
2748
+ }
2749
+ throw new AsgardeoAPIError(
2750
+ `Network or parsing error: ${error instanceof Error ? error.message : "Unknown error"}`,
2751
+ "getBrandingPreference-NetworkError-001",
2752
+ "javascript",
2753
+ 0,
2754
+ "Network Error"
2755
+ );
2756
+ }
2757
+ };
2758
+ var getBrandingPreference_default = getBrandingPreference;
2759
+
2693
2760
  // src/constants/ApplicationNativeAuthenticationConstants.ts
2694
2761
  var ApplicationNativeAuthenticationConstants = {
2695
2762
  SupportedAuthenticators: {
@@ -2978,6 +3045,58 @@ var deepMerge = (target, ...sources) => {
2978
3045
  };
2979
3046
  var deepMerge_default = deepMerge;
2980
3047
 
3048
+ // src/utils/deriveOrganizationHandleFromBaseUrl.ts
3049
+ var deriveOrganizationHandleFromBaseUrl = (baseUrl) => {
3050
+ if (!baseUrl) {
3051
+ throw new AsgardeoRuntimeError(
3052
+ "Base URL is required to derive organization handle.",
3053
+ "javascript-deriveOrganizationHandleFromBaseUrl-ValidationError-001",
3054
+ "javascript",
3055
+ "A valid base URL must be provided to extract the organization handle."
3056
+ );
3057
+ }
3058
+ let parsedUrl;
3059
+ try {
3060
+ parsedUrl = new URL(baseUrl);
3061
+ } catch (error) {
3062
+ throw new AsgardeoRuntimeError(
3063
+ `Invalid base URL format: ${baseUrl}`,
3064
+ "javascript-deriveOrganizationHandleFromBaseUrl-ValidationError-002",
3065
+ "javascript",
3066
+ "The provided base URL does not conform to valid URL syntax."
3067
+ );
3068
+ }
3069
+ const hostname = parsedUrl.hostname.toLowerCase();
3070
+ if (!hostname.endsWith(".asgardeo.io")) {
3071
+ throw new AsgardeoRuntimeError(
3072
+ "Organization handle is required since a custom domain is configured.",
3073
+ "javascript-deriveOrganizationHandleFromBaseUrl-CustomDomainError-001",
3074
+ "javascript",
3075
+ "The provided base URL uses a custom domain. Please provide the organizationHandle explicitly in the configuration."
3076
+ );
3077
+ }
3078
+ const pathSegments = parsedUrl.pathname.split("/").filter((segment) => segment.length > 0);
3079
+ if (pathSegments.length < 2 || pathSegments[0] !== "t") {
3080
+ throw new AsgardeoRuntimeError(
3081
+ "Organization handle is required since a custom domain is configured.",
3082
+ "javascript-deriveOrganizationHandleFromBaseUrl-CustomDomainError-002",
3083
+ "javascript",
3084
+ "The provided base URL does not follow the expected Asgardeo URL pattern (/t/{orgHandle}). Please provide the organizationHandle explicitly in the configuration."
3085
+ );
3086
+ }
3087
+ const organizationHandle = pathSegments[1];
3088
+ if (!organizationHandle || organizationHandle.trim().length === 0) {
3089
+ throw new AsgardeoRuntimeError(
3090
+ "Organization handle is required since a custom domain is configured.",
3091
+ "javascript-deriveOrganizationHandleFromBaseUrl-CustomDomainError-003",
3092
+ "javascript",
3093
+ "The organization handle could not be extracted from the base URL. Please provide the organizationHandle explicitly in the configuration."
3094
+ );
3095
+ }
3096
+ return organizationHandle;
3097
+ };
3098
+ var deriveOrganizationHandleFromBaseUrl_default = deriveOrganizationHandleFromBaseUrl;
3099
+
2981
3100
  // src/utils/flattenUserSchema.ts
2982
3101
  var flattenUserSchema = (schemas) => {
2983
3102
  const flattenedAttributes = [];
@@ -3336,6 +3455,7 @@ export {
3336
3455
  createPatchOperations,
3337
3456
  createTheme_default as createTheme,
3338
3457
  deepMerge_default as deepMerge,
3458
+ deriveOrganizationHandleFromBaseUrl_default as deriveOrganizationHandleFromBaseUrl,
3339
3459
  executeEmbeddedSignInFlow_default as executeEmbeddedSignInFlow,
3340
3460
  executeEmbeddedSignUpFlow_default as executeEmbeddedSignUpFlow,
3341
3461
  extractPkceStorageKeyFromState_default as extractPkceStorageKeyFromState,
@@ -3345,6 +3465,7 @@ export {
3345
3465
  generateUserProfile_default as generateUserProfile,
3346
3466
  get_default as get,
3347
3467
  getAllOrganizations_default as getAllOrganizations,
3468
+ getBrandingPreference_default as getBrandingPreference,
3348
3469
  getI18nBundles_default as getI18nBundles,
3349
3470
  getLatestStateParam_default as getLatestStateParam,
3350
3471
  getMeOrganizations_default as getMeOrganizations,