@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.js CHANGED
@@ -438,7 +438,14 @@ var error = (...args) => {
438
438
  // src/http/interceptors/request.ts
439
439
  var requiresAuth = (url) => {
440
440
  if (!url) return false;
441
- const authEndpoints = ["/jwt-auth/", "/customers/me", "/wp/v2/users/me"];
441
+ const authEndpoints = [
442
+ "/jwt-auth/",
443
+ "/customers/me",
444
+ "/wp/v2/users/me",
445
+ // Store API non-cart endpoints: inject JWT when available so authenticated
446
+ // users can access their own resources (e.g. orders, personalised product data)
447
+ "/wc/store/v1/order"
448
+ ];
442
449
  return authEndpoints.some((endpoint) => url.includes(endpoint));
443
450
  };
444
451
  var requiresCartAuth = (url) => {
@@ -1437,6 +1444,15 @@ var productSchema = zod.z.object({
1437
1444
  review_count: zod.z.number(),
1438
1445
  extensions: zod.z.record(zod.z.string(), zod.z.unknown())
1439
1446
  });
1447
+ zod.z.object({
1448
+ /** Attribution source type (e.g., 'mobile_app', 'organic', 'referral') */
1449
+ source_type: zod.z.string(),
1450
+ /** UTM source identifier (e.g., 'moja-apoteka-app', 'google') */
1451
+ utm_source: zod.z.string(),
1452
+ /** Device type (e.g., 'mobile', 'desktop', 'tablet') */
1453
+ device_type: zod.z.string()
1454
+ });
1455
+ var ORDER_ATTRIBUTION_NAMESPACE = "woocommerce/order-attribution";
1440
1456
 
1441
1457
  // src/api/cart.ts
1442
1458
  var createCartAPI = (client, endpoints, options) => ({
@@ -1475,13 +1491,20 @@ var createCartAPI = (client, endpoints, options) => ({
1475
1491
  });
1476
1492
 
1477
1493
  // src/api/checkout.ts
1478
- var createCheckoutAPI = (client, endpoints, options) => ({
1494
+ var createCheckoutAPI = (client, endpoints, options, orderAttribution) => ({
1479
1495
  get: async () => {
1480
1496
  const response = await client.get(endpoints.checkout);
1481
1497
  return handleApiResponse(response, checkoutSchema, options);
1482
1498
  },
1483
1499
  process: async (input) => {
1484
- const response = await client.post(endpoints.checkout, input);
1500
+ const body = orderAttribution ? {
1501
+ ...input,
1502
+ extensions: {
1503
+ [ORDER_ATTRIBUTION_NAMESPACE]: orderAttribution,
1504
+ ...input.extensions
1505
+ }
1506
+ } : input;
1507
+ const response = await client.post(endpoints.checkout, body);
1485
1508
  return handleApiResponse(response, checkoutSchema, options);
1486
1509
  }
1487
1510
  });
@@ -1567,7 +1590,12 @@ var createClient = (config) => {
1567
1590
  axios: axiosInstance,
1568
1591
  products: createProductsAPI(axiosInstance, endpoints, responseOptions),
1569
1592
  cart: createCartAPI(axiosInstance, endpoints, responseOptions),
1570
- checkout: createCheckoutAPI(axiosInstance, endpoints, responseOptions),
1593
+ checkout: createCheckoutAPI(
1594
+ axiosInstance,
1595
+ endpoints,
1596
+ responseOptions,
1597
+ fullConfig.orderAttribution
1598
+ ),
1571
1599
  orders: createOrdersAPI(axiosInstance, endpoints, responseOptions)
1572
1600
  };
1573
1601
  setupRequestInterceptor(axiosInstance, fullConfig, client);