@atomic-solutions/woocommerce-api-client 0.1.3 → 0.1.5

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.mjs CHANGED
@@ -772,6 +772,8 @@ var pricesSchema = z.object({
772
772
  sale_price: z.string()
773
773
  }).optional()
774
774
  }).merge(moneySchema);
775
+
776
+ // ../schemas/src/woocommerce/store-api/cart-item.schema.ts
775
777
  var itemTotalsSchema = z.object({
776
778
  /** Subtotal before taxes */
777
779
  line_subtotal: z.string(),
@@ -948,6 +950,8 @@ var shippingPackageSchema = z.object({
948
950
  /** Available shipping rates for this package */
949
951
  shipping_rates: z.array(shippingRateSchema)
950
952
  });
953
+
954
+ // ../schemas/src/woocommerce/store-api/cart.ts
951
955
  var cartSchema = z.object({
952
956
  items: z.array(cartItemSchema),
953
957
  items_count: z.number(),
@@ -1167,6 +1171,8 @@ var orderTotalsSchema = z.object({
1167
1171
  /** Currency suffix (e.g., 'USD') */
1168
1172
  currency_suffix: z.string()
1169
1173
  });
1174
+
1175
+ // ../schemas/src/woocommerce/store-api/order.schema.ts
1170
1176
  var orderStatusEnum = z.enum([
1171
1177
  "pending",
1172
1178
  // Order received, awaiting payment
@@ -1213,21 +1219,6 @@ var storeApiOrderSchema = z.object({
1213
1219
  /** Payment method title (optional - returned from checkout) */
1214
1220
  payment_method_title: z.string().optional()
1215
1221
  });
1216
- z.object({
1217
- id: z.number(),
1218
- status: z.string(),
1219
- order_key: z.string(),
1220
- number: z.string(),
1221
- currency: z.string(),
1222
- total: z.string(),
1223
- date_created: z.string(),
1224
- customer_note: z.string(),
1225
- billing: z.record(z.string(), z.unknown()),
1226
- shipping: z.record(z.string(), z.unknown()),
1227
- payment_method: z.string(),
1228
- payment_method_title: z.string(),
1229
- line_items: z.array(z.unknown())
1230
- });
1231
1222
  var checkoutSchema = z.object({
1232
1223
  order_id: z.number(),
1233
1224
  status: z.string(),
@@ -1408,6 +1399,8 @@ var storeProductsSearchParamsSchema = z.object({
1408
1399
  /** Filter by product rating (1-5 stars) */
1409
1400
  rating: z.array(z.number().min(1).max(5)).optional()
1410
1401
  });
1402
+
1403
+ // ../schemas/src/woocommerce/store-api/products.ts
1411
1404
  var productSchema = z.object({
1412
1405
  id: z.number(),
1413
1406
  name: z.string(),
@@ -1438,23 +1431,15 @@ var productSchema = z.object({
1438
1431
  review_count: z.number(),
1439
1432
  extensions: z.record(z.string(), z.unknown())
1440
1433
  });
1441
- var paymentDataItemSchema = z.object({
1442
- /** Key identifier for the payment data field */
1443
- key: z.string(),
1444
- /** Value can be string or boolean depending on the field */
1445
- value: z.union([z.string(), z.boolean()])
1446
- });
1447
1434
  z.object({
1448
- /** Payment method ID (e.g., "cod", "stripe", "bacs") */
1449
- payment_method: z.string().min(1, "Payment method is required"),
1450
- /**
1451
- * Optional payment gateway-specific data
1452
- *
1453
- * Array of key-value pairs that will be passed to the payment gateway
1454
- * Example: [{ key: "stripe_token", value: "tok_xyz" }]
1455
- */
1456
- payment_data: z.array(paymentDataItemSchema).optional()
1457
- });
1435
+ /** Attribution source type (e.g., 'mobile_app', 'organic', 'referral') */
1436
+ source_type: z.string(),
1437
+ /** UTM source identifier (e.g., 'moja-apoteka-app', 'google') */
1438
+ utm_source: z.string(),
1439
+ /** Device type (e.g., 'mobile', 'desktop', 'tablet') */
1440
+ device_type: z.string()
1441
+ });
1442
+ var ORDER_ATTRIBUTION_NAMESPACE = "woocommerce/order-attribution";
1458
1443
 
1459
1444
  // src/api/cart.ts
1460
1445
  var createCartAPI = (client, endpoints, options) => ({
@@ -1493,13 +1478,20 @@ var createCartAPI = (client, endpoints, options) => ({
1493
1478
  });
1494
1479
 
1495
1480
  // src/api/checkout.ts
1496
- var createCheckoutAPI = (client, endpoints, options) => ({
1481
+ var createCheckoutAPI = (client, endpoints, options, orderAttribution) => ({
1497
1482
  get: async () => {
1498
1483
  const response = await client.get(endpoints.checkout);
1499
1484
  return handleApiResponse(response, checkoutSchema, options);
1500
1485
  },
1501
1486
  process: async (input) => {
1502
- const response = await client.post(endpoints.checkout, input);
1487
+ const body = orderAttribution ? {
1488
+ ...input,
1489
+ extensions: {
1490
+ [ORDER_ATTRIBUTION_NAMESPACE]: orderAttribution,
1491
+ ...input.extensions
1492
+ }
1493
+ } : input;
1494
+ const response = await client.post(endpoints.checkout, body);
1503
1495
  return handleApiResponse(response, checkoutSchema, options);
1504
1496
  }
1505
1497
  });
@@ -1585,7 +1577,12 @@ var createClient = (config) => {
1585
1577
  axios: axiosInstance,
1586
1578
  products: createProductsAPI(axiosInstance, endpoints, responseOptions),
1587
1579
  cart: createCartAPI(axiosInstance, endpoints, responseOptions),
1588
- checkout: createCheckoutAPI(axiosInstance, endpoints, responseOptions),
1580
+ checkout: createCheckoutAPI(
1581
+ axiosInstance,
1582
+ endpoints,
1583
+ responseOptions,
1584
+ fullConfig.orderAttribution
1585
+ ),
1589
1586
  orders: createOrdersAPI(axiosInstance, endpoints, responseOptions)
1590
1587
  };
1591
1588
  setupRequestInterceptor(axiosInstance, fullConfig, client);
@@ -1593,6 +1590,8 @@ var createClient = (config) => {
1593
1590
  setupErrorInterceptor(axiosInstance, fullConfig, client);
1594
1591
  return client;
1595
1592
  };
1593
+
1594
+ // ../schemas/src/woocommerce/admin-api/enums/enums-raw.ts
1596
1595
  var ORDER_STATUS = [
1597
1596
  "cancelled",
1598
1597
  "completed",
@@ -1706,6 +1705,8 @@ var ENUM_RAW = {
1706
1705
  ORDER_BY: COUPONS_ORDER_BY
1707
1706
  }
1708
1707
  };
1708
+
1709
+ // ../schemas/src/woocommerce/admin-api/enums/enums.ts
1709
1710
  var APP_ENUMS = {
1710
1711
  PRODUCT_TYPES: {
1711
1712
  RAW: ENUM_RAW.PRODUCT.TYPES,
@@ -1811,6 +1812,8 @@ var wpLinksSchema = z.object({
1811
1812
  })
1812
1813
  ).optional()
1813
1814
  });
1815
+
1816
+ // ../schemas/src/woocommerce/admin-api/base/base-wc.schema.ts
1814
1817
  var wcSortingSchema = z.object({
1815
1818
  order: getAppEnumZod("COMMON_SORT_ORDER").default("desc"),
1816
1819
  orderby: z.string().optional()
@@ -1849,7 +1852,7 @@ var wcBaseResponseSchema = z.object({
1849
1852
  _links: wpLinksSchema,
1850
1853
  meta_data: z.array(wcMetaDataSchema).optional()
1851
1854
  });
1852
- z.object({
1855
+ var wcPaginationMetaSchema = z.object({
1853
1856
  total: z.number(),
1854
1857
  totalPages: z.number(),
1855
1858
  currentPage: z.number(),
@@ -1862,6 +1865,12 @@ var wcErrorResponseSchema = z.object({
1862
1865
  status: z.number()
1863
1866
  }).optional()
1864
1867
  }).passthrough();
1868
+ var createPaginatedSchema = (schema) => z.object({
1869
+ data: z.array(schema),
1870
+ meta: wcPaginationMetaSchema
1871
+ });
1872
+
1873
+ // ../schemas/src/woocommerce/admin-api/coupons/coupon-filter.schema.ts
1865
1874
  var couponFilterSchema = wcBaseParamsSchema.extend({
1866
1875
  orderby: getAppEnumZod("COUPONS_ORDER_BY").default("date"),
1867
1876
  code: z.string().optional()
@@ -1952,7 +1961,7 @@ var orderLineItemSchema = z.object({
1952
1961
  sku: z.string(),
1953
1962
  price: z.number()
1954
1963
  });
1955
- var orderSchema2 = wcBaseResponseSchema.extend({
1964
+ var orderSchema = wcBaseResponseSchema.extend({
1956
1965
  id: z.number(),
1957
1966
  parent_id: z.number(),
1958
1967
  status: getAppEnumZod("ORDER_STATUS"),
@@ -1984,7 +1993,7 @@ var orderSchema2 = wcBaseResponseSchema.extend({
1984
1993
  var paymentMethodFilterSchema = wcBaseParamsSchema.extend({
1985
1994
  enabled: z.boolean().optional()
1986
1995
  });
1987
- var paymentMethodSchema2 = wcBaseResponseSchema.extend({
1996
+ var paymentMethodSchema = wcBaseResponseSchema.extend({
1988
1997
  id: getAppEnumZod("PAYMENT_METHODS"),
1989
1998
  title: z.string(),
1990
1999
  description: z.string(),
@@ -2047,6 +2056,8 @@ var productSchema2 = wcBaseResponseSchema.extend({
2047
2056
  on_sale: z.boolean(),
2048
2057
  manufacturer: z.string().optional()
2049
2058
  });
2059
+
2060
+ // ../schemas/src/woocommerce/admin-api/products/category.schema.ts
2050
2061
  var productCategorySchema2 = wcBaseResponseSchema.extend({
2051
2062
  id: z.number(),
2052
2063
  name: z.string(),
@@ -2080,6 +2091,8 @@ var createCategorySchema = productCategorySchema2.omit({
2080
2091
  }).extend({
2081
2092
  name: z.string().min(1, "Name is required")
2082
2093
  });
2094
+
2095
+ // ../schemas/src/woocommerce/admin-api/index.ts
2083
2096
  var schemas = {
2084
2097
  resources: {
2085
2098
  product: {
@@ -2092,7 +2105,7 @@ var schemas = {
2092
2105
  },
2093
2106
  order: {
2094
2107
  filter: orderFilterSchema,
2095
- entity: orderSchema2,
2108
+ entity: orderSchema,
2096
2109
  lineItem: orderLineItemSchema
2097
2110
  },
2098
2111
  customer: {
@@ -2108,11 +2121,11 @@ var schemas = {
2108
2121
  },
2109
2122
  paymentMethod: {
2110
2123
  filter: paymentMethodFilterSchema,
2111
- entity: paymentMethodSchema2
2124
+ entity: paymentMethodSchema
2112
2125
  }
2113
2126
  }
2114
2127
  };
2115
2128
 
2116
- export { WooCommerceApiError, WooCommerceDataValidationError, addToCartInputSchema, addressSchema, categoryFilterSchema as adminCategoryFilterSchema, couponFilterSchema as adminCouponFilterSchema, couponSchema as adminCouponSchema, orderFilterSchema as adminOrderFilterSchema, orderSchema2 as adminOrderSchema, productCategorySchema2 as adminProductCategorySchema, productFilterSchema as adminProductFilterSchema, productSchema2 as adminProductSchema, billingAddressSchemaMandatory as billingAddressSchema, cartItemImageSchema, cartSchema, checkoutInputSchema, checkoutSchema, couponInputSchema, createCategorySchema, createClient, createCouponSchema, createCustomerSchema, customerFilterSchema, customerSchema, getAppEnumRaw, getAppEnumZod, paginationMetaSchema, paginationParamsSchema, paymentMethodFilterSchema, paymentMethodSchema2 as paymentMethodSchema, productCategorySchema, productImageSchema, productSchema, removeCartItemInputSchema, schemas, storeProductsSearchParamsSchema as searchParamsSchema, selectShippingRateInputSchema, storeApiOrderSchema, updateCartItemInputSchema, updateCustomerInputSchema, updateCustomerSchema, wcErrorResponseSchema };
2129
+ export { WooCommerceApiError, WooCommerceDataValidationError, addToCartInputSchema, addressSchema, categoryFilterSchema as adminCategoryFilterSchema, couponFilterSchema as adminCouponFilterSchema, couponSchema as adminCouponSchema, orderFilterSchema as adminOrderFilterSchema, orderSchema as adminOrderSchema, productCategorySchema2 as adminProductCategorySchema, productFilterSchema as adminProductFilterSchema, productSchema2 as adminProductSchema, billingAddressSchemaMandatory as billingAddressSchema, cartItemImageSchema, cartSchema, checkoutInputSchema, checkoutSchema, couponInputSchema, createCategorySchema, createClient, createCouponSchema, createCustomerSchema, createPaginatedSchema, customerFilterSchema, customerSchema, getAppEnumRaw, getAppEnumZod, paginationMetaSchema, paginationParamsSchema, paymentMethodFilterSchema, paymentMethodSchema, productCategorySchema, productImageSchema, productSchema, removeCartItemInputSchema, schemas, storeProductsSearchParamsSchema as searchParamsSchema, selectShippingRateInputSchema, storeApiOrderSchema, updateCartItemInputSchema, updateCustomerInputSchema, updateCustomerSchema, wcBaseParamsSchema, wcErrorResponseSchema, wcPaginationMetaSchema };
2117
2130
  //# sourceMappingURL=index.mjs.map
2118
2131
  //# sourceMappingURL=index.mjs.map