@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.
@@ -1,5 +1,5 @@
1
- import { W as WooCommerceConfig, a as WooCommerceClient } from '../types-B09FKPkT.mjs';
2
- export { k as CartAPI, C as CartHeadersAdapter, o as CheckoutAPI, J as JwtTokenAdapter, O as OrdersAPI, w as ProductsAPI } from '../types-B09FKPkT.mjs';
1
+ import { W as WooCommerceConfig, a as WooCommerceClient } from '../types-CgTmmyIP.mjs';
2
+ export { k as CartAPI, C as CartHeadersAdapter, o as CheckoutAPI, J as JwtTokenAdapter, r as OrdersAPI, x as ProductsAPI } from '../types-CgTmmyIP.mjs';
3
3
  import 'axios';
4
4
  import 'zod';
5
5
 
@@ -1,5 +1,5 @@
1
- import { W as WooCommerceConfig, a as WooCommerceClient } from '../types-B09FKPkT.js';
2
- export { k as CartAPI, C as CartHeadersAdapter, o as CheckoutAPI, J as JwtTokenAdapter, O as OrdersAPI, w as ProductsAPI } from '../types-B09FKPkT.js';
1
+ import { W as WooCommerceConfig, a as WooCommerceClient } from '../types-CgTmmyIP.js';
2
+ export { k as CartAPI, C as CartHeadersAdapter, o as CheckoutAPI, J as JwtTokenAdapter, r as OrdersAPI, x as ProductsAPI } from '../types-CgTmmyIP.js';
3
3
  import 'axios';
4
4
  import 'zod';
5
5
 
@@ -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) => {
@@ -1318,6 +1325,15 @@ var productSchema = zod.z.object({
1318
1325
  review_count: zod.z.number(),
1319
1326
  extensions: zod.z.record(zod.z.string(), zod.z.unknown())
1320
1327
  });
1328
+ zod.z.object({
1329
+ /** Attribution source type (e.g., 'mobile_app', 'organic', 'referral') */
1330
+ source_type: zod.z.string(),
1331
+ /** UTM source identifier (e.g., 'moja-apoteka-app', 'google') */
1332
+ utm_source: zod.z.string(),
1333
+ /** Device type (e.g., 'mobile', 'desktop', 'tablet') */
1334
+ device_type: zod.z.string()
1335
+ });
1336
+ var ORDER_ATTRIBUTION_NAMESPACE = "woocommerce/order-attribution";
1321
1337
 
1322
1338
  // src/api/cart.ts
1323
1339
  var createCartAPI = (client, endpoints, options) => ({
@@ -1356,13 +1372,20 @@ var createCartAPI = (client, endpoints, options) => ({
1356
1372
  });
1357
1373
 
1358
1374
  // src/api/checkout.ts
1359
- var createCheckoutAPI = (client, endpoints, options) => ({
1375
+ var createCheckoutAPI = (client, endpoints, options, orderAttribution) => ({
1360
1376
  get: async () => {
1361
1377
  const response = await client.get(endpoints.checkout);
1362
1378
  return handleApiResponse(response, checkoutSchema, options);
1363
1379
  },
1364
1380
  process: async (input) => {
1365
- const response = await client.post(endpoints.checkout, input);
1381
+ const body = orderAttribution ? {
1382
+ ...input,
1383
+ extensions: {
1384
+ [ORDER_ATTRIBUTION_NAMESPACE]: orderAttribution,
1385
+ ...input.extensions
1386
+ }
1387
+ } : input;
1388
+ const response = await client.post(endpoints.checkout, body);
1366
1389
  return handleApiResponse(response, checkoutSchema, options);
1367
1390
  }
1368
1391
  });
@@ -1448,7 +1471,12 @@ var createClient = (config) => {
1448
1471
  axios: axiosInstance,
1449
1472
  products: createProductsAPI(axiosInstance, endpoints, responseOptions),
1450
1473
  cart: createCartAPI(axiosInstance, endpoints, responseOptions),
1451
- checkout: createCheckoutAPI(axiosInstance, endpoints, responseOptions),
1474
+ checkout: createCheckoutAPI(
1475
+ axiosInstance,
1476
+ endpoints,
1477
+ responseOptions,
1478
+ fullConfig.orderAttribution
1479
+ ),
1452
1480
  orders: createOrdersAPI(axiosInstance, endpoints, responseOptions)
1453
1481
  };
1454
1482
  setupRequestInterceptor(axiosInstance, fullConfig, client);