@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.
@@ -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) => {
@@ -1312,6 +1319,15 @@ var productSchema = z.object({
1312
1319
  review_count: z.number(),
1313
1320
  extensions: z.record(z.string(), z.unknown())
1314
1321
  });
1322
+ z.object({
1323
+ /** Attribution source type (e.g., 'mobile_app', 'organic', 'referral') */
1324
+ source_type: z.string(),
1325
+ /** UTM source identifier (e.g., 'moja-apoteka-app', 'google') */
1326
+ utm_source: z.string(),
1327
+ /** Device type (e.g., 'mobile', 'desktop', 'tablet') */
1328
+ device_type: z.string()
1329
+ });
1330
+ var ORDER_ATTRIBUTION_NAMESPACE = "woocommerce/order-attribution";
1315
1331
 
1316
1332
  // src/api/cart.ts
1317
1333
  var createCartAPI = (client, endpoints, options) => ({
@@ -1350,13 +1366,20 @@ var createCartAPI = (client, endpoints, options) => ({
1350
1366
  });
1351
1367
 
1352
1368
  // src/api/checkout.ts
1353
- var createCheckoutAPI = (client, endpoints, options) => ({
1369
+ var createCheckoutAPI = (client, endpoints, options, orderAttribution) => ({
1354
1370
  get: async () => {
1355
1371
  const response = await client.get(endpoints.checkout);
1356
1372
  return handleApiResponse(response, checkoutSchema, options);
1357
1373
  },
1358
1374
  process: async (input) => {
1359
- const response = await client.post(endpoints.checkout, input);
1375
+ const body = orderAttribution ? {
1376
+ ...input,
1377
+ extensions: {
1378
+ [ORDER_ATTRIBUTION_NAMESPACE]: orderAttribution,
1379
+ ...input.extensions
1380
+ }
1381
+ } : input;
1382
+ const response = await client.post(endpoints.checkout, body);
1360
1383
  return handleApiResponse(response, checkoutSchema, options);
1361
1384
  }
1362
1385
  });
@@ -1442,7 +1465,12 @@ var createClient = (config) => {
1442
1465
  axios: axiosInstance,
1443
1466
  products: createProductsAPI(axiosInstance, endpoints, responseOptions),
1444
1467
  cart: createCartAPI(axiosInstance, endpoints, responseOptions),
1445
- checkout: createCheckoutAPI(axiosInstance, endpoints, responseOptions),
1468
+ checkout: createCheckoutAPI(
1469
+ axiosInstance,
1470
+ endpoints,
1471
+ responseOptions,
1472
+ fullConfig.orderAttribution
1473
+ ),
1446
1474
  orders: createOrdersAPI(axiosInstance, endpoints, responseOptions)
1447
1475
  };
1448
1476
  setupRequestInterceptor(axiosInstance, fullConfig, client);