@commercelayer/organization-config 2.3.0 → 2.5.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/getMfeConfig.ts"],"sourcesContent":["export {\n getMfeConfig,\n type MfeConfigs,\n type DefaultMfeConfig,\n} from \"./getMfeConfig\"\n","import { merge } from \"merge-anything\"\nimport type { ValidConfigForOrganizationsInCommerceLayer } from \"./schema/types\"\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 */\ntype 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 * Organization slug used to replace the `:slug` placeholder in URLs.\n */\n slug?: 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 * Order token string used to replace the `:token` placeholder in URLs.\n */\n token?: NullableType<string>\n /**\n * Unique identifier for an SKU list used to replace the `:sku_list_id` placeholder in URLs.\n */\n skuListId?: NullableType<string>\n /**\n * Unique identifier for an SKU used to replace the `:sku_id` placeholder in URLs.\n */\n skuId?: NullableType<string>\n}\n\ninterface GetMfeConfigProps {\n /**\n * `config` attribute of the organization\n */\n jsonConfig?: { mfe?: MfeConfigs }\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\nexport type MfeConfigs = NonNullable<\n ValidConfigForOrganizationsInCommerceLayer[\"mfe\"]\n>\n\nexport type DefaultMfeConfig = NonNullable<\n NonNullable<ValidConfigForOrganizationsInCommerceLayer[\"mfe\"]>[\"default\"]\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 getMfeConfig({\n jsonConfig,\n market,\n params,\n}: GetMfeConfigProps): DefaultMfeConfig | null {\n if (jsonConfig?.mfe == null) {\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: DefaultMfeConfig): DefaultMfeConfig {\n const replacedConfig = JSON.stringify(config)\n .replace(/:lang/g, params?.lang ?? \":lang\")\n .replace(/:slug/g, params?.slug ?? \":slug\")\n .replace(/:token/g, params?.token ?? \":token\")\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 .replace(/:sku_id/g, params?.skuId ?? \":sku_id\")\n\n return JSON.parse(replacedConfig)\n }\n\n const mergedConfig: DefaultMfeConfig = merge(\n JSON.parse(JSON.stringify(defaultConfig)),\n overrideConfig,\n )\n return replacePlaceholders(mergedConfig)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAsB,0BA2Ef,SAASC,EAAa,CAC3B,WAAAC,EACA,OAAAC,EACA,OAAAC,CACF,EAA+C,CA/E/C,IAAAC,EAAAC,EAAAC,EAgFE,IAAIL,GAAA,YAAAA,EAAY,MAAO,KACrB,OAAO,KAGT,IAAMM,GAAgBF,GAAAD,EAAAH,GAAA,YAAAA,EAAY,MAAZ,YAAAG,EAAiB,UAAjB,KAAAC,EAA4B,CAAC,EAC7CG,EAAiBN,GAAU,MAAQI,EAAAL,GAAA,YAAAA,EAAY,IAAIC,KAAhB,KAAAI,EAA2B,CAAC,EAAK,CAAC,EAG3E,SAASG,EAAoBC,EAA4C,CAxF3E,IAAAN,EAAAC,EAAAC,EAAAK,EAAAC,EAAAC,EAAAC,EAyFI,IAAMC,EAAiB,KAAK,UAAUL,CAAM,EACzC,QAAQ,UAAUN,EAAAD,GAAA,YAAAA,EAAQ,OAAR,KAAAC,EAAgB,OAAO,EACzC,QAAQ,UAAUC,EAAAF,GAAA,YAAAA,EAAQ,OAAR,KAAAE,EAAgB,OAAO,EACzC,QAAQ,WAAWC,EAAAH,GAAA,YAAAA,EAAQ,QAAR,KAAAG,EAAiB,QAAQ,EAC5C,QAAQ,kBAAkBK,EAAAR,GAAA,YAAAA,EAAQ,cAAR,KAAAQ,EAAuB,eAAe,EAChE,QAAQ,cAAcC,EAAAT,GAAA,YAAAA,EAAQ,UAAR,KAAAS,EAAmB,WAAW,EACpD,QAAQ,iBAAiBC,EAAAV,GAAA,YAAAA,EAAQ,YAAR,KAAAU,EAAqB,cAAc,EAC5D,QAAQ,YAAYC,EAAAX,GAAA,YAAAA,EAAQ,QAAR,KAAAW,EAAiB,SAAS,EAEjD,OAAO,KAAK,MAAMC,CAAc,CAClC,CAEA,IAAMC,KAAiC,SACrC,KAAK,MAAM,KAAK,UAAUT,CAAa,CAAC,EACxCC,CACF,EACA,OAAOC,EAAoBO,CAAY,CACzC","names":["index_exports","__export","getMfeConfig","__toCommonJS","import_merge_anything","getMfeConfig","jsonConfig","market","params","_a","_b","_c","defaultConfig","overrideConfig","replacePlaceholders","config","_d","_e","_f","_g","replacedConfig","mergedConfig"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/getMfeConfig.ts"],"sourcesContent":["export {\n type DefaultMfeConfig,\n getMfeConfig,\n type MfeConfigs,\n} from \"./getMfeConfig\"\n","import { merge } from \"merge-anything\"\nimport type { ValidConfigForOrganizationsInCommerceLayer } from \"./schema/types\"\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 */\ntype 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 * Organization slug used to replace the `:slug` placeholder in URLs.\n */\n slug?: 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 * Order token string used to replace the `:token` placeholder in URLs.\n */\n token?: NullableType<string>\n /**\n * Unique identifier for an SKU list used to replace the `:sku_list_id` placeholder in URLs.\n */\n skuListId?: NullableType<string>\n /**\n * Unique identifier for an SKU used to replace the `:sku_id` placeholder in URLs.\n */\n skuId?: NullableType<string>\n}\n\ninterface GetMfeConfigProps {\n /**\n * `config` attribute of the organization\n */\n jsonConfig?: { mfe?: MfeConfigs }\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\nexport type MfeConfigs = NonNullable<\n ValidConfigForOrganizationsInCommerceLayer[\"mfe\"]\n>\n\nexport type DefaultMfeConfig = NonNullable<\n NonNullable<ValidConfigForOrganizationsInCommerceLayer[\"mfe\"]>[\"default\"]\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 getMfeConfig({\n jsonConfig,\n market,\n params,\n}: GetMfeConfigProps): DefaultMfeConfig | null {\n if (jsonConfig?.mfe == null) {\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: DefaultMfeConfig): DefaultMfeConfig {\n const replacedConfig = JSON.stringify(config)\n .replace(/:lang/g, params?.lang ?? \":lang\")\n .replace(/:slug/g, params?.slug ?? \":slug\")\n .replace(/:token/g, params?.token ?? \":token\")\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 .replace(/:sku_id/g, params?.skuId ?? \":sku_id\")\n\n return JSON.parse(replacedConfig)\n }\n\n const mergedConfig: DefaultMfeConfig = merge(\n JSON.parse(JSON.stringify(defaultConfig)),\n overrideConfig,\n )\n return replacePlaceholders(mergedConfig)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAsB,0BA2Ef,SAASC,EAAa,CAC3B,WAAAC,EACA,OAAAC,EACA,OAAAC,CACF,EAA+C,CA/E/C,IAAAC,EAAAC,EAAAC,EAgFE,IAAIL,GAAA,YAAAA,EAAY,MAAO,KACrB,OAAO,KAGT,IAAMM,GAAgBF,GAAAD,EAAAH,GAAA,YAAAA,EAAY,MAAZ,YAAAG,EAAiB,UAAjB,KAAAC,EAA4B,CAAC,EAC7CG,EAAiBN,GAAU,MAAQI,EAAAL,GAAA,YAAAA,EAAY,IAAIC,KAAhB,KAAAI,EAA2B,CAAC,EAAK,CAAC,EAG3E,SAASG,EAAoBC,EAA4C,CAxF3E,IAAAN,EAAAC,EAAAC,EAAAK,EAAAC,EAAAC,EAAAC,EAyFI,IAAMC,EAAiB,KAAK,UAAUL,CAAM,EACzC,QAAQ,UAAUN,EAAAD,GAAA,YAAAA,EAAQ,OAAR,KAAAC,EAAgB,OAAO,EACzC,QAAQ,UAAUC,EAAAF,GAAA,YAAAA,EAAQ,OAAR,KAAAE,EAAgB,OAAO,EACzC,QAAQ,WAAWC,EAAAH,GAAA,YAAAA,EAAQ,QAAR,KAAAG,EAAiB,QAAQ,EAC5C,QAAQ,kBAAkBK,EAAAR,GAAA,YAAAA,EAAQ,cAAR,KAAAQ,EAAuB,eAAe,EAChE,QAAQ,cAAcC,EAAAT,GAAA,YAAAA,EAAQ,UAAR,KAAAS,EAAmB,WAAW,EACpD,QAAQ,iBAAiBC,EAAAV,GAAA,YAAAA,EAAQ,YAAR,KAAAU,EAAqB,cAAc,EAC5D,QAAQ,YAAYC,EAAAX,GAAA,YAAAA,EAAQ,QAAR,KAAAW,EAAiB,SAAS,EAEjD,OAAO,KAAK,MAAMC,CAAc,CAClC,CAEA,IAAMC,KAAiC,SACrC,KAAK,MAAM,KAAK,UAAUT,CAAa,CAAC,EACxCC,CACF,EACA,OAAOC,EAAoBO,CAAY,CACzC","names":["index_exports","__export","getMfeConfig","__toCommonJS","import_merge_anything","getMfeConfig","jsonConfig","market","params","_a","_b","_c","defaultConfig","overrideConfig","replacePlaceholders","config","_d","_e","_f","_g","replacedConfig","mergedConfig"]}
package/dist/index.d.cts CHANGED
@@ -4,6 +4,10 @@
4
4
  * and run json-schema-to-typescript to regenerate this file.
