@simpleapps-com/augur-utils 0.3.1 → 0.4.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.cjs +85 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +84 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
3
|
var _chunk5UMFBGVAcjs = require('./chunk-5UMFBGVA.cjs');
|
|
4
4
|
|
|
@@ -49,9 +49,92 @@ function isAddressDifferent(userAddress, smartyAddress) {
|
|
|
49
49
|
return smartyAddress.deliveryLine1.toLowerCase() !== userAddress.address1.toLowerCase() || smartyAddress.cityName.toLowerCase() !== userAddress.city.toLowerCase() || smartyAddress.stateAbbreviation !== userAddress.state || smartyAddress.zipCode !== userAddress.postalCode;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
// src/get-payment-status.ts
|
|
53
|
+
function getPaymentStatus(invoice) {
|
|
54
|
+
if (invoice.paidInFullFlag === "Y") return "Paid";
|
|
55
|
+
if (invoice.amountPaid != null && invoice.totalAmount != null && invoice.amountPaid > 0)
|
|
56
|
+
return "Partially Paid";
|
|
57
|
+
return "Unpaid";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/transform-ship-to-address.ts
|
|
61
|
+
function str(value) {
|
|
62
|
+
if (value == null) return "";
|
|
63
|
+
return String(value).trim();
|
|
64
|
+
}
|
|
65
|
+
function pick(raw, keys) {
|
|
66
|
+
for (const k of keys) {
|
|
67
|
+
if (raw[k] != null) return str(raw[k]);
|
|
68
|
+
}
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
var PHYS_FIELDS = {
|
|
72
|
+
address1: ["physAddress1", "phys_address1"],
|
|
73
|
+
address2: ["physAddress2", "phys_address2"],
|
|
74
|
+
city: ["physCity", "phys_city"],
|
|
75
|
+
state: ["physState", "phys_state"],
|
|
76
|
+
zip: ["physPostalCode", "phys_postal_code"],
|
|
77
|
+
country: ["physCountry", "phys_country"]
|
|
78
|
+
};
|
|
79
|
+
var MAIL_FIELDS = {
|
|
80
|
+
address1: ["mailAddress1", "mail_address1", "address1"],
|
|
81
|
+
address2: ["mailAddress2", "mail_address2", "address2"],
|
|
82
|
+
city: ["mailCity", "mail_city", "city"],
|
|
83
|
+
state: ["mailState", "mail_state", "state"],
|
|
84
|
+
zip: ["mailPostalCode", "mail_postal_code", "postalCode", "zip"],
|
|
85
|
+
country: ["mailCountry", "mail_country", "country"]
|
|
86
|
+
};
|
|
87
|
+
function transformShipToAddress(raw) {
|
|
88
|
+
const isPhys = raw.physAddress1 != null || raw.physCity != null || raw.physState != null;
|
|
89
|
+
const f = isPhys ? PHYS_FIELDS : MAIL_FIELDS;
|
|
90
|
+
const address = {
|
|
91
|
+
shipToId: _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(raw.shipToId, () => ( raw.ship_to_id)), () => ( raw.id)), () => ( "")),
|
|
92
|
+
name: str(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(raw.shipToName, () => ( raw.ship_to_name)), () => ( raw.name)), () => ( ""))),
|
|
93
|
+
address1: pick(raw, [...f.address1]),
|
|
94
|
+
city: pick(raw, [...f.city]),
|
|
95
|
+
state: pick(raw, [...f.state]),
|
|
96
|
+
zip: pick(raw, [...f.zip])
|
|
97
|
+
};
|
|
98
|
+
const address2 = pick(raw, [...f.address2]);
|
|
99
|
+
if (address2) address.address2 = address2;
|
|
100
|
+
const country = pick(raw, [...f.country]);
|
|
101
|
+
if (country) address.country = country;
|
|
102
|
+
return address;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/build-checkout-payload.ts
|
|
106
|
+
function buildCheckoutPayload(input) {
|
|
107
|
+
const oe_hdr = {
|
|
108
|
+
customer_id: input.customerId,
|
|
109
|
+
company_id: input.companyId,
|
|
110
|
+
sales_location_id: input.salesLocationId,
|
|
111
|
+
user_id: input.userId,
|
|
112
|
+
user_email: input.userEmail,
|
|
113
|
+
taker: _nullishCoalesce(input.taker, () => ( "ESTORE"))
|
|
114
|
+
};
|
|
115
|
+
if (input.poNumber != null) oe_hdr.customer_po_no = input.poNumber;
|
|
116
|
+
if (input.shipToId != null) oe_hdr.ship_to_id = input.shipToId;
|
|
117
|
+
if (input.deliveryInstructions != null)
|
|
118
|
+
oe_hdr.delivery_instructions = input.deliveryInstructions;
|
|
119
|
+
const oe_line = input.cartLines.map((line) => {
|
|
120
|
+
const oeLine = {
|
|
121
|
+
item_id: line.itemId,
|
|
122
|
+
unit_quantity: line.quantity,
|
|
123
|
+
unit_of_measure: line.unitOfMeasure,
|
|
124
|
+
inv_mast_uid: line.invMastUid
|
|
125
|
+
};
|
|
126
|
+
if (line.unitPrice != null) oeLine.unit_price = line.unitPrice;
|
|
127
|
+
return oeLine;
|
|
128
|
+
});
|
|
129
|
+
return { oe_hdr, oe_line };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
52
135
|
|
|
53
136
|
|
|
54
137
|
|
|
55
138
|
|
|
56
|
-
exports.CACHE_CONFIG = CACHE_CONFIG; exports.cn = _chunk5UMFBGVAcjs.cn; exports.formatPrice = formatPrice; exports.isAddressDifferent = isAddressDifferent;
|
|
139
|
+
exports.CACHE_CONFIG = CACHE_CONFIG; exports.buildCheckoutPayload = buildCheckoutPayload; exports.cn = _chunk5UMFBGVAcjs.cn; exports.formatPrice = formatPrice; exports.getPaymentStatus = getPaymentStatus; exports.isAddressDifferent = isAddressDifferent; exports.transformShipToAddress = transformShipToAddress;
|
|
57
140
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-utils/dist/index.cjs","../src/cache-config.ts","../src/format-price.ts","../src/address-comparison.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACcO,IAAM,aAAA,EAAe;AAAA,EAC1B,MAAA,EAAQ;AAAA,IACN,SAAA,EAAW,IAAA,EAAO,GAAA,EAAK,EAAA;AAAA;AAAA,IACvB,MAAA,EAAQ,IAAA,EAAO,GAAA,EAAK,GAAA,EAAK;AAAA;AAAA,EAC3B,CAAA;AAAA,EACA,WAAA,EAAa;AAAA,IACX,SAAA,EAAW,IAAA,EAAO,GAAA,EAAK,EAAA;AAAA;AAAA,IACvB,MAAA,EAAQ,IAAA,EAAO,GAAA,EAAK,GAAA,EAAK;AAAA;AAAA,EAC3B,CAAA;AAAA,EACA,OAAA,EAAS;AAAA,IACP,SAAA,EAAW,IAAA,EAAO,GAAA,EAAK,CAAA;AAAA;AAAA,IACvB,MAAA,EAAQ,IAAA,EAAO,GAAA,EAAK;AAAA;AAAA,EACtB,CAAA;AAAA,EACA,IAAA,EAAM;AAAA,IACJ,SAAA,EAAW,IAAA,EAAO,GAAA,EAAK,CAAA;AAAA;AAAA,IACvB,MAAA,EAAQ,IAAA,EAAO,GAAA,EAAK;AAAA;AAAA,EACtB,CAAA;AAAA,EACA,QAAA,EAAU;AAAA,IACR,SAAA,EAAW,CAAA;AAAA,IACX,MAAA,EAAQ,IAAA,EAAO,GAAA,EAAK;AAAA;AAAA,EACtB;AACF,CAAA;ADHA;AACA;AEjCO,SAAS,WAAA,CACd,KAAA,EACA,OAAA,EAAiB,OAAA,EACjB,SAAA,EAAmB,KAAA,EACX;AACR,EAAA,OAAO,IAAI,IAAA,CAAK,YAAA,CAAa,MAAA,EAAQ;AAAA,IACnC,KAAA,EAAO,UAAA;AAAA,IACP,QAAA;AAAA,IACA,qBAAA,EAAuB;AAAA,EACzB,CAAC,CAAA,CAAE,MAAA,CAAO,KAAK,CAAA;AACjB;AF+BA;AACA;AG5BO,SAAS,kBAAA,CACd,WAAA,EACA,aAAA,EACS;AACT,EAAA,OACE,aAAA,CAAc,aAAA,CAAc,WAAA,CAAY,EAAA,IAAM,WAAA,CAAY,QAAA,CAAS,WAAA,CAAY,EAAA,GAC/E,aAAA,CAAc,QAAA,CAAS,WAAA,CAAY,EAAA,IAAM,WAAA,CAAY,IAAA,CAAK,WAAA,CAAY,EAAA,GACtE,aAAA,CAAc,kBAAA,IAAsB,WAAA,CAAY,MAAA,GAChD,aAAA,CAAc,QAAA,IAAY,WAAA,CAAY,UAAA;AAE1C;AHsBA;AACE;AACA;AACA;AACA;AACF,2JAAC","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-utils/dist/index.cjs","sourcesContent":[null,"/**\n * Centralized cache configuration for React Query (TanStack Query)\n *\n * staleTime -- How long cached data is considered \"fresh\". While fresh,\n * React Query serves the cache instantly and does NOT refetch in the\n * background. After staleTime expires the data is \"stale\" and will be\n * refetched on the next access (mount, window focus, etc.).\n *\n * gcTime (garbage collection time) -- How long UNUSED cached data stays in\n * memory after all components using it unmount. Once gcTime expires the\n * cache entry is deleted entirely.\n *\n * STATIC (1h): categories, menus, item details\n * SEMI_STATIC (10m): pricing, stock, search results\n * DYNAMIC (5m): infinite scroll data\n * CART (2m): cart lines, cart header\n * REALTIME (0): active orders, checkout state\n */\nexport const CACHE_CONFIG = {\n STATIC: {\n staleTime: 1000 * 60 * 60, // 1 hour\n gcTime: 1000 * 60 * 60 * 24, // 24 hours\n },\n SEMI_STATIC: {\n staleTime: 1000 * 60 * 10, // 10 minutes\n gcTime: 1000 * 60 * 60 * 4, // 4 hours\n },\n DYNAMIC: {\n staleTime: 1000 * 60 * 5, // 5 minutes\n gcTime: 1000 * 60 * 30, // 30 minutes\n },\n CART: {\n staleTime: 1000 * 60 * 2, // 2 minutes\n gcTime: 1000 * 60 * 30, // 30 minutes\n },\n REALTIME: {\n staleTime: 0,\n gcTime: 1000 * 60 * 5, // 5 minutes\n },\n} as const;\n\nexport type CacheTier = keyof typeof CACHE_CONFIG;\n","/**\n * Locale-aware currency formatting.\n * Defaults to USD -- consumers can override locale and currency.\n */\nexport function formatPrice(\n price: number,\n locale: string = \"en-US\",\n currency: string = \"USD\",\n): string {\n return new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency,\n minimumFractionDigits: 2,\n }).format(price);\n}\n","import type { TSmartyStreets } from \"./types/smarty-streets\";\n\n/** User-entered address fields for comparison. */\nexport interface UserAddress {\n address1: string;\n city: string;\n state: string;\n postalCode: string;\n}\n\n/**\n * Compares a user-entered address with a SmartyStreets-validated address.\n * Returns true if any field differs (case-insensitive for address/city,\n * exact match for state abbreviation and zip code).\n *\n * Used in checkout to prompt users when their input differs from the\n * USPS-validated address.\n */\nexport function isAddressDifferent(\n userAddress: UserAddress,\n smartyAddress: TSmartyStreets,\n): boolean {\n return (\n smartyAddress.deliveryLine1.toLowerCase() !== userAddress.address1.toLowerCase() ||\n smartyAddress.cityName.toLowerCase() !== userAddress.city.toLowerCase() ||\n smartyAddress.stateAbbreviation !== userAddress.state ||\n smartyAddress.zipCode !== userAddress.postalCode\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-utils/dist/index.cjs","../src/cache-config.ts","../src/format-price.ts","../src/address-comparison.ts","../src/get-payment-status.ts","../src/transform-ship-to-address.ts","../src/build-checkout-payload.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACcO,IAAM,aAAA,EAAe;AAAA,EAC1B,MAAA,EAAQ;AAAA,IACN,SAAA,EAAW,IAAA,EAAO,GAAA,EAAK,EAAA;AAAA;AAAA,IACvB,MAAA,EAAQ,IAAA,EAAO,GAAA,EAAK,GAAA,EAAK;AAAA;AAAA,EAC3B,CAAA;AAAA,EACA,WAAA,EAAa;AAAA,IACX,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AAA;AAAA,MACpB,eAAA,EAAiB,IAAA,CAAK,aAAA;AAAA,MACtB,YAAA,EAAc,IAAA,CAAK;AAAA,IACrB,CAAA;AACA,IAAA,GAAA,CAAI,IAAA,CAAK,UAAA,GAAa,IAAA,EAAM,MAAA,CAAO,WAAA,EAAa,IAAA,CAAK,SAAA;AACrD,IAAA,OAAO,MAAA;AAAA,EACT,CAAC,CAAA;AAED,EAAA,OAAO,EAAE,MAAA,EAAQ,QAAQ,CAAA;AAC3B;ANiEA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,sTAAC","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-utils/dist/index.cjs","sourcesContent":[null,"/**\n * Centralized cache configuration for React Query (TanStack Query)\n *\n * staleTime -- How long cached data is considered \"fresh\". While fresh,\n * React Query serves the cache instantly and does NOT refetch in the\n * background. After staleTime expires the data is \"stale\" and will be\n * refetched on the next access (mount, window focus, etc.).\n *\n * gcTime (garbage collection time) -- How long UNUSED cached data stays in\n * memory after all components using it unmount. Once gcTime expires the\n * cache entry is deleted entirely.\n *\n * STATIC (1h): categories, menus, item details\n * SEMI_STATIC (10m): pricing, stock, search results\n * DYNAMIC (5m): infinite scroll data\n * CART (2m): cart lines, cart header\n * REALTIME (0): active orders, checkout state\n */\nexport const CACHE_CONFIG = {\n STATIC: {\n staleTime: 1000 * 60 * 60, // 1 hour\n gcTime: 1000 * 60 * 60 * 24, // 24 hours\n },\n SEMI_STATIC: {\n staleTime: 1000 * 60 * 10, // 10 minutes\n gcTime: 1000 * 60 * 60 * 4, // 4 hours\n },\n DYNAMIC: {\n staleTime: 1000 * 60 * 5, // 5 minutes\n gcTime: 1000 * 60 * 30, // 30 minutes\n },\n CART: {\n staleTime: 1000 * 60 * 2, // 2 minutes\n gcTime: 1000 * 60 * 30, // 30 minutes\n },\n REALTIME: {\n staleTime: 0,\n gcTime: 1000 * 60 * 5, // 5 minutes\n },\n} as const;\n\nexport type CacheTier = keyof typeof CACHE_CONFIG;\n","/**\n * Locale-aware currency formatting.\n * Defaults to USD -- consumers can override locale and currency.\n */\nexport function formatPrice(\n price: number,\n locale: string = \"en-US\",\n currency: string = \"USD\",\n): string {\n return new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency,\n minimumFractionDigits: 2,\n }).format(price);\n}\n","import type { TSmartyStreets } from \"./types/smarty-streets\";\n\n/** User-entered address fields for comparison. */\nexport interface UserAddress {\n address1: string;\n city: string;\n state: string;\n postalCode: string;\n}\n\n/**\n * Compares a user-entered address with a SmartyStreets-validated address.\n * Returns true if any field differs (case-insensitive for address/city,\n * exact match for state abbreviation and zip code).\n *\n * Used in checkout to prompt users when their input differs from the\n * USPS-validated address.\n */\nexport function isAddressDifferent(\n userAddress: UserAddress,\n smartyAddress: TSmartyStreets,\n): boolean {\n return (\n smartyAddress.deliveryLine1.toLowerCase() !== userAddress.address1.toLowerCase() ||\n smartyAddress.cityName.toLowerCase() !== userAddress.city.toLowerCase() ||\n smartyAddress.stateAbbreviation !== userAddress.state ||\n smartyAddress.zipCode !== userAddress.postalCode\n );\n}\n","export type PaymentStatusInvoice = {\n paidInFullFlag?: string | null;\n amountPaid?: number;\n totalAmount?: number;\n};\n\nexport type PaymentStatus = \"Paid\" | \"Partially Paid\" | \"Unpaid\";\n\nexport function getPaymentStatus(invoice: PaymentStatusInvoice): PaymentStatus {\n if (invoice.paidInFullFlag === \"Y\") return \"Paid\";\n if (\n invoice.amountPaid != null &&\n invoice.totalAmount != null &&\n invoice.amountPaid > 0\n )\n return \"Partially Paid\";\n return \"Unpaid\";\n}\n","export type ShipToAddress = {\n shipToId: string | number;\n name: string;\n address1: string;\n address2?: string;\n city: string;\n state: string;\n zip: string;\n country?: string;\n};\n\ntype RawShipTo = Record<string, unknown>;\n\nfunction str(value: unknown): string {\n if (value == null) return \"\";\n return String(value).trim();\n}\n\nfunction pick(raw: RawShipTo, keys: string[]): string {\n for (const k of keys) {\n if (raw[k] != null) return str(raw[k]);\n }\n return \"\";\n}\n\nconst PHYS_FIELDS = {\n address1: [\"physAddress1\", \"phys_address1\"],\n address2: [\"physAddress2\", \"phys_address2\"],\n city: [\"physCity\", \"phys_city\"],\n state: [\"physState\", \"phys_state\"],\n zip: [\"physPostalCode\", \"phys_postal_code\"],\n country: [\"physCountry\", \"phys_country\"],\n} as const;\n\nconst MAIL_FIELDS = {\n address1: [\"mailAddress1\", \"mail_address1\", \"address1\"],\n address2: [\"mailAddress2\", \"mail_address2\", \"address2\"],\n city: [\"mailCity\", \"mail_city\", \"city\"],\n state: [\"mailState\", \"mail_state\", \"state\"],\n zip: [\"mailPostalCode\", \"mail_postal_code\", \"postalCode\", \"zip\"],\n country: [\"mailCountry\", \"mail_country\", \"country\"],\n} as const;\n\nexport function transformShipToAddress(raw: RawShipTo): ShipToAddress {\n const isPhys =\n raw.physAddress1 != null ||\n raw.physCity != null ||\n raw.physState != null;\n\n const f = isPhys ? PHYS_FIELDS : MAIL_FIELDS;\n\n const address: ShipToAddress = {\n shipToId: (raw.shipToId ?? raw.ship_to_id ?? raw.id ?? \"\") as\n | string\n | number,\n name: str(raw.shipToName ?? raw.ship_to_name ?? raw.name ?? \"\"),\n address1: pick(raw, [...f.address1]),\n city: pick(raw, [...f.city]),\n state: pick(raw, [...f.state]),\n zip: pick(raw, [...f.zip]),\n };\n\n const address2 = pick(raw, [...f.address2]);\n if (address2) address.address2 = address2;\n\n const country = pick(raw, [...f.country]);\n if (country) address.country = country;\n\n return address;\n}\n","import type { TCartLine } from \"./types/cart\";\n\nexport type OeHdr = {\n customer_id: number;\n company_id: string;\n sales_location_id: number;\n user_id: number;\n user_email: string;\n taker: string;\n customer_po_no?: string;\n ship_to_id?: string | number;\n delivery_instructions?: string;\n};\n\nexport type OeLine = {\n item_id: string;\n unit_quantity: number;\n unit_of_measure: string;\n inv_mast_uid: number;\n unit_price?: number;\n};\n\nexport type CheckoutInput = {\n customerId: number;\n companyId: string;\n salesLocationId: number;\n userId: number;\n userEmail: string;\n taker?: string;\n cartLines: TCartLine[];\n poNumber?: string;\n shipToId?: string | number;\n deliveryInstructions?: string;\n};\n\nexport function buildCheckoutPayload(input: CheckoutInput): {\n oe_hdr: OeHdr;\n oe_line: OeLine[];\n} {\n const oe_hdr: OeHdr = {\n customer_id: input.customerId,\n company_id: input.companyId,\n sales_location_id: input.salesLocationId,\n user_id: input.userId,\n user_email: input.userEmail,\n taker: input.taker ?? \"ESTORE\",\n };\n\n if (input.poNumber != null) oe_hdr.customer_po_no = input.poNumber;\n if (input.shipToId != null) oe_hdr.ship_to_id = input.shipToId;\n if (input.deliveryInstructions != null)\n oe_hdr.delivery_instructions = input.deliveryInstructions;\n\n const oe_line: OeLine[] = input.cartLines.map((line) => {\n const oeLine: OeLine = {\n item_id: line.itemId,\n unit_quantity: line.quantity,\n unit_of_measure: line.unitOfMeasure,\n inv_mast_uid: line.invMastUid,\n };\n if (line.unitPrice != null) oeLine.unit_price = line.unitPrice;\n return oeLine;\n });\n\n return { oe_hdr, oe_line };\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -833,4 +833,60 @@ interface UserAddress {
|
|
|
833
833
|
*/
|
|
834
834
|
declare function isAddressDifferent(userAddress: UserAddress, smartyAddress: TSmartyStreets): boolean;
|
|
835
835
|
|
|
836
|
-
|
|
836
|
+
type PaymentStatusInvoice = {
|
|
837
|
+
paidInFullFlag?: string | null;
|
|
838
|
+
amountPaid?: number;
|
|
839
|
+
totalAmount?: number;
|
|
840
|
+
};
|
|
841
|
+
type PaymentStatus = "Paid" | "Partially Paid" | "Unpaid";
|
|
842
|
+
declare function getPaymentStatus(invoice: PaymentStatusInvoice): PaymentStatus;
|
|
843
|
+
|
|
844
|
+
type ShipToAddress = {
|
|
845
|
+
shipToId: string | number;
|
|
846
|
+
name: string;
|
|
847
|
+
address1: string;
|
|
848
|
+
address2?: string;
|
|
849
|
+
city: string;
|
|
850
|
+
state: string;
|
|
851
|
+
zip: string;
|
|
852
|
+
country?: string;
|
|
853
|
+
};
|
|
854
|
+
type RawShipTo = Record<string, unknown>;
|
|
855
|
+
declare function transformShipToAddress(raw: RawShipTo): ShipToAddress;
|
|
856
|
+
|
|
857
|
+
type OeHdr = {
|
|
858
|
+
customer_id: number;
|
|
859
|
+
company_id: string;
|
|
860
|
+
sales_location_id: number;
|
|
861
|
+
user_id: number;
|
|
862
|
+
user_email: string;
|
|
863
|
+
taker: string;
|
|
864
|
+
customer_po_no?: string;
|
|
865
|
+
ship_to_id?: string | number;
|
|
866
|
+
delivery_instructions?: string;
|
|
867
|
+
};
|
|
868
|
+
type OeLine = {
|
|
869
|
+
item_id: string;
|
|
870
|
+
unit_quantity: number;
|
|
871
|
+
unit_of_measure: string;
|
|
872
|
+
inv_mast_uid: number;
|
|
873
|
+
unit_price?: number;
|
|
874
|
+
};
|
|
875
|
+
type CheckoutInput = {
|
|
876
|
+
customerId: number;
|
|
877
|
+
companyId: string;
|
|
878
|
+
salesLocationId: number;
|
|
879
|
+
userId: number;
|
|
880
|
+
userEmail: string;
|
|
881
|
+
taker?: string;
|
|
882
|
+
cartLines: TCartLine[];
|
|
883
|
+
poNumber?: string;
|
|
884
|
+
shipToId?: string | number;
|
|
885
|
+
deliveryInstructions?: string;
|
|
886
|
+
};
|
|
887
|
+
declare function buildCheckoutPayload(input: CheckoutInput): {
|
|
888
|
+
oe_hdr: OeHdr;
|
|
889
|
+
oe_line: OeLine[];
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
export { CACHE_CONFIG, type CacheTier, type CheckoutInput, type CustomerDocument, type MenuItem, type OeHdr, type OeLine, type OrderHeader, type OrderLine, type OrderNote, type OrderPayment, type PaymentStatus, type PaymentStatusInvoice, type ShipToAddress, type TApiResponse, type TAttribute, type TAttributeValue, type TCartHdrUid, type TCartLine, type TCartLookUp, type TCategory, type TCategoryChild, type TInvMast, type TInvMastDoc, type TInventorySupplier, type TItemAccessory, type TItemAttribute, type TItemAttributes, type TItemCategory, type TItemDetails, type TItemRelatedProduct, type TItemUom, type TItemsFilters, type TJoomlaContent, type TJoomlaContentFilters, type TLibraryPriceBreak, type TLibraryPriceData, type TLtlRatesResponse, type TLtlShipmentData, type TMenu, type TMenuFilters, type TMetaTags, type TOrderCartLine, type TPriceData, type TProductCategory, type TProductItem, type TProductStockData, type TProfileValues, type TRelatedProduct, type TSearchSuggestion, type TSearchSuggestionsResponse, type TShippingMethod, type TSmartyStreets, type TStock, type TStockData, type TTax, type TTaxItem, type TUserProfile, type TWebDesc, type UserAddress, buildCheckoutPayload, formatPrice, getPaymentStatus, isAddressDifferent, transformShipToAddress };
|
package/dist/index.d.ts
CHANGED
|
@@ -833,4 +833,60 @@ interface UserAddress {
|
|
|
833
833
|
*/
|
|
834
834
|
declare function isAddressDifferent(userAddress: UserAddress, smartyAddress: TSmartyStreets): boolean;
|
|
835
835
|
|
|
836
|
-
|
|
836
|
+
type PaymentStatusInvoice = {
|
|
837
|
+
paidInFullFlag?: string | null;
|
|
838
|
+
amountPaid?: number;
|
|
839
|
+
totalAmount?: number;
|
|
840
|
+
};
|
|
841
|
+
type PaymentStatus = "Paid" | "Partially Paid" | "Unpaid";
|
|
842
|
+
declare function getPaymentStatus(invoice: PaymentStatusInvoice): PaymentStatus;
|
|
843
|
+
|
|
844
|
+
type ShipToAddress = {
|
|
845
|
+
shipToId: string | number;
|
|
846
|
+
name: string;
|
|
847
|
+
address1: string;
|
|
848
|
+
address2?: string;
|
|
849
|
+
city: string;
|
|
850
|
+
state: string;
|
|
851
|
+
zip: string;
|
|
852
|
+
country?: string;
|
|
853
|
+
};
|
|
854
|
+
type RawShipTo = Record<string, unknown>;
|
|
855
|
+
declare function transformShipToAddress(raw: RawShipTo): ShipToAddress;
|
|
856
|
+
|
|
857
|
+
type OeHdr = {
|
|
858
|
+
customer_id: number;
|
|
859
|
+
company_id: string;
|
|
860
|
+
sales_location_id: number;
|
|
861
|
+
user_id: number;
|
|
862
|
+
user_email: string;
|
|
863
|
+
taker: string;
|
|
864
|
+
customer_po_no?: string;
|
|
865
|
+
ship_to_id?: string | number;
|
|
866
|
+
delivery_instructions?: string;
|
|
867
|
+
};
|
|
868
|
+
type OeLine = {
|
|
869
|
+
item_id: string;
|
|
870
|
+
unit_quantity: number;
|
|
871
|
+
unit_of_measure: string;
|
|
872
|
+
inv_mast_uid: number;
|
|
873
|
+
unit_price?: number;
|
|
874
|
+
};
|
|
875
|
+
type CheckoutInput = {
|
|
876
|
+
customerId: number;
|
|
877
|
+
companyId: string;
|
|
878
|
+
salesLocationId: number;
|
|
879
|
+
userId: number;
|
|
880
|
+
userEmail: string;
|
|
881
|
+
taker?: string;
|
|
882
|
+
cartLines: TCartLine[];
|
|
883
|
+
poNumber?: string;
|
|
884
|
+
shipToId?: string | number;
|
|
885
|
+
deliveryInstructions?: string;
|
|
886
|
+
};
|
|
887
|
+
declare function buildCheckoutPayload(input: CheckoutInput): {
|
|
888
|
+
oe_hdr: OeHdr;
|
|
889
|
+
oe_line: OeLine[];
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
export { CACHE_CONFIG, type CacheTier, type CheckoutInput, type CustomerDocument, type MenuItem, type OeHdr, type OeLine, type OrderHeader, type OrderLine, type OrderNote, type OrderPayment, type PaymentStatus, type PaymentStatusInvoice, type ShipToAddress, type TApiResponse, type TAttribute, type TAttributeValue, type TCartHdrUid, type TCartLine, type TCartLookUp, type TCategory, type TCategoryChild, type TInvMast, type TInvMastDoc, type TInventorySupplier, type TItemAccessory, type TItemAttribute, type TItemAttributes, type TItemCategory, type TItemDetails, type TItemRelatedProduct, type TItemUom, type TItemsFilters, type TJoomlaContent, type TJoomlaContentFilters, type TLibraryPriceBreak, type TLibraryPriceData, type TLtlRatesResponse, type TLtlShipmentData, type TMenu, type TMenuFilters, type TMetaTags, type TOrderCartLine, type TPriceData, type TProductCategory, type TProductItem, type TProductStockData, type TProfileValues, type TRelatedProduct, type TSearchSuggestion, type TSearchSuggestionsResponse, type TShippingMethod, type TSmartyStreets, type TStock, type TStockData, type TTax, type TTaxItem, type TUserProfile, type TWebDesc, type UserAddress, buildCheckoutPayload, formatPrice, getPaymentStatus, isAddressDifferent, transformShipToAddress };
|
package/dist/index.js
CHANGED
|
@@ -48,10 +48,93 @@ function formatPrice(price, locale = "en-US", currency = "USD") {
|
|
|
48
48
|
function isAddressDifferent(userAddress, smartyAddress) {
|
|
49
49
|
return smartyAddress.deliveryLine1.toLowerCase() !== userAddress.address1.toLowerCase() || smartyAddress.cityName.toLowerCase() !== userAddress.city.toLowerCase() || smartyAddress.stateAbbreviation !== userAddress.state || smartyAddress.zipCode !== userAddress.postalCode;
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
// src/get-payment-status.ts
|
|
53
|
+
function getPaymentStatus(invoice) {
|
|
54
|
+
if (invoice.paidInFullFlag === "Y") return "Paid";
|
|
55
|
+
if (invoice.amountPaid != null && invoice.totalAmount != null && invoice.amountPaid > 0)
|
|
56
|
+
return "Partially Paid";
|
|
57
|
+
return "Unpaid";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/transform-ship-to-address.ts
|
|
61
|
+
function str(value) {
|
|
62
|
+
if (value == null) return "";
|
|
63
|
+
return String(value).trim();
|
|
64
|
+
}
|
|
65
|
+
function pick(raw, keys) {
|
|
66
|
+
for (const k of keys) {
|
|
67
|
+
if (raw[k] != null) return str(raw[k]);
|
|
68
|
+
}
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
var PHYS_FIELDS = {
|
|
72
|
+
address1: ["physAddress1", "phys_address1"],
|
|
73
|
+
address2: ["physAddress2", "phys_address2"],
|
|
74
|
+
city: ["physCity", "phys_city"],
|
|
75
|
+
state: ["physState", "phys_state"],
|
|
76
|
+
zip: ["physPostalCode", "phys_postal_code"],
|
|
77
|
+
country: ["physCountry", "phys_country"]
|
|
78
|
+
};
|
|
79
|
+
var MAIL_FIELDS = {
|
|
80
|
+
address1: ["mailAddress1", "mail_address1", "address1"],
|
|
81
|
+
address2: ["mailAddress2", "mail_address2", "address2"],
|
|
82
|
+
city: ["mailCity", "mail_city", "city"],
|
|
83
|
+
state: ["mailState", "mail_state", "state"],
|
|
84
|
+
zip: ["mailPostalCode", "mail_postal_code", "postalCode", "zip"],
|
|
85
|
+
country: ["mailCountry", "mail_country", "country"]
|
|
86
|
+
};
|
|
87
|
+
function transformShipToAddress(raw) {
|
|
88
|
+
const isPhys = raw.physAddress1 != null || raw.physCity != null || raw.physState != null;
|
|
89
|
+
const f = isPhys ? PHYS_FIELDS : MAIL_FIELDS;
|
|
90
|
+
const address = {
|
|
91
|
+
shipToId: raw.shipToId ?? raw.ship_to_id ?? raw.id ?? "",
|
|
92
|
+
name: str(raw.shipToName ?? raw.ship_to_name ?? raw.name ?? ""),
|
|
93
|
+
address1: pick(raw, [...f.address1]),
|
|
94
|
+
city: pick(raw, [...f.city]),
|
|
95
|
+
state: pick(raw, [...f.state]),
|
|
96
|
+
zip: pick(raw, [...f.zip])
|
|
97
|
+
};
|
|
98
|
+
const address2 = pick(raw, [...f.address2]);
|
|
99
|
+
if (address2) address.address2 = address2;
|
|
100
|
+
const country = pick(raw, [...f.country]);
|
|
101
|
+
if (country) address.country = country;
|
|
102
|
+
return address;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/build-checkout-payload.ts
|
|
106
|
+
function buildCheckoutPayload(input) {
|
|
107
|
+
const oe_hdr = {
|
|
108
|
+
customer_id: input.customerId,
|
|
109
|
+
company_id: input.companyId,
|
|
110
|
+
sales_location_id: input.salesLocationId,
|
|
111
|
+
user_id: input.userId,
|
|
112
|
+
user_email: input.userEmail,
|
|
113
|
+
taker: input.taker ?? "ESTORE"
|
|
114
|
+
};
|
|
115
|
+
if (input.poNumber != null) oe_hdr.customer_po_no = input.poNumber;
|
|
116
|
+
if (input.shipToId != null) oe_hdr.ship_to_id = input.shipToId;
|
|
117
|
+
if (input.deliveryInstructions != null)
|
|
118
|
+
oe_hdr.delivery_instructions = input.deliveryInstructions;
|
|
119
|
+
const oe_line = input.cartLines.map((line) => {
|
|
120
|
+
const oeLine = {
|
|
121
|
+
item_id: line.itemId,
|
|
122
|
+
unit_quantity: line.quantity,
|
|
123
|
+
unit_of_measure: line.unitOfMeasure,
|
|
124
|
+
inv_mast_uid: line.invMastUid
|
|
125
|
+
};
|
|
126
|
+
if (line.unitPrice != null) oeLine.unit_price = line.unitPrice;
|
|
127
|
+
return oeLine;
|
|
128
|
+
});
|
|
129
|
+
return { oe_hdr, oe_line };
|
|
130
|
+
}
|
|
51
131
|
export {
|
|
52
132
|
CACHE_CONFIG,
|
|
133
|
+
buildCheckoutPayload,
|
|
53
134
|
cn,
|
|
54
135
|
formatPrice,
|
|
55
|
-
|
|
136
|
+
getPaymentStatus,
|
|
137
|
+
isAddressDifferent,
|
|
138
|
+
transformShipToAddress
|
|
56
139
|
};
|
|
57
140
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cache-config.ts","../src/format-price.ts","../src/address-comparison.ts"],"sourcesContent":["/**\n * Centralized cache configuration for React Query (TanStack Query)\n *\n * staleTime -- How long cached data is considered \"fresh\". While fresh,\n * React Query serves the cache instantly and does NOT refetch in the\n * background. After staleTime expires the data is \"stale\" and will be\n * refetched on the next access (mount, window focus, etc.).\n *\n * gcTime (garbage collection time) -- How long UNUSED cached data stays in\n * memory after all components using it unmount. Once gcTime expires the\n * cache entry is deleted entirely.\n *\n * STATIC (1h): categories, menus, item details\n * SEMI_STATIC (10m): pricing, stock, search results\n * DYNAMIC (5m): infinite scroll data\n * CART (2m): cart lines, cart header\n * REALTIME (0): active orders, checkout state\n */\nexport const CACHE_CONFIG = {\n STATIC: {\n staleTime: 1000 * 60 * 60, // 1 hour\n gcTime: 1000 * 60 * 60 * 24, // 24 hours\n },\n SEMI_STATIC: {\n staleTime: 1000 * 60 * 10, // 10 minutes\n gcTime: 1000 * 60 * 60 * 4, // 4 hours\n },\n DYNAMIC: {\n staleTime: 1000 * 60 * 5, // 5 minutes\n gcTime: 1000 * 60 * 30, // 30 minutes\n },\n CART: {\n staleTime: 1000 * 60 * 2, // 2 minutes\n gcTime: 1000 * 60 * 30, // 30 minutes\n },\n REALTIME: {\n staleTime: 0,\n gcTime: 1000 * 60 * 5, // 5 minutes\n },\n} as const;\n\nexport type CacheTier = keyof typeof CACHE_CONFIG;\n","/**\n * Locale-aware currency formatting.\n * Defaults to USD -- consumers can override locale and currency.\n */\nexport function formatPrice(\n price: number,\n locale: string = \"en-US\",\n currency: string = \"USD\",\n): string {\n return new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency,\n minimumFractionDigits: 2,\n }).format(price);\n}\n","import type { TSmartyStreets } from \"./types/smarty-streets\";\n\n/** User-entered address fields for comparison. */\nexport interface UserAddress {\n address1: string;\n city: string;\n state: string;\n postalCode: string;\n}\n\n/**\n * Compares a user-entered address with a SmartyStreets-validated address.\n * Returns true if any field differs (case-insensitive for address/city,\n * exact match for state abbreviation and zip code).\n *\n * Used in checkout to prompt users when their input differs from the\n * USPS-validated address.\n */\nexport function isAddressDifferent(\n userAddress: UserAddress,\n smartyAddress: TSmartyStreets,\n): boolean {\n return (\n smartyAddress.deliveryLine1.toLowerCase() !== userAddress.address1.toLowerCase() ||\n smartyAddress.cityName.toLowerCase() !== userAddress.city.toLowerCase() ||\n smartyAddress.stateAbbreviation !== userAddress.state ||\n smartyAddress.zipCode !== userAddress.postalCode\n );\n}\n"],"mappings":";;;;;AAkBO,IAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,IACN,WAAW,MAAO,KAAK;AAAA;AAAA,IACvB,QAAQ,MAAO,KAAK,KAAK;AAAA;AAAA,EAC3B;AAAA,EACA,aAAa;AAAA,IACX,WAAW,MAAO,KAAK;AAAA;AAAA,IACvB,QAAQ,MAAO,KAAK,KAAK;AAAA;AAAA,EAC3B;AAAA,EACA,SAAS;AAAA,IACP,WAAW,MAAO,KAAK;AAAA;AAAA,IACvB,QAAQ,MAAO,KAAK;AAAA;AAAA,EACtB;AAAA,EACA,MAAM;AAAA,IACJ,WAAW,MAAO,KAAK;AAAA;AAAA,IACvB,QAAQ,MAAO,KAAK;AAAA;AAAA,EACtB;AAAA,EACA,UAAU;AAAA,IACR,WAAW;AAAA,IACX,QAAQ,MAAO,KAAK;AAAA;AAAA,EACtB;AACF;;;ACnCO,SAAS,YACd,OACA,SAAiB,SACjB,WAAmB,OACX;AACR,SAAO,IAAI,KAAK,aAAa,QAAQ;AAAA,IACnC,OAAO;AAAA,IACP;AAAA,IACA,uBAAuB;AAAA,EACzB,CAAC,EAAE,OAAO,KAAK;AACjB;;;ACIO,SAAS,mBACd,aACA,eACS;AACT,SACE,cAAc,cAAc,YAAY,MAAM,YAAY,SAAS,YAAY,KAC/E,cAAc,SAAS,YAAY,MAAM,YAAY,KAAK,YAAY,KACtE,cAAc,sBAAsB,YAAY,SAChD,cAAc,YAAY,YAAY;AAE1C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/cache-config.ts","../src/format-price.ts","../src/address-comparison.ts","../src/get-payment-status.ts","../src/transform-ship-to-address.ts","../src/build-checkout-payload.ts"],"sourcesContent":["/**\n * Centralized cache configuration for React Query (TanStack Query)\n *\n * staleTime -- How long cached data is considered \"fresh\". While fresh,\n * React Query serves the cache instantly and does NOT refetch in the\n * background. After staleTime expires the data is \"stale\" and will be\n * refetched on the next access (mount, window focus, etc.).\n *\n * gcTime (garbage collection time) -- How long UNUSED cached data stays in\n * memory after all components using it unmount. Once gcTime expires the\n * cache entry is deleted entirely.\n *\n * STATIC (1h): categories, menus, item details\n * SEMI_STATIC (10m): pricing, stock, search results\n * DYNAMIC (5m): infinite scroll data\n * CART (2m): cart lines, cart header\n * REALTIME (0): active orders, checkout state\n */\nexport const CACHE_CONFIG = {\n STATIC: {\n staleTime: 1000 * 60 * 60, // 1 hour\n gcTime: 1000 * 60 * 60 * 24, // 24 hours\n },\n SEMI_STATIC: {\n staleTime: 1000 * 60 * 10, // 10 minutes\n gcTime: 1000 * 60 * 60 * 4, // 4 hours\n },\n DYNAMIC: {\n staleTime: 1000 * 60 * 5, // 5 minutes\n gcTime: 1000 * 60 * 30, // 30 minutes\n },\n CART: {\n staleTime: 1000 * 60 * 2, // 2 minutes\n gcTime: 1000 * 60 * 30, // 30 minutes\n },\n REALTIME: {\n staleTime: 0,\n gcTime: 1000 * 60 * 5, // 5 minutes\n },\n} as const;\n\nexport type CacheTier = keyof typeof CACHE_CONFIG;\n","/**\n * Locale-aware currency formatting.\n * Defaults to USD -- consumers can override locale and currency.\n */\nexport function formatPrice(\n price: number,\n locale: string = \"en-US\",\n currency: string = \"USD\",\n): string {\n return new Intl.NumberFormat(locale, {\n style: \"currency\",\n currency,\n minimumFractionDigits: 2,\n }).format(price);\n}\n","import type { TSmartyStreets } from \"./types/smarty-streets\";\n\n/** User-entered address fields for comparison. */\nexport interface UserAddress {\n address1: string;\n city: string;\n state: string;\n postalCode: string;\n}\n\n/**\n * Compares a user-entered address with a SmartyStreets-validated address.\n * Returns true if any field differs (case-insensitive for address/city,\n * exact match for state abbreviation and zip code).\n *\n * Used in checkout to prompt users when their input differs from the\n * USPS-validated address.\n */\nexport function isAddressDifferent(\n userAddress: UserAddress,\n smartyAddress: TSmartyStreets,\n): boolean {\n return (\n smartyAddress.deliveryLine1.toLowerCase() !== userAddress.address1.toLowerCase() ||\n smartyAddress.cityName.toLowerCase() !== userAddress.city.toLowerCase() ||\n smartyAddress.stateAbbreviation !== userAddress.state ||\n smartyAddress.zipCode !== userAddress.postalCode\n );\n}\n","export type PaymentStatusInvoice = {\n paidInFullFlag?: string | null;\n amountPaid?: number;\n totalAmount?: number;\n};\n\nexport type PaymentStatus = \"Paid\" | \"Partially Paid\" | \"Unpaid\";\n\nexport function getPaymentStatus(invoice: PaymentStatusInvoice): PaymentStatus {\n if (invoice.paidInFullFlag === \"Y\") return \"Paid\";\n if (\n invoice.amountPaid != null &&\n invoice.totalAmount != null &&\n invoice.amountPaid > 0\n )\n return \"Partially Paid\";\n return \"Unpaid\";\n}\n","export type ShipToAddress = {\n shipToId: string | number;\n name: string;\n address1: string;\n address2?: string;\n city: string;\n state: string;\n zip: string;\n country?: string;\n};\n\ntype RawShipTo = Record<string, unknown>;\n\nfunction str(value: unknown): string {\n if (value == null) return \"\";\n return String(value).trim();\n}\n\nfunction pick(raw: RawShipTo, keys: string[]): string {\n for (const k of keys) {\n if (raw[k] != null) return str(raw[k]);\n }\n return \"\";\n}\n\nconst PHYS_FIELDS = {\n address1: [\"physAddress1\", \"phys_address1\"],\n address2: [\"physAddress2\", \"phys_address2\"],\n city: [\"physCity\", \"phys_city\"],\n state: [\"physState\", \"phys_state\"],\n zip: [\"physPostalCode\", \"phys_postal_code\"],\n country: [\"physCountry\", \"phys_country\"],\n} as const;\n\nconst MAIL_FIELDS = {\n address1: [\"mailAddress1\", \"mail_address1\", \"address1\"],\n address2: [\"mailAddress2\", \"mail_address2\", \"address2\"],\n city: [\"mailCity\", \"mail_city\", \"city\"],\n state: [\"mailState\", \"mail_state\", \"state\"],\n zip: [\"mailPostalCode\", \"mail_postal_code\", \"postalCode\", \"zip\"],\n country: [\"mailCountry\", \"mail_country\", \"country\"],\n} as const;\n\nexport function transformShipToAddress(raw: RawShipTo): ShipToAddress {\n const isPhys =\n raw.physAddress1 != null ||\n raw.physCity != null ||\n raw.physState != null;\n\n const f = isPhys ? PHYS_FIELDS : MAIL_FIELDS;\n\n const address: ShipToAddress = {\n shipToId: (raw.shipToId ?? raw.ship_to_id ?? raw.id ?? \"\") as\n | string\n | number,\n name: str(raw.shipToName ?? raw.ship_to_name ?? raw.name ?? \"\"),\n address1: pick(raw, [...f.address1]),\n city: pick(raw, [...f.city]),\n state: pick(raw, [...f.state]),\n zip: pick(raw, [...f.zip]),\n };\n\n const address2 = pick(raw, [...f.address2]);\n if (address2) address.address2 = address2;\n\n const country = pick(raw, [...f.country]);\n if (country) address.country = country;\n\n return address;\n}\n","import type { TCartLine } from \"./types/cart\";\n\nexport type OeHdr = {\n customer_id: number;\n company_id: string;\n sales_location_id: number;\n user_id: number;\n user_email: string;\n taker: string;\n customer_po_no?: string;\n ship_to_id?: string | number;\n delivery_instructions?: string;\n};\n\nexport type OeLine = {\n item_id: string;\n unit_quantity: number;\n unit_of_measure: string;\n inv_mast_uid: number;\n unit_price?: number;\n};\n\nexport type CheckoutInput = {\n customerId: number;\n companyId: string;\n salesLocationId: number;\n userId: number;\n userEmail: string;\n taker?: string;\n cartLines: TCartLine[];\n poNumber?: string;\n shipToId?: string | number;\n deliveryInstructions?: string;\n};\n\nexport function buildCheckoutPayload(input: CheckoutInput): {\n oe_hdr: OeHdr;\n oe_line: OeLine[];\n} {\n const oe_hdr: OeHdr = {\n customer_id: input.customerId,\n company_id: input.companyId,\n sales_location_id: input.salesLocationId,\n user_id: input.userId,\n user_email: input.userEmail,\n taker: input.taker ?? \"ESTORE\",\n };\n\n if (input.poNumber != null) oe_hdr.customer_po_no = input.poNumber;\n if (input.shipToId != null) oe_hdr.ship_to_id = input.shipToId;\n if (input.deliveryInstructions != null)\n oe_hdr.delivery_instructions = input.deliveryInstructions;\n\n const oe_line: OeLine[] = input.cartLines.map((line) => {\n const oeLine: OeLine = {\n item_id: line.itemId,\n unit_quantity: line.quantity,\n unit_of_measure: line.unitOfMeasure,\n inv_mast_uid: line.invMastUid,\n };\n if (line.unitPrice != null) oeLine.unit_price = line.unitPrice;\n return oeLine;\n });\n\n return { oe_hdr, oe_line };\n}\n"],"mappings":";;;;;AAkBO,IAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,IACN,WAAW,MAAO,KAAK;AAAA;AAAA,IACvB,QAAQ,MAAO,KAAK,KAAK;AAAA;AAAA,EAC3B;AAAA,EACA,aAAa;AAAA,IACX,WAAW,MAAO,KAAK;AAAA;AAAA,IACvB,QAAQ,MAAO,KAAK,KAAK;AAAA;AAAA,EAC3B;AAAA,EACA,SAAS;AAAA,IACP,WAAW,MAAO,KAAK;AAAA;AAAA,IACvB,QAAQ,MAAO,KAAK;AAAA;AAAA,EACtB;AAAA,EACA,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