@commercelayer/organization-config 1.4.6 → 1.4.8

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.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var S=(e,n)=>{for(var t in n)l(e,t,{get:n[t],enumerable:!0})},b=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of _(n))!N.call(e,i)&&i!==t&&l(e,i,{get:()=>n[i],enumerable:!(r=p(n,i))||r.enumerable});return e};var h=e=>b(l({},"__esModule",{value:!0}),e);var D={};S(D,{getConfig:()=>T});module.exports=h(D);var s=require("merge-anything");function T({jsonConfig:e,market:n,params:t}){var g,f,c;if((e==null?void 0:e.mfe)==null)return console.warn("No configuration found."),null;let r=(f=(g=e==null?void 0:e.mfe)==null?void 0:g.default)!=null?f:{},i=n!=null?(c=e==null?void 0:e.mfe[n])!=null?c:{}:{};function d(y){var o,u,a;let k=JSON.stringify(y).replace(/:lang/g,(o=t==null?void 0:t.lang)!=null?o:":lang").replace(/:access_token/g,(u=t==null?void 0:t.accessToken)!=null?u:":access_token").replace(/:order_id/g,(a=t==null?void 0:t.orderId)!=null?a:":order_id");return JSON.parse(k)}let C=(0,s.merge)(JSON.parse(JSON.stringify(r)),i);return d(C)}0&&(module.exports={getConfig});
1
+ "use strict";var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var S=(e,i)=>{for(var t in i)l(e,t,{get:i[t],enumerable:!0})},T=(e,i,t,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of N(i))!b.call(e,n)&&n!==t&&l(e,n,{get:()=>i[n],enumerable:!(r=p(i,n))||r.enumerable});return e};var h=e=>T(l({},"__esModule",{value:!0}),e);var P={};S(P,{getConfig:()=>D});module.exports=h(P);var d=require("merge-anything");function D({jsonConfig:e,market:i,params:t}){var g,u,c;if((e==null?void 0:e.mfe)==null)return console.warn("No configuration found."),null;let r=(u=(g=e==null?void 0:e.mfe)==null?void 0:g.default)!=null?u:{},n=i!=null?(c=e==null?void 0:e.mfe[i])!=null?c:{}:{};function C(k){var f,o,s,a;let _=JSON.stringify(k).replace(/:lang/g,(f=t==null?void 0:t.lang)!=null?f:":lang").replace(/:access_token/g,(o=t==null?void 0:t.accessToken)!=null?o:":access_token").replace(/:order_id/g,(s=t==null?void 0:t.orderId)!=null?s:":order_id").replace(/:sku_list_id/g,(a=t==null?void 0:t.skuListId)!=null?a:":sku_list_id");return JSON.parse(_)}let y=(0,d.merge)(JSON.parse(JSON.stringify(r)),n);return C(y)}0&&(module.exports={getConfig});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { merge } from 'merge-anything'\n\n/**\n * Represents a type that can be null or undefined, making it optional in use.\n * @template T The type that is being made nullable.\n */\nexport type NullableType<T> = T | null | undefined\n\n/**\n * Params used by the getConfig function\n */\ninterface ConfigParams {\n /**\n * Language code (e.g., 'en', 'fr') used to dynamically replace the `:lang` placeholder in URLs.\n */\n lang?: NullableType<string>\n /**\n * Access token string used to replace the `:access_token` placeholder in URLs.\n */\n accessToken?: NullableType<string>\n /**\n * Unique identifier for an order used to replace the `:order_id` placeholder in URLs.\n */\n orderId?: NullableType<string>\n}\n\n/**\n * Configuration for overriding default links of the micro frontends,\n * allowing customization of specific components.\n */\ninterface LinkConfig {\n /** URL for a custom cart. */\n cart?: string\n /** URL for a custom checkout */\n checkout?: string\n /** URL for a custom my account */\n my_account?: string\n /** URL for a custom identity */\n identity?: string\n}\n\ninterface Country {\n /** The country code (e.g., 'US', 'UK') */\n value: string\n /** The display name of the country (e.g., 'United States', 'United Kingdom') */\n label: string\n}\n\ninterface State {\n /** The province/state code (e.g., 'FI', 'LI') */\n value: string\n /** The display name of the province/state (e.g., 'Firenze', 'Livorno') */\n label: string\n}\n\ntype StatesConfig = Record<string, State[]>\n\n/**\n * Configuration settings for customizing the Checkout application.\n */\ninterface CheckoutConfig {\n /** URL for a custom thank you page displayed after completing a purchase. */\n thankyou_page?: string\n /** List of countries available for selection in billing address forms. */\n billing_countries?: Country[]\n /** List of countries available for selection in shipping address forms. */\n shipping_countries?: Country[]\n /** Configuration for states or regions to display in billing address forms, which may override default settings. */\n billing_states?: StatesConfig\n /** Configuration for states or regions to display in shipping address forms, which may override default settings. */\n shipping_states?: StatesConfig\n /** Country code preselected by default in billing and shipping address forms. */\n default_country?: string\n}\n\ninterface UrlsConfig {\n /** URL of the privacy policy page */\n privacy: string\n /** URL of the terms and conditions page */\n terms: string\n}\n\n/** Interface of the config of the organization */\nexport interface DefaultConfig {\n /** Custom links for overriding default micro frontends. */\n links?: LinkConfig\n /** Checkout-specific configuration, like custom thank you page and country lists. */\n checkout?: CheckoutConfig\n /** URLs for privacy policy and terms of service pages. */\n urls?: UrlsConfig\n}\n\n/** Configuration structure containing defaults and market-specific overrides. */\nexport interface Configs {\n /** Default configuration applicable to all markets. */\n default: DefaultConfig\n /** Market-specific configuration overrides, keyed by market identifier. */\n [key: string]: Partial<DefaultConfig>\n}\n\ninterface GetConfigProps {\n /**\n * `config` attribute of the organization\n */\n jsonConfig?: { mfe?: Configs }\n /**\n * Market identifier for fetching specific configuration overrides. (`market:id:hashid`)\n */\n market?: string\n /**\n * Parameters for replacing URL placeholders.\n */\n params?: ConfigParams\n}\n\n/**\n * Retrieves and merges the default organization configuration with market-specific overrides based on the provided market identifier.\n * Placeholder values in the configuration URLs can be replaced with actual values from the `params`.\n *\n * @param jsonConfig The complete configuration object of the organization.\n * @param market The market identifier used to get market-specific configuration overrides.\n * @param params The object containing replacement values for URL placeholders, such as language and access token.\n * @returns The merged configuration object for the specified market, or null if no configuration is found.\n */\nexport function getConfig({\n jsonConfig,\n market,\n params\n}: GetConfigProps): DefaultConfig | null {\n if (jsonConfig?.mfe == null) {\n console.warn('No configuration found.')\n return null\n }\n\n const defaultConfig = jsonConfig?.mfe?.default ?? {}\n const overrideConfig = market != null ? jsonConfig?.mfe[market] ?? {} : {}\n\n // Replace placeholders in all string values within the object\n function replacePlaceholders(config: DefaultConfig): DefaultConfig {\n const replacedConfig = JSON.stringify(config)\n .replace(/:lang/g, params?.lang ?? ':lang')\n .replace(/:access_token/g, params?.accessToken ?? ':access_token')\n .replace(/:order_id/g, params?.orderId ?? ':order_id')\n\n return JSON.parse(replacedConfig)\n }\n\n const mergedConfig: DefaultConfig = merge(\n JSON.parse(JSON.stringify(defaultConfig)),\n overrideConfig\n )\n return replacePlaceholders(mergedConfig)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsB,0BA4Hf,SAASF,EAAU,CACxB,WAAAG,EACA,OAAAC,EACA,OAAAC,CACF,EAAyC,CAhIzC,IAAAC,EAAAC,EAAAC,EAiIE,IAAIL,GAAA,YAAAA,EAAY,MAAO,KACrB,eAAQ,KAAK,yBAAyB,EAC/B,KAGT,IAAMM,GAAgBF,GAAAD,EAAAH,GAAA,YAAAA,EAAY,MAAZ,YAAAG,EAAiB,UAAjB,KAAAC,EAA4B,CAAC,EAC7CG,EAAiBN,GAAU,MAAOI,EAAAL,GAAA,YAAAA,EAAY,IAAIC,KAAhB,KAAAI,EAA2B,CAAC,EAAI,CAAC,EAGzE,SAASG,EAAoBC,EAAsC,CA1IrE,IAAAN,EAAAC,EAAAC,EA2II,IAAMK,EAAiB,KAAK,UAAUD,CAAM,EACzC,QAAQ,UAAUN,EAAAD,GAAA,YAAAA,EAAQ,OAAR,KAAAC,EAAgB,OAAO,EACzC,QAAQ,kBAAkBC,EAAAF,GAAA,YAAAA,EAAQ,cAAR,KAAAE,EAAuB,eAAe,EAChE,QAAQ,cAAcC,EAAAH,GAAA,YAAAA,EAAQ,UAAR,KAAAG,EAAmB,WAAW,EAEvD,OAAO,KAAK,MAAMK,CAAc,CAClC,CAEA,IAAMC,KAA8B,SAClC,KAAK,MAAM,KAAK,UAAUL,CAAa,CAAC,EACxCC,CACF,EACA,OAAOC,EAAoBG,CAAY,CACzC","names":["src_exports","__export","getConfig","__toCommonJS","import_merge_anything","jsonConfig","market","params","_a","_b","_c","defaultConfig","overrideConfig","replacePlaceholders","config","replacedConfig","mergedConfig"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { merge } from 'merge-anything'\n\n/**\n * Represents a type that can be null or undefined, making it optional in use.\n * @template T The type that is being made nullable.\n */\nexport type NullableType<T> = T | null | undefined\n\n/**\n * Params used by the getConfig function\n */\ninterface ConfigParams {\n /**\n * Language code (e.g., 'en', 'fr') used to dynamically replace the `:lang` placeholder in URLs.\n */\n lang?: NullableType<string>\n /**\n * Access token string used to replace the `:access_token` placeholder in URLs.\n */\n accessToken?: NullableType<string>\n /**\n * Unique identifier for an order used to replace the `:order_id` placeholder in URLs.\n */\n orderId?: NullableType<string>\n /**\n * Unique identifier for an SKU list used to replace the `:order_id` placeholder in URLs.\n */\n skuListId?: NullableType<string>\n}\n\n/**\n * Configuration for overriding default links of the micro frontends,\n * allowing customization of specific components.\n */\ninterface LinkConfig {\n /** URL for a custom cart. */\n cart?: string\n /** URL for a custom checkout */\n checkout?: string\n /** URL for a custom my account */\n my_account?: string\n /** URL for a custom identity */\n identity?: string\n /** URL for a custom microstore */\n microstore?: string\n}\n\ninterface Country {\n /** The country code (e.g., 'US', 'UK') */\n value: string\n /** The display name of the country (e.g., 'United States', 'United Kingdom') */\n label: string\n}\n\ninterface State {\n /** The province/state code (e.g., 'FI', 'LI') */\n value: string\n /** The display name of the province/state (e.g., 'Firenze', 'Livorno') */\n label: string\n}\n\ntype StatesConfig = Record<string, State[]>\n\n/**\n * Configuration settings for customizing the Checkout application.\n */\ninterface CheckoutConfig {\n /** URL for a custom thank you page displayed after completing a purchase. */\n thankyou_page?: string\n /** List of countries available for selection in billing address forms. */\n billing_countries?: Country[]\n /** List of countries available for selection in shipping address forms. */\n shipping_countries?: Country[]\n /** Configuration for states or regions to display in billing address forms, which may override default settings. */\n billing_states?: StatesConfig\n /** Configuration for states or regions to display in shipping address forms, which may override default settings. */\n shipping_states?: StatesConfig\n /** Country code preselected by default in billing and shipping address forms. */\n default_country?: string\n}\n\ninterface UrlsConfig {\n /** URL of the privacy policy page */\n privacy: string\n /** URL of the terms and conditions page */\n terms: string\n}\n\n/** Interface of the config of the organization */\nexport interface DefaultConfig {\n /** Custom links for overriding default micro frontends. */\n links?: LinkConfig\n /** Checkout-specific configuration, like custom thank you page and country lists. */\n checkout?: CheckoutConfig\n /** URLs for privacy policy and terms of service pages. */\n urls?: UrlsConfig\n}\n\n/** Configuration structure containing defaults and market-specific overrides. */\nexport interface Configs {\n /** Default configuration applicable to all markets. */\n default: DefaultConfig\n /** Market-specific configuration overrides, keyed by market identifier. */\n [key: string]: Partial<DefaultConfig>\n}\n\ninterface GetConfigProps {\n /**\n * `config` attribute of the organization\n */\n jsonConfig?: { mfe?: Configs }\n /**\n * Market identifier for fetching specific configuration overrides. (`market:id:hashid`)\n */\n market?: string\n /**\n * Parameters for replacing URL placeholders.\n */\n params?: ConfigParams\n}\n\n/**\n * Retrieves and merges the default organization configuration with market-specific overrides based on the provided market identifier.\n * Placeholder values in the configuration URLs can be replaced with actual values from the `params`.\n *\n * @param jsonConfig The complete configuration object of the organization.\n * @param market The market identifier used to get market-specific configuration overrides.\n * @param params The object containing replacement values for URL placeholders, such as language and access token.\n * @returns The merged configuration object for the specified market, or null if no configuration is found.\n */\nexport function getConfig({\n jsonConfig,\n market,\n params\n}: GetConfigProps): DefaultConfig | null {\n if (jsonConfig?.mfe == null) {\n console.warn('No configuration found.')\n return null\n }\n\n const defaultConfig = jsonConfig?.mfe?.default ?? {}\n const overrideConfig = market != null ? jsonConfig?.mfe[market] ?? {} : {}\n\n // Replace placeholders in all string values within the object\n function replacePlaceholders(config: DefaultConfig): DefaultConfig {\n const replacedConfig = JSON.stringify(config)\n .replace(/:lang/g, params?.lang ?? ':lang')\n .replace(/:access_token/g, params?.accessToken ?? ':access_token')\n .replace(/:order_id/g, params?.orderId ?? ':order_id')\n .replace(/:sku_list_id/g, params?.skuListId ?? ':sku_list_id')\n\n return JSON.parse(replacedConfig)\n }\n\n const mergedConfig: DefaultConfig = merge(\n JSON.parse(JSON.stringify(defaultConfig)),\n overrideConfig\n )\n return replacePlaceholders(mergedConfig)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsB,0BAkIf,SAASF,EAAU,CACxB,WAAAG,EACA,OAAAC,EACA,OAAAC,CACF,EAAyC,CAtIzC,IAAAC,EAAAC,EAAAC,EAuIE,IAAIL,GAAA,YAAAA,EAAY,MAAO,KACrB,eAAQ,KAAK,yBAAyB,EAC/B,KAGT,IAAMM,GAAgBF,GAAAD,EAAAH,GAAA,YAAAA,EAAY,MAAZ,YAAAG,EAAiB,UAAjB,KAAAC,EAA4B,CAAC,EAC7CG,EAAiBN,GAAU,MAAOI,EAAAL,GAAA,YAAAA,EAAY,IAAIC,KAAhB,KAAAI,EAA2B,CAAC,EAAI,CAAC,EAGzE,SAASG,EAAoBC,EAAsC,CAhJrE,IAAAN,EAAAC,EAAAC,EAAAK,EAiJI,IAAMC,EAAiB,KAAK,UAAUF,CAAM,EACzC,QAAQ,UAAUN,EAAAD,GAAA,YAAAA,EAAQ,OAAR,KAAAC,EAAgB,OAAO,EACzC,QAAQ,kBAAkBC,EAAAF,GAAA,YAAAA,EAAQ,cAAR,KAAAE,EAAuB,eAAe,EAChE,QAAQ,cAAcC,EAAAH,GAAA,YAAAA,EAAQ,UAAR,KAAAG,EAAmB,WAAW,EACpD,QAAQ,iBAAiBK,EAAAR,GAAA,YAAAA,EAAQ,YAAR,KAAAQ,EAAqB,cAAc,EAE/D,OAAO,KAAK,MAAMC,CAAc,CAClC,CAEA,IAAMC,KAA8B,SAClC,KAAK,MAAM,KAAK,UAAUN,CAAa,CAAC,EACxCC,CACF,EACA,OAAOC,EAAoBI,CAAY,CACzC","names":["src_exports","__export","getConfig","__toCommonJS","import_merge_anything","jsonConfig","market","params","_a","_b","_c","defaultConfig","overrideConfig","replacePlaceholders","config","_d","replacedConfig","mergedConfig"]}
package/dist/index.d.cts CHANGED
@@ -19,6 +19,10 @@ interface ConfigParams {
19
19
  * Unique identifier for an order used to replace the `:order_id` placeholder in URLs.
20
20
  */
21
21
  orderId?: NullableType<string>;
22
+ /**
23
+ * Unique identifier for an SKU list used to replace the `:order_id` placeholder in URLs.
24
+ */
25
+ skuListId?: NullableType<string>;
22
26
  }
23
27
  /**
24
28
  * Configuration for overriding default links of the micro frontends,
@@ -33,6 +37,8 @@ interface LinkConfig {
33
37
  my_account?: string;
34
38
  /** URL for a custom identity */
35
39
  identity?: string;
40
+ /** URL for a custom microstore */
41
+ microstore?: string;
36
42
  }