5
5
  */
6
6
  type Url = string;
7
+ /**
8
+ * Don't show promo code.
9
+ */
10
+ type HidePromoCode = boolean;
7
11
  /**
8
12
  * The international 2-letter country code as defined by the ISO 3166-1 standard.
9
13
  */
@@ -54,6 +58,10 @@ type StateCountry3 = {
54
58
  */
55
59
  label: string;
56
60
  }[];
61
+ /**
62
+ * Enable this option if you want to hide item codes.
63
+ */
64
+ type HideItemCodes = boolean;
57
65
  /**
58
66
  * Payload to use when using the config field of the Organization on CommerceLayer.
59
67
  */
@@ -62,6 +70,49 @@ interface ValidConfigForOrganizationsInCommerceLayer {
62
70
  default?: MfeConfig;
63
71
  [k: string]: MfeConfig | undefined;
64
72
  };
73
+ /**
74
+ * Default settings for apps.
75
+ */
76
+ apps?: {
77
+ /**
78
+ * Customers app settings.
79
+ */
80
+ customers?: {
81
+ /**
82
+ * Enable reset password flow for customers.
83
+ */
84
+ enable_reset_password?: boolean;
85
+ };
86
+ /**
87
+ * Orders app settings.
88
+ */
89
+ orders?: {
90
+ /**
91
+ * Enable this option to allow external price.
92
+ */
93
+ external_price?: boolean;
94
+ };
95
+ };
96
+ /**
97
+ * Organization API behavior settings.
98
+ */
99
+ api?: {
100
+ auth?: {
101
+ /**
102
+ * Allow JWT bearer token to see guest orders.
103
+ */
104
+ guest_orders?: boolean;
105
+ };
106
+ /**
107
+ * Stream pusher configuration.
108
+ */
109
+ stream?: {
110
+ /**
111
+ * Where streaming is enabled: none, live, test or both.
112
+ */
113
+ scope?: "none" | "live" | "test" | "both";
114
+ };
115
+ };
65
116
  [k: string]: unknown;
