@atomic-solutions/woocommerce-api-client 0.1.4 → 0.2.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.mjs CHANGED
@@ -432,7 +432,14 @@ var error = (...args) => {
432
432
  // src/http/interceptors/request.ts
433
433
  var requiresAuth = (url) => {
434
434
  if (!url) return false;
435
- const authEndpoints = ["/jwt-auth/", "/customers/me", "/wp/v2/users/me"];
435
+ const authEndpoints = [
436
+ "/jwt-auth/",
437
+ "/customers/me",
438
+ "/wp/v2/users/me",
439
+ // Store API non-cart endpoints: inject JWT when available so authenticated
440
+ // users can access their own resources (e.g. orders, personalised product data)
441
+ "/wc/store/v1/order"
442
+ ];
436
443
  return authEndpoints.some((endpoint) => url.includes(endpoint));
437
444
  };
438
445
  var requiresCartAuth = (url) => {
@@ -1431,6 +1438,15 @@ var productSchema = z.object({
1431
1438
  review_count: z.number(),
1432
1439
  extensions: z.record(z.string(), z.unknown())
1433
1440
  });
1441
+ z.object({
1442
+ /** Attribution source type (e.g., 'mobile_app', 'organic', 'referral') */
1443
+ source_type: z.string(),
1444
+ /** UTM source identifier (e.g., 'moja-apoteka-app', 'google') */
1445
+ utm_source: z.string(),
1446
+ /** Device type (e.g., 'mobile', 'desktop', 'tablet') */
1447
+ device_type: z.string()
1448
+ });
1449
+ var ORDER_ATTRIBUTION_NAMESPACE = "woocommerce/order-attribution";
1434
1450
 
1435
1451
  // src/api/cart.ts
1436
1452
  var createCartAPI = (client, endpoints, options) => ({
@@ -1469,13 +1485,20 @@ var createCartAPI = (client, endpoints, options) => ({
1469
1485
  });
1470
1486
 
1471
1487
  // src/api/checkout.ts
1472
- var createCheckoutAPI = (client, endpoints, options) => ({
1488
+ var createCheckoutAPI = (client, endpoints, options, orderAttribution) => ({
1473
1489
  get: async () => {
1474
1490
  const response = await client.get(endpoints.checkout);
1475
1491
  return handleApiResponse(response, checkoutSchema, options);
1476
1492
  },
1477
1493
  process: async (input) => {
1478
- const response = await client.post(endpoints.checkout, input);
1494
+ const body = orderAttribution ? {
1495
+ ...input,
1496
+ extensions: {
1497
+ [ORDER_ATTRIBUTION_NAMESPACE]: orderAttribution,
1498
+ ...input.extensions
1499
+ }
1500
+ } : input;
1501
+ const response = await client.post(endpoints.checkout, body);
1479
1502
  return handleApiResponse(response, checkoutSchema, options);
1480
1503
  }
1481
1504
  });
@@ -1561,7 +1584,12 @@ var createClient = (config) => {
1561
1584
  axios: axiosInstance,
1562
1585
  products: createProductsAPI(axiosInstance, endpoints, responseOptions),
1563
1586
  cart: createCartAPI(axiosInstance, endpoints, responseOptions),
1564
- checkout: createCheckoutAPI(axiosInstance, endpoints, responseOptions),
1587
+ checkout: createCheckoutAPI(
1588
+ axiosInstance,
1589
+ endpoints,
1590
+ responseOptions,
1591
+ fullConfig.orderAttribution
1592
+ ),
1565
1593
  orders: createOrdersAPI(axiosInstance, endpoints, responseOptions)
1566
1594
  };
1567
1595
  setupRequestInterceptor(axiosInstance, fullConfig, client);