@final-commerce/common 2.11.1-staging2.1 → 2.11.2-preprod.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.
package/dist/index.js CHANGED
@@ -49,6 +49,7 @@ __export(index_exports, {
49
49
  DEFAULT_DISPLAY_STATE_MAP: () => DEFAULT_DISPLAY_STATE_MAP,
50
50
  DEFAULT_HOLD_MINUTES: () => DEFAULT_HOLD_MINUTES,
51
51
  DEFAULT_RESOLVED_CONFIG: () => DEFAULT_RESOLVED_CONFIG,
52
+ DEFAULT_SHELL_SETTINGS: () => DEFAULT_SHELL_SETTINGS,
52
53
  DEFAULT_UNIT_ID: () => DEFAULT_UNIT_ID,
53
54
  DualWriteStrategy: () => DualWriteStrategy,
54
55
  EUFixedRates: () => EUFixedRates,
@@ -104,6 +105,11 @@ __export(index_exports, {
104
105
  ResidualPaymentMethod: () => ResidualPaymentMethod,
105
106
  ResidualStatus: () => ResidualStatus,
106
107
  ResourceAvailabilityState: () => ResourceAvailabilityState,
108
+ SHELL_FLOW_SETTINGS_PREFIX: () => SHELL_FLOW_SETTINGS_PREFIX,
109
+ SHELL_FLOW_TIPS_KEY: () => SHELL_FLOW_TIPS_KEY,
110
+ SHELL_TIP_LABEL_MAX_LENGTH: () => SHELL_TIP_LABEL_MAX_LENGTH,
111
+ SHELL_TIP_PERCENT_MAX: () => SHELL_TIP_PERCENT_MAX,
112
+ SHELL_TIP_PERCENT_MIN: () => SHELL_TIP_PERCENT_MIN,
107
113
  SHIPPING_COUNTRIES: () => SHIPPING_COUNTRIES,
108
114
  STATE_SCHEMA: () => STATE_SCHEMA,
109
115
  STRIPE_SUPPORTED_COUNTRIES: () => STRIPE_SUPPORTED_COUNTRIES,
@@ -170,6 +176,7 @@ __export(index_exports, {
170
176
  evaluateConditionSet: () => evaluateConditionSet,
171
177
  extendPrice: () => extendPrice,
172
178
  extendPriceFor: () => extendPriceFor,
179
+ flowSettingsFromShellSettings: () => flowSettingsFromShellSettings,
173
180
  formatCurrency: () => formatCurrency,
174
181
  formatInUnit: () => formatInUnit,
175
182
  formatMinorUnitsToString: () => formatMinorUnitsToString,
@@ -203,6 +210,7 @@ __export(index_exports, {
203
210
  isFulfillmentState: () => isFulfillmentState,
204
211
  isInCart: () => isInCart,
205
212
  isPaymentState: () => isPaymentState,
213
+ isShellTipPercent: () => isShellTipPercent,
206
214
  isSupportedCurrency: () => isSupportedCurrency,
207
215
  isSystemFamilyCode: () => isSystemFamilyCode,
208
216
  isValidQuantity: () => isValidQuantity,
@@ -237,15 +245,22 @@ __export(index_exports, {
237
245
  presentAt: () => presentAt,
238
246
  priceForTotal: () => priceForTotal,
239
247
  provincesForPostCode: () => provincesForPostCode,
248
+ readShellTipSettings: () => readShellTipSettings,
240
249
  removeFragment: () => removeFragment,
241
250
  resolveFamily: () => resolveFamily,
242
251
  resolveModifiersForProduct: () => resolveModifiersForProduct,
252
+ resolveShellSettings: () => resolveShellSettings,
253
+ resolveShellSettingsWithSources: () => resolveShellSettingsWithSources,
243
254
  resolveShipping: () => resolveShipping,
244
255
  resolveTemplate: () => resolveTemplate,
245
256
  resolveUnit: () => resolveUnit,
246
257
  roundToPrecision: () => roundToPrecision,
247
258
  sameFamily: () => sameFamily,
248
259
  setOrderState: () => setOrderState,
260
+ shellSettingsFromCompanyTips: () => shellSettingsFromCompanyTips,
261
+ shellSettingsFromFlowSettings: () => shellSettingsFromFlowSettings,
262
+ shellSettingsProblems: () => shellSettingsProblems,
263
+ shellTipSettingsProblems: () => shellTipSettingsProblems,
249
264
  shipsToCountry: () => shipsToCountry,
250
265
  shopDayKey: () => shopDayKey,
251
266
  shopDayRange: () => shopDayRange,
@@ -2048,6 +2063,157 @@ function lineStockMoves(item, quantity, reservations = []) {
2048
2063
  });
2049
2064
  }
2050
2065
 
2066
+ // utils/shell-settings.util.ts
2067
+ var DEFAULT_SHELL_SETTINGS = {
2068
+ pinSwitchUser: false,
2069
+ pinSession: false,
2070
+ stationLock: 0,
2071
+ buildTimeout: 0,
2072
+ lockedAccess: false,
2073
+ cashManagement: true,
2074
+ tips: {
2075
+ enabled: true,
2076
+ tip1: { label: "Good", value: 15 },
2077
+ tip2: { label: "Great", value: 18 },
2078
+ tip3: { label: "Amazing!", value: 25 },
2079
+ customTipLabel: "Custom",
2080
+ noTipLabel: "No tip"
2081
+ }
2082
+ };
2083
+ var FIELD_ORDER = ["station"];
2084
+ var TIP_ORDER = ["station", "outlet", "flow", "company"];
2085
+ var TOP_FIELDS = [
2086
+ "pinSwitchUser",
2087
+ "pinSession",
2088
+ "stationLock",
2089
+ "buildTimeout",
2090
+ "lockedAccess",
2091
+ "cashManagement"
2092
+ ];
2093
+ var TIP_FIELDS = ["enabled", "tip1", "tip2", "tip3", "customTipLabel", "noTipLabel"];
2094
+ function pick(levels, order, read, fallback) {
2095
+ for (const level of order) {
2096
+ const settings = levels[level];
2097
+ if (!settings) continue;
2098
+ const value = read(settings);
2099
+ if (value !== void 0 && value !== null) return { value, source: level };
2100
+ }
2101
+ return { value: fallback, source: "default" };
2102
+ }
2103
+ function resolveShellSettingsWithSources(levels) {
2104
+ const settings = { ...DEFAULT_SHELL_SETTINGS, tips: { ...DEFAULT_SHELL_SETTINGS.tips } };
2105
+ const sources = { fields: {}, tips: {} };
2106
+ for (const field of TOP_FIELDS) {
2107
+ const { value, source } = pick(levels, FIELD_ORDER, (s) => s[field], DEFAULT_SHELL_SETTINGS[field]);
2108
+ settings[field] = value;
2109
+ sources.fields[field] = source;
2110
+ }
2111
+ for (const field of TIP_FIELDS) {
2112
+ const { value, source } = pick(levels, TIP_ORDER, (s) => s.tips?.[field], DEFAULT_SHELL_SETTINGS.tips[field]);
2113
+ settings.tips[field] = value;
2114
+ sources.tips[field] = source;
2115
+ }
2116
+ return { settings, sources };
2117
+ }
2118
+ function resolveShellSettings(levels) {
2119
+ return resolveShellSettingsWithSources(levels).settings;
2120
+ }
2121
+ var SHELL_TIP_PERCENT_MIN = 1;
2122
+ var SHELL_TIP_PERCENT_MAX = 100;
2123
+ var SHELL_TIP_LABEL_MAX_LENGTH = 20;
2124
+ var isLabel = (raw) => typeof raw === "string" && raw.trim().length > 0 && raw.length <= SHELL_TIP_LABEL_MAX_LENGTH;
2125
+ var isShellTipPercent = (raw) => typeof raw === "number" && Number.isInteger(raw) && raw >= SHELL_TIP_PERCENT_MIN && raw <= SHELL_TIP_PERCENT_MAX;
2126
+ function shellTipSettingsProblems(tips) {
2127
+ if (!tips) return [];
2128
+ const problems = [];
2129
+ if (tips.enabled !== void 0 && typeof tips.enabled !== "boolean") {
2130
+ problems.push({ field: "tips.enabled", code: "boolean" });
2131
+ }
2132
+ for (const key of ["tip1", "tip2", "tip3"]) {
2133
+ const option = tips[key];
2134
+ if (option === void 0) continue;
2135
+ if (!option || typeof option !== "object") {
2136
+ problems.push({ field: `tips.${key}`, code: "preset" });
2137
+ continue;
2138
+ }
2139
+ if (!isShellTipPercent(option.value)) problems.push({ field: `tips.${key}`, code: "percent" });
2140
+ if (!isLabel(option.label)) problems.push({ field: `tips.${key}`, code: "label" });
2141
+ }
2142
+ for (const key of ["customTipLabel", "noTipLabel"]) {
2143
+ if (tips[key] !== void 0 && !isLabel(tips[key])) problems.push({ field: `tips.${key}`, code: "label" });
2144
+ }
2145
+ return problems;
2146
+ }
2147
+ function shellSettingsProblems(settings) {
2148
+ if (!settings) return [];
2149
+ const problems = [];
2150
+ for (const field of ["pinSwitchUser", "pinSession", "lockedAccess", "cashManagement"]) {
2151
+ if (settings[field] !== void 0 && typeof settings[field] !== "boolean")
2152
+ problems.push({ field, code: "boolean" });
2153
+ }
2154
+ for (const field of ["stationLock", "buildTimeout"]) {
2155
+ const value = settings[field];
2156
+ if (value !== void 0 && !(typeof value === "number" && Number.isInteger(value) && value >= 0)) {
2157
+ problems.push({ field, code: "timeout" });
2158
+ }
2159
+ }
2160
+ return [...problems, ...shellTipSettingsProblems(settings.tips)];
2161
+ }
2162
+ var SHELL_FLOW_SETTINGS_PREFIX = "flowSettingsKey";
2163
+ var SHELL_FLOW_TIPS_KEY = `${SHELL_FLOW_SETTINGS_PREFIX}.tips`;
2164
+ var readBoolean = (raw) => {
2165
+ if (raw === void 0 || raw === "") return void 0;
2166
+ const v = raw.trim().toLowerCase();
2167
+ if (v === "true") return true;
2168
+ if (v === "false") return false;
2169
+ return void 0;
2170
+ };
2171
+ function readTipOption(raw) {
2172
+ if (!raw || typeof raw !== "object") return void 0;
2173
+ const { label, value } = raw;
2174
+ const n = typeof value === "number" ? value : parseFloat(String(value ?? ""));
2175
+ if (typeof label !== "string" || !Number.isFinite(n) || n < 0) return void 0;
2176
+ return { label, value: n };
2177
+ }
2178
+ function readShellTipSettings(raw) {
2179
+ if (!raw || typeof raw !== "object") return void 0;
2180
+ const r = raw;
2181
+ const tips = {};
2182
+ if (typeof r.enabled === "boolean") tips.enabled = r.enabled;
2183
+ const tip1 = readTipOption(r.tip1);
2184
+ const tip2 = readTipOption(r.tip2);
2185
+ const tip3 = readTipOption(r.tip3);
2186
+ if (tip1) tips.tip1 = tip1;
2187
+ if (tip2) tips.tip2 = tip2;
2188
+ if (tip3) tips.tip3 = tip3;
2189
+ if (typeof r.customTipLabel === "string") tips.customTipLabel = r.customTipLabel;
2190
+ if (typeof r.noTipLabel === "string") tips.noTipLabel = r.noTipLabel;
2191
+ return Object.keys(tips).length > 0 ? tips : void 0;
2192
+ }
2193
+ var parseJson = (raw) => {
2194
+ if (!raw) return void 0;
2195
+ try {
2196
+ return JSON.parse(raw);
2197
+ } catch {
2198
+ return void 0;
2199
+ }
2200
+ };
2201
+ function shellSettingsFromFlowSettings(dict) {
2202
+ const tips = readShellTipSettings(parseJson(dict?.[SHELL_FLOW_TIPS_KEY]));
2203
+ return tips ? { tips } : {};
2204
+ }
2205
+ function flowSettingsFromShellSettings(settings) {
2206
+ return settings.tips && Object.keys(settings.tips).length > 0 ? { [SHELL_FLOW_TIPS_KEY]: JSON.stringify(settings.tips) } : {};
2207
+ }
2208
+ function shellSettingsFromCompanyTips(enabled, options) {
2209
+ const tips = {
2210
+ ...readShellTipSettings(typeof options === "string" ? parseJson(options) : options)
2211
+ };
2212
+ const on = typeof enabled === "boolean" ? enabled : readBoolean(typeof enabled === "string" ? enabled : void 0);
2213
+ if (on !== void 0) tips.enabled = on;
2214
+ return Object.keys(tips).length > 0 ? { tips } : {};
2215
+ }
2216
+
2051
2217
  // units/family-code.ts
2052
2218
  var MAX_SLUG_LENGTH = 32;
2053
2219
  var FALLBACK_SLUG = "family";
@@ -4437,6 +4603,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4437
4603
  DEFAULT_DISPLAY_STATE_MAP,
4438
4604
  DEFAULT_HOLD_MINUTES,
4439
4605
  DEFAULT_RESOLVED_CONFIG,
4606
+ DEFAULT_SHELL_SETTINGS,
4440
4607
  DEFAULT_UNIT_ID,
4441
4608
  DualWriteStrategy,
4442
4609
  EUFixedRates,
@@ -4492,6 +4659,11 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4492
4659
  ResidualPaymentMethod,
4493
4660
  ResidualStatus,
4494
4661
  ResourceAvailabilityState,
4662
+ SHELL_FLOW_SETTINGS_PREFIX,
4663
+ SHELL_FLOW_TIPS_KEY,
4664
+ SHELL_TIP_LABEL_MAX_LENGTH,
4665
+ SHELL_TIP_PERCENT_MAX,
4666
+ SHELL_TIP_PERCENT_MIN,
4495
4667
  SHIPPING_COUNTRIES,
4496
4668
  STATE_SCHEMA,
4497
4669
  STRIPE_SUPPORTED_COUNTRIES,
@@ -4558,6 +4730,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4558
4730
  evaluateConditionSet,
4559
4731
  extendPrice,
4560
4732
  extendPriceFor,
4733
+ flowSettingsFromShellSettings,
4561
4734
  formatCurrency,
4562
4735
  formatInUnit,
4563
4736
  formatMinorUnitsToString,
@@ -4591,6 +4764,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4591
4764
  isFulfillmentState,
4592
4765
  isInCart,
4593
4766
  isPaymentState,
4767
+ isShellTipPercent,
4594
4768
  isSupportedCurrency,
4595
4769
  isSystemFamilyCode,
4596
4770
  isValidQuantity,
@@ -4625,15 +4799,22 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4625
4799
  presentAt,
4626
4800
  priceForTotal,
4627
4801
  provincesForPostCode,
4802
+ readShellTipSettings,
4628
4803
  removeFragment,
4629
4804
  resolveFamily,
4630
4805
  resolveModifiersForProduct,
4806
+ resolveShellSettings,
4807
+ resolveShellSettingsWithSources,
4631
4808
  resolveShipping,
4632
4809
  resolveTemplate,
4633
4810
  resolveUnit,
4634
4811
  roundToPrecision,
4635
4812
  sameFamily,
4636
4813
  setOrderState,
4814
+ shellSettingsFromCompanyTips,
4815
+ shellSettingsFromFlowSettings,
4816
+ shellSettingsProblems,
4817
+ shellTipSettingsProblems,
4637
4818
  shipsToCountry,
4638
4819
  shopDayKey,
4639
4820
  shopDayRange,