@aglyn/plugins-commerce 1.30.0 → 1.31.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.
Files changed (32) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/cart.js +11 -5
  3. package/src/lib/components/cart.js.map +1 -1
  4. package/src/lib/components/console/product-editor-dialog.component.js +5 -0
  5. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  6. package/src/lib/components/console/product-traffic-card.component.d.ts +24 -0
  7. package/src/lib/components/console/product-traffic-card.component.js +172 -0
  8. package/src/lib/components/console/product-traffic-card.component.js.map +1 -0
  9. package/src/lib/components/console/products-hub-card.component.js +181 -59
  10. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  11. package/src/lib/components/console/shipping-settings-card.component.js +31 -9
  12. package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
  13. package/src/lib/model/commerce-record-routes.js +31 -0
  14. package/src/lib/model/commerce-record-routes.js.map +1 -1
  15. package/src/lib/model/commerce-shipping.d.ts +39 -16
  16. package/src/lib/model/commerce-shipping.js +315 -30
  17. package/src/lib/model/commerce-shipping.js.map +1 -1
  18. package/src/lib/model/product-write.d.ts +10 -1
  19. package/src/lib/model/product-write.js +13 -2
  20. package/src/lib/model/product-write.js.map +1 -1
  21. package/src/lib/server/carrier-shipping.js +3 -2
  22. package/src/lib/server/carrier-shipping.js.map +1 -1
  23. package/src/lib/server/cart-checkout.js +10 -4
  24. package/src/lib/server/cart-checkout.js.map +1 -1
  25. package/src/lib/server/cart.js +2 -2
  26. package/src/lib/server/cart.js.map +1 -1
  27. package/src/lib/server/checkout.js +6 -4
  28. package/src/lib/server/checkout.js.map +1 -1
  29. package/src/lib/server/draft-order.js +3 -3
  30. package/src/lib/server/draft-order.js.map +1 -1
  31. package/src/lib/server/products-write.js +10 -2
  32. package/src/lib/server/products-write.js.map +1 -1
@@ -197,14 +197,10 @@ function tierAmount(tiers, value) {
197
197
  }
198
198
  /** Stripe Checkout accepts at most 5 `shipping_options` on one session. */ export const MAX_CHECKOUT_SHIPPING_OPTIONS = 5;
