@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.js CHANGED
@@ -778,6 +778,8 @@ var pricesSchema = zod.z.object({
778
778
  sale_price: zod.z.string()
779
779
  }).optional()
780
780
  }).merge(moneySchema);
781
+
782
+ // ../schemas/src/woocommerce/store-api/cart-item.schema.ts
781
783
  var itemTotalsSchema = zod.z.object({
782
784
  /** Subtotal before taxes */
783
785
  line_subtotal: zod.z.string(),
@@ -954,6 +956,8 @@ var shippingPackageSchema = zod.z.object({
954
956
  /** Available shipping rates for this package */
955
957
  shipping_rates: zod.z.array(shippingRateSchema)
956
958
  });
959
+
960
+ // ../schemas/src/woocommerce/store-api/cart.ts
957
961
  var cartSchema = zod.z.object({
958
962
  items: zod.z.array(cartItemSchema),
959
963
  items_count: zod.z.number(),
@@ -1173,6 +1177,8 @@ var orderTotalsSchema = zod.z.object({
1173
1177
  /** Currency suffix (e.g., 'USD') */
1174
1178
  currency_suffix: zod.z.string()
1175
1179
  });
1180
+
1181
+ // ../schemas/src/woocommerce/store-api/order.schema.ts
1176
1182
  var orderStatusEnum = zod.z.enum([
1177
1183
  "pending",
1178
1184
  // Order received, awaiting payment
@@ -1219,21 +1225,6 @@ var storeApiOrderSchema = zod.z.object({
1219
1225
  /** Payment method title (optional - returned from checkout) */
1220
1226
  payment_method_title: zod.z.string().optional()
1221
1227
  });
1222
- zod.z.object({
1223
- id: zod.z.number(),
1224
- status: zod.z.string(),
1225
- order_key: zod.z.string(),
1226
- number: zod.z.string(),
1227
- currency: zod.z.string(),
1228
- total: zod.z.string(),
1229
- date_created: zod.z.string(),
1230
- customer_note: zod.z.string(),
1231
- billing: zod.z.record(zod.z.string(), zod.z.unknown()),
1232
- shipping: zod.z.record(zod.z.string(), zod.z.unknown()),
1233
- payment_method: zod.z.string(),
1234
- payment_method_title: zod.z.string(),
1235
- line_items: zod.z.array(zod.z.unknown())
1236
- });
1237
1228
  var checkoutSchema = zod.z.object({
1238
1229
  order_id: zod.z.number(),
1239
1230
  status: zod.z.string(),
@@ -1414,6 +1405,8 @@ var storeProductsSearchParamsSchema = zod.z.object({
1414
1405
  /** Filter by product rating (1-5 stars) */
1415
1406
  rating: zod.z.array(zod.z.number().min(1).max(5)).optional()
1416
1407
  });
1408
+
1409
+ // ../schemas/src/woocommerce/store-api/products.ts
1417
1410
  var productSchema = zod.z.object({
1418
1411
  id: zod.z.number(),
1419
1412
  name: zod.z.string(),
@@ -1444,23 +1437,15 @@ var productSchema = zod.z.object({
1444
1437
  review_count: zod.z.number(),
1445
1438
  extensions: zod.z.record(zod.z.string(), zod.z.unknown())
1446
1439
  });
1447
- var paymentDataItemSchema = zod.z.object({
1448
- /** Key identifier for the payment data field */
1449
- key: zod.z.string(),
1450
- /** Value can be string or boolean depending on the field */
1451
- value: zod.z.union([zod.z.string(), zod.z.boolean()])
1452
- });
1453
1440
  zod.z.object({
1454
- /** Payment method ID (e.g., "cod", "stripe", "bacs") */
1455
- payment_method: zod.z.string().min(1, "Payment method is required"),
1456
- /**
1457
- * Optional payment gateway-specific data
1458
- *
1459
- * Array of key-value pairs that will be passed to the payment gateway
1460
- * Example: [{ key: "stripe_token", value: "tok_xyz" }]
1461
- */
1462
- payment_data: zod.z.array(paymentDataItemSchema).optional()
1463
- });
1441
+ /** Attribution source type (e.g., 'mobile_app', 'organic', 'referral') */
1442
+ source_type: zod.z.string(),
1443
+ /** UTM source identifier (e.g., 'moja-apoteka-app', 'google') */
1444
+ utm_source: zod.z.string(),
1445
+ /** Device type (e.g., 'mobile', 'desktop', 'tablet') */
1446
+ device_type: zod.z.string()
1447
+ });
1448
+ var ORDER_ATTRIBUTION_NAMESPACE = "woocommerce/order-attribution";
1464
1449
 
1465
1450
  // src/api/cart.ts
1466
1451
  var createCartAPI = (client, endpoints, options) => ({
@@ -1499,13 +1484,20 @@ var createCartAPI = (client, endpoints, options) => ({
1499
1484
  });
1500
1485
 
1501
1486
  // src/api/checkout.ts
1502
- var createCheckoutAPI = (client, endpoints, options) => ({
1487
+ var createCheckoutAPI = (client, endpoints, options, orderAttribution) => ({
1503
1488
  get: async () => {
1504
1489
  const response = await client.get(endpoints.checkout);
1505
1490
  return handleApiResponse(response, checkoutSchema, options);
1506
1491
  },
1507
1492
  process: async (input) => {
1508
- const response = await client.post(endpoints.checkout, input);
1493
+ const body = orderAttribution ? {
1494
+ ...input,
1495
+ extensions: {
1496
+ [ORDER_ATTRIBUTION_NAMESPACE]: orderAttribution,
1497
+ ...input.extensions
1498
+ }
1499
+ } : input;
1500
+ const response = await client.post(endpoints.checkout, body);
1509
1501
  return handleApiResponse(response, checkoutSchema, options);
1510
1502
  }
1511
1503
  });
@@ -1591,7 +1583,12 @@ var createClient = (config) => {
1591
1583
  axios: axiosInstance,
1592
1584
  products: createProductsAPI(axiosInstance, endpoints, responseOptions),
1593
1585
  cart: createCartAPI(axiosInstance, endpoints, responseOptions),
1594
- checkout: createCheckoutAPI(axiosInstance, endpoints, responseOptions),
1586
+ checkout: createCheckoutAPI(
1587
+ axiosInstance,
1588
+ endpoints,
1589
+ responseOptions,
1590
+ fullConfig.orderAttribution
1591
+ ),
1595
1592
  orders: createOrdersAPI(axiosInstance, endpoints, responseOptions)
1596
1593
  };
1597
1594
  setupRequestInterceptor(axiosInstance, fullConfig, client);
@@ -1599,6 +1596,8 @@ var createClient = (config) => {
1599
1596
  setupErrorInterceptor(axiosInstance, fullConfig, client);
1600
1597
  return client;
1601
1598
  };
1599
+
1600
+ // ../schemas/src/woocommerce/admin-api/enums/enums-raw.ts
1602
1601
  var ORDER_STATUS = [
1603
1602
  "cancelled",
1604
1603
  "completed",
@@ -1712,6 +1711,8 @@ var ENUM_RAW = {
1712
1711
  ORDER_BY: COUPONS_ORDER_BY
1713
1712
  }
1714
1713
  };
1714
+
1715
+ // ../schemas/src/woocommerce/admin-api/enums/enums.ts
1715
1716
  var APP_ENUMS = {
1716
1717
  PRODUCT_TYPES: {
1717
1718
  RAW: ENUM_RAW.PRODUCT.TYPES,
@@ -1817,6 +1818,8 @@ var wpLinksSchema = zod.z.object({
1817
1818
  })
1818
1819
  ).optional()
1819
1820
  });
1821
+
1822
+ // ../schemas/src/woocommerce/admin-api/base/base-wc.schema.ts
1820
1823
  var wcSortingSchema = zod.z.object({
1821
1824
  order: getAppEnumZod("COMMON_SORT_ORDER").default("desc"),
1822
1825
  orderby: zod.z.string().optional()
@@ -1855,7 +1858,7 @@ var wcBaseResponseSchema = zod.z.object({
1855
1858
  _links: wpLinksSchema,
1856
1859
  meta_data: zod.z.array(wcMetaDataSchema).optional()
1857
1860
  });
1858
- zod.z.object({
1861
+ var wcPaginationMetaSchema = zod.z.object({
1859
1862
  total: zod.z.number(),
1860
1863
  totalPages: zod.z.number(),
1861
1864
  currentPage: zod.z.number(),
@@ -1868,6 +1871,12 @@ var wcErrorResponseSchema = zod.z.object({
1868
1871
  status: zod.z.number()
1869
1872
  }).optional()
1870
1873
  }).passthrough();
1874
+ var createPaginatedSchema = (schema) => zod.z.object({
1875
+ data: zod.z.array(schema),
1876
+ meta: wcPaginationMetaSchema
1877
+ });
1878
+
1879
+ // ../schemas/src/woocommerce/admin-api/coupons/coupon-filter.schema.ts
1871
1880
  var couponFilterSchema = wcBaseParamsSchema.extend({
1872
1881
  orderby: getAppEnumZod("COUPONS_ORDER_BY").default("date"),
1873
1882
  code: zod.z.string().optional()
@@ -1958,7 +1967,7 @@ var orderLineItemSchema = zod.z.object({
1958
1967
  sku: zod.z.string(),
1959
1968
  price: zod.z.number()
1960
1969
  });
1961
- var orderSchema2 = wcBaseResponseSchema.extend({
1970
+ var orderSchema = wcBaseResponseSchema.extend({
1962
1971
  id: zod.z.number(),
1963
1972
  parent_id: zod.z.number(),
1964
1973
  status: getAppEnumZod("ORDER_STATUS"),
@@ -1990,7 +1999,7 @@ var orderSchema2 = wcBaseResponseSchema.extend({
1990
1999
  var paymentMethodFilterSchema = wcBaseParamsSchema.extend({
1991
2000
  enabled: zod.z.boolean().optional()
1992
2001
  });
1993
- var paymentMethodSchema2 = wcBaseResponseSchema.extend({
2002
+ var paymentMethodSchema = wcBaseResponseSchema.extend({
1994
2003
  id: getAppEnumZod("PAYMENT_METHODS"),
1995
2004
  title: zod.z.string(),
1996
2005
  description: zod.z.string(),
@@ -2053,6 +2062,8 @@ var productSchema2 = wcBaseResponseSchema.extend({
2053
2062
  on_sale: zod.z.boolean(),
2054
2063
  manufacturer: zod.z.string().optional()
2055
2064
  });
2065
+
2066
+ // ../schemas/src/woocommerce/admin-api/products/category.schema.ts
2056
2067
  var productCategorySchema2 = wcBaseResponseSchema.extend({
2057
2068
  id: zod.z.number(),
2058
2069
  name: zod.z.string(),
@@ -2086,6 +2097,8 @@ var createCategorySchema = productCategorySchema2.omit({
2086
2097
  }).extend({
2087
2098
  name: zod.z.string().min(1, "Name is required")
2088
2099
  });
2100
+
2101
+ // ../schemas/src/woocommerce/admin-api/index.ts
2089
2102
  var schemas = {
2090
2103
  resources: {
2091
2104
  product: {
@@ -2098,7 +2111,7 @@ var schemas = {
2098
2111
  },
2099
2112
  order: {
2100
2113
  filter: orderFilterSchema,
2101
- entity: orderSchema2,
2114
+ entity: orderSchema,
2102
2115
  lineItem: orderLineItemSchema
2103
2116
  },
2104
2117
  customer: {
@@ -2114,7 +2127,7 @@ var schemas = {
2114
2127
  },
2115
2128
  paymentMethod: {
2116
2129
  filter: paymentMethodFilterSchema,
2117
- entity: paymentMethodSchema2
2130
+ entity: paymentMethodSchema
2118
2131
  }
2119
2132
  }
2120
2133
  };
@@ -2127,7 +2140,7 @@ exports.adminCategoryFilterSchema = categoryFilterSchema;
2127
2140
  exports.adminCouponFilterSchema = couponFilterSchema;
2128
2141
  exports.adminCouponSchema = couponSchema;
2129
2142
  exports.adminOrderFilterSchema = orderFilterSchema;
2130
- exports.adminOrderSchema = orderSchema2;
2143
+ exports.adminOrderSchema = orderSchema;
2131
2144
  exports.adminProductCategorySchema = productCategorySchema2;
2132
2145
  exports.adminProductFilterSchema = productFilterSchema;
2133
2146
  exports.adminProductSchema = productSchema2;
@@ -2141,6 +2154,7 @@ exports.createCategorySchema = createCategorySchema;
2141
2154
  exports.createClient = createClient;
2142
2155
  exports.createCouponSchema = createCouponSchema;
2143
2156
  exports.createCustomerSchema = createCustomerSchema;
2157
+ exports.createPaginatedSchema = createPaginatedSchema;
2144
2158
  exports.customerFilterSchema = customerFilterSchema;
2145
2159
  exports.customerSchema = customerSchema;
2146
2160
  exports.getAppEnumRaw = getAppEnumRaw;
@@ -2148,7 +2162,7 @@ exports.getAppEnumZod = getAppEnumZod;
2148
2162
  exports.paginationMetaSchema = paginationMetaSchema;
2149
2163
  exports.paginationParamsSchema = paginationParamsSchema;
2150
2164
  exports.paymentMethodFilterSchema = paymentMethodFilterSchema;
2151
- exports.paymentMethodSchema = paymentMethodSchema2;
2165
+ exports.paymentMethodSchema = paymentMethodSchema;
2152
2166
  exports.productCategorySchema = productCategorySchema;
2153
2167
  exports.productImageSchema = productImageSchema;
2154
2168
  exports.productSchema = productSchema;
@@ -2160,6 +2174,8 @@ exports.storeApiOrderSchema = storeApiOrderSchema;
2160
2174
  exports.updateCartItemInputSchema = updateCartItemInputSchema;
2161
2175
  exports.updateCustomerInputSchema = updateCustomerInputSchema;
2162
2176
  exports.updateCustomerSchema = updateCustomerSchema;
2177
+ exports.wcBaseParamsSchema = wcBaseParamsSchema;
2163
2178
  exports.wcErrorResponseSchema = wcErrorResponseSchema;
2179
+ exports.wcPaginationMetaSchema = wcPaginationMetaSchema;
2164
2180
  //# sourceMappingURL=index.js.map
2165
2181
  //# sourceMappingURL=index.js.map