@disconetwork/shopify 0.0.8 → 0.0.10

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.
@@ -5,8 +5,8 @@ import { withImpressionDedupe } from "@disconetwork/core";
5
5
  import { Fragment, jsx } from "preact/jsx-runtime";
6
6
  import { INTERNAL_BASE_URL, InternalDiscoClient, parseScreens } from "@disconetwork/core/internal";
7
7
  import { Fragment as Fragment$1, jsx as jsx$1, jsxs } from "preact/jsx-runtime";
8
- import { useApi, useApplyAttributeChange, useApplyCartLinesChange, useAttributeValues, useBillingAddress, useCartLines, useCheckoutToken, useCustomer, useDiscountCodes, useEmail, useExtensionEditor, useInstructions, useLocalizationCountry, usePhone, usePurchasingCompany, useShippingAddress, useShop, useSubscription, useSubtotalAmount, useTotalAmount } from "@shopify/ui-extensions/checkout/preact";
9
- import { useApi as useApi$1, useBillingAddress as useBillingAddress$1, useCartLines as useCartLines$1, useCustomer as useCustomer$1, useDiscountCodes as useDiscountCodes$1, useEmail as useEmail$1, useOrder, usePhone as usePhone$1, usePurchasingCompany as usePurchasingCompany$1, useShippingAddress as useShippingAddress$1, useShop as useShop$1, useSubscription as useSubscription$1, useTotalAmount as useTotalAmount$1 } from "@shopify/ui-extensions/customer-account/preact";
8
+ import { useApi, useApplyAttributeChange, useApplyCartLinesChange, useAttributeValues, useBillingAddress, useCartLines, useCheckoutToken, useCustomer, useDiscountCodes, useEmail, useExtensionEditor, useInstructions, useLocalizationCountry, usePurchasingCompany, useShippingAddress, useShop, useSubscription, useSubtotalAmount, useTotalAmount } from "@shopify/ui-extensions/checkout/preact";
9
+ import { useApi as useApi$1, useCartLines as useCartLines$1, useDiscountCodes as useDiscountCodes$1, useOrder, usePurchasingCompany as usePurchasingCompany$1, useShop as useShop$1, useSubscription as useSubscription$1, useTotalAmount as useTotalAmount$1 } from "@shopify/ui-extensions/customer-account/preact";
10
10
  import { QueryClient, QueryClientProvider, useMutation, useQuery } from "@tanstack/preact-query";
11
11
  import { boolean, email, nullable, object, optional, string } from "zod/mini";
12
12
  //#region ../react-shared/dist/createHeadlessBindings-CPuF5wZQ.js
@@ -261,6 +261,8 @@ const getRecommendationsRequest = ({ payload, widgetId }) => {
261
261
  currencyCode: payload.currencyCode,
262
262
  id: shopifyOrderIdFormatter(payload.orderId) ?? void 0
263
263
  },
