@moonbase.sh/storefront-api 2.0.1 → 2.1.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.cjs CHANGED
@@ -46,7 +46,9 @@ __export(index_exports, {
46
46
  SubscriptionStatus: () => SubscriptionStatus,
47
47
  TokenStore: () => TokenStore,
48
48
  objectToQuery: () => objectToQuery,
49
+ parseOffSiteReferrer: () => parseOffSiteReferrer,
49
50
  problemDetailsSchema: () => problemDetailsSchema,
51
+ resolveUtm: () => resolveUtm,
50
52
  schemas: () => schemas_exports12,
51
53
  utmToObject: () => utmToObject
52
54
  });
@@ -1685,6 +1687,27 @@ var OfferUtils = class _OfferUtils {
1685
1687
  }
1686
1688
  };
1687
1689
 
1690
+ // src/utils/utm.ts
1691
+ function parseOffSiteReferrer(rawReferrer, currentOrigin) {
1692
+ if (!rawReferrer)
1693
+ return void 0;
1694
+ try {
1695
+ const referrerUrl = new URL(rawReferrer);
1696
+ if (referrerUrl.origin === currentOrigin)
1697
+ return void 0;
1698
+ return referrerUrl.host || void 0;
1699
+ } catch (e) {
1700
+ return void 0;
1701
+ }
1702
+ }
1703
+ function resolveUtm(cached, fresh) {
1704
+ const freshHasUtm = !!(fresh.source || fresh.medium || fresh.campaign || fresh.term || fresh.content);
1705
+ const freshIsExternalArrival = freshHasUtm || !!fresh.referrer;
1706
+ if (freshIsExternalArrival)
1707
+ return fresh;
1708
+ return cached != null ? cached : fresh;
1709
+ }
1710
+
1688
1711
  // src/index.ts
1689
1712
  var MoonbaseClient = class {
1690
1713
  constructor(configuration) {
@@ -1732,7 +1755,9 @@ var MoonbaseClient = class {
1732
1755
  SubscriptionStatus,
1733
1756
  TokenStore,
1734
1757
  objectToQuery,
1758
+ parseOffSiteReferrer,
1735
1759
  problemDetailsSchema,
1760
+ resolveUtm,
1736
1761
  schemas,
1737
1762
  utmToObject
1738
1763
  });
package/dist/index.d.cts CHANGED
@@ -38421,6 +38421,32 @@ declare class DiscountUtils {
38421
38421
  static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38422
38422
  }
38423
38423
 
38424
+ /**
38425
+ * Returns the host of `rawReferrer` if it parses as a URL with a different
38426
+ * origin from `currentOrigin`. Returns `undefined` for same-origin (internal
38427
+ * navigation), empty, or unparseable referrers — these should not count as
38428
+ * attribution signals.
38429
+ */
38430
+ declare function parseOffSiteReferrer(rawReferrer: string | undefined, currentOrigin: string): string | undefined;
38431
+ /**
38432
+ * Resolves the effective attribution state given the cached attribution from
38433
+ * a previous pageview and the freshly captured attribution on the current
38434
+ * page.
38435
+ *
38436
+ * Model: session-last-touch with atomic attribution events. UTM fields and
38437
+ * the referrer describe one and the same arrival, so they move together.
38438
+ *
38439
+ * - If the current page has any external signal — a UTM field or an off-site
38440
+ * referrer — that's a new attribution event and `fresh` is adopted
38441
+ * wholesale. No mixing with prior attribution.
38442
+ * - Otherwise (typically internal navigation, where same-origin referrers
38443
+ * are filtered to undefined upstream), the cached attribution is restored
38444
+ * verbatim so it carries through the session.
38445
+ * - With nothing fresh and nothing cached, the result is an empty
38446
+ * attribution (direct visit, no signal).
38447
+ */
38448
+ declare function resolveUtm(cached: UrchinTrackingModule | undefined, fresh: UrchinTrackingModule): UrchinTrackingModule;
38449
+
38424
38450
  interface MoonbaseConfiguration {
38425
38451
  endpoint: string;
38426
38452
  persistUtm?: boolean;
@@ -38444,4 +38470,4 @@ declare class MoonbaseClient {
38444
38470
  orders: OrderEndpoints;
38445
38471
  }
38446
38472
 
38447
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, objectToQuery, problemDetailsSchema, schemas, utmToObject };
38473
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, resolveUtm, schemas, utmToObject };
package/dist/index.d.ts CHANGED
@@ -38421,6 +38421,32 @@ declare class DiscountUtils {
38421
38421
  static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38422
38422
  }