66
117
  }
67
118
  /**
@@ -85,8 +136,20 @@ interface MfeConfig {
85
136
  * Settings for the Checkout micro front end.
86
137
  */
87
138
  checkout?: {
88
- thankyou_page?: Url;
139
+ /**
140
+ * Billing details not required for processing.
141
+ */
89
142
  optional_billing_info?: boolean;
143
+ hide_promo_code?: HidePromoCode;
144
+ /**
145
+ * Company name not required for processing.
146
+ */
147
+ optional_company_name?: boolean;
148
+ /**
149
+ * Show notes.
150
+ */
151
+ show_notes?: boolean;
152
+ thankyou_page?: Url;
90
153
  billing_countries?: StateCountry;
91
154
  shipping_countries?: StateCountry1;
92
155
  default_country?: CountryCode;
@@ -102,6 +165,7 @@ interface MfeConfig {
102
165
  shipping_states?: {
103
166
  [k: string]: StateCountry3;
104
167
  };
168
+ hide_item_codes?: HideItemCodes;
105
169
  };
106
170
  /**
107
171
  * Checkout internal links settings.
@@ -114,6 +178,41 @@ interface MfeConfig {
114
178
  * Default language setting.
115
179
  */
116
180
  language?: string;
181
+ /**
182
+ * Cart settings.
183
+ */
184
+ cart?: {
185
+ hide_item_codes?: HideItemCodes;
186
+ hide_promo_code?: HidePromoCode;
187
+ };
188
+ /**
189
+ * Microstore settings.
190
+ */
191
+ microstore?: {
192
+ hide_item_codes?: HideItemCodes;
193
+ };
194
+ /**
195
+ * My Account settings.
196
+ */
197
+ my_account?: {
198
+ hide_item_codes?: HideItemCodes;
199
+ /**
200
+ * Enable this option if you want to hide returns.
201
+ */
202
+ hide_returns?: boolean;
203
+ /**
204
+ * Enable this option if you want to hide subscriptions.
205
+ */
206
+ hide_subscriptions?: boolean;
207
+ /**
208
+ * Don't show the wallet.
209
+ */
210
+ hide_wallet?: boolean;
211
+ /**
212
+ * Don't show the logout.
213
+ */
214
+ hide_logout?: boolean;
215
+ };
117
216
  }