264
+ shipping: payload.shippingAddress,
265
+ billing: payload.billingAddress,
264
266
  purchases: payload.cartLines.map((cartLine) => {
265
267
  return {
266
268
  name: cartLine.merchandise.title,
@@ -359,7 +361,7 @@ const RecommendationsWidgetSkeleton = () => /* @__PURE__ */ jsx$1("s-box", {
359
361
  //#region src/sdkIdentity.ts
360
362
  const SDK_IDENTITY = {
361
363
  name: "@disconetwork/shopify",
362
- version: "0.0.8"
364
+ version: "0.0.10"
363
365
  };
364
366
  //#endregion
365
367
  //#region ../react-shared/dist/sdk-internals.js
@@ -425,6 +427,26 @@ const RecommendationsContent = ({ children, request }) => {
425
427
  });
426
428
  };
427
429
  //#endregion
430
+ //#region src/utils/address.ts
431
+ /**
432
+ * Map a Shopify `MailingAddress` onto the recommendations `Address`, dropping
433
+ * empty fields. `undefined` when Shopify gives no address (e.g. no protected
434
+ * customer data access) or the address has none of the fields we forward.
435
+ */
436
+ const toRecommendationsAddress = (address) => {
437
+ if (!address) return void 0;
438
+ const mapped = {
439
+ addressLine1: address.address1 || void 0,
440
+ addressLine2: address.address2 || void 0,
441
+ city: address.city || void 0,
442
+ state: address.provinceCode || void 0,
443
+ zip: address.zip || void 0,
444
+ phone: address.phone || void 0,
445
+ countryCode: address.countryCode || void 0
446
+ };
447
+ return Object.values(mapped).some(Boolean) ? mapped : void 0;
448
+ };
449
+ //#endregion
428
450
  //#region src/managers/PayloadManager.tsx
429
451
  const GenericPayloadProvider = ({ target, children, payload, additionalPayload, isB2BPurchase }) => {
430
452
  useEffect(() => {
@@ -455,6 +477,8 @@ function createGenericPayload({ buyerPhone, buyerEmail, customer, shippingAddres
455
477
  billingLastName: billingAddress?.lastName,
456
478
  billingZipCode: billingAddress?.zip,
457
479
  shippingZipCode: shippingAddress?.zip,
480
+ shippingAddress: toRecommendationsAddress(shippingAddress),
481
+ billingAddress: toRecommendationsAddress(billingAddress),
458
482
  extrapolatedFirstName: customer?.firstName || derivedFirstName,
459
483
  extrapolatedPhone: buyerPhone || shippingAddress?.phone || billingAddress?.phone || "",
460
484
  totalCost: totalAmount.amount,
@@ -469,12 +493,7 @@ function createGenericPayload({ buyerPhone, buyerEmail, customer, shippingAddres
469
493
  }
470
494
  const ThankYouPayloadManager = ({ children }) => {
471
495
  const target = PAYLOAD_MANAGER_TARGET.THANK_YOU;
472
- const customer = useCustomer();
473
- const buyerEmail = useEmail();
474
- const buyerPhone = usePhone();
475
496
  const purchasingCompany = usePurchasingCompany();
476
- const shippingAddress = useShippingAddress();
477
- const billingAddress = useBillingAddress();
478
497
  const totalAmount = useTotalAmount();
479
498
  const cartLines = useCartLines();
480
499
  const checkoutToken = useCheckoutToken();
@@ -486,11 +505,11 @@ const ThankYouPayloadManager = ({ children }) => {
486
505
  return /* @__PURE__ */ jsx$1(GenericPayloadProvider, {
487
506
  target,
488
507
  payload: createGenericPayload({
489
- buyerPhone,
490
- buyerEmail,
491
- customer,
492
- shippingAddress,
493
- billingAddress,
508
+ buyerPhone: shopify.buyerIdentity?.phone.value,
509
+ buyerEmail: shopify.buyerIdentity?.email.value,
510
+ customer: shopify.buyerIdentity?.customer.value,
511
+ shippingAddress: shopify.shippingAddress?.value,
512
+ billingAddress: shopify.billingAddress?.value,
494
513
  totalAmount,
495
514
  cartLines,
496
515
  checkoutToken,
@@ -508,29 +527,25 @@ const ThankYouPayloadManager = ({ children }) => {
508
527
  };
509
528
  const OrderStatusPayloadManager = ({ children }) => {
510
529
  const target = PAYLOAD_MANAGER_TARGET.ORDER_STATUS;
511
- const customer = useCustomer$1();
512
- const buyerEmail = useEmail$1();
513
- const buyerPhone = usePhone$1();
514
530
  const purchasingCompany = usePurchasingCompany$1();
515
- const shippingAddress = useShippingAddress$1();
516
- const billingAddress = useBillingAddress$1();
517
531
  const totalAmount = useTotalAmount$1();
518
532
  const cartLines = useCartLines$1();
519
533
  const discountCodes = useDiscountCodes$1();
520
534
  const shop = useShop$1();
521
535
  const order = useOrder();
522
536
  const api = useApi$1();
537
+ const checkoutToken = useSubscription$1(api.checkoutToken);
523
538
  return /* @__PURE__ */ jsx$1(GenericPayloadProvider, {
524
539
  target,
525
540
  payload: createGenericPayload({
526
- buyerPhone,
527
- buyerEmail,
528
- customer,
529
- shippingAddress,
530
- billingAddress,
541
+ buyerPhone: shopify.buyerIdentity?.phone.value,
542
+ buyerEmail: shopify.buyerIdentity?.email.value,
543
+ customer: shopify.buyerIdentity?.customer.value,
544
+ shippingAddress: shopify.shippingAddress?.value,
545
+ billingAddress: shopify.billingAddress?.value,
531
546
  totalAmount,
532
547
  cartLines,
533
- checkoutToken: useSubscription$1(api.checkoutToken),
548
+ checkoutToken,
534
549
  discountCodes,
535
550
  shopGid: shop.id,
536
551
  extensionTarget: api.extension.target
@@ -553,13 +568,12 @@ const EXTENSION_TARGETS = {
553
568
  "purchase.thank-you.block.render": PAYLOAD_MANAGER_TARGET.THANK_YOU,
554
569
  "customer-account.order-status.block.render": PAYLOAD_MANAGER_TARGET.ORDER_STATUS
555
570
  };
556
- const getExtensionTarget = () => globalThis.shopify?.extension?.target;
557
571
  const PayloadManager = ({ children }) => {
558
- const extensionTarget = getExtensionTarget();
559
- const target = extensionTarget && EXTENSION_TARGETS[extensionTarget];
572
+ const extensionTarget = shopify.extension.target;
573
+ const target = EXTENSION_TARGETS[extensionTarget];
560
574
  if (target === PAYLOAD_MANAGER_TARGET.THANK_YOU) return /* @__PURE__ */ jsx$1(ThankYouPayloadManager, { children });
561
575
  if (target === PAYLOAD_MANAGER_TARGET.ORDER_STATUS) return /* @__PURE__ */ jsx$1(OrderStatusPayloadManager, { children });
562
- throw new Error(`[Disco]: Unsupported extension target ${extensionTarget ?? "(none)"}`);
576
+ throw new Error(`[Disco]: Unsupported extension target ${extensionTarget}`);
563
577
  };
564
578
  //#endregion
565
579
  //#region src/managers/UserManager.tsx
@@ -4893,4 +4907,4 @@ function OrderSubmitter({ trackingTicketId, idempotencyKey, insertionId }) {
4893
4907
  //#endregion
4894
4908
  export { DiscoRecommendations as a, PrepurchaseIncentive as i, PrepurchaseThankYou as n, Recommendations as o, DiscoPrepurchaseIncentive as r, DiscoPrepurchaseThankYou as t };
4895
4909
 
4896
- //# sourceMappingURL=DiscoPrepurchaseThankYou-0LqiJGuU.js.map
4910
+ //# sourceMappingURL=DiscoPrepurchaseThankYou-Cu3yyFVs.js.map