37
43
  interface Country {
38
44
  /** The country code (e.g., 'US', 'UK') */
package/dist/index.d.ts CHANGED
@@ -19,6 +19,10 @@ interface ConfigParams {
19
19
  * Unique identifier for an order used to replace the `:order_id` placeholder in URLs.
20
20
  */
21
21
  orderId?: NullableType<string>;
22
+ /**
23
+ * Unique identifier for an SKU list used to replace the `:order_id` placeholder in URLs.
24
+ */
25
+ skuListId?: NullableType<string>;
22
26
  }
23
27
  /**
24
28
  * Configuration for overriding default links of the micro frontends,
@@ -33,6 +37,8 @@ interface LinkConfig {
33
37
  my_account?: string;
34
38
  /** URL for a custom identity */
35
39
  identity?: string;
40
+ /** URL for a custom microstore */
41
+ microstore?: string;
36
42
  }
37
43
  interface Country {
38
44
  /** The country code (e.g., 'US', 'UK') */
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{merge as y}from"merge-anything";function p({jsonConfig:e,market:n,params:t}){var i,r,l;if((e==null?void 0:e.mfe)==null)return console.warn("No configuration found."),null;let o=(r=(i=e==null?void 0:e.mfe)==null?void 0:i.default)!=null?r:{},u=n!=null?(l=e==null?void 0:e.mfe[n])!=null?l:{}:{};function a(d){var g,f,c;let C=JSON.stringify(d).replace(/:lang/g,(g=t==null?void 0:t.lang)!=null?g:":lang").replace(/:access_token/g,(f=t==null?void 0:t.accessToken)!=null?f:":access_token").replace(/:order_id/g,(c=t==null?void 0:t.orderId)!=null?c:":order_id");return JSON.parse(C)}let s=y(JSON.parse(JSON.stringify(o)),u);return a(s)}export{p as getConfig};
1
+ import{merge as k}from"merge-anything";function p({jsonConfig:t,market:i,params:e}){var n,r,l;if((t==null?void 0:t.mfe)==null)return console.warn("No configuration found."),null;let o=(r=(n=t==null?void 0:t.mfe)==null?void 0:n.default)!=null?r:{},s=i!=null?(l=t==null?void 0:t.mfe[i])!=null?l:{}:{};function a(C){var g,u,c,f;let y=JSON.stringify(C).replace(/:lang/g,(g=e==null?void 0:e.lang)!=null?g:":lang").replace(/:access_token/g,(u=e==null?void 0:e.accessToken)!=null?u:":access_token").replace(/:order_id/g,(c=e==null?void 0:e.orderId)!=null?c:":order_id").replace(/:sku_list_id/g,(f=e==null?void 0:e.skuListId)!=null?f:":sku_list_id");return JSON.parse(y)}let d=k(JSON.parse(JSON.stringify(o)),s);return a(d)}export{p as getConfig};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { merge } from 'merge-anything'\n\n/**\n * Represents a type that can be null or undefined, making it optional in use.\n * @template T The type that is being made nullable.\n */\nexport type NullableType<T> = T | null | undefined\n\n/**\n * Params used by the getConfig function\n */\ninterface ConfigParams {\n /**\n * Language code (e.g., 'en', 'fr') used to dynamically replace the `:lang` placeholder in URLs.\n */\n lang?: NullableType<string>\n /**\n * Access token string used to replace the `:access_token` placeholder in URLs.\n */\n accessToken?: NullableType<string>\n /**\n * Unique identifier for an order used to replace the `:order_id` placeholder in URLs.\n */\n orderId?: NullableType<string>\n}\n\n/**\n * Configuration for overriding default links of the micro frontends,\n * allowing customization of specific components.\n */\ninterface LinkConfig {\n /** URL for a custom cart. */\n cart?: string\n /** URL for a custom checkout */\n checkout?: string\n /** URL for a custom my account */\n my_account?: string\n /** URL for a custom identity */\n identity?: string\n}\n\ninterface Country {\n /** The country code (e.g., 'US', 'UK') */\n value: string\n /** The display name of the country (e.g., 'United States', 'United Kingdom') */\n label: string\n}\n\ninterface State {\n /** The province/state code (e.g., 'FI', 'LI') */\n value: string\n /** The display name of the province/state (e.g., 'Firenze', 'Livorno') */\n label: string\n}\n\ntype StatesConfig = Record<string, State[]>\n\n/**\n * Configuration settings for customizing the Checkout application.\n */\ninterface CheckoutConfig {\n /** URL for a custom thank you page displayed after completing a purchase. */\n thankyou_page?: string\n /** List of countries available for selection in billing address forms. */\n billing_countries?: Country[]\n /** List of countries available for selection in shipping address forms. */\n shipping_countries?: Country[]\n /** Configuration for states or regions to display in billing address forms, which may override default settings. */\n billing_states?: StatesConfig\n /** Configuration for states or regions to display in shipping address forms, which may override default settings. */\n shipping_states?: StatesConfig\n /** Country code preselected by default in billing and shipping address forms. */\n default_country?: string\n}\n\ninterface UrlsConfig {\n /** URL of the privacy policy page */\n privacy: string\n /** URL of the terms and conditions page */\n terms: string\n}\n\n/** Interface of the config of the organization */\nexport interface DefaultConfig {\n /** Custom links for overriding default micro frontends. */\n links?: LinkConfig\n /** Checkout-specific configuration, like custom thank you page and country lists. */\n checkout?: CheckoutConfig\n /** URLs for privacy policy and terms of service pages. */\n urls?: UrlsConfig\n}\n\n/** Configuration structure containing defaults and market-specific overrides. */\nexport interface Configs {\n /** Default configuration applicable to all markets. */\n default: DefaultConfig\n /** Market-specific configuration overrides, keyed by market identifier. */\n [key: string]: Partial<DefaultConfig>\n}\n\ninterface GetConfigProps {\n /**\n * `config` attribute of the organization\n */\n jsonConfig?: { mfe?: Configs }\n /**\n * Market identifier for fetching specific configuration overrides. (`market:id:hashid`)\n */\n market?: string\n /**\n * Parameters for replacing URL placeholders.\n */\n params?: ConfigParams\n}\n\n/**\n * Retrieves and merges the default organization configuration with market-specific overrides based on the provided market identifier.\n * Placeholder values in the configuration URLs can be replaced with actual values from the `params`.\n *\n * @param jsonConfig The complete configuration object of the organization.\n * @param market The market identifier used to get market-specific configuration overrides.\n * @param params The object containing replacement values for URL placeholders, such as language and access token.\n * @returns The merged configuration object for the specified market, or null if no configuration is found.\n */\nexport function getConfig({\n jsonConfig,\n market,\n params\n}: GetConfigProps): DefaultConfig | null {\n if (jsonConfig?.mfe == null) {\n console.warn('No configuration found.')\n return null\n }\n\n const defaultConfig = jsonConfig?.mfe?.default ?? {}\n const overrideConfig = market != null ? jsonConfig?.mfe[market] ?? {} : {}\n\n // Replace placeholders in all string values within the object\n function replacePlaceholders(config: DefaultConfig): DefaultConfig {\n const replacedConfig = JSON.stringify(config)\n .replace(/:lang/g, params?.lang ?? ':lang')\n .replace(/:access_token/g, params?.accessToken ?? ':access_token')\n .replace(/:order_id/g, params?.orderId ?? ':order_id')\n\n return JSON.parse(replacedConfig)\n }\n\n const mergedConfig: DefaultConfig = merge(\n JSON.parse(JSON.stringify(defaultConfig)),\n overrideConfig\n )\n return replacePlaceholders(mergedConfig)\n}\n"],"mappings":"AAAA,OAAS,SAAAA,MAAa,iBA4Hf,SAASC,EAAU,CACxB,WAAAC,EACA,OAAAC,EACA,OAAAC,CACF,EAAyC,CAhIzC,IAAAC,EAAAC,EAAAC,EAiIE,IAAIL,GAAA,YAAAA,EAAY,MAAO,KACrB,eAAQ,KAAK,yBAAyB,EAC/B,KAGT,IAAMM,GAAgBF,GAAAD,EAAAH,GAAA,YAAAA,EAAY,MAAZ,YAAAG,EAAiB,UAAjB,KAAAC,EAA4B,CAAC,EAC7CG,EAAiBN,GAAU,MAAOI,EAAAL,GAAA,YAAAA,EAAY,IAAIC,KAAhB,KAAAI,EAA2B,CAAC,EAAI,CAAC,EAGzE,SAASG,EAAoBC,EAAsC,CA1IrE,IAAAN,EAAAC,EAAAC,EA2II,IAAMK,EAAiB,KAAK,UAAUD,CAAM,EACzC,QAAQ,UAAUN,EAAAD,GAAA,YAAAA,EAAQ,OAAR,KAAAC,EAAgB,OAAO,EACzC,QAAQ,kBAAkBC,EAAAF,GAAA,YAAAA,EAAQ,cAAR,KAAAE,EAAuB,eAAe,EAChE,QAAQ,cAAcC,EAAAH,GAAA,YAAAA,EAAQ,UAAR,KAAAG,EAAmB,WAAW,EAEvD,OAAO,KAAK,MAAMK,CAAc,CAClC,CAEA,IAAMC,EAA8Bb,EAClC,KAAK,MAAM,KAAK,UAAUQ,CAAa,CAAC,EACxCC,CACF,EACA,OAAOC,EAAoBG,CAAY,CACzC","names":["merge","getConfig","jsonConfig","market","params","_a","_b","_c","defaultConfig","overrideConfig","replacePlaceholders","config","replacedConfig","mergedConfig"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { merge } from 'merge-anything'\n\n/**\n * Represents a type that can be null or undefined, making it optional in use.\n * @template T The type that is being made nullable.\n */\nexport type NullableType<T> = T | null | undefined\n\n/**\n * Params used by the getConfig function\n */\ninterface ConfigParams {\n /**\n * Language code (e.g., 'en', 'fr') used to dynamically replace the `:lang` placeholder in URLs.\n */\n lang?: NullableType<string>\n /**\n * Access token string used to replace the `:access_token` placeholder in URLs.\n */\n accessToken?: NullableType<string>\n /**\n * Unique identifier for an order used to replace the `:order_id` placeholder in URLs.\n */\n orderId?: NullableType<string>\n /**\n * Unique identifier for an SKU list used to replace the `:order_id` placeholder in URLs.\n */\n skuListId?: NullableType<string>\n}\n\n/**\n * Configuration for overriding default links of the micro frontends,\n * allowing customization of specific components.\n */\ninterface LinkConfig {\n /** URL for a custom cart. */\n cart?: string\n /** URL for a custom checkout */\n checkout?: string\n /** URL for a custom my account */\n my_account?: string\n /** URL for a custom identity */\n identity?: string\n /** URL for a custom microstore */\n microstore?: string\n}\n\ninterface Country {\n /** The country code (e.g., 'US', 'UK') */\n value: string\n /** The display name of the country (e.g., 'United States', 'United Kingdom') */\n label: string\n}\n\ninterface State {\n /** The province/state code (e.g., 'FI', 'LI') */\n value: string\n /** The display name of the province/state (e.g., 'Firenze', 'Livorno') */\n label: string\n}\n\ntype StatesConfig = Record<string, State[]>\n\n/**\n * Configuration settings for customizing the Checkout application.\n */\ninterface CheckoutConfig {\n /** URL for a custom thank you page displayed after completing a purchase. */\n thankyou_page?: string\n /** List of countries available for selection in billing address forms. */\n billing_countries?: Country[]\n /** List of countries available for selection in shipping address forms. */\n shipping_countries?: Country[]\n /** Configuration for states or regions to display in billing address forms, which may override default settings. */\n billing_states?: StatesConfig\n /** Configuration for states or regions to display in shipping address forms, which may override default settings. */\n shipping_states?: StatesConfig\n /** Country code preselected by default in billing and shipping address forms. */\n default_country?: string\n}\n\ninterface UrlsConfig {\n /** URL of the privacy policy page */\n privacy: string\n /** URL of the terms and conditions page */\n terms: string\n}\n\n/** Interface of the config of the organization */\nexport interface DefaultConfig {\n /** Custom links for overriding default micro frontends. */\n links?: LinkConfig\n /** Checkout-specific configuration, like custom thank you page and country lists. */\n checkout?: CheckoutConfig\n /** URLs for privacy policy and terms of service pages. */\n urls?: UrlsConfig\n}\n\n/** Configuration structure containing defaults and market-specific overrides. */\nexport interface Configs {\n /** Default configuration applicable to all markets. */\n default: DefaultConfig\n /** Market-specific configuration overrides, keyed by market identifier. */\n [key: string]: Partial<DefaultConfig>\n}\n\ninterface GetConfigProps {\n /**\n * `config` attribute of the organization\n */\n jsonConfig?: { mfe?: Configs }\n /**\n * Market identifier for fetching specific configuration overrides. (`market:id:hashid`)\n */\n market?: string\n /**\n * Parameters for replacing URL placeholders.\n */\n params?: ConfigParams\n}\n\n/**\n * Retrieves and merges the default organization configuration with market-specific overrides based on the provided market identifier.\n * Placeholder values in the configuration URLs can be replaced with actual values from the `params`.\n *\n * @param jsonConfig The complete configuration object of the organization.\n * @param market The market identifier used to get market-specific configuration overrides.\n * @param params The object containing replacement values for URL placeholders, such as language and access token.\n * @returns The merged configuration object for the specified market, or null if no configuration is found.\n */\nexport function getConfig({\n jsonConfig,\n market,\n params\n}: GetConfigProps): DefaultConfig | null {\n if (jsonConfig?.mfe == null) {\n console.warn('No configuration found.')\n return null\n }\n\n const defaultConfig = jsonConfig?.mfe?.default ?? {}\n const overrideConfig = market != null ? jsonConfig?.mfe[market] ?? {} : {}\n\n // Replace placeholders in all string values within the object\n function replacePlaceholders(config: DefaultConfig): DefaultConfig {\n const replacedConfig = JSON.stringify(config)\n .replace(/:lang/g, params?.lang ?? ':lang')\n .replace(/:access_token/g, params?.accessToken ?? ':access_token')\n .replace(/:order_id/g, params?.orderId ?? ':order_id')\n .replace(/:sku_list_id/g, params?.skuListId ?? ':sku_list_id')\n\n return JSON.parse(replacedConfig)\n }\n\n const mergedConfig: DefaultConfig = merge(\n JSON.parse(JSON.stringify(defaultConfig)),\n overrideConfig\n )\n return replacePlaceholders(mergedConfig)\n}\n"],"mappings":"AAAA,OAAS,SAAAA,MAAa,iBAkIf,SAASC,EAAU,CACxB,WAAAC,EACA,OAAAC,EACA,OAAAC,CACF,EAAyC,CAtIzC,IAAAC,EAAAC,EAAAC,EAuIE,IAAIL,GAAA,YAAAA,EAAY,MAAO,KACrB,eAAQ,KAAK,yBAAyB,EAC/B,KAGT,IAAMM,GAAgBF,GAAAD,EAAAH,GAAA,YAAAA,EAAY,MAAZ,YAAAG,EAAiB,UAAjB,KAAAC,EAA4B,CAAC,EAC7CG,EAAiBN,GAAU,MAAOI,EAAAL,GAAA,YAAAA,EAAY,IAAIC,KAAhB,KAAAI,EAA2B,CAAC,EAAI,CAAC,EAGzE,SAASG,EAAoBC,EAAsC,CAhJrE,IAAAN,EAAAC,EAAAC,EAAAK,EAiJI,IAAMC,EAAiB,KAAK,UAAUF,CAAM,EACzC,QAAQ,UAAUN,EAAAD,GAAA,YAAAA,EAAQ,OAAR,KAAAC,EAAgB,OAAO,EACzC,QAAQ,kBAAkBC,EAAAF,GAAA,YAAAA,EAAQ,cAAR,KAAAE,EAAuB,eAAe,EAChE,QAAQ,cAAcC,EAAAH,GAAA,YAAAA,EAAQ,UAAR,KAAAG,EAAmB,WAAW,EACpD,QAAQ,iBAAiBK,EAAAR,GAAA,YAAAA,EAAQ,YAAR,KAAAQ,EAAqB,cAAc,EAE/D,OAAO,KAAK,MAAMC,CAAc,CAClC,CAEA,IAAMC,EAA8Bd,EAClC,KAAK,MAAM,KAAK,UAAUQ,CAAa,CAAC,EACxCC,CACF,EACA,OAAOC,EAAoBI,CAAY,CACzC","names":["merge","getConfig","jsonConfig","market","params","_a","_b","_c","defaultConfig","overrideConfig","replacePlaceholders","config","_d","replacedConfig","mergedConfig"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/organization-config",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
4
4
  "description": "Organization config utils for extracting config by market",
5
5
  "author": {
6
6
  "name": "Matteo Alessani",
@@ -35,13 +35,13 @@
35
35
  "url": "https://github.com/commercelayer/common-utils/issues"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/lodash": "^4.17.4",
38
+ "@types/lodash": "^4.17.6",
39
39
  "deepmerge": "^4.3.1",
40
- "deepmerge-ts": "^5.1.0",
40
+ "deepmerge-ts": "^7.0.3",
41
41
  "eslint": "^8.57.0",
42
42
  "lodash": "^4.17.21",
43
- "tsup": "^8.0.2",
44
- "typescript": "^5.4.5",
43
+ "tsup": "^8.1.0",
44
+ "typescript": "^5.5.2",
45
45
  "vitest": "^1.6.0",
46
46
  "@commercelayer/eslint-config-ts": "^1.4.5"
47
47
  },
@@ -59,6 +59,6 @@
59
59
  "test:verbose": "pnpm run lint && vitest run --silent=false",
60
60
  "bench": "vitest bench",
61
61
  "build": "tsup",
62
- "jsr:publish": "pnpm dlx jsr publish"
62
+ "jsr:publish": "npx jsr publish"
63
63
  }
64
64
  }