118
217
 
119
218
  /**
package/dist/index.d.ts CHANGED
@@ -4,6 +4,10 @@
4
4
  * and run json-schema-to-typescript to regenerate this file.
5
5
  */
6
6
  type Url = string;
7
+ /**
8
+ * Don't show promo code.
9
+ */
10
+ type HidePromoCode = boolean;
7
11
  /**
8
12
  * The international 2-letter country code as defined by the ISO 3166-1 standard.
9
13
  */
@@ -54,6 +58,10 @@ type StateCountry3 = {
54
58
  */
55
59
  label: string;
56
60
  }[];
61
+ /**
62
+ * Enable this option if you want to hide item codes.
63
+ */
64
+ type HideItemCodes = boolean;
57
65
  /**
58
66
  * Payload to use when using the config field of the Organization on CommerceLayer.
59
67
  */
@@ -62,6 +70,49 @@ interface ValidConfigForOrganizationsInCommerceLayer {
62
70
  default?: MfeConfig;
63
71
  [k: string]: MfeConfig | undefined;
64
72
  };
73
+ /**
74
+ * Default settings for apps.
75
+ */
76
+ apps?: {
77
+ /**
78
+ * Customers app settings.
79
+ */
80
+ customers?: {
81
+ /**
82
+ * Enable reset password flow for customers.
83
+ */
84
+ enable_reset_password?: boolean;
85
+ };
86
+ /**
87
+ * Orders app settings.
88
+ */
89
+ orders?: {
90
+ /**
91
+ * Enable this option to allow external price.
92
+ */
93
+ external_price?: boolean;
94
+ };
95
+ };
96
+ /**
97
+ * Organization API behavior settings.
98
+ */
99
+ api?: {
100
+ auth?: {
101
+ /**
102
+ * Allow JWT bearer token to see guest orders.
103
+ */
104
+ guest_orders?: boolean;
105
+ };
106
+ /**
107
+ * Stream pusher configuration.
108
+ */
109
+ stream?: {
110
+ /**
111
+ * Where streaming is enabled: none, live, test or both.
112
+ */
113
+ scope?: "none" | "live" | "test" | "both";
114
+ };
115
+ };
65
116
  [k: string]: unknown;
