@kizlo/woocommerce 0.11.0 → 0.13.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
@@ -193,6 +193,105 @@ const REMOVE_COUPON_ERROR_MAP = defineErrorMap({
193
193
  }
194
194
  });
195
195
 
196
+ //#endregion
197
+ //#region src/field-projections.ts
198
+ /** The native API is a projection of a registered value, never a second storage field. */
199
+ const BillingFieldProjections = { taxId: {
200
+ id: "kizlo/tax-id",
201
+ location: "address",
202
+ group: "billing",
203
+ excludedGroups: ["shipping"],
204
+ schema: z$1.string().default("")
205
+ } };
206
+ const BillingNativeFields = Object.fromEntries(Object.entries(BillingFieldProjections).map(([property, projection]) => [property, projection.schema]));
207
+ /** Partial updates must not execute the response/full-submission default for an omitted property. */
208
+ const BillingNativeInputFields = Object.fromEntries(Object.entries(BillingFieldProjections).map(([property, projection]) => [property, projection.schema.removeDefault().optional()]));
209
+ function isProjectedBillingField(id) {
210
+ return Object.values(BillingFieldProjections).some((projection) => projection.id === id);
211
+ }
212
+ /** Preserve the existing billing-only policy independently of Woo's address registration and UI rules. */
213
+ function isExcludedRegisteredField(id, group) {
214
+ return Object.values(BillingFieldProjections).some((projection) => projection.id === id && projection.excludedGroups.includes(group));
215
+ }
216
+ function deserializeBillingFields(fields) {
217
+ return Object.fromEntries(Object.entries(BillingFieldProjections).map(([property, projection]) => {
218
+ const parsed = projection.schema.safeParse(fields[projection.id]);
219
+ return [property, parsed.success ? parsed.data : projection.schema.parse(void 0)];
220
+ }));
221
+ }
222
+ /** Bypass callers must obey the same single-value contract as typed/schema-validated callers. */
223
+ function serializeBillingFields(address) {
224
+ const fields = {};
225
+ for (const [property, projection] of Object.entries(BillingFieldProjections)) {
226
+ if (Object.hasOwn(address.additionalFields ?? {}, projection.id)) throw new TypeError(`Use billingAddress.${property} instead of additionalFields["${projection.id}"].`);
227
+ const value = address[property];
228
+ if (value !== void 0) fields[projection.id] = value;
229
+ }
230
+ return fields;
231
+ }
232
+ /** Resolve only registered, unambiguous identities. Group-level errors need no invented leaf target. */
233
+ function resolveRegisteredFieldTarget(locations, id, group, surface = "checkout") {
234
+ const matches = Object.keys(locations).filter((location$1) => locations[location$1].includes(id));
235
+ const location = matches[0];
236
+ if (matches.length !== 1 || location === void 0) return null;
237
+ if (location !== "address") {
238
+ if (group !== void 0 && group !== "other" || surface === "customer" && location === "order") return null;
239
+ return {
240
+ id,
241
+ location,
242
+ group: "other",
243
+ path: ["additionalFields", id],
244
+ wirePath: ["additional_fields", id]
245
+ };
246
+ }
247
+ if (group !== "billing" && group !== "shipping") return null;
248
+ if (isExcludedRegisteredField(id, group)) return null;
249
+ const address = surface === "customer" ? group : `${group}Address`;
250
+ const wireAddress = surface === "customer" ? group : `${group}_address`;
251
+ const projection = Object.entries(BillingFieldProjections).find(([, projection$1]) => projection$1.id === id && projection$1.group === group);
252
+ return {
253
+ id,
254
+ location,
255
+ group,
256
+ path: projection ? [address, projection[0]] : [
257
+ address,
258
+ "additionalFields",
259
+ id
260
+ ],
261
+ wirePath: surface === "customer" ? [
262
+ wireAddress,
263
+ "additional_fields",
264
+ id
265
+ ] : [wireAddress, id]
266
+ };
267
+ }
268
+
269
+ //#endregion
270
+ //#region src/additional-fields.ts
271
+ /** Structural scalar guard only. Generated types do not execute field enums, requirements or conditions. */
272
+ function fieldsSchema(acceptKey = () => true) {
273
+ return z$1.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.entries(value).every(([id, field]) => acceptKey(id) && (field === void 0 || typeof field === "string" || typeof field === "boolean")));
274
+ }
275
+ const AddressAdditionalFieldsSchema = fieldsSchema();
276
+ const AddressAdditionalFieldsSubmissionSchema = fieldsSchema();
277
+ const BillingAdditionalFieldsSchema = fieldsSchema((id) => !isProjectedBillingField(id));
278
+ const BillingAdditionalFieldsSubmissionSchema = fieldsSchema((id) => !isProjectedBillingField(id));
279
+ const ContactAdditionalFieldsSchema = fieldsSchema();
280
+ const CheckoutAdditionalFieldsSchema = fieldsSchema();
281
+ const CheckoutAdditionalFieldsSubmissionSchema = fieldsSchema();
282
+ /** Retain compatible unknown response keys. WooCommerce validates writes against its live registry. */
283
+ function additionalFieldValues(value) {
284
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
285
+ return Object.fromEntries(Object.entries(value).filter(([, field]) => typeof field === "string" || typeof field === "boolean"));
286
+ }
287
+ /** Keep unprojected and compatible unknown values while exposing each billing value only once. */
288
+ function billingAdditionalFieldValues(value) {
289
+ return Object.fromEntries(Object.entries(additionalFieldValues(value)).filter(([id]) => !isProjectedBillingField(id)));
290
+ }
291
+ function shippingAdditionalFieldValues(value) {
292
+ return Object.fromEntries(Object.entries(additionalFieldValues(value)).filter(([id]) => !isExcludedRegisteredField(id, "shipping")));
293
+ }
294
+
196
295
  //#endregion