38423
38423
 
38424
+ /**
38425
+ * Returns the host of `rawReferrer` if it parses as a URL with a different
38426
+ * origin from `currentOrigin`. Returns `undefined` for same-origin (internal
38427
+ * navigation), empty, or unparseable referrers — these should not count as
38428
+ * attribution signals.
38429
+ */
38430
+ declare function parseOffSiteReferrer(rawReferrer: string | undefined, currentOrigin: string): string | undefined;
38431
+ /**
38432
+ * Resolves the effective attribution state given the cached attribution from
38433
+ * a previous pageview and the freshly captured attribution on the current
38434
+ * page.
38435
+ *
38436
+ * Model: session-last-touch with atomic attribution events. UTM fields and
38437
+ * the referrer describe one and the same arrival, so they move together.
38438
+ *
38439
+ * - If the current page has any external signal — a UTM field or an off-site
38440
+ * referrer — that's a new attribution event and `fresh` is adopted
38441
+ * wholesale. No mixing with prior attribution.
38442
+ * - Otherwise (typically internal navigation, where same-origin referrers
38443
+ * are filtered to undefined upstream), the cached attribution is restored
38444
+ * verbatim so it carries through the session.
38445
+ * - With nothing fresh and nothing cached, the result is an empty
38446
+ * attribution (direct visit, no signal).
38447
+ */
38448
+ declare function resolveUtm(cached: UrchinTrackingModule | undefined, fresh: UrchinTrackingModule): UrchinTrackingModule;
38449
+
38424
38450
  interface MoonbaseConfiguration {
38425
38451
  endpoint: string;
38426
38452
  persistUtm?: boolean;
@@ -38444,4 +38470,4 @@ declare class MoonbaseClient {
38444
38470
  orders: OrderEndpoints;
38445
38471
  }
38446
38472
 
38447
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, objectToQuery, problemDetailsSchema, schemas, utmToObject };
38473
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, type BundleLineItem, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, resolveUtm, schemas, utmToObject };
package/dist/index.js CHANGED
@@ -1637,6 +1637,27 @@ var OfferUtils = class _OfferUtils {
1637
1637
  }
1638
1638
  };
1639
1639
 
1640
+ // src/utils/utm.ts
1641
+ function parseOffSiteReferrer(rawReferrer, currentOrigin) {
1642
+ if (!rawReferrer)
1643
+ return void 0;
1644
+ try {
1645
+ const referrerUrl = new URL(rawReferrer);
1646
+ if (referrerUrl.origin === currentOrigin)
1647
+ return void 0;
1648
+ return referrerUrl.host || void 0;
1649
+ } catch (e) {
1650
+ return void 0;
1651
+ }
1652
+ }
1653
+ function resolveUtm(cached, fresh) {
1654
+ const freshHasUtm = !!(fresh.source || fresh.medium || fresh.campaign || fresh.term || fresh.content);
1655
+ const freshIsExternalArrival = freshHasUtm || !!fresh.referrer;
1656
+ if (freshIsExternalArrival)
1657
+ return fresh;
1658
+ return cached != null ? cached : fresh;
1659
+ }
1660
+
1640
1661
  // src/index.ts
1641
1662
  var MoonbaseClient = class {
1642
1663
  constructor(configuration) {
@@ -1683,7 +1704,9 @@ export {
1683
1704
  SubscriptionStatus,
1684
1705
  TokenStore,
1685
1706
  objectToQuery,
1707
+ parseOffSiteReferrer,
1686
1708
  problemDetailsSchema,
1709
+ resolveUtm,
1687
1710
  schemas_exports12 as schemas,
1688
1711
  utmToObject
1689
1712
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "2.0.1",
4
+ "version": "2.1.0",
5
5
  "description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",