66
117
  }
67
118
  /**
@@ -85,8 +136,20 @@ interface MfeConfig {
85
136
  * Settings for the Checkout micro front end.
86
137
  */
87
138
  checkout?: {
88
- thankyou_page?: Url;
139
+ /**
140
+ * Billing details not required for processing.
141
+ */
89
142
  optional_billing_info?: boolean;
143
+ hide_promo_code?: HidePromoCode;
144
+ /**
145
+ * Company name not required for processing.
146
+ */
147
+ optional_company_name?: boolean;
148
+ /**
149
+ * Show notes.
150
+ */
151
+ show_notes?: boolean;
152
+ thankyou_page?: Url;
90
153
  billing_countries?: StateCountry;
91
154
  shipping_countries?: StateCountry1;
92
155
  default_country?: CountryCode;
@@ -102,6 +165,7 @@ interface MfeConfig {
102
165
  shipping_states?: {
103
166
  [k: string]: StateCountry3;
104
167
  };
168
+ hide_item_codes?: HideItemCodes;
105
169
  };
106
170
  /**
107
171
  * Checkout internal links settings.
@@ -114,6 +178,41 @@ interface MfeConfig {
114
178
  * Default language setting.
115
179
  */
116
180
  language?: string;
181
+ /**
182
+ * Cart settings.
183
+ */
184
+ cart?: {
185
+ hide_item_codes?: HideItemCodes;
186
+ hide_promo_code?: HidePromoCode;
187
+ };
188
+ /**
189
+ * Microstore settings.
190
+ */
191
+ microstore?: {
192
+ hide_item_codes?: HideItemCodes;
193
+ };
194
+ /**
195
+ * My Account settings.
196
+ */
197
+ my_account?: {
198
+ hide_item_codes?: HideItemCodes;
199
+ /**
200
+ * Enable this option if you want to hide returns.
201
+ */
202
+ hide_returns?: boolean;
203
+ /**
204
+ * Enable this option if you want to hide subscriptions.
205
+ */
206
+ hide_subscriptions?: boolean;
207
+ /**
208
+ * Don't show the wallet.
209
+ */
210
+ hide_wallet?: boolean;
211
+ /**
212
+ * Don't show the logout.
213
+ */
214
+ hide_logout?: boolean;
215
+ };
117
216
  }
118
217
 
119
218
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/organization-config",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "description": "Organization config utils for extracting config by market",
5
5
  "author": {
6
6
  "name": "Matteo Alessani",
@@ -35,17 +35,17 @@
35
35
  "url": "https://github.com/commercelayer/common-utils/issues"
36
36
  },
37
37
  "devDependencies": {
38
- "@biomejs/biome": "^1.9.4",
39
- "@types/lodash": "^4.17.16",
40
- "@types/node": "^22.15.16",
38
+ "@biomejs/biome": "^2.3.5",
39
+ "@types/lodash": "^4.17.20",
40
+ "@types/node": "^24.10.1",
41
41
  "deepmerge": "^4.3.1",
42
42
  "deepmerge-ts": "^7.1.5",
43
43
  "json-schema-to-typescript": "^15.0.4",
44
44
  "lodash": "^4.17.21",
45
- "tsup": "^8.4.0",
46
- "type-fest": "^4.41.0",
47
- "typescript": "^5.8.3",
48
- "vitest": "^3.1.3"
45
+ "tsup": "^8.5.1",
46
+ "type-fest": "^5.2.0",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^4.0.10"
49
49
  },
50
50
  "dependencies": {
51
51
  "merge-anything": "^5.1.7"
@@ -58,6 +58,6 @@
58
58
  "bench": "vitest bench",
59
59
  "build": "tsup",
60
60
  "jsr:publish": "npx jsr publish",
61
- "generate:types": "node src/schema/generate.js"
61
+ "generate:types": "node src/schema/generate.js && pnpm run lint:fix"
62
62
  }
63
63
  }