@commercelayer/organization-config 1.4.12 → 2.0.1
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +168 -72
- package/dist/index.d.ts +168 -72
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty,O=Object.defineProperties,T=Object.getOwnPropertyDescriptor,x=Object.getOwnPropertyDescriptors,F=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var m=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var b=(t,l,e)=>l in t?s(t,l,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[l]=e,D=(t,l)=>{for(var e in l||(l={}))m.call(l,e)&&b(t,e,l[e]);if(N)for(var e of N(l))W.call(l,e)&&b(t,e,l[e]);return t},I=(t,l)=>O(t,x(l));var L=(t,l)=>{for(var e in l)s(t,e,{get:l[e],enumerable:!0})},z=(t,l,e,n)=>{if(l&&typeof l=="object"||typeof l=="function")for(let i of F(l))!m.call(t,i)&&i!==e&&s(t,i,{get:()=>l[i],enumerable:!(n=T(l,i))||n.enumerable});return t};var P=t=>z(s({},"__esModule",{value:!0}),t);var H={};L(H,{getAppsConfig:()=>A,getMfeConfig:()=>k});module.exports=P(H);var h=require("merge-anything");function k({jsonConfig:t,market:l,params:e}){var r,o,g;if((t==null?void 0:t.mfe)==null)return null;let n=(o=(r=t==null?void 0:t.mfe)==null?void 0:r.default)!=null?o:{},i=l!=null?(g=t==null?void 0:t.mfe[l])!=null?g:{}:{};function f(_){var p,d,a,c,y,C;let M=JSON.stringify(_).replace(/:lang/g,(p=e==null?void 0:e.lang)!=null?p:":lang").replace(/:slug/g,(d=e==null?void 0:e.slug)!=null?d:":slug").replace(/:access_token/g,(a=e==null?void 0:e.accessToken)!=null?a:":access_token").replace(/:order_id/g,(c=e==null?void 0:e.orderId)!=null?c:":order_id").replace(/:sku_list_id/g,(y=e==null?void 0:e.skuListId)!=null?y:":sku_list_id").replace(/:sku_id/g,(C=e==null?void 0:e.skuId)!=null?C:":sku_id");return JSON.parse(M)}let u=(0,h.merge)(JSON.parse(JSON.stringify(n)),i);return f(u)}var V=["default","bundles","customers","exports","gift_cards","imports","inventory","orders","price_lists","promotions","resources","returns","shipments","skus","sku_lists","stock_transfers","subscriptions","tags","webhooks"];function A({jsonConfig:t}){var e;let l=(e=t==null?void 0:t.apps)!=null?e:{};return V.reduce((n,i)=>i==="default"?n:I(D({},n),{[i]:S(l,i)}),{})}function S(t,l){var f,u,r,o;let e=(u=(f=t.default)==null?void 0:f.hide)!=null?u:[],n=(o=(r=t[l])==null?void 0:r.hide)!=null?o:[];return{hide:Array.from(new Set(e.concat(n)))}}0&&(module.exports={getAppsConfig,getMfeConfig});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.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 */\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/getMfeConfig.ts","../src/getAppsConfig.ts"],"sourcesContent":["export {\n getMfeConfig,\n type MfeConfigs,\n type DefaultMfeConfig\n} from './getMfeConfig'\nexport {\n getAppsConfig,\n type FullAppsConfig,\n type AppsConfigWithDefault\n} from './getAppsConfig'\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 * 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(/: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","import { type ValidConfigForOrganizationsInCommerceLayer } from './schema/types'\n\nconst apps: Array<\n keyof NonNullable<ValidConfigForOrganizationsInCommerceLayer['apps']>\n> = [\n 'default',\n 'bundles',\n 'customers',\n 'exports',\n 'gift_cards',\n 'imports',\n 'inventory',\n 'orders',\n 'price_lists',\n 'promotions',\n 'resources',\n 'returns',\n 'shipments',\n 'skus',\n 'sku_lists',\n 'stock_transfers',\n 'subscriptions',\n 'tags',\n 'webhooks'\n]\n\nexport type AppsConfigWithDefault = NonNullable<\n ValidConfigForOrganizationsInCommerceLayer['apps']\n>\n\nexport type FullAppsConfig = Required<Omit<AppsConfigWithDefault, 'default'>>\n\ntype HideableItems = NonNullable<\n Required<AppsConfigWithDefault>['default']['hide']\n>\n\n/**\n * Get the apps configuration filling them with with the default values, if specified\n */\nexport function getAppsConfig({\n jsonConfig\n}: {\n /** `config` attribute of the organization */\n jsonConfig?: { apps?: AppsConfigWithDefault }\n}): FullAppsConfig {\n const cfg = jsonConfig?.apps ?? {}\n\n return apps.reduce((acc, key) => {\n if (key === 'default') {\n return acc\n }\n return {\n ...acc,\n [key]: mergeWithDefaults(cfg, key)\n }\n }, {}) as FullAppsConfig\n}\n\n/**\n * Merge the default `hide` array with the app specific `hide` array\n */\nfunction mergeWithDefaults<\n Item extends keyof Omit<AppsConfigWithDefault, 'default'>\n>(cfg: Partial<AppsConfigWithDefault>, app: Item): AppsConfigWithDefault[Item] {\n const defaultHide = cfg.default?.hide ?? []\n const itemHide = (cfg[app]?.hide ?? []) as HideableItems\n const mergedDeduped = Array.from(new Set(defaultHide.concat(itemHide)))\n return {\n hide: mergedDeduped\n }\n}\n"],"mappings":"owBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,iBAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAAsB,0BAuEf,SAASC,EAAa,CAC3B,WAAAC,EACA,OAAAC,EACA,OAAAC,CACF,EAA+C,CA3E/C,IAAAC,EAAAC,EAAAC,EA4EE,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,CApF3E,IAAAN,EAAAC,EAAAC,EAAAK,EAAAC,EAAAC,EAqFI,IAAMC,EAAiB,KAAK,UAAUJ,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,kBAAkBC,EAAAH,GAAA,YAAAA,EAAQ,cAAR,KAAAG,EAAuB,eAAe,EAChE,QAAQ,cAAcK,EAAAR,GAAA,YAAAA,EAAQ,UAAR,KAAAQ,EAAmB,WAAW,EACpD,QAAQ,iBAAiBC,EAAAT,GAAA,YAAAA,EAAQ,YAAR,KAAAS,EAAqB,cAAc,EAC5D,QAAQ,YAAYC,EAAAV,GAAA,YAAAA,EAAQ,QAAR,KAAAU,EAAiB,SAAS,EAEjD,OAAO,KAAK,MAAMC,CAAc,CAClC,CAEA,IAAMC,KAAiC,SACrC,KAAK,MAAM,KAAK,UAAUR,CAAa,CAAC,EACxCC,CACF,EACA,OAAOC,EAAoBM,CAAY,CACzC,CCnGA,IAAMC,EAEF,CACF,UACA,UACA,YACA,UACA,aACA,UACA,YACA,SACA,cACA,aACA,YACA,UACA,YACA,OACA,YACA,kBACA,gBACA,OACA,UACF,EAeO,SAASC,EAAc,CAC5B,WAAAC,CACF,EAGmB,CA5CnB,IAAAC,EA6CE,IAAMC,GAAMD,EAAAD,GAAA,YAAAA,EAAY,OAAZ,KAAAC,EAAoB,CAAC,EAEjC,OAAOH,EAAK,OAAO,CAACK,EAAKC,IACnBA,IAAQ,UACHD,EAEFE,EAAAC,EAAA,GACFH,GADE,CAEL,CAACC,CAAG,EAAGG,EAAkBL,EAAKE,CAAG,CACnC,GACC,CAAC,CAAC,CACP,CAKA,SAASG,EAEPL,EAAqCM,EAAwC,CA/D/E,IAAAP,EAAAQ,EAAAC,EAAAC,EAgEE,IAAMC,GAAcH,GAAAR,EAAAC,EAAI,UAAJ,YAAAD,EAAa,OAAb,KAAAQ,EAAqB,CAAC,EACpCI,GAAYF,GAAAD,EAAAR,EAAIM,CAAG,IAAP,YAAAE,EAAU,OAAV,KAAAC,EAAkB,CAAC,EAErC,MAAO,CACL,KAFoB,MAAM,KAAK,IAAI,IAAIC,EAAY,OAAOC,CAAQ,CAAC,CAAC,CAGtE,CACF","names":["src_exports","__export","getAppsConfig","getMfeConfig","__toCommonJS","import_merge_anything","getMfeConfig","jsonConfig","market","params","_a","_b","_c","defaultConfig","overrideConfig","replacePlaceholders","config","_d","_e","_f","replacedConfig","mergedConfig","apps","getAppsConfig","jsonConfig","_a","cfg","acc","key","__spreadProps","__spreadValues","mergeWithDefaults","app","_b","_c","_d","defaultHide","itemHide"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
3
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
5
|
+
*/
|
|
6
|
+
type Url = string;
|
|
7
|
+
/**
|
|
8
|
+
* The international 2-letter country code as defined by the ISO 3166-1 standard.
|
|
9
|
+
*/
|
|
10
|
+
type CountryCode = string;
|
|
11
|
+
/**
|
|
12
|
+
* List of billing countries by identifier and label.
|
|
13
|
+
*/
|
|
14
|
+
type StateCountry = {
|
|
15
|
+
value: CountryCode;
|
|
16
|
+
/**
|
|
17
|
+
* Name of the country.
|
|
18
|
+
*/
|
|
19
|
+
label: string;
|
|
20
|
+
}[];
|
|
21
|
+
/**
|
|
22
|
+
* List of shipping countries by identifier and label.
|
|
23
|
+
*/
|
|
24
|
+
type StateCountry1 = {
|
|
25
|
+
value: CountryCode;
|
|
26
|
+
/**
|
|
27
|
+
* Name of the country.
|
|
28
|
+
*/
|
|
29
|
+
label: string;
|
|
30
|
+
}[];
|
|
31
|
+
/**
|
|
32
|
+
* List of shipping countries by identifier and label.
|
|
33
|
+
*
|
|
34
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
35
|
+
* via the `patternProperty` "^.*$".
|
|
36
|
+
*/
|
|
37
|
+
type StateCountry2 = {
|
|
38
|
+
value: CountryCode;
|
|
39
|
+
/**
|
|
40
|
+
* Name of the country.
|
|
41
|
+
*/
|
|
42
|
+
label: string;
|
|
43
|
+
}[];
|
|
44
|
+
/**
|
|
45
|
+
* List of shipping countries by identifier and label.
|
|
46
|
+
*
|
|
47
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
48
|
+
* via the `patternProperty` "^.*$".
|
|
49
|
+
*/
|
|
50
|
+
type StateCountry3 = {
|
|
51
|
+
value: CountryCode;
|
|
52
|
+
/**
|
|
53
|
+
* Name of the country.
|
|
54
|
+
*/
|
|
55
|
+
label: string;
|
|
56
|
+
}[];
|
|
57
|
+
/**
|
|
58
|
+
* Payload to use when using the config field of the Organization on CommerceLayer.
|
|
59
|
+
*/
|
|
60
|
+
interface ValidConfigForOrganizationsInCommerceLayer {
|
|
61
|
+
mfe?: {
|
|
62
|
+
default?: MfeConfig;
|
|
63
|
+
[k: string]: MfeConfig | undefined;
|
|
64
|
+
};
|
|
65
|
+
apps?: {
|
|
66
|
+
default?: AppsConfig;
|
|
67
|
+
bundles?: AppsConfig;
|
|
68
|
+
/**
|
|
69
|
+
* Settings for app-customers.
|
|
70
|
+
*/
|
|
71
|
+
customers?: {
|
|
72
|
+
hide?: ("metadata" | "tags" | "details" | "customer_groups")[] | null;
|
|
73
|
+
};
|
|
74
|
+
exports?: AppsConfig;
|
|
75
|
+
gift_cards?: AppsConfig;
|
|
76
|
+
imports?: AppsConfig;
|
|
77
|
+
inventory?: AppsConfig;
|
|
78
|
+
/**
|
|
79
|
+
* Settings for app-orders.
|
|
80
|
+
*/
|
|
81
|
+
orders?: {
|
|
82
|
+
hide?: ("metadata" | "tags" | "details" | "markets")[] | null;
|
|
83
|
+
};
|
|
84
|
+
price_lists?: AppsConfig;
|
|
85
|
+
promotions?: AppsConfig;
|
|
86
|
+
resources?: AppsConfig;
|
|
87
|
+
returns?: AppsConfig;
|
|
88
|
+
shipments?: AppsConfig;
|
|
89
|
+
skus?: AppsConfig;
|
|
90
|
+
sku_lists?: AppsConfig;
|
|
91
|
+
stock_transfers?: AppsConfig;
|
|
92
|
+
subscriptions?: AppsConfig;
|
|
93
|
+
tags?: AppsConfig;
|
|
94
|
+
webhooks?: AppsConfig;
|
|
95
|
+
};
|
|
96
|
+
[k: string]: unknown;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Default settings for links and checkout.
|
|
100
|
+
*
|
|
101
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
102
|
+
* via the `patternProperty` "^market:id:[a-zA-Z0-9]*$$".
|
|
103
|
+
*/
|
|
104
|
+
interface MfeConfig {
|
|
105
|
+
/**
|
|
106
|
+
* Links for specific micro frontends.
|
|
107
|
+
*/
|
|
108
|
+
links?: {
|
|
109
|
+
cart?: Url;
|
|
110
|
+
checkout?: Url;
|
|
111
|
+
identity?: Url;
|
|
112
|
+
microstore?: Url;
|
|
113
|
+
my_account?: Url;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Settings for the Checkout micro front end.
|
|
117
|
+
*/
|
|
118
|
+
checkout?: {
|
|
119
|
+
thankyou_page?: Url;
|
|
120
|
+
billing_countries?: StateCountry;
|
|
121
|
+
shipping_countries?: StateCountry1;
|
|
122
|
+
default_country?: CountryCode;
|
|
123
|
+
/**
|
|
124
|
+
* List of states by country with identifier and label.
|
|
125
|
+
*/
|
|
126
|
+
billing_states?: {
|
|
127
|
+
[k: string]: StateCountry2;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* List of states by country with identifier and label.
|
|
131
|
+
*/
|
|
132
|
+
shipping_states?: {
|
|
133
|
+
[k: string]: StateCountry3;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Checkout internal links settings.
|
|
138
|
+
*/
|
|
139
|
+
urls?: {
|
|
140
|
+
privacy?: Url;
|
|
141
|
+
terms?: Url;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Default settings for the app.
|
|
146
|
+
*/
|
|
147
|
+
interface AppsConfig {
|
|
148
|
+
hide?: ("metadata" | "tags" | "details")[] | null;
|
|
149
|
+
}
|
|
150
|
+
|
|
1
151
|
/**
|
|
2
152
|
* Represents a type that can be null or undefined, making it optional in use.
|
|
3
153
|
* @template T The type that is being made nullable.
|
|
@@ -32,80 +182,12 @@ interface ConfigParams {
|
|
|
32
182
|
*/
|
|
33
183
|
skuId?: NullableType<string>;
|
|
34
184
|
}
|
|
35
|
-
|
|
36
|
-
* Configuration for overriding default links of the micro frontends,
|
|
37
|
-
* allowing customization of specific components.
|
|
38
|
-
*/
|
|
39
|
-
interface LinkConfig {
|
|
40
|
-
/** URL for a custom cart. */
|
|
41
|
-
cart?: string;
|
|
42
|
-
/** URL for a custom checkout */
|
|
43
|
-
checkout?: string;
|
|
44
|
-
/** URL for a custom my account */
|
|
45
|
-
my_account?: string;
|
|
46
|
-
/** URL for a custom identity */
|
|
47
|
-
identity?: string;
|
|
48
|
-
/** URL for a custom microstore */
|
|
49
|
-
microstore?: string;
|
|
50
|
-
}
|
|
51
|
-
interface Country {
|
|
52
|
-
/** The country code (e.g., 'US', 'UK') */
|
|
53
|
-
value: string;
|
|
54
|
-
/** The display name of the country (e.g., 'United States', 'United Kingdom') */
|
|
55
|
-
label: string;
|
|
56
|
-
}
|
|
57
|
-
interface State {
|
|
58
|
-
/** The province/state code (e.g., 'FI', 'LI') */
|
|
59
|
-
value: string;
|
|
60
|
-
/** The display name of the province/state (e.g., 'Firenze', 'Livorno') */
|
|
61
|
-
label: string;
|
|
62
|
-
}
|
|
63
|
-
type StatesConfig = Record<string, State[]>;
|
|
64
|
-
/**
|
|
65
|
-
* Configuration settings for customizing the Checkout application.
|
|
66
|
-
*/
|
|
67
|
-
interface CheckoutConfig {
|
|
68
|
-
/** URL for a custom thank you page displayed after completing a purchase. */
|
|
69
|
-
thankyou_page?: string;
|
|
70
|
-
/** List of countries available for selection in billing address forms. */
|
|
71
|
-
billing_countries?: Country[];
|
|
72
|
-
/** List of countries available for selection in shipping address forms. */
|
|
73
|
-
shipping_countries?: Country[];
|
|
74
|
-
/** Configuration for states or regions to display in billing address forms, which may override default settings. */
|
|
75
|
-
billing_states?: StatesConfig;
|
|
76
|
-
/** Configuration for states or regions to display in shipping address forms, which may override default settings. */
|
|
77
|
-
shipping_states?: StatesConfig;
|
|
78
|
-
/** Country code preselected by default in billing and shipping address forms. */
|
|
79
|
-
default_country?: string;
|
|
80
|
-
}
|
|
81
|
-
interface UrlsConfig {
|
|
82
|
-
/** URL of the privacy policy page */
|
|
83
|
-
privacy: string;
|
|
84
|
-
/** URL of the terms and conditions page */
|
|
85
|
-
terms: string;
|
|
86
|
-
}
|
|
87
|
-
/** Interface of the config of the organization */
|
|
88
|
-
interface DefaultConfig {
|
|
89
|
-
/** Custom links for overriding default micro frontends. */
|
|
90
|
-
links?: LinkConfig;
|
|
91
|
-
/** Checkout-specific configuration, like custom thank you page and country lists. */
|
|
92
|
-
checkout?: CheckoutConfig;
|
|
93
|
-
/** URLs for privacy policy and terms of service pages. */
|
|
94
|
-
urls?: UrlsConfig;
|
|
95
|
-
}
|
|
96
|
-
/** Configuration structure containing defaults and market-specific overrides. */
|
|
97
|
-
interface Configs {
|
|
98
|
-
/** Default configuration applicable to all markets. */
|
|
99
|
-
default: DefaultConfig;
|
|
100
|
-
/** Market-specific configuration overrides, keyed by market identifier. */
|
|
101
|
-
[key: string]: Partial<DefaultConfig>;
|
|
102
|
-
}
|
|
103
|
-
interface GetConfigProps {
|
|
185
|
+
interface GetMfeConfigProps {
|
|
104
186
|
/**
|
|
105
187
|
* `config` attribute of the organization
|
|
106
188
|
*/
|
|
107
189
|
jsonConfig?: {
|
|
108
|
-
mfe?:
|
|
190
|
+
mfe?: MfeConfigs;
|
|
109
191
|
};
|
|
110
192
|
/**
|
|
111
193
|
* Market identifier for fetching specific configuration overrides. (`market:id:hashid`)
|
|
@@ -116,6 +198,8 @@ interface GetConfigProps {
|
|
|
116
198
|
*/
|
|
117
199
|
params?: ConfigParams;
|
|
118
200
|
}
|
|
201
|
+
type MfeConfigs = NonNullable<ValidConfigForOrganizationsInCommerceLayer['mfe']>;
|
|
202
|
+
type DefaultMfeConfig = NonNullable<NonNullable<ValidConfigForOrganizationsInCommerceLayer['mfe']>['default']>;
|
|
119
203
|
/**
|
|
120
204
|
* Retrieves and merges the default organization configuration with market-specific overrides based on the provided market identifier.
|
|
121
205
|
* Placeholder values in the configuration URLs can be replaced with actual values from the `params`.
|
|
@@ -125,6 +209,18 @@ interface GetConfigProps {
|
|
|
125
209
|
* @param params The object containing replacement values for URL placeholders, such as language and access token.
|
|
126
210
|
* @returns The merged configuration object for the specified market, or null if no configuration is found.
|
|
127
211
|
*/
|
|
128
|
-
declare function
|
|
212
|
+
declare function getMfeConfig({ jsonConfig, market, params }: GetMfeConfigProps): DefaultMfeConfig | null;
|
|
213
|
+
|
|
214
|
+
type AppsConfigWithDefault = NonNullable<ValidConfigForOrganizationsInCommerceLayer['apps']>;
|
|
215
|
+
type FullAppsConfig = Required<Omit<AppsConfigWithDefault, 'default'>>;
|
|
216
|
+
/**
|
|
217
|
+
* Get the apps configuration filling them with with the default values, if specified
|
|
218
|
+
*/
|
|
219
|
+
declare function getAppsConfig({ jsonConfig }: {
|
|
220
|
+
/** `config` attribute of the organization */
|
|
221
|
+
jsonConfig?: {
|
|
222
|
+
apps?: AppsConfigWithDefault;
|
|
223
|
+
};
|
|
224
|
+
}): FullAppsConfig;
|
|
129
225
|
|
|
130
|
-
export { type
|
|
226
|
+
export { type AppsConfigWithDefault, type DefaultMfeConfig, type FullAppsConfig, type MfeConfigs, getAppsConfig, getMfeConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
3
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
5
|
+
*/
|
|
6
|
+
type Url = string;
|
|
7
|
+
/**
|
|
8
|
+
* The international 2-letter country code as defined by the ISO 3166-1 standard.
|
|
9
|
+
*/
|
|
10
|
+
type CountryCode = string;
|
|
11
|
+
/**
|
|
12
|
+
* List of billing countries by identifier and label.
|
|
13
|
+
*/
|
|
14
|
+
type StateCountry = {
|
|
15
|
+
value: CountryCode;
|
|
16
|
+
/**
|
|
17
|
+
* Name of the country.
|
|
18
|
+
*/
|
|
19
|
+
label: string;
|
|
20
|
+
}[];
|
|
21
|
+
/**
|
|
22
|
+
* List of shipping countries by identifier and label.
|
|
23
|
+
*/
|
|
24
|
+
type StateCountry1 = {
|
|
25
|
+
value: CountryCode;
|
|
26
|
+
/**
|
|
27
|
+
* Name of the country.
|
|
28
|
+
*/
|
|
29
|
+
label: string;
|
|
30
|
+
}[];
|
|
31
|
+
/**
|
|
32
|
+
* List of shipping countries by identifier and label.
|
|
33
|
+
*
|
|
34
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
35
|
+
* via the `patternProperty` "^.*$".
|
|
36
|
+
*/
|
|
37
|
+
type StateCountry2 = {
|
|
38
|
+
value: CountryCode;
|
|
39
|
+
/**
|
|
40
|
+
* Name of the country.
|
|
41
|
+
*/
|
|
42
|
+
label: string;
|
|
43
|
+
}[];
|
|
44
|
+
/**
|
|
45
|
+
* List of shipping countries by identifier and label.
|
|
46
|
+
*
|
|
47
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
48
|
+
* via the `patternProperty` "^.*$".
|
|
49
|
+
*/
|
|
50
|
+
type StateCountry3 = {
|
|
51
|
+
value: CountryCode;
|
|
52
|
+
/**
|
|
53
|
+
* Name of the country.
|
|
54
|
+
*/
|
|
55
|
+
label: string;
|
|
56
|
+
}[];
|
|
57
|
+
/**
|
|
58
|
+
* Payload to use when using the config field of the Organization on CommerceLayer.
|
|
59
|
+
*/
|
|
60
|
+
interface ValidConfigForOrganizationsInCommerceLayer {
|
|
61
|
+
mfe?: {
|
|
62
|
+
default?: MfeConfig;
|
|
63
|
+
[k: string]: MfeConfig | undefined;
|
|
64
|
+
};
|
|
65
|
+
apps?: {
|
|
66
|
+
default?: AppsConfig;
|
|
67
|
+
bundles?: AppsConfig;
|
|
68
|
+
/**
|
|
69
|
+
* Settings for app-customers.
|
|
70
|
+
*/
|
|
71
|
+
customers?: {
|
|
72
|
+
hide?: ("metadata" | "tags" | "details" | "customer_groups")[] | null;
|
|
73
|
+
};
|
|
74
|
+
exports?: AppsConfig;
|
|
75
|
+
gift_cards?: AppsConfig;
|
|
76
|
+
imports?: AppsConfig;
|
|
77
|
+
inventory?: AppsConfig;
|
|
78
|
+
/**
|
|
79
|
+
* Settings for app-orders.
|
|
80
|
+
*/
|
|
81
|
+
orders?: {
|
|
82
|
+
hide?: ("metadata" | "tags" | "details" | "markets")[] | null;
|
|
83
|
+
};
|
|
84
|
+
price_lists?: AppsConfig;
|
|
85
|
+
promotions?: AppsConfig;
|
|
86
|
+
resources?: AppsConfig;
|
|
87
|
+
returns?: AppsConfig;
|
|
88
|
+
shipments?: AppsConfig;
|
|
89
|
+
skus?: AppsConfig;
|
|
90
|
+
sku_lists?: AppsConfig;
|
|
91
|
+
stock_transfers?: AppsConfig;
|
|
92
|
+
subscriptions?: AppsConfig;
|
|
93
|
+
tags?: AppsConfig;
|
|
94
|
+
webhooks?: AppsConfig;
|
|
95
|
+
};
|
|
96
|
+
[k: string]: unknown;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Default settings for links and checkout.
|
|
100
|
+
*
|
|
101
|
+
* This interface was referenced by `undefined`'s JSON-Schema definition
|
|
102
|
+
* via the `patternProperty` "^market:id:[a-zA-Z0-9]*$$".
|
|
103
|
+
*/
|
|
104
|
+
interface MfeConfig {
|
|
105
|
+
/**
|
|
106
|
+
* Links for specific micro frontends.
|
|
107
|
+
*/
|
|
108
|
+
links?: {
|
|
109
|
+
cart?: Url;
|
|
110
|
+
checkout?: Url;
|
|
111
|
+
identity?: Url;
|
|
112
|
+
microstore?: Url;
|
|
113
|
+
my_account?: Url;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Settings for the Checkout micro front end.
|
|
117
|
+
*/
|
|
118
|
+
checkout?: {
|
|
119
|
+
thankyou_page?: Url;
|
|
120
|
+
billing_countries?: StateCountry;
|
|
121
|
+
shipping_countries?: StateCountry1;
|
|
122
|
+
default_country?: CountryCode;
|
|
123
|
+
/**
|
|
124
|
+
* List of states by country with identifier and label.
|
|
125
|
+
*/
|
|
126
|
+
billing_states?: {
|
|
127
|
+
[k: string]: StateCountry2;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* List of states by country with identifier and label.
|
|
131
|
+
*/
|
|
132
|
+
shipping_states?: {
|
|
133
|
+
[k: string]: StateCountry3;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Checkout internal links settings.
|
|
138
|
+
*/
|
|
139
|
+
urls?: {
|
|
140
|
+
privacy?: Url;
|
|
141
|
+
terms?: Url;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Default settings for the app.
|
|
146
|
+
*/
|
|
147
|
+
interface AppsConfig {
|
|
148
|
+
hide?: ("metadata" | "tags" | "details")[] | null;
|
|
149
|
+
}
|
|
150
|
+
|
|
1
151
|
/**
|
|
2
152
|
* Represents a type that can be null or undefined, making it optional in use.
|
|
3
153
|
* @template T The type that is being made nullable.
|
|
@@ -32,80 +182,12 @@ interface ConfigParams {
|
|
|
32
182
|
*/
|
|
33
183
|
skuId?: NullableType<string>;
|
|
34
184
|
}
|
|
35
|
-
|
|
36
|
-
* Configuration for overriding default links of the micro frontends,
|
|
37
|
-
* allowing customization of specific components.
|
|
38
|
-
*/
|
|
39
|
-
interface LinkConfig {
|
|
40
|
-
/** URL for a custom cart. */
|
|
41
|
-
cart?: string;
|
|
42
|
-
/** URL for a custom checkout */
|
|
43
|
-
checkout?: string;
|
|
44
|
-
/** URL for a custom my account */
|
|
45
|
-
my_account?: string;
|
|
46
|
-
/** URL for a custom identity */
|
|
47
|
-
identity?: string;
|
|
48
|
-
/** URL for a custom microstore */
|
|
49
|
-
microstore?: string;
|
|
50
|
-
}
|
|
51
|
-
interface Country {
|
|
52
|
-
/** The country code (e.g., 'US', 'UK') */
|
|
53
|
-
value: string;
|
|
54
|
-
/** The display name of the country (e.g., 'United States', 'United Kingdom') */
|
|
55
|
-
label: string;
|
|
56
|
-
}
|
|
57
|
-
interface State {
|
|
58
|
-
/** The province/state code (e.g., 'FI', 'LI') */
|
|
59
|
-
value: string;
|
|
60
|
-
/** The display name of the province/state (e.g., 'Firenze', 'Livorno') */
|
|
61
|
-
label: string;
|
|
62
|
-
}
|
|
63
|
-
type StatesConfig = Record<string, State[]>;
|
|
64
|
-
/**
|
|
65
|
-
* Configuration settings for customizing the Checkout application.
|
|
66
|
-
*/
|
|
67
|
-
interface CheckoutConfig {
|
|
68
|
-
/** URL for a custom thank you page displayed after completing a purchase. */
|
|
69
|
-
thankyou_page?: string;
|
|
70
|
-
/** List of countries available for selection in billing address forms. */
|
|
71
|
-
billing_countries?: Country[];
|
|
72
|
-
/** List of countries available for selection in shipping address forms. */
|
|
73
|
-
shipping_countries?: Country[];
|
|
74
|
-
/** Configuration for states or regions to display in billing address forms, which may override default settings. */
|
|
75
|
-
billing_states?: StatesConfig;
|
|
76
|
-
/** Configuration for states or regions to display in shipping address forms, which may override default settings. */
|
|
77
|
-
shipping_states?: StatesConfig;
|
|
78
|
-
/** Country code preselected by default in billing and shipping address forms. */
|
|
79
|
-
default_country?: string;
|
|
80
|
-
}
|
|
81
|
-
interface UrlsConfig {
|
|
82
|
-
/** URL of the privacy policy page */
|
|
83
|
-
privacy: string;
|
|
84
|
-
/** URL of the terms and conditions page */
|
|
85
|
-
terms: string;
|
|
86
|
-
}
|
|
87
|
-
/** Interface of the config of the organization */
|
|
88
|
-
interface DefaultConfig {
|
|
89
|
-
/** Custom links for overriding default micro frontends. */
|
|
90
|
-
links?: LinkConfig;
|
|
91
|
-
/** Checkout-specific configuration, like custom thank you page and country lists. */
|
|
92
|
-
checkout?: CheckoutConfig;
|
|
93
|
-
/** URLs for privacy policy and terms of service pages. */
|
|
94
|
-
urls?: UrlsConfig;
|
|
95
|
-
}
|
|
96
|
-
/** Configuration structure containing defaults and market-specific overrides. */
|
|
97
|
-
interface Configs {
|
|
98
|
-
/** Default configuration applicable to all markets. */
|
|
99
|
-
default: DefaultConfig;
|
|
100
|
-
/** Market-specific configuration overrides, keyed by market identifier. */
|
|
101
|
-
[key: string]: Partial<DefaultConfig>;
|
|
102
|
-
}
|
|
103
|
-
interface GetConfigProps {
|
|
185
|
+
interface GetMfeConfigProps {
|
|
104
186
|
/**
|
|
105
187
|
* `config` attribute of the organization
|
|
106
188
|
*/
|
|
107
189
|
jsonConfig?: {
|
|
108
|
-
mfe?:
|
|
190
|
+
mfe?: MfeConfigs;
|
|
109
191
|
};
|
|
110
192
|
/**
|
|
111
193
|
* Market identifier for fetching specific configuration overrides. (`market:id:hashid`)
|
|
@@ -116,6 +198,8 @@ interface GetConfigProps {
|
|
|
116
198
|
*/
|
|
117
199
|
params?: ConfigParams;
|
|
118
200
|
}
|
|
201
|
+
type MfeConfigs = NonNullable<ValidConfigForOrganizationsInCommerceLayer['mfe']>;
|
|
202
|
+
type DefaultMfeConfig = NonNullable<NonNullable<ValidConfigForOrganizationsInCommerceLayer['mfe']>['default']>;
|
|
119
203
|
/**
|
|
120
204
|
* Retrieves and merges the default organization configuration with market-specific overrides based on the provided market identifier.
|
|
121
205
|
* Placeholder values in the configuration URLs can be replaced with actual values from the `params`.
|
|
@@ -125,6 +209,18 @@ interface GetConfigProps {
|
|
|
125
209
|
* @param params The object containing replacement values for URL placeholders, such as language and access token.
|
|
126
210
|
* @returns The merged configuration object for the specified market, or null if no configuration is found.
|
|
127
211
|
*/
|
|
128
|
-
declare function
|
|
212
|
+
declare function getMfeConfig({ jsonConfig, market, params }: GetMfeConfigProps): DefaultMfeConfig | null;
|
|
213
|
+
|
|
214
|
+
type AppsConfigWithDefault = NonNullable<ValidConfigForOrganizationsInCommerceLayer['apps']>;
|
|
215
|
+
type FullAppsConfig = Required<Omit<AppsConfigWithDefault, 'default'>>;
|
|
216
|
+
/**
|
|
217
|
+
* Get the apps configuration filling them with with the default values, if specified
|
|
218
|
+
*/
|
|
219
|
+
declare function getAppsConfig({ jsonConfig }: {
|
|
220
|
+
/** `config` attribute of the organization */
|
|
221
|
+
jsonConfig?: {
|
|
222
|
+
apps?: AppsConfigWithDefault;
|
|
223
|
+
};
|
|
224
|
+
}): FullAppsConfig;
|
|
129
225
|
|
|
130
|
-
export { type
|
|
226
|
+
export { type AppsConfigWithDefault, type DefaultMfeConfig, type FullAppsConfig, type MfeConfigs, getAppsConfig, getMfeConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{merge as
|
|
1
|
+
var h=Object.defineProperty,k=Object.defineProperties;var A=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var N=(t,l,e)=>l in t?h(t,l,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[l]=e,b=(t,l)=>{for(var e in l||(l={}))_.call(l,e)&&N(t,e,l[e]);if(C)for(var e of C(l))M.call(l,e)&&N(t,e,l[e]);return t},m=(t,l)=>k(t,A(l));import{merge as O}from"merge-anything";function T({jsonConfig:t,market:l,params:e}){var r,o,s;if((t==null?void 0:t.mfe)==null)return null;let i=(o=(r=t==null?void 0:t.mfe)==null?void 0:r.default)!=null?o:{},n=l!=null?(s=t==null?void 0:t.mfe[l])!=null?s:{}:{};function f(D){var g,p,d,a,c,y;let I=JSON.stringify(D).replace(/:lang/g,(g=e==null?void 0:e.lang)!=null?g:":lang").replace(/:slug/g,(p=e==null?void 0:e.slug)!=null?p:":slug").replace(/:access_token/g,(d=e==null?void 0:e.accessToken)!=null?d:":access_token").replace(/:order_id/g,(a=e==null?void 0:e.orderId)!=null?a:":order_id").replace(/:sku_list_id/g,(c=e==null?void 0:e.skuListId)!=null?c:":sku_list_id").replace(/:sku_id/g,(y=e==null?void 0:e.skuId)!=null?y:":sku_id");return JSON.parse(I)}let u=O(JSON.parse(JSON.stringify(i)),n);return f(u)}var x=["default","bundles","customers","exports","gift_cards","imports","inventory","orders","price_lists","promotions","resources","returns","shipments","skus","sku_lists","stock_transfers","subscriptions","tags","webhooks"];function F({jsonConfig:t}){var e;let l=(e=t==null?void 0:t.apps)!=null?e:{};return x.reduce((i,n)=>n==="default"?i:m(b({},i),{[n]:W(l,n)}),{})}function W(t,l){var f,u,r,o;let e=(u=(f=t.default)==null?void 0:f.hide)!=null?u:[],i=(o=(r=t[l])==null?void 0:r.hide)!=null?o:[];return{hide:Array.from(new Set(e.concat(i)))}}export{F as getAppsConfig,T as getMfeConfig};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/getMfeConfig.ts","../src/getAppsConfig.ts"],"sourcesContent":["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 * 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(/: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","import { type ValidConfigForOrganizationsInCommerceLayer } from './schema/types'\n\nconst apps: Array<\n keyof NonNullable<ValidConfigForOrganizationsInCommerceLayer['apps']>\n> = [\n 'default',\n 'bundles',\n 'customers',\n 'exports',\n 'gift_cards',\n 'imports',\n 'inventory',\n 'orders',\n 'price_lists',\n 'promotions',\n 'resources',\n 'returns',\n 'shipments',\n 'skus',\n 'sku_lists',\n 'stock_transfers',\n 'subscriptions',\n 'tags',\n 'webhooks'\n]\n\nexport type AppsConfigWithDefault = NonNullable<\n ValidConfigForOrganizationsInCommerceLayer['apps']\n>\n\nexport type FullAppsConfig = Required<Omit<AppsConfigWithDefault, 'default'>>\n\ntype HideableItems = NonNullable<\n Required<AppsConfigWithDefault>['default']['hide']\n>\n\n/**\n * Get the apps configuration filling them with with the default values, if specified\n */\nexport function getAppsConfig({\n jsonConfig\n}: {\n /** `config` attribute of the organization */\n jsonConfig?: { apps?: AppsConfigWithDefault }\n}): FullAppsConfig {\n const cfg = jsonConfig?.apps ?? {}\n\n return apps.reduce((acc, key) => {\n if (key === 'default') {\n return acc\n }\n return {\n ...acc,\n [key]: mergeWithDefaults(cfg, key)\n }\n }, {}) as FullAppsConfig\n}\n\n/**\n * Merge the default `hide` array with the app specific `hide` array\n */\nfunction mergeWithDefaults<\n Item extends keyof Omit<AppsConfigWithDefault, 'default'>\n>(cfg: Partial<AppsConfigWithDefault>, app: Item): AppsConfigWithDefault[Item] {\n const defaultHide = cfg.default?.hide ?? []\n const itemHide = (cfg[app]?.hide ?? []) as HideableItems\n const mergedDeduped = Array.from(new Set(defaultHide.concat(itemHide)))\n return {\n hide: mergedDeduped\n }\n}\n"],"mappings":"6aAAA,OAAS,SAAAA,MAAa,iBAuEf,SAASC,EAAa,CAC3B,WAAAC,EACA,OAAAC,EACA,OAAAC,CACF,EAA+C,CA3E/C,IAAAC,EAAAC,EAAAC,EA4EE,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,CApF3E,IAAAN,EAAAC,EAAAC,EAAAK,EAAAC,EAAAC,EAqFI,IAAMC,EAAiB,KAAK,UAAUJ,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,kBAAkBC,EAAAH,GAAA,YAAAA,EAAQ,cAAR,KAAAG,EAAuB,eAAe,EAChE,QAAQ,cAAcK,EAAAR,GAAA,YAAAA,EAAQ,UAAR,KAAAQ,EAAmB,WAAW,EACpD,QAAQ,iBAAiBC,EAAAT,GAAA,YAAAA,EAAQ,YAAR,KAAAS,EAAqB,cAAc,EAC5D,QAAQ,YAAYC,EAAAV,GAAA,YAAAA,EAAQ,QAAR,KAAAU,EAAiB,SAAS,EAEjD,OAAO,KAAK,MAAMC,CAAc,CAClC,CAEA,IAAMC,EAAiCC,EACrC,KAAK,MAAM,KAAK,UAAUT,CAAa,CAAC,EACxCC,CACF,EACA,OAAOC,EAAoBM,CAAY,CACzC,CCnGA,IAAME,EAEF,CACF,UACA,UACA,YACA,UACA,aACA,UACA,YACA,SACA,cACA,aACA,YACA,UACA,YACA,OACA,YACA,kBACA,gBACA,OACA,UACF,EAeO,SAASC,EAAc,CAC5B,WAAAC,CACF,EAGmB,CA5CnB,IAAAC,EA6CE,IAAMC,GAAMD,EAAAD,GAAA,YAAAA,EAAY,OAAZ,KAAAC,EAAoB,CAAC,EAEjC,OAAOH,EAAK,OAAO,CAACK,EAAKC,IACnBA,IAAQ,UACHD,EAEFE,EAAAC,EAAA,GACFH,GADE,CAEL,CAACC,CAAG,EAAGG,EAAkBL,EAAKE,CAAG,CACnC,GACC,CAAC,CAAC,CACP,CAKA,SAASG,EAEPL,EAAqCM,EAAwC,CA/D/E,IAAAP,EAAAQ,EAAAC,EAAAC,EAgEE,IAAMC,GAAcH,GAAAR,EAAAC,EAAI,UAAJ,YAAAD,EAAa,OAAb,KAAAQ,EAAqB,CAAC,EACpCI,GAAYF,GAAAD,EAAAR,EAAIM,CAAG,IAAP,YAAAE,EAAU,OAAV,KAAAC,EAAkB,CAAC,EAErC,MAAO,CACL,KAFoB,MAAM,KAAK,IAAI,IAAIC,EAAY,OAAOC,CAAQ,CAAC,CAAC,CAGtE,CACF","names":["merge","getMfeConfig","jsonConfig","market","params","_a","_b","_c","defaultConfig","overrideConfig","replacePlaceholders","config","_d","_e","_f","replacedConfig","mergedConfig","merge","apps","getAppsConfig","jsonConfig","_a","cfg","acc","key","__spreadProps","__spreadValues","mergeWithDefaults","app","_b","_c","_d","defaultHide","itemHide"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/organization-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Organization config utils for extracting config by market",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Matteo Alessani",
|
|
@@ -36,14 +36,17 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/lodash": "^4.17.6",
|
|
39
|
+
"@types/node": "^22.10.5",
|
|
39
40
|
"deepmerge": "^4.3.1",
|
|
40
41
|
"deepmerge-ts": "^7.0.3",
|
|
41
42
|
"eslint": "^8.57.0",
|
|
43
|
+
"json-schema-to-typescript": "^15.0.3",
|
|
42
44
|
"lodash": "^4.17.21",
|
|
43
45
|
"tsup": "^8.1.0",
|
|
46
|
+
"type-fest": "^4.32.0",
|
|
44
47
|
"typescript": "^5.5.2",
|
|
45
48
|
"vitest": "^1.6.0",
|
|
46
|
-
"@commercelayer/eslint-config-ts": "^
|
|
49
|
+
"@commercelayer/eslint-config-ts": "^2.0.1"
|
|
47
50
|
},
|
|
48
51
|
"dependencies": {
|
|
49
52
|
"merge-anything": "^5.1.7"
|
|
@@ -55,6 +58,7 @@
|
|
|
55
58
|
"test:verbose": "pnpm run lint && vitest run --silent=false",
|
|
56
59
|
"bench": "vitest bench",
|
|
57
60
|
"build": "tsup",
|
|
58
|
-
"jsr:publish": "npx jsr publish"
|
|
61
|
+
"jsr:publish": "npx jsr publish",
|
|
62
|
+
"generate:types": "node src/schema/generate.js"
|
|
59
63
|
}
|
|
60
64
|
}
|