197
296
  //#region src/product/schema.ts
198
297
  const SWATCH_TYPES = [
@@ -485,7 +584,7 @@ const RetrieveProductFiltersInput = ListProductInput.omit({ recommendations: tru
485
584
 
486
585
  //#endregion
487
586
  //#region src/cart/schema.ts
488
- const CartAdditionalFields = z$1.record(z$1.string(), z$1.union([z$1.string(), z$1.boolean()]));
587
+ const CartAdditionalFields = AddressAdditionalFieldsSchema;
489
588
  const CartAddressFields = {
490
589
  firstName: z$1.string(),
491
590
  lastName: z$1.string(),
@@ -503,8 +602,12 @@ const CartShippingAddress = z$1.object(CartAddressFields);
503
602
  const CartBillingAddress = z$1.object({
504
603
  ...CartAddressFields,
505
604
  email: z$1.string(),
506
- taxId: z$1.string().default("")
605
+ ...BillingNativeFields,
606
+ additionalFields: BillingAdditionalFieldsSchema
507
607
  });
608
+ /** Full submissions retain registered requirements; cart mutations use the partial schemas below. */
609
+ const CartShippingAddressSubmission = CartShippingAddress.extend({ additionalFields: AddressAdditionalFieldsSubmissionSchema });
610
+ const CartBillingAddressSubmission = CartBillingAddress.extend({ additionalFields: BillingAdditionalFieldsSubmissionSchema });
508
611
  const CartShippingDestination = z$1.object({
509
612
  address1: z$1.string(),
510
613
  address2: z$1.string(),
@@ -677,12 +780,34 @@ const SelectCartShippingRateInput = z$1.object({
677
780
  packageId: z$1.union([z$1.number(), z$1.string()]).nullable().optional()
678
781
  });
679
782
  const CartShippingAddressInput = z$1.object(CartAddressFields).partial();
680
- const CartBillingAddressInput = CartBillingAddress.partial();
783
+ const CartBillingAddressInput = CartBillingAddress.partial().extend(BillingNativeInputFields);
681
784
  const UpdateCartInput = z$1.object({
682
785
  shippingAddress: CartShippingAddressInput.optional(),
683
786
  billingAddress: CartBillingAddressInput.optional()
684
787
  });
685
788
 
789
+ //#endregion
790
+ //#region src/address-fields.ts
791
+ /** Identity shared by Store API address serialization and storefront bindings. */
792
+ const CoreAddressFieldKeys = {
793
+ first_name: "firstName",
794
+ last_name: "lastName",
795
+ company: "company",
796
+ address_1: "address1",
797
+ address_2: "address2",
798
+ city: "city",
799
+ state: "state",
800
+ postcode: "postcode",
801
+ country: "country",
802
+ phone: "phone"
803
+ };
804
+ function deserializeCoreAddress(address) {
805
+ return Object.fromEntries(Object.entries(CoreAddressFieldKeys).map(([id, key]) => [key, address[id]]));
806
+ }
807
+ function serializeCoreAddress(address) {
808
+ return Object.fromEntries(Object.entries(CoreAddressFieldKeys).flatMap(([id, key]) => address[key] === void 0 ? [] : [[id, address[key]]]));
809
+ }
810
+
686
811
  //#endregion
687
812
  //#region src/product/utils.ts
688
813
  function assertNoMissingStoreProductInputs() {}
@@ -931,7 +1056,6 @@ function nullableNumber(value) {
931
1056
 
932
1057
  //#endregion
933
1058
  //#region src/cart/utils.ts
934
- const TAX_ID_KEY = "kizlo/tax-id";
935
1059
  function assertNoMissing$2() {}
936
1060
  assertNoMissing$2();
937
1061
  assertNoMissing$2();
@@ -1123,46 +1247,22 @@ function deserializePaymentMethods(value) {
1123
1247
  }
1124
1248
  function deserializeCartShippingAddress(address) {
1125
1249
  return {
1126
- firstName: address.first_name,
1127
- lastName: address.last_name,
1128
- company: address.company,
1129
- address1: address.address_1,
1130
- address2: address.address_2,
1131
- city: address.city,
1132
- state: address.state,
1133
- postcode: address.postcode,
1134
- country: address.country,
1135
- phone: address.phone,
1136
- additionalFields: additionalAddressFields(address, SHIPPING_ADDRESS_KEYS)
1250
+ ...deserializeCoreAddress(address),
1251
+ additionalFields: shippingAdditionalFieldValues(additionalAddressFields(address, SHIPPING_ADDRESS_KEYS))
1137
1252
  };
1138
1253
  }
1139
1254
  function deserializeCartBillingAddress(address) {
1140
1255
  return {
1141
1256
  ...deserializeCartShippingAddress(address),
1142
1257
  email: address.email,
1143
- taxId: taxId(address),
1144
- additionalFields: additionalAddressFields(address, BILLING_ADDRESS_KEYS)
1258
+ ...deserializeBillingFields(address),
1259
+ additionalFields: billingAdditionalFieldValues(additionalAddressFields(address, BILLING_ADDRESS_KEYS))
1145
1260
  };
1146
1261
  }
1147
- const SHIPPING_ADDRESS_KEYS = new Set([
1148
- "first_name",
1149
- "last_name",
1150
- "company",
1151
- "address_1",
1152
- "address_2",
1153
- "city",
1154
- "state",
1155
- "postcode",
1156
- "country",
1157
- "phone",
1158
- TAX_ID_KEY
1159
- ]);
1262
+ const SHIPPING_ADDRESS_KEYS = new Set(Object.keys(CoreAddressFieldKeys));
1160
1263
  const BILLING_ADDRESS_KEYS = new Set([...SHIPPING_ADDRESS_KEYS, "email"]);
1161
1264
  function additionalAddressFields(address, standardKeys) {
1162
- return Object.fromEntries(Object.entries(address).filter((entry) => !standardKeys.has(entry[0]) && (typeof entry[1] === "string" || typeof entry[1] === "boolean")));
1163
- }
1164
- function taxId(address) {
1165
- return typeof address[TAX_ID_KEY] === "string" ? address[TAX_ID_KEY] : "";
1265
+ return additionalFieldValues(Object.fromEntries(Object.entries(address).filter((entry) => !standardKeys.has(entry[0]) && (typeof entry[1] === "string" || typeof entry[1] === "boolean"))));
1166
1266
  }
1167
1267
  function serializeCartUpdateInput(input) {
1168
1268
  return {
@@ -1172,24 +1272,15 @@ function serializeCartUpdateInput(input) {
1172
1272
  }
1173
1273
  function serializeCartShippingAddress(address) {
1174
1274
  return compactAddress({
1175
- ...Object.fromEntries(Object.entries(address.additionalFields ?? {}).filter(([key]) => key !== TAX_ID_KEY)),
1176
- first_name: address.firstName,
1177
- last_name: address.lastName,
1178
- company: address.company,
1179
- address_1: address.address1,
1180
- address_2: address.address2,
1181
- city: address.city,
1182
- state: address.state,
1183
- postcode: address.postcode,
1184
- country: address.country,
1185
- phone: address.phone
1275
+ ...Object.fromEntries(Object.entries(address.additionalFields ?? {}).filter(([key]) => !BILLING_ADDRESS_KEYS.has(key) && !isExcludedRegisteredField(key, "shipping"))),
1276
+ ...serializeCoreAddress(address)
1186
1277
  });
1187
1278
  }
1188
1279
  function serializeCartBillingAddress(address) {
1189
1280
  return compactAddress({
1190
1281
  ...serializeCartShippingAddress(address),
1191
1282
  email: address.email,
1192
- [TAX_ID_KEY]: address.taxId
1283
+ ...serializeBillingFields(address)
1193
1284
  });
1194
1285
  }
1195
1286
  function compactAddress(address) {
@@ -1206,7 +1297,7 @@ const CART_PROCEDURES = {
1206
1297
  scope: "api",
1207
1298
  method: "GET",
1208
1299
  path: "/cart",
1209
- output: Cart,
1300
+ output: schemaType(Cart),
1210
1301
  errors: GET_CART_ERROR_MAP,
1211
1302
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1212
1303
  }, async ({ context, errors }) => {
@@ -1222,8 +1313,8 @@ const CART_PROCEDURES = {
1222
1313
  scope: "api",
1223
1314
  method: "PUT",
1224
1315
  path: "/cart",
1225
- output: Cart,
1226
- body: UpdateCartInput,
1316
+ output: schemaType(Cart),
1317
+ body: schemaType(UpdateCartInput),
1227
1318
  errors: UPDATE_CART_ERROR_MAP,
1228
1319
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1229
1320
  }, async ({ context, input: { body: input }, errors }) => {
@@ -1245,7 +1336,7 @@ const CART_PROCEDURES = {
1245
1336
  method: "PUT",
1246
1337
  path: "/cart/shipping-rate",
1247
1338
  body: SelectCartShippingRateInput,
1248
- output: Cart,
1339
+ output: schemaType(Cart),
1249
1340
  errors: SELECT_SHIPPING_RATE_ERROR_MAP,
1250
1341
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1251
1342
  }, async ({ context, input: { body }, errors }) => {
@@ -1268,7 +1359,7 @@ const CART_PROCEDURES = {
1268
1359
  method: "POST",
1269
1360
  path: "/cart/items",
1270
1361
  body: AddCartItemInput,
1271
- output: Cart,
1362
+ output: schemaType(Cart),
1272
1363
  errors: ADD_CART_ITEM_ERROR_MAP,
1273
1364
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1274
1365
  }, async ({ context, input: { body: input }, errors }) => {
@@ -1301,7 +1392,7 @@ const CART_PROCEDURES = {
1301
1392
  path: "/cart/items/{key}",
1302
1393
  params: UpdateCartItemInput.pick({ key: true }),
1303
1394
  body: UpdateCartItemInput.pick({ quantity: true }),
1304
- output: Cart,
1395
+ output: schemaType(Cart),
1305
1396
  errors: UPDATE_CART_ITEM_ERROR_MAP,
1306
1397
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1307
1398
  }, async ({ context, input: { params, body }, errors }) => {
@@ -1326,7 +1417,7 @@ const CART_PROCEDURES = {
1326
1417
  method: "DELETE",
1327
1418
  path: "/cart/items/{key}",
1328
1419
  params: RemoveCartItemInput.pick({ key: true }),
1329
- output: Cart,
1420
+ output: schemaType(Cart),
1330
1421
  errors: REMOVE_CART_ITEM_ERROR_MAP,
1331
1422
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1332
1423
  }, async ({ context, input: { params }, errors }) => {
@@ -1346,7 +1437,7 @@ const CART_PROCEDURES = {
1346
1437
  method: "POST",
1347
1438
  path: "/cart/coupons",
1348
1439
  body: ApplyCouponInput,
1349
- output: Cart,
1440
+ output: schemaType(Cart),
1350
1441
  errors: APPLY_COUPON_ERROR_MAP,
1351
1442
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1352
1443
  }, async ({ context, input: { body }, errors }) => {
@@ -1365,7 +1456,7 @@ const CART_PROCEDURES = {
1365
1456
  method: "DELETE",
1366
1457
  path: "/cart/coupons/{code}",
1367
1458
  params: RemoveCouponInput.pick({ code: true }),
1368
- output: Cart,
1459
+ output: schemaType(Cart),
1369
1460
  errors: REMOVE_COUPON_ERROR_MAP,
1370
1461
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1371
1462
  }, async ({ context, input, errors }) => {
@@ -1575,7 +1666,7 @@ const UPDATE_CHECKOUT_ERROR_MAP = defineErrorMap({
1575
1666
 
1576
1667
  //#endregion
1577
1668
  //#region src/checkout/schema.ts
1578
- const CheckoutAdditionalFields = z$2.record(z$2.string(), z$2.union([z$2.string(), z$2.boolean()]));
1669
+ const CheckoutAdditionalFields = CheckoutAdditionalFieldsSchema;
1579
1670
  const CheckoutExtensions = z$2.record(z$2.string(), z$2.unknown());
1580
1671
  const CheckoutPaymentData = z$2.array(z$2.object({
1581
1672
  key: z$2.string(),
@@ -1614,14 +1705,14 @@ const UpdateCheckoutInput = z$2.object({
1614
1705
  extensions: CheckoutExtensions.optional()
1615
1706
  });
1616
1707
  const ConfirmCheckoutInput = z$2.object({
1617
- billingAddress: CartBillingAddress,
1618
- shippingAddress: CartShippingAddress.optional(),
1708
+ billingAddress: CartBillingAddressSubmission,
1709
+ shippingAddress: CartShippingAddressSubmission.optional(),
1619
1710
  paymentMethod: z$2.string(),
1620
1711
  customerNote: z$2.string().optional(),
1621
1712
  createAccount: z$2.boolean().optional(),
1622
1713
  customerPassword: z$2.string().optional(),
1623
1714
  paymentData: CheckoutPaymentData.optional(),
1624
- additionalFields: CheckoutAdditionalFields.optional(),
1715
+ additionalFields: CheckoutAdditionalFieldsSubmissionSchema.optional(),
1625
1716
  extensions: CheckoutExtensions.optional(),
1626
1717
  successPath: RelativePath.optional(),
1627
1718
  cancelPath: RelativePath.optional()
@@ -1631,11 +1722,11 @@ const RetryCheckoutInput = z$2.object({
1631
1722
  orderId: NumberLike,
1632
1723
  paymentMethod: z$2.string(),
1633
1724
  billingEmail: z$2.email().optional(),
1634
- billingAddress: CartBillingAddress,
1725
+ billingAddress: CartBillingAddressSubmission,
1635
1726
  paymentData: CheckoutPaymentData.optional(),
1636
- shippingAddress: CartShippingAddress.optional(),
1727
+ shippingAddress: CartShippingAddressSubmission.optional(),
1637
1728
  customerNote: z$2.string().optional(),
1638
- additionalFields: CheckoutAdditionalFields.optional(),
1729
+ additionalFields: CheckoutAdditionalFieldsSubmissionSchema.optional(),
1639
1730
  extensions: CheckoutExtensions.optional(),
1640
1731
  successPath: RelativePath.optional(),
1641
1732
  cancelPath: RelativePath.optional()
@@ -1703,7 +1794,7 @@ function serializeCheckoutBillingAddress(address) {
1703
1794
  return serializeCartBillingAddress(address);
1704
1795
  }
1705
1796
  function checkoutAdditionalFields(fields) {
1706
- return Object.fromEntries(Object.entries(fields ?? {}).filter((entry) => typeof entry[1] === "string" || typeof entry[1] === "boolean"));
1797
+ return additionalFieldValues(fields);
1707
1798
  }
1708
1799
 
1709
1800
  //#endregion
@@ -1713,7 +1804,7 @@ const CHECKOUT_PROCEDURES = {
1713
1804
  scope: "api",
1714
1805
  method: "GET",
1715
1806
  path: "/checkout",
1716
- output: Checkout,
1807
+ output: schemaType(Checkout),
1717
1808
  errors: GET_CHECKOUT_ERROR_MAP,
1718
1809
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1719
1810
  }, async ({ context, errors }) => {
@@ -1729,8 +1820,8 @@ const CHECKOUT_PROCEDURES = {
1729
1820
  scope: "api",
1730
1821
  method: "PUT",
1731
1822
  path: "/checkout",
1732
- body: UpdateCheckoutInput,
1733
- output: Checkout,
1823
+ body: schemaType(UpdateCheckoutInput),
1824
+ output: schemaType(Checkout),
1734
1825
  errors: UPDATE_CHECKOUT_ERROR_MAP,
1735
1826
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1736
1827
  }, async ({ context, input, errors }) => {
@@ -1782,8 +1873,8 @@ const CHECKOUT_PROCEDURES = {
1782
1873
  scope: "api",
1783
1874
  method: "POST",
1784
1875
  path: "/checkout",
1785
- body: ConfirmCheckoutInput,
1786
- output: Checkout,
1876
+ body: schemaType(ConfirmCheckoutInput),
1877
+ output: schemaType(Checkout),
1787
1878
  errors: CONFIRM_CHECKOUT_ERROR_MAP,
1788
1879
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1789
1880
  }, async ({ context, input, errors }) => {
@@ -1867,8 +1958,8 @@ const CHECKOUT_PROCEDURES = {
1867
1958
  method: "POST",
1868
1959
  path: "/checkout/{orderId}",
1869
1960
  params: RetryCheckoutInput.pick({ orderId: true }),
1870
- body: RetryCheckoutInput.omit({ orderId: true }),
1871
- output: Checkout,
1961
+ body: schemaType(RetryCheckoutInput.omit({ orderId: true })),
1962
+ output: schemaType(Checkout),
1872
1963
  errors: RETRY_CHECKOUT_ERROR_MAP,
1873
1964
  middlewares: [sessionMiddleware({ transitionGuestCart: true })]
1874
1965
  }, async ({ context, input, errors }) => {
@@ -1956,6 +2047,7 @@ const ItemTotals = z$1.object({
1956
2047
  total: z$1.number()
1957
2048
  });
1958
2049
  const ShippingAddress = z$1.object({
2050
+ additionalFields: AddressAdditionalFieldsSchema.optional(),
1959
2051
  firstName: z$1.string(),
1960
2052
  lastName: z$1.string(),
1961
2053
  phone: z$1.string(),
@@ -1969,11 +2061,14 @@ const ShippingAddress = z$1.object({
1969
2061
  });
1970
2062
  const BillingAddress = ShippingAddress.extend({
1971
2063
  email: z$1.string(),
1972
- taxId: z$1.string().default("")
2064
+ ...BillingNativeFields,
2065
+ additionalFields: BillingAdditionalFieldsSchema.optional()
1973
2066
  });
1974
2067
 
1975
2068
  //#endregion
1976
2069
  //#region src/customer/schema.ts
2070
+ const CustomerBillingAddress = BillingAddress.extend({ additionalFields: BillingAdditionalFieldsSchema });
2071
+ const CustomerShippingAddress = ShippingAddress.extend({ additionalFields: AddressAdditionalFieldsSchema });
1977
2072
  const Customer = z$2.object({
1978
2073
  id: z$2.number(),
1979
2074
  email: z$2.string(),
@@ -1981,8 +2076,9 @@ const Customer = z$2.object({
1981
2076
  lastName: z$2.string(),
1982
2077
  role: z$2.string(),
1983
2078
  username: z$2.string(),
1984
- billing: BillingAddress,
1985
- shipping: ShippingAddress,
2079
+ billing: CustomerBillingAddress,
2080
+ shipping: CustomerShippingAddress,
2081
+ additionalFields: ContactAdditionalFieldsSchema,
1986
2082
  isPayingCustomer: z$2.boolean(),
1987
2083
  avatarUrl: z$2.string().nullable(),
1988
2084
  registeredAt: z$2.number(),
@@ -2008,9 +2104,11 @@ function deserializeCustomer(data) {
2008
2104
  state: billing.state,
2009
2105
  address2: billing.address_2,
2010
2106
  company: billing.company,
2011
- taxId: typeof billing.tax_id === "string" ? billing.tax_id : ""
2107
+ ...deserializeBillingFields(additionalFieldValues(billing.additional_fields)),
2108
+ additionalFields: billingAdditionalFieldValues(billing.additional_fields)
2012
2109
  },
2013
2110
  shipping: {
2111
+ additionalFields: shippingAdditionalFieldValues(data.shipping.additional_fields),
2014
2112
  firstName: data.shipping.first_name,
2015
2113
  lastName: data.shipping.last_name,
2016
2114
  address1: data.shipping.address_1,
@@ -2022,6 +2120,7 @@ function deserializeCustomer(data) {
2022
2120
  address2: data.shipping.address_2,
2023
2121
  company: data.shipping.company
2024
2122
  },
2123
+ additionalFields: additionalFieldValues(data.additional_fields),
2025
2124
  email: data.email,
2026
2125
  firstName: data.first_name,
2027
2126
  lastName: data.last_name,
@@ -2039,7 +2138,7 @@ const CUSTOMER_PROCEDURES = { get: createProcedure({
2039
2138
  scope: "api",
2040
2139
  method: "GET",
2041
2140
  path: "/customers",
2042
- output: Customer
2141
+ output: schemaType(Customer)
2043
2142
  }, async ({ context, errors }) => {
2044
2143
  const session = await context.getSession();
2045
2144
  if (!session) throw errors.FORBIDDEN();
@@ -2123,6 +2222,7 @@ const OrderTotals = z.object({
2123
2222
  taxLines: z.array(CartTaxLine)
2124
2223
  });
2125
2224
  const Order = z.object({
2225
+ additionalFields: CheckoutAdditionalFieldsSchema,
2126
2226
  id: z.number(),
2127
2227
  status: z.string(),
2128
2228
  isPaid: z.boolean(),
@@ -2166,6 +2266,7 @@ assertNoMissing();
2166
2266
  function deserializeOrder(data) {
2167
2267
  const { kizlo } = deserializeExtensions(data.extensions);
2168
2268
  return {
2269
+ additionalFields: additionalFieldValues(data.additional_fields),
2169
2270
  id: data.id,
2170
2271
  status: data.status,
2171
2272
  isPaid: kizlo.is_paid === true,
@@ -2438,7 +2539,22 @@ const StorefrontFieldOption = z$2.object({
2438
2539
  value: z$2.string(),
2439
2540
  label: z$2.string()
2440
2541
  });
2542
+ /** JSON Schema draft-07, retained as data for the consumer's validator. */
2543
+ const StorefrontFieldSchema = z$2.union([z$2.boolean(), z$2.record(z$2.string(), z$2.unknown())]);
2441
2544
  const StorefrontField = z$2.object({
2545
+ id: z$2.string(),
2546
+ location: z$2.enum([
2547
+ "address",
2548
+ "contact",
2549
+ "order"
2550
+ ]),
2551
+ attributes: z$2.record(z$2.string(), z$2.unknown()),
2552
+ schema: StorefrontFieldSchema,
2553
+ bindings: z$2.object({
2554
+ billing: z$2.array(z$2.string()).optional(),
2555
+ shipping: z$2.array(z$2.string()).optional(),
2556
+ other: z$2.array(z$2.string()).optional()
2557
+ }),
2442
2558
  label: z$2.string(),
2443
2559
  optionalLabel: z$2.string(),
2444
2560
  required: StorefrontFieldRule,
@@ -2471,12 +2587,7 @@ const StorefrontCountry = z$2.object({
2471
2587
  const StorefrontAddress = z$2.object({
2472
2588
  countries: z$2.array(StorefrontCountry),
2473
2589
  defaultAddressFormat: z$2.string(),
2474
- fields: z$2.record(z$2.string(), StorefrontField),
2475
- fieldLocations: z$2.object({
2476
- address: z$2.array(z$2.string()),
2477
- contact: z$2.array(z$2.string()),
2478
- order: z$2.array(z$2.string())
2479
- }),
2590
+ fields: z$2.array(StorefrontField),
2480
2591
  baseCountry: z$2.string(),
2481
2592
  defaultCountry: z$2.string().nullable()
2482
2593
  });
@@ -2491,7 +2602,8 @@ const StorefrontCheckout = z$2.object({
2491
2602
  localPickup: z$2.object({
2492
2603
  enabled: z$2.boolean(),
2493
2604
  title: z$2.string(),
2494
- cost: z$2.string()
2605
+ cost: z$2.string(),
2606
+ methodIds: z$2.array(z$2.string()).nullable()
2495
2607
  })
2496
2608
  });
2497
2609
  const StorefrontPricing = z$2.object({
@@ -2523,12 +2635,12 @@ const Storefront = z$2.object({
2523
2635
  //#region src/storefront/utils.ts
2524
2636
  function deserializeStorefront(data) {
2525
2637
  const { address, checkout, pricing, catalog } = data;
2638
+ const pickup = checkout.local_pickup;
2526
2639
  return {
2527
2640
  address: {
2528
2641
  countries: address.countries.map(deserializeCountry),
2529
2642
  defaultAddressFormat: address.default_address_format,
2530
- fields: Object.fromEntries(Object.entries(address.fields).map(([key, field]) => [key, deserializeField(field)])),
2531
- fieldLocations: address.field_locations,
2643
+ fields: address.fields.map(deserializeField),
2532
2644
  baseCountry: address.base_country,
2533
2645
  defaultCountry: address.default_country ?? null
2534
2646
  },
@@ -2540,7 +2652,12 @@ function deserializeStorefront(data) {
2540
2652
  displayCartPricesIncludingTax: checkout.display_cart_prices_including_tax,
2541
2653
  displayItemizedTaxes: checkout.display_itemized_taxes,
2542
2654
  shippingEnabled: checkout.shipping_enabled,
2543
- localPickup: checkout.local_pickup
2655
+ localPickup: {
2656
+ enabled: pickup.enabled,
2657
+ title: pickup.title,
2658
+ cost: pickup.cost,
2659
+ methodIds: deserializeMethodIds(pickup.method_ids)
2660
+ }
2544
2661
  },
2545
2662
  pricing: {
2546
2663
  currency: deserializeCurrencyFormat(pricing.currency),
@@ -2562,6 +2679,9 @@ function deserializeStorefront(data) {
2562
2679
  }
2563
2680
  };
2564
2681
  }
2682
+ function deserializeMethodIds(value) {
2683
+ return Array.isArray(value) && Array.from(value).every((id) => typeof id === "string") ? [...value] : null;
2684
+ }
2565
2685
  function deserializeCountry(country) {
2566
2686
  return {
2567
2687
  code: country.code,
@@ -2583,6 +2703,11 @@ function deserializeOverride(override) {
2583
2703
  }
2584
2704
  function deserializeField(field) {
2585
2705
  return {
2706
+ id: field.id,
2707
+ location: field.location,
2708
+ attributes: field.attributes ?? {},
2709
+ schema: field.schema,
2710
+ bindings: fieldBindings(field.id, field.location),
2586
2711
  label: field.label,
2587
2712
  optionalLabel: field.optionalLabel,
2588
2713
  required: deserializeRule(field.required),
@@ -2598,6 +2723,15 @@ function deserializeRule(rule) {
2598
2723
  if (typeof rule === "boolean") return rule;
2599
2724
  return typeof rule === "object" && rule !== null && !Array.isArray(rule) ? rule : false;
2600
2725
  }
2726
+ function fieldBindings(id, location) {
2727
+ if (location !== "address") return { other: id === "email" ? ["billingAddress", "email"] : ["additionalFields", id] };
2728
+ const core = Object.hasOwn(CoreAddressFieldKeys, id) ? CoreAddressFieldKeys[id] : void 0;
2729
+ const projection = Object.entries(BillingFieldProjections).find(([, entry]) => entry.id === id);
2730
+ return {
2731
+ billing: core ? [core] : projection ? [projection[0]] : ["additionalFields", id],
2732
+ ...!isExcludedRegisteredField(id, "shipping") && { shipping: core ? [core] : ["additionalFields", id] }
2733
+ };
2734
+ }
2601
2735
 
2602
2736
  //#endregion
2603
2737
  //#region src/storefront/index.ts
@@ -2647,4 +2781,4 @@ function woocommerce() {
2647
2781
  }
2648
2782
 
2649
2783
  //#endregion
2650
- export { AddCartItemInput, ApplyCouponInput, Cart, CartAdditionalFields, CartBillingAddress, CartCoupon, CartCouponTotals, CartError, CartFee, CartFeeTotals, CartItem, CartItemData, CartItemQuantityLimits, CartItemTotals, CartPaymentMethod, CartSelectedAttribute, CartShippingAddress, CartShippingDestination, CartShippingItem, CartShippingPackage, CartShippingRate, CartShippingRateMetadata, CartTaxLine, CartTotals, Checkout, CheckoutAdditionalFields, CheckoutExtensions, CheckoutPaymentData, CheckoutPaymentResult, ConfirmCheckoutInput, GetOrderInput, ListProductInput, Order, OrderFee, OrderItem, OrderItemProduct, OrderTotals, PRODUCT_ATTRIBUTE_RELATIONS, PRODUCT_CATALOG_VISIBILITIES, PRODUCT_DATE_COLUMNS, PRODUCT_RATINGS, PRODUCT_STOCK_STATUSES, PRODUCT_TYPES, Product, ProductAddToCart, ProductAttributeCount, ProductAttributeFilter, ProductAttributeRelation, ProductAttributeSummary, ProductAttributeTermSummary, ProductBrandSummary, ProductCatalogVisibility, ProductCategorySummary, ProductCustomFieldsSchema, ProductDateColumn, ProductDimensions, ProductExtensions, ProductFilters, ProductFiltersAttributeTerm, ProductFiltersPriceRange, ProductFiltersRatingCount, ProductFiltersStockStatus, ProductFiltersTaxonomyTerm, ProductFiltersTerm, ProductList, ProductOrderBy, ProductPriceRange, ProductPrices, ProductRating, ProductRecommendations, ProductStockAvailability, ProductStockStatus, ProductSummary, ProductTagSummary, ProductTaxonomyFilter, ProductTaxonomyOperator, ProductTermSummary, ProductType, ProductVariationAttributeSummary, ProductVariationSummary, RemoveCartItemInput, RemoveCouponInput, RetrieveProductFiltersInput, RetrieveProductInput, RetryCheckoutInput, SWATCH_TYPES, SelectCartShippingRateInput, Storefront, StorefrontAddress, StorefrontCatalog, StorefrontCheckout, StorefrontCountry, StorefrontField, StorefrontFieldOption, StorefrontFieldOverride, StorefrontFieldRule, StorefrontPricing, SwatchType, UpdateCartInput, UpdateCartItemInput, UpdateCheckoutInput, woocommerce };
2784
+ export { AddCartItemInput, ApplyCouponInput, BillingFieldProjections, Cart, CartAdditionalFields, CartBillingAddress, CartBillingAddressSubmission, CartCoupon, CartCouponTotals, CartError, CartFee, CartFeeTotals, CartItem, CartItemData, CartItemQuantityLimits, CartItemTotals, CartPaymentMethod, CartSelectedAttribute, CartShippingAddress, CartShippingAddressSubmission, CartShippingDestination, CartShippingItem, CartShippingPackage, CartShippingRate, CartShippingRateMetadata, CartTaxLine, CartTotals, Checkout, CheckoutAdditionalFields, CheckoutExtensions, CheckoutPaymentData, CheckoutPaymentResult, ConfirmCheckoutInput, GetOrderInput, ListProductInput, Order, OrderFee, OrderItem, OrderItemProduct, OrderTotals, PRODUCT_ATTRIBUTE_RELATIONS, PRODUCT_CATALOG_VISIBILITIES, PRODUCT_DATE_COLUMNS, PRODUCT_RATINGS, PRODUCT_STOCK_STATUSES, PRODUCT_TYPES, Product, ProductAddToCart, ProductAttributeCount, ProductAttributeFilter, ProductAttributeRelation, ProductAttributeSummary, ProductAttributeTermSummary, ProductBrandSummary, ProductCatalogVisibility, ProductCategorySummary, ProductCustomFieldsSchema, ProductDateColumn, ProductDimensions, ProductExtensions, ProductFilters, ProductFiltersAttributeTerm, ProductFiltersPriceRange, ProductFiltersRatingCount, ProductFiltersStockStatus, ProductFiltersTaxonomyTerm, ProductFiltersTerm, ProductList, ProductOrderBy, ProductPriceRange, ProductPrices, ProductRating, ProductRecommendations, ProductStockAvailability, ProductStockStatus, ProductSummary, ProductTagSummary, ProductTaxonomyFilter, ProductTaxonomyOperator, ProductTermSummary, ProductType, ProductVariationAttributeSummary, ProductVariationSummary, RemoveCartItemInput, RemoveCouponInput, RetrieveProductFiltersInput, RetrieveProductInput, RetryCheckoutInput, SWATCH_TYPES, SelectCartShippingRateInput, Storefront, StorefrontAddress, StorefrontCatalog, StorefrontCheckout, StorefrontCountry, StorefrontField, StorefrontFieldOption, StorefrontFieldOverride, StorefrontFieldRule, StorefrontFieldSchema, StorefrontPricing, SwatchType, UpdateCartInput, UpdateCartItemInput, UpdateCheckoutInput, resolveRegisteredFieldTarget, woocommerce };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizlo/woocommerce",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "WooCommerce integration for Kizlo.",