@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/README.md +20 -0
- package/bin/gate-done.mjs +71 -36
- package/bin/lib/budget.mjs +71 -0
- package/dist/index.d.mts +73 -1
- package/dist/index.d.ts +73 -1
- package/dist/index.js +181 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +166 -0
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +28 -1
- package/dist/pos-types/index.d.ts +28 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1781,6 +1781,157 @@ function lineStockMoves(item, quantity, reservations = []) {
|
|
|
1781
1781
|
});
|
|
1782
1782
|
}
|
|
1783
1783
|
|
|
1784
|
+
// utils/shell-settings.util.ts
|
|
1785
|
+
var DEFAULT_SHELL_SETTINGS = {
|
|
1786
|
+
pinSwitchUser: false,
|
|
1787
|
+
pinSession: false,
|
|
1788
|
+
stationLock: 0,
|
|
1789
|
+
buildTimeout: 0,
|
|
1790
|
+
lockedAccess: false,
|
|
1791
|
+
cashManagement: true,
|
|
1792
|
+
tips: {
|
|
1793
|
+
enabled: true,
|
|
1794
|
+
tip1: { label: "Good", value: 15 },
|
|
1795
|
+
tip2: { label: "Great", value: 18 },
|
|
1796
|
+
tip3: { label: "Amazing!", value: 25 },
|
|
1797
|
+
customTipLabel: "Custom",
|
|
1798
|
+
noTipLabel: "No tip"
|
|
1799
|
+
}
|
|
1800
|
+
};
|
|
1801
|
+
var FIELD_ORDER = ["station"];
|
|
1802
|
+
var TIP_ORDER = ["station", "outlet", "flow", "company"];
|
|
1803
|
+
var TOP_FIELDS = [
|
|
1804
|
+
"pinSwitchUser",
|
|
1805
|
+
"pinSession",
|
|
1806
|
+
"stationLock",
|
|
1807
|
+
"buildTimeout",
|
|
1808
|
+
"lockedAccess",
|
|
1809
|
+
"cashManagement"
|
|
1810
|
+
];
|
|
1811
|
+
var TIP_FIELDS = ["enabled", "tip1", "tip2", "tip3", "customTipLabel", "noTipLabel"];
|
|
1812
|
+
function pick(levels, order, read, fallback) {
|
|
1813
|
+
for (const level of order) {
|
|
1814
|
+
const settings = levels[level];
|
|
1815
|
+
if (!settings) continue;
|
|
1816
|
+
const value = read(settings);
|
|
1817
|
+
if (value !== void 0 && value !== null) return { value, source: level };
|
|
1818
|
+
}
|
|
1819
|
+
return { value: fallback, source: "default" };
|
|
1820
|
+
}
|
|
1821
|
+
function resolveShellSettingsWithSources(levels) {
|
|
1822
|
+
const settings = { ...DEFAULT_SHELL_SETTINGS, tips: { ...DEFAULT_SHELL_SETTINGS.tips } };
|
|
1823
|
+
const sources = { fields: {}, tips: {} };
|
|
1824
|
+
for (const field of TOP_FIELDS) {
|
|
1825
|
+
const { value, source } = pick(levels, FIELD_ORDER, (s) => s[field], DEFAULT_SHELL_SETTINGS[field]);
|
|
1826
|
+
settings[field] = value;
|
|
1827
|
+
sources.fields[field] = source;
|
|
1828
|
+
}
|
|
1829
|
+
for (const field of TIP_FIELDS) {
|
|
1830
|
+
const { value, source } = pick(levels, TIP_ORDER, (s) => s.tips?.[field], DEFAULT_SHELL_SETTINGS.tips[field]);
|
|
1831
|
+
settings.tips[field] = value;
|
|
1832
|
+
sources.tips[field] = source;
|
|
1833
|
+
}
|
|
1834
|
+
return { settings, sources };
|
|
1835
|
+
}
|
|
1836
|
+
function resolveShellSettings(levels) {
|
|
1837
|
+
return resolveShellSettingsWithSources(levels).settings;
|
|
1838
|
+
}
|
|
1839
|
+
var SHELL_TIP_PERCENT_MIN = 1;
|
|
1840
|
+
var SHELL_TIP_PERCENT_MAX = 100;
|
|
1841
|
+
var SHELL_TIP_LABEL_MAX_LENGTH = 20;
|
|
1842
|
+
var isLabel = (raw) => typeof raw === "string" && raw.trim().length > 0 && raw.length <= SHELL_TIP_LABEL_MAX_LENGTH;
|
|
1843
|
+
var isShellTipPercent = (raw) => typeof raw === "number" && Number.isInteger(raw) && raw >= SHELL_TIP_PERCENT_MIN && raw <= SHELL_TIP_PERCENT_MAX;
|
|
1844
|
+
function shellTipSettingsProblems(tips) {
|
|
1845
|
+
if (!tips) return [];
|
|
1846
|
+
const problems = [];
|
|
1847
|
+
if (tips.enabled !== void 0 && typeof tips.enabled !== "boolean") {
|
|
1848
|
+
problems.push({ field: "tips.enabled", code: "boolean" });
|
|
1849
|
+
}
|
|
1850
|
+
for (const key of ["tip1", "tip2", "tip3"]) {
|
|
1851
|
+
const option = tips[key];
|
|
1852
|
+
if (option === void 0) continue;
|
|
1853
|
+
if (!option || typeof option !== "object") {
|
|
1854
|
+
problems.push({ field: `tips.${key}`, code: "preset" });
|
|
1855
|
+
continue;
|
|
1856
|
+
}
|
|
1857
|
+
if (!isShellTipPercent(option.value)) problems.push({ field: `tips.${key}`, code: "percent" });
|
|
1858
|
+
if (!isLabel(option.label)) problems.push({ field: `tips.${key}`, code: "label" });
|
|
1859
|
+
}
|
|
1860
|
+
for (const key of ["customTipLabel", "noTipLabel"]) {
|
|
1861
|
+
if (tips[key] !== void 0 && !isLabel(tips[key])) problems.push({ field: `tips.${key}`, code: "label" });
|
|
1862
|
+
}
|
|
1863
|
+
return problems;
|
|
1864
|
+
}
|
|
1865
|
+
function shellSettingsProblems(settings) {
|
|
1866
|
+
if (!settings) return [];
|
|
1867
|
+
const problems = [];
|
|
1868
|
+
for (const field of ["pinSwitchUser", "pinSession", "lockedAccess", "cashManagement"]) {
|
|
1869
|
+
if (settings[field] !== void 0 && typeof settings[field] !== "boolean")
|
|
1870
|
+
problems.push({ field, code: "boolean" });
|
|
1871
|
+
}
|
|
1872
|
+
for (const field of ["stationLock", "buildTimeout"]) {
|
|
1873
|
+
const value = settings[field];
|
|
1874
|
+
if (value !== void 0 && !(typeof value === "number" && Number.isInteger(value) && value >= 0)) {
|
|
1875
|
+
problems.push({ field, code: "timeout" });
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
return [...problems, ...shellTipSettingsProblems(settings.tips)];
|
|
1879
|
+
}
|
|
1880
|
+
var SHELL_FLOW_SETTINGS_PREFIX = "flowSettingsKey";
|
|
1881
|
+
var SHELL_FLOW_TIPS_KEY = `${SHELL_FLOW_SETTINGS_PREFIX}.tips`;
|
|
1882
|
+
var readBoolean = (raw) => {
|
|
1883
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
1884
|
+
const v = raw.trim().toLowerCase();
|
|
1885
|
+
if (v === "true") return true;
|
|
1886
|
+
if (v === "false") return false;
|
|
1887
|
+
return void 0;
|
|
1888
|
+
};
|
|
1889
|
+
function readTipOption(raw) {
|
|
1890
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
1891
|
+
const { label, value } = raw;
|
|
1892
|
+
const n = typeof value === "number" ? value : parseFloat(String(value ?? ""));
|
|
1893
|
+
if (typeof label !== "string" || !Number.isFinite(n) || n < 0) return void 0;
|
|
1894
|
+
return { label, value: n };
|
|
1895
|
+
}
|
|
1896
|
+
function readShellTipSettings(raw) {
|
|
1897
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
1898
|
+
const r = raw;
|
|
1899
|
+
const tips = {};
|
|
1900
|
+
if (typeof r.enabled === "boolean") tips.enabled = r.enabled;
|
|
1901
|
+
const tip1 = readTipOption(r.tip1);
|
|
1902
|
+
const tip2 = readTipOption(r.tip2);
|
|
1903
|
+
const tip3 = readTipOption(r.tip3);
|
|
1904
|
+
if (tip1) tips.tip1 = tip1;
|
|
1905
|
+
if (tip2) tips.tip2 = tip2;
|
|
1906
|
+
if (tip3) tips.tip3 = tip3;
|
|
1907
|
+
if (typeof r.customTipLabel === "string") tips.customTipLabel = r.customTipLabel;
|
|
1908
|
+
if (typeof r.noTipLabel === "string") tips.noTipLabel = r.noTipLabel;
|
|
1909
|
+
return Object.keys(tips).length > 0 ? tips : void 0;
|
|
1910
|
+
}
|
|
1911
|
+
var parseJson = (raw) => {
|
|
1912
|
+
if (!raw) return void 0;
|
|
1913
|
+
try {
|
|
1914
|
+
return JSON.parse(raw);
|
|
1915
|
+
} catch {
|
|
1916
|
+
return void 0;
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
function shellSettingsFromFlowSettings(dict) {
|
|
1920
|
+
const tips = readShellTipSettings(parseJson(dict?.[SHELL_FLOW_TIPS_KEY]));
|
|
1921
|
+
return tips ? { tips } : {};
|
|
1922
|
+
}
|
|
1923
|
+
function flowSettingsFromShellSettings(settings) {
|
|
1924
|
+
return settings.tips && Object.keys(settings.tips).length > 0 ? { [SHELL_FLOW_TIPS_KEY]: JSON.stringify(settings.tips) } : {};
|
|
1925
|
+
}
|
|
1926
|
+
function shellSettingsFromCompanyTips(enabled, options) {
|
|
1927
|
+
const tips = {
|
|
1928
|
+
...readShellTipSettings(typeof options === "string" ? parseJson(options) : options)
|
|
1929
|
+
};
|
|
1930
|
+
const on = typeof enabled === "boolean" ? enabled : readBoolean(typeof enabled === "string" ? enabled : void 0);
|
|
1931
|
+
if (on !== void 0) tips.enabled = on;
|
|
1932
|
+
return Object.keys(tips).length > 0 ? { tips } : {};
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1784
1935
|
// units/family-code.ts
|
|
1785
1936
|
var MAX_SLUG_LENGTH = 32;
|
|
1786
1937
|
var FALLBACK_SLUG = "family";
|
|
@@ -4169,6 +4320,7 @@ export {
|
|
|
4169
4320
|
DEFAULT_DISPLAY_STATE_MAP,
|
|
4170
4321
|
DEFAULT_HOLD_MINUTES,
|
|
4171
4322
|
DEFAULT_RESOLVED_CONFIG,
|
|
4323
|
+
DEFAULT_SHELL_SETTINGS,
|
|
4172
4324
|
DEFAULT_UNIT_ID,
|
|
4173
4325
|
DualWriteStrategy,
|
|
4174
4326
|
EUFixedRates,
|
|
@@ -4224,6 +4376,11 @@ export {
|
|
|
4224
4376
|
ResidualPaymentMethod,
|
|
4225
4377
|
ResidualStatus,
|
|
4226
4378
|
ResourceAvailabilityState,
|
|
4379
|
+
SHELL_FLOW_SETTINGS_PREFIX,
|
|
4380
|
+
SHELL_FLOW_TIPS_KEY,
|
|
4381
|
+
SHELL_TIP_LABEL_MAX_LENGTH,
|
|
4382
|
+
SHELL_TIP_PERCENT_MAX,
|
|
4383
|
+
SHELL_TIP_PERCENT_MIN,
|
|
4227
4384
|
SHIPPING_COUNTRIES,
|
|
4228
4385
|
STATE_SCHEMA,
|
|
4229
4386
|
STRIPE_SUPPORTED_COUNTRIES,
|
|
@@ -4290,6 +4447,7 @@ export {
|
|
|
4290
4447
|
evaluateConditionSet,
|
|
4291
4448
|
extendPrice,
|
|
4292
4449
|
extendPriceFor,
|
|
4450
|
+
flowSettingsFromShellSettings,
|
|
4293
4451
|
formatCurrency,
|
|
4294
4452
|
formatInUnit,
|
|
4295
4453
|
formatMinorUnitsToString,
|
|
@@ -4323,6 +4481,7 @@ export {
|
|
|
4323
4481
|
isFulfillmentState,
|
|
4324
4482
|
isInCart,
|
|
4325
4483
|
isPaymentState,
|
|
4484
|
+
isShellTipPercent,
|
|
4326
4485
|
isSupportedCurrency,
|
|
4327
4486
|
isSystemFamilyCode,
|
|
4328
4487
|
isValidQuantity,
|
|
@@ -4357,15 +4516,22 @@ export {
|
|
|
4357
4516
|
presentAt,
|
|
4358
4517
|
priceForTotal,
|
|
4359
4518
|
provincesForPostCode,
|
|
4519
|
+
readShellTipSettings,
|
|
4360
4520
|
removeFragment,
|
|
4361
4521
|
resolveFamily,
|
|
4362
4522
|
resolveModifiersForProduct,
|
|
4523
|
+
resolveShellSettings,
|
|
4524
|
+
resolveShellSettingsWithSources,
|
|
4363
4525
|
resolveShipping,
|
|
4364
4526
|
resolveTemplate,
|
|
4365
4527
|
resolveUnit,
|
|
4366
4528
|
roundToPrecision,
|
|
4367
4529
|
sameFamily,
|
|
4368
4530
|
setOrderState,
|
|
4531
|
+
shellSettingsFromCompanyTips,
|
|
4532
|
+
shellSettingsFromFlowSettings,
|
|
4533
|
+
shellSettingsProblems,
|
|
4534
|
+
shellTipSettingsProblems,
|
|
4369
4535
|
shipsToCountry,
|
|
4370
4536
|
shopDayKey,
|
|
4371
4537
|
shopDayRange,
|