199
199
  /**
200
- * Destinations a storefront Checkout Session collects an address for, and
201
- * therefore the destinations shipping rates are resolved against (AGL-1707).
202
- *
203
- * NOT narrowed to the zones the merchant configured: narrowing would block
204
- * checkouts that complete today, turning a money fix into lost sales. The
205
- * wider list only means a shopper outside the merchant's zones is offered some
206
- * rate rather than none. Shared by cart checkout and buy-now (AGL-1720) so the
207
- * two paths cannot drift into offering different destinations.
200
+ * The destinations a Checkout Session collects an address for when the
201
+ * merchant prices NO shipping (AGL-1707), and so the session such a store has
202
+ * always had. A merchant with zones gets `checkoutShippingCountries` instead:
203
+ * the countries their zones name, or every country for rest of world.
208
204
  */ export const CHECKOUT_SHIPPING_COUNTRIES = [
209
205
  'US',
210
206
  'CA',
@@ -258,27 +254,299 @@ function tierAmount(tiers, value) {
258
254
  // to lose: a shopper offered the cheap options would have taken one.
259
255
  .slice(0, MAX_CHECKOUT_SHIPPING_OPTIONS);
260
256
  }
261
- /** {@link CHECKOUT_SHIPPING_COUNTRIES} as plain codes, for the apps' draft order (AGL-3841). */ export const CHECKOUT_SHIPPING_COUNTRY_CODES = CHECKOUT_SHIPPING_COUNTRIES;
262
- /** Shopper-facing names for the collectable destinations (AGL-1721). */ export const CHECKOUT_SHIPPING_COUNTRY_NAMES = {
263
- US: 'United States',
264
- CA: 'Canada',
265
- GB: 'United Kingdom',
266
- AU: 'Australia',
267
- DE: 'Germany',
268
- FR: 'France'
257
+ /**
258
+ * {@link CHECKOUT_SHIPPING_COUNTRIES} as plain codes: the apps' draft order
259
+ * falls back to it only when the server names no list (AGL-3841).
260
+ */ export const CHECKOUT_SHIPPING_COUNTRY_CODES = CHECKOUT_SHIPPING_COUNTRIES;
261
+ /**
262
+ * Every country Stripe Checkout can collect a shipping address for
263
+ * (`shipping_address_collection[allowed_countries]`), with the name a shopper
264
+ * reads. A rest-of-world `*` zone opens checkout to all of them.
265
+ */ export const CHECKOUT_SHIPPING_COUNTRY_NAMES = {
266
+ AC: "Ascension Island",
267
+ AD: "Andorra",
268
+ AE: "United Arab Emirates",
269
+ AF: "Afghanistan",
270
+ AG: "Antigua & Barbuda",
271
+ AI: "Anguilla",
272
+ AL: "Albania",
273
+ AM: "Armenia",
274
+ AO: "Angola",
275
+ AQ: "Antarctica",
276
+ AR: "Argentina",
277
+ AT: "Austria",
278
+ AU: "Australia",
279
+ AW: "Aruba",
280
+ AX: "Åland Islands",
281
+ AZ: "Azerbaijan",
282
+ BA: "Bosnia & Herzegovina",
283
+ BB: "Barbados",
284
+ BD: "Bangladesh",
285
+ BE: "Belgium",
286
+ BF: "Burkina Faso",
287
+ BG: "Bulgaria",
288
+ BH: "Bahrain",
289
+ BI: "Burundi",
290
+ BJ: "Benin",
291
+ BL: "St. Barthélemy",
292
+ BM: "Bermuda",
293
+ BN: "Brunei",
294
+ BO: "Bolivia",
295
+ BQ: "Caribbean Netherlands",
296
+ BR: "Brazil",
297
+ BS: "Bahamas",
298
+ BT: "Bhutan",
299
+ BV: "Bouvet Island",
300
+ BW: "Botswana",
301
+ BY: "Belarus",
302
+ BZ: "Belize",
303
+ CA: "Canada",
304
+ CD: "Congo - Kinshasa",
305
+ CF: "Central African Republic",
306
+ CG: "Congo - Brazzaville",
307
+ CH: "Switzerland",
308
+ CI: "Côte d’Ivoire",
309
+ CK: "Cook Islands",
310
+ CL: "Chile",
311
+ CM: "Cameroon",
312
+ CN: "China",
313
+ CO: "Colombia",
314
+ CR: "Costa Rica",
315
+ CV: "Cape Verde",
316
+ CW: "Curaçao",
317
+ CY: "Cyprus",
318
+ CZ: "Czechia",
319
+ DE: "Germany",
320
+ DJ: "Djibouti",
321
+ DK: "Denmark",
322
+ DM: "Dominica",
323
+ DO: "Dominican Republic",
324
+ DZ: "Algeria",
325
+ EC: "Ecuador",
326
+ EE: "Estonia",
327
+ EG: "Egypt",
328
+ EH: "Western Sahara",
329
+ ER: "Eritrea",
330
+ ES: "Spain",
331
+ ET: "Ethiopia",
332
+ FI: "Finland",
333
+ FJ: "Fiji",
334
+ FK: "Falkland Islands",
335
+ FO: "Faroe Islands",
336
+ FR: "France",
337
+ GA: "Gabon",
338
+ GB: "United Kingdom",
339
+ GD: "Grenada",
340
+ GE: "Georgia",
341
+ GF: "French Guiana",
342
+ GG: "Guernsey",
343
+ GH: "Ghana",
344
+ GI: "Gibraltar",
345
+ GL: "Greenland",
346
+ GM: "Gambia",
347
+ GN: "Guinea",
348
+ GP: "Guadeloupe",
349
+ GQ: "Equatorial Guinea",
350
+ GR: "Greece",
351
+ GS: "South Georgia & South Sandwich Islands",
352
+ GT: "Guatemala",
353
+ GU: "Guam",
354
+ GW: "Guinea-Bissau",
355
+ GY: "Guyana",
356
+ HK: "Hong Kong SAR China",
357
+ HN: "Honduras",
358
+ HR: "Croatia",
359
+ HT: "Haiti",
360
+ HU: "Hungary",
361
+ ID: "Indonesia",
362
+ IE: "Ireland",
363
+ IL: "Israel",
364
+ IM: "Isle of Man",
365
+ IN: "India",
366
+ IO: "British Indian Ocean Territory",
367
+ IQ: "Iraq",
368
+ IS: "Iceland",
369
+ IT: "Italy",
370
+ JE: "Jersey",
371
+ JM: "Jamaica",
372
+ JO: "Jordan",
373
+ JP: "Japan",
374
+ KE: "Kenya",
375
+ KG: "Kyrgyzstan",
376
+ KH: "Cambodia",
377
+ KI: "Kiribati",
378
+ KM: "Comoros",
379
+ KN: "St. Kitts & Nevis",
380
+ KR: "South Korea",
381
+ KW: "Kuwait",
382
+ KY: "Cayman Islands",
383
+ KZ: "Kazakhstan",
384
+ LA: "Laos",
385
+ LB: "Lebanon",
386
+ LC: "St. Lucia",
387
+ LI: "Liechtenstein",
388
+ LK: "Sri Lanka",
389
+ LR: "Liberia",
390
+ LS: "Lesotho",
391
+ LT: "Lithuania",
392
+ LU: "Luxembourg",
393
+ LV: "Latvia",
394
+ LY: "Libya",
395
+ MA: "Morocco",
396
+ MC: "Monaco",
397
+ MD: "Moldova",
398
+ ME: "Montenegro",
399
+ MF: "St. Martin",
400
+ MG: "Madagascar",
401
+ MK: "North Macedonia",
402
+ ML: "Mali",
403
+ MM: "Myanmar (Burma)",
404
+ MN: "Mongolia",
405
+ MO: "Macao SAR China",
406
+ MQ: "Martinique",
407
+ MR: "Mauritania",
408
+ MS: "Montserrat",
409
+ MT: "Malta",
410
+ MU: "Mauritius",
411
+ MV: "Maldives",
412
+ MW: "Malawi",
413
+ MX: "Mexico",
414
+ MY: "Malaysia",
415
+ MZ: "Mozambique",
416
+ NA: "Namibia",
417
+ NC: "New Caledonia",
418
+ NE: "Niger",
419
+ NG: "Nigeria",
420
+ NI: "Nicaragua",
421
+ NL: "Netherlands",
422
+ NO: "Norway",
423
+ NP: "Nepal",
424
+ NR: "Nauru",
425
+ NU: "Niue",
426
+ NZ: "New Zealand",
427
+ OM: "Oman",
428
+ PA: "Panama",
429
+ PE: "Peru",
430
+ PF: "French Polynesia",
431
+ PG: "Papua New Guinea",
432
+ PH: "Philippines",
433
+ PK: "Pakistan",
434
+ PL: "Poland",
435
+ PM: "St. Pierre & Miquelon",
436
+ PN: "Pitcairn Islands",
437
+ PR: "Puerto Rico",
438
+ PS: "Palestinian Territories",
439
+ PT: "Portugal",
440
+ PY: "Paraguay",
441
+ QA: "Qatar",
442
+ RE: "Réunion",
443
+ RO: "Romania",
444
+ RS: "Serbia",
445
+ RU: "Russia",
446
+ RW: "Rwanda",
447
+ SA: "Saudi Arabia",
448
+ SB: "Solomon Islands",
449
+ SC: "Seychelles",
450
+ SE: "Sweden",
451
+ SG: "Singapore",
452
+ SH: "St. Helena",
453
+ SI: "Slovenia",
454
+ SJ: "Svalbard & Jan Mayen",
455
+ SK: "Slovakia",
456
+ SL: "Sierra Leone",
457
+ SM: "San Marino",
458
+ SN: "Senegal",
459
+ SO: "Somalia",
460
+ SR: "Suriname",
461
+ SS: "South Sudan",
462
+ ST: "São Tomé & Príncipe",
463
+ SV: "El Salvador",
464
+ SX: "Sint Maarten",
465
+ SZ: "Eswatini",
466
+ TA: "Tristan da Cunha",
467
+ TC: "Turks & Caicos Islands",
468
+ TD: "Chad",
469
+ TF: "French Southern Territories",
470
+ TG: "Togo",
471
+ TH: "Thailand",
472
+ TJ: "Tajikistan",
473
+ TK: "Tokelau",
474
+ TL: "Timor-Leste",
475
+ TM: "Turkmenistan",
476
+ TN: "Tunisia",
477
+ TO: "Tonga",
478
+ TR: "Türkiye",
479
+ TT: "Trinidad & Tobago",
480
+ TV: "Tuvalu",
481
+ TW: "Taiwan",
482
+ TZ: "Tanzania",
483
+ UA: "Ukraine",
484
+ UG: "Uganda",
485
+ US: "United States",
486
+ UY: "Uruguay",
487
+ UZ: "Uzbekistan",
488
+ VA: "Vatican City",
489
+ VC: "St. Vincent & Grenadines",
490
+ VE: "Venezuela",
491
+ VG: "British Virgin Islands",
492
+ VN: "Vietnam",
493
+ VU: "Vanuatu",
494
+ WF: "Wallis & Futuna",
495
+ WS: "Samoa",
496
+ XK: "Kosovo",
497
+ YE: "Yemen",
498
+ YT: "Mayotte",
499
+ ZA: "South Africa",
500
+ ZM: "Zambia",
501
+ ZW: "Zimbabwe"
269
502
  };
503
+ /** {@link CHECKOUT_SHIPPING_COUNTRY_NAMES}' codes, in order. */ export const STRIPE_SHIPPING_COUNTRY_CODES = Object.keys(CHECKOUT_SHIPPING_COUNTRY_NAMES);
504
+ /**
505
+ * The countries ONE merchant's checkout collects an address for: the
506
+ * destinations their own zones name (international selling).
507
+ *
508
+ * `CHECKOUT_SHIPPING_COUNTRIES` used to be the only list, so a shopper in New
509
+ * Zealand, Ireland or any EU country but Germany and France could not enter an
510
+ * address at all, whatever zones the merchant saved. Now:
511
+ *
512
+ * - every country a zone names, in the order the merchant wrote them;
513
+ * - every Stripe-collectable country when a zone claims rest of world (`*`);
514
+ * - today's six for a merchant who prices no shipping (no zones and rates, or
515
+ * pickup only), so a store that never set shipping up keeps the session it
516
+ * has today, byte for byte.
517
+ *
518
+ * The AGL-1721 rule is unchanged, because `planCheckoutShipping` still pairs
519
+ * this list with the options it unions over it.
520
+ */ export function checkoutShippingCountries(settings) {
521
+ var _settings_zones;
522
+ if (!merchantPricesShipping(settings) || !(settings == null ? void 0 : (_settings_zones = settings.zones) == null ? void 0 : _settings_zones.length)) {
523
+ return CHECKOUT_SHIPPING_COUNTRIES;
524
+ }
525
+ const named = [];
526
+ for (const zone of settings.zones){
527
+ var _zone_countries;
528
+ for (const raw of (_zone_countries = zone.countries) != null ? _zone_countries : []){
529
+ const code = String(raw).trim().toUpperCase();
530
+ if (code === '*') return STRIPE_SHIPPING_COUNTRY_CODES;
531
+ if (code in CHECKOUT_SHIPPING_COUNTRY_NAMES && !named.includes(code)) {
532
+ named.push(code);
533
+ }
534
+ }
535
+ }
536
+ return named.length ? named : CHECKOUT_SHIPPING_COUNTRIES;
537
+ }
270
538
  /**
271
539
  * A destination a shopper declared, or `undefined` for anything this session
272
540
  * could not collect an address for anyway. Never throws: an unknown code is
273
541
  * an undeclared destination, not an error, so a stale storefront that posts
274
542
  * one is answered by the plan below rather than by a 400 nobody can act on.
275
- */ export function normalizeCheckoutShippingCountry(value) {
543
+ */ export function normalizeCheckoutShippingCountry(value, countries = STRIPE_SHIPPING_COUNTRY_CODES) {
276
544
  // `typeof` rather than `String(value)`: a JSON body is caller-shaped, and
277
545
  // `String(['US'])` is 'US'. Coercing would let an array declare a
278
546
  // destination, which is not a spelling any storefront sends.
279
547
  if (typeof value !== 'string') return undefined;
280
548
  const code = value.trim().toUpperCase();
281
- return CHECKOUT_SHIPPING_COUNTRIES.includes(code) ? code : undefined;
549
+ return countries.includes(code) ? code : undefined;
282
550
  }
283
551
  /**
284
552
  * Whether this merchant prices shipping AT ALL (AGL-2232).
@@ -353,8 +621,22 @@ function tierAmount(tiers, value) {
353
621
  * `cart.subtotalCents` is the PRE-discount items total, matching what the cart
354
622
  * displays, so a free-over threshold means what the shopper saw it mean.
355
623
  */ export function planCheckoutShipping(settings, cart, destinationCountry) {
356
- const countries = CHECKOUT_SHIPPING_COUNTRIES;
357
- const destination = normalizeCheckoutShippingCountry(destinationCountry);
624
+ const countries = checkoutShippingCountries(settings);
625
+ // Any Stripe-collectable code counts as DECLARED, so a shopper naming a
626
+ // country this store's zones do not reach is told it is not served rather
627
+ // than asked again. Only a store whose list comes from its zones refuses
628
+ // that way: one on the fallback list ships nowhere in particular, and an
629
+ // outside code stays undeclared there exactly as it always was.
630
+ const declared = normalizeCheckoutShippingCountry(destinationCountry);
631
+ const fromZones = countries !== CHECKOUT_SHIPPING_COUNTRIES;
632
+ if (declared && !countries.includes(declared) && fromZones) {
633
+ return {
634
+ countries,
635
+ options: [],
636
+ refusal: 'destination-unserved'
637
+ };
638
+ }
639
+ const destination = declared && countries.includes(declared) ? declared : undefined;
358
640
  if (destination) {
359
641
  const options = resolveCheckoutShippingOptions(settings, [
360
642
  destination
@@ -458,11 +740,9 @@ function tierAmount(tiers, value) {
458
740
  * Which of the collectable destinations a merchant's settings actually cover
459
741
  * (AGL-1791), for a console surface to show them.
460
742
  *
461
- * Measured against `CHECKOUT_SHIPPING_COUNTRIES` and nothing wider: those six
462
- * are the only destinations a storefront session collects an address for, so
463
- * they are the only ones a merchant can lose an order to. Counting coverage
464
- * against every country on earth would report a gap for destinations no
465
- * shopper can reach checkout from.
743
+ * Measured against `checkoutShippingCountries(settings)` and nothing wider:
744
+ * those are the only destinations this store's session collects an address
745
+ * for, so they are the only ones a merchant can lose an order to.
466
746
  *
467
747
  * Answered through `resolveCheckoutShippingOptions` — the same function the
468
748
  * session is built from — so a row the console allows but Stripe would reject
@@ -474,7 +754,8 @@ function tierAmount(tiers, value) {
474
754
  const served = [];
475
755
  const unserved = [];
476
756
  const offers = new Set();
477
- for (const country of CHECKOUT_SHIPPING_COUNTRIES){
757
+ const collectable = checkoutShippingCountries(settings);
758
+ for (const country of collectable){
478
759
  const options = resolveCheckoutShippingOptions(settings, [
479
760
  country
480
761
  ], COVERAGE_PROBE_CART);
@@ -485,6 +766,7 @@ function tierAmount(tiers, value) {
485
766
  (shippableOnly(options).length > 0 ? served : unserved).push(country);
486
767
  }
487
768
  return {
769
+ collectable: collectable.length,
488
770
  served,
489
771
  unserved: served.length > 0 ? unserved : [],
490
772
  shipsNowhere: served.length === 0,
@@ -493,15 +775,18 @@ function tierAmount(tiers, value) {
493
775
  hasRestOfWorldZone: ((_ref = settings == null ? void 0 : settings.zones) != null ? _ref : []).some((zone)=>zone.countries.some((code)=>code === '*'))
494
776
  };
495
777
  }
496
- const coverageCountryNames = (codes)=>codes.map((code)=>{
778
+ /** Names, the first eight in full: a rest-of-world gap can be 200 countries. */ const coverageCountryNames = (codes)=>{
779
+ const names = codes.map((code)=>{
497
780
  var _CHECKOUT_SHIPPING_COUNTRY_NAMES_code;
498
781
  return (_CHECKOUT_SHIPPING_COUNTRY_NAMES_code = CHECKOUT_SHIPPING_COUNTRY_NAMES[code]) != null ? _CHECKOUT_SHIPPING_COUNTRY_NAMES_code : code;
499
- }).join(', ');
782
+ });
783
+ return names.length > 8 ? `${names.slice(0, 8).join(', ')} and ${names.length - 8} more` : names.join(', ');
784
+ };
500
785
  export function describeShippingCoverage(coverage) {
501
786
  const asks = coverage.asksDestination ? 'Rates differ by destination, so checkout asks the shopper where the parcel is going before it can price one.' : '';
502
787
  if (coverage.unserved.length > 0) {
503
788
  return {
504
- headline: `Checkout turns away ${coverage.unserved.length} of the ${CHECKOUT_SHIPPING_COUNTRIES.length} destinations it collects addresses for`,
789
+ headline: `Checkout turns away ${coverage.unserved.length} of the ${coverage.collectable} destinations it collects addresses for`,
505
790
  detail: `No rate reaches ${coverageCountryNames(coverage.unserved)}, so an order shipping there is refused rather than posted for free. ` + (coverage.offersLocalPickup ? 'Local pickup does not cover them: it is a collection choice, not a rate, so it is offered where checkout completes and closes no gap here. ' : '') + (coverage.hasRestOfWorldZone ? 'A rest-of-world zone is already saved, so what those destinations are missing is a rate on the zone that covers them.' : 'Give them a zone with a rate, or add a rest-of-world zone and price one on it.'),
506
791
  note: '',
507
792
  asks
@@ -510,7 +795,7 @@ export function describeShippingCoverage(coverage) {
510
795
  return {
511
796
  headline: '',
512
797
  detail: '',
513
- note: coverage.shipsNowhere ? coverage.offersLocalPickup ? 'No rate reaches any destination, so local pickup is the only delivery choice checkout offers. Nobody is turned away and no shipping is charged.' : 'No rate reaches any destination, so checkout charges no shipping and turns nobody away.' : `Checkout can price shipping to every destination it collects an address for: ${coverageCountryNames(coverage.served)}.`,
798
+ note: coverage.shipsNowhere ? coverage.offersLocalPickup ? 'No rate reaches any destination, so local pickup is the only delivery choice checkout offers. Nobody is turned away and no shipping is charged.' : 'No rate reaches any destination, so checkout charges no shipping and turns nobody away.' : coverage.hasRestOfWorldZone && coverage.served.length === STRIPE_SHIPPING_COUNTRY_CODES.length ? 'Checkout can price shipping to every country it can collect an address for.' : `Checkout can price shipping to every destination it collects an address for: ${coverageCountryNames(coverage.served)}.`,
514
799
  asks
515
800
  };
516
801
  }