@moonbase.sh/storefront-api 3.0.0 → 3.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.
- package/README.md +11 -1
- package/dist/index.cjs +307 -39
- package/dist/index.d.cts +139 -7
- package/dist/index.d.ts +139 -7
- package/dist/index.js +306 -39
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -26,12 +26,47 @@ interface IStore {
|
|
|
26
26
|
set: <TItem>(key: string, item: TItem) => void;
|
|
27
27
|
remove: (key: string) => void;
|
|
28
28
|
listen: <TItem>(key: string, callback: (item: TItem | null) => void) => void;
|
|
29
|
+
/**
|
|
30
|
+
* True once any storage operation has failed and the store has fallen back to
|
|
31
|
+
* memory. Optional so custom stores don't have to implement it.
|
|
32
|
+
*/
|
|
33
|
+
readonly isDegraded?: boolean;
|
|
29
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether `localStorage` can be reached at all.
|
|
37
|
+
*
|
|
38
|
+
* Deliberately *not* a write probe. Writability is not the right question here,
|
|
39
|
+
* because `LocalStorageStore` degrades per operation when a write fails, so a
|
|
40
|
+
* storage that reads fine but is at quota is still worth using: it is holding the
|
|
41
|
+
* buyer's existing session, and refusing it would throw away a perfectly readable
|
|
42
|
+
* sign-in and send them back to the login form. The only thing that makes
|
|
43
|
+
* `localStorage` unusable is not being able to touch it, which is what Firefox
|
|
44
|
+
* does (`SecurityError` from the property getter) when the buyer has blocked
|
|
45
|
+
* cookies and site data. That is why even the truthiness check sits inside a
|
|
46
|
+
* `try`.
|
|
47
|
+
*/
|
|
48
|
+
declare function isLocalStorageAvailable(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* `localStorage`-backed store that degrades to memory instead of throwing.
|
|
51
|
+
*
|
|
52
|
+
* Storage can start failing at any point in a session, not just at construction:
|
|
53
|
+
* the origin hits quota, an extension clears site data, the profile's storage
|
|
54
|
+
* file goes corrupt. Since this is where the auth tokens live, an unhandled
|
|
55
|
+
* throw here surfaces as a failed sign-in for a buyer whose credentials were
|
|
56
|
+
* accepted. So every operation falls back to an in-memory copy. The session
|
|
57
|
+
* keeps working; it just stops surviving a reload.
|
|
58
|
+
*/
|
|
30
59
|
declare class LocalStorageStore implements IStore {
|
|
60
|
+
private readonly onDegraded?;
|
|
61
|
+
private readonly fallback;
|
|
62
|
+
private degraded;
|
|
63
|
+
constructor(onDegraded?: ((err: unknown) => void) | undefined);
|
|
64
|
+
get isDegraded(): boolean;
|
|
31
65
|
get<TItem>(key: string): TItem | null;
|
|
32
66
|
set<TItem>(key: string, item: TItem): void;
|
|
33
67
|
remove(key: string): void;
|
|
34
68
|
listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
|
|
69
|
+
private reportDegraded;
|
|
35
70
|
}
|
|
36
71
|
declare class InMemoryStore implements IStore {
|
|
37
72
|
private readonly store;
|
|
@@ -47,6 +82,7 @@ type IdentityWithExpiry = Identity & {
|
|
|
47
82
|
};
|
|
48
83
|
interface ITokenStore {
|
|
49
84
|
get user(): User | null;
|
|
85
|
+
get isPersistent(): boolean;
|
|
50
86
|
getAccessToken: () => Promise<string | null>;
|
|
51
87
|
setUser: (user: Identity | User) => User | null;
|
|
52
88
|
clear: () => void;
|
|
@@ -57,15 +93,26 @@ declare class TokenStore implements ITokenStore {
|
|
|
57
93
|
private refreshTimeoutId;
|
|
58
94
|
private refreshPromise;
|
|
59
95
|
private readonly store;
|
|
96
|
+
private readonly logger;
|
|
60
97
|
static readonly storageKey = "moonbase_auth";
|
|
61
98
|
constructor(configuration: MoonbaseConfiguration);
|
|
62
99
|
get user(): User | null;
|
|
100
|
+
get isPersistent(): boolean;
|
|
63
101
|
getAccessToken(): Promise<string | null>;
|
|
64
102
|
setUser(user: Identity | User): IdentityWithExpiry | null;
|
|
65
103
|
clear(): null;
|
|
66
104
|
private get isExpired();
|
|
105
|
+
/**
|
|
106
|
+
* Start a refresh and hold it so concurrent callers join it rather than firing
|
|
107
|
+
* their own. The slot is cleared as soon as it settles: a retained promise
|
|
108
|
+
* would hand every later expiry the same stale access token, and a rejected one
|
|
109
|
+
* that stayed put would re-throw on every subsequent request (including the
|
|
110
|
+
* anonymous ones) for the rest of the session.
|
|
111
|
+
*/
|
|
112
|
+
private startRefresh;
|
|
67
113
|
private refreshTokens;
|
|
68
114
|
private handleStorageUpdate;
|
|
115
|
+
private warnAboutStorage;
|
|
69
116
|
}
|
|
70
117
|
|
|
71
118
|
type HttpMethods = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
@@ -1682,6 +1729,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1682
1729
|
releaseDescription: z.ZodOptional<z.ZodString>;
|
|
1683
1730
|
downloadsNeedsUser: z.ZodBoolean;
|
|
1684
1731
|
downloadsNeedsOwnership: z.ZodBoolean;
|
|
1732
|
+
downloadsNeedsGroupMembership: z.ZodBoolean;
|
|
1733
|
+
downloadsAllowed: z.ZodBoolean;
|
|
1685
1734
|
downloads: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1686
1735
|
name: z.ZodString;
|
|
1687
1736
|
key: z.ZodString;
|
|
@@ -1749,6 +1798,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1749
1798
|
currentVersion: string | null;
|
|
1750
1799
|
downloadsNeedsUser: boolean;
|
|
1751
1800
|
downloadsNeedsOwnership: boolean;
|
|
1801
|
+
downloadsNeedsGroupMembership: boolean;
|
|
1802
|
+
downloadsAllowed: boolean;
|
|
1752
1803
|
description?: string | null | undefined;
|
|
1753
1804
|
tagline?: string | null | undefined;
|
|
1754
1805
|
website?: string | undefined;
|
|
@@ -1783,6 +1834,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1783
1834
|
currentVersion: string | null;
|
|
1784
1835
|
downloadsNeedsUser: boolean;
|
|
1785
1836
|
downloadsNeedsOwnership: boolean;
|
|
1837
|
+
downloadsNeedsGroupMembership: boolean;
|
|
1838
|
+
downloadsAllowed: boolean;
|
|
1786
1839
|
description?: string | null | undefined;
|
|
1787
1840
|
tagline?: string | null | undefined;
|
|
1788
1841
|
website?: string | undefined;
|
|
@@ -1850,6 +1903,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1850
1903
|
currentVersion: string | null;
|
|
1851
1904
|
downloadsNeedsUser: boolean;
|
|
1852
1905
|
downloadsNeedsOwnership: boolean;
|
|
1906
|
+
downloadsNeedsGroupMembership: boolean;
|
|
1907
|
+
downloadsAllowed: boolean;
|
|
1853
1908
|
description?: string | null | undefined;
|
|
1854
1909
|
tagline?: string | null | undefined;
|
|
1855
1910
|
website?: string | undefined;
|
|
@@ -1903,6 +1958,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1903
1958
|
currentVersion: string | null;
|
|
1904
1959
|
downloadsNeedsUser: boolean;
|
|
1905
1960
|
downloadsNeedsOwnership: boolean;
|
|
1961
|
+
downloadsNeedsGroupMembership: boolean;
|
|
1962
|
+
downloadsAllowed: boolean;
|
|
1906
1963
|
description?: string | null | undefined;
|
|
1907
1964
|
tagline?: string | null | undefined;
|
|
1908
1965
|
website?: string | undefined;
|
|
@@ -2450,6 +2507,8 @@ declare const productSummarySchema: z.ZodObject<{
|
|
|
2450
2507
|
releaseDescription: z.ZodOptional<z.ZodString>;
|
|
2451
2508
|
downloadsNeedsUser: z.ZodBoolean;
|
|
2452
2509
|
downloadsNeedsOwnership: z.ZodBoolean;
|
|
2510
|
+
downloadsNeedsGroupMembership: z.ZodBoolean;
|
|
2511
|
+
downloadsAllowed: z.ZodBoolean;
|
|
2453
2512
|
downloads: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2454
2513
|
name: z.ZodString;
|
|
2455
2514
|
key: z.ZodString;
|
|
@@ -2517,6 +2576,8 @@ declare const productSummarySchema: z.ZodObject<{
|
|
|
2517
2576
|
currentVersion: string | null;
|
|
2518
2577
|
downloadsNeedsUser: boolean;
|
|
2519
2578
|
downloadsNeedsOwnership: boolean;
|
|
2579
|
+
downloadsNeedsGroupMembership: boolean;
|
|
2580
|
+
downloadsAllowed: boolean;
|
|
2520
2581
|
description?: string | null | undefined;
|
|
2521
2582
|
tagline?: string | null | undefined;
|
|
2522
2583
|
website?: string | undefined;
|
|
@@ -2551,6 +2612,8 @@ declare const productSummarySchema: z.ZodObject<{
|
|
|
2551
2612
|
currentVersion: string | null;
|
|
2552
2613
|
downloadsNeedsUser: boolean;
|
|
2553
2614
|
downloadsNeedsOwnership: boolean;
|
|
2615
|
+
downloadsNeedsGroupMembership: boolean;
|
|
2616
|
+
downloadsAllowed: boolean;
|
|
2554
2617
|
description?: string | null | undefined;
|
|
2555
2618
|
tagline?: string | null | undefined;
|
|
2556
2619
|
website?: string | undefined;
|
|
@@ -22703,15 +22766,25 @@ type LineItem = z.infer<typeof openOrderLineItem>;
|
|
|
22703
22766
|
type ProductLineItem = z.infer<typeof openProductLineItem>;
|
|
22704
22767
|
type BundleLineItem = z.infer<typeof openBundleLineItem>;
|
|
22705
22768
|
|
|
22769
|
+
interface CheckoutUrlOptions {
|
|
22770
|
+
/** Where to send the buyer once the checkout is done with them. */
|
|
22771
|
+
returnUrl?: string;
|
|
22772
|
+
/**
|
|
22773
|
+
* Whether checkout will be rendered in the overlay iframe rather than as a
|
|
22774
|
+
* full-page redirect. Tells the backend whether a checkout login token is
|
|
22775
|
+
* worth minting: the returned `hostedCheckoutUrl` only carries one when this
|
|
22776
|
+
* is not `false`. Say `false` whenever you intend to redirect, so a day-long
|
|
22777
|
+
* credential is never minted for a URL that will not use it.
|
|
22778
|
+
*/
|
|
22779
|
+
embedded?: boolean;
|
|
22780
|
+
}
|
|
22706
22781
|
declare class OrderEndpoints {
|
|
22707
22782
|
private api;
|
|
22708
22783
|
constructor(api: MoonbaseApi);
|
|
22709
22784
|
get(orderId: string, options?: {
|
|
22710
22785
|
abort?: AbortSignal;
|
|
22711
22786
|
finalize?: boolean;
|
|
22712
|
-
checkout?:
|
|
22713
|
-
returnUrl?: string;
|
|
22714
|
-
};
|
|
22787
|
+
checkout?: CheckoutUrlOptions;
|
|
22715
22788
|
}): Promise<{
|
|
22716
22789
|
id: string;
|
|
22717
22790
|
status: OrderStatus.Completed;
|
|
@@ -24102,9 +24175,7 @@ declare class OrderEndpoints {
|
|
|
24102
24175
|
offerId?: string;
|
|
24103
24176
|
replaced?: string[];
|
|
24104
24177
|
})[];
|
|
24105
|
-
}, checkout?:
|
|
24106
|
-
returnUrl?: string;
|
|
24107
|
-
}, utm?: UrchinTrackingModule): Promise<OpenOrder>;
|
|
24178
|
+
}, checkout?: CheckoutUrlOptions, utm?: UrchinTrackingModule): Promise<OpenOrder>;
|
|
24108
24179
|
addBillingDetails(orderId: string, details: {
|
|
24109
24180
|
name: string;
|
|
24110
24181
|
email: string;
|
|
@@ -46733,6 +46804,18 @@ declare class OfferUtils {
|
|
|
46733
46804
|
static progress(offer: StorefrontOffer, context: Order | OfferConditionContext): OfferProgress | null;
|
|
46734
46805
|
private static evaluate;
|
|
46735
46806
|
static relevantTargets(offer: StorefrontOffer, cartItems: LineItem[]): StorefrontOfferTarget[];
|
|
46807
|
+
/**
|
|
46808
|
+
* Whether every item an offer targets is already in the cart, so the offer has no upsell left to
|
|
46809
|
+
* show.
|
|
46810
|
+
*
|
|
46811
|
+
* This is the set of offers the cart hides: a card inviting the buyer to add what they have already
|
|
46812
|
+
* added says nothing, so it is dropped. Which makes it exactly the set whose discount nothing can
|
|
46813
|
+
* currently claim: an offer is only good for one line, and there is no card left to spend it from.
|
|
46814
|
+
*
|
|
46815
|
+
* An offer with no targets names nothing and so is never in this set.
|
|
46816
|
+
*/
|
|
46817
|
+
static allTargetsInCart(offer: StorefrontOffer, cartItems: LineItem[]): boolean;
|
|
46818
|
+
private static targetInCart;
|
|
46736
46819
|
static targetedVariations(target: StorefrontOfferTarget): PricingVariation[];
|
|
46737
46820
|
static relevantTargetVariations(offer: StorefrontOffer, cartItems: LineItem[]): {
|
|
46738
46821
|
target: StorefrontProduct | StorefrontBundle;
|
|
@@ -46764,6 +46847,7 @@ declare class CartUtils {
|
|
|
46764
46847
|
static measure(catalog: CartCatalog, items: LineItem[], currency: string): Money | undefined;
|
|
46765
46848
|
static conditionContext(catalog: CartCatalog, order: CartOrder, currency: string): OfferConditionContext;
|
|
46766
46849
|
static cartOfferAppliesToLine(offer: StorefrontOffer, item: LineItem): boolean;
|
|
46850
|
+
static offerTargetsLine(offer: StorefrontOffer, item: LineItem): boolean;
|
|
46767
46851
|
static appliedCartOffer(catalog: CartCatalog, order: CartOrder, context: OfferConditionContext): StorefrontOffer | undefined;
|
|
46768
46852
|
static total(catalog: CartCatalog, order: CartOrder, currency: string): CartTotal;
|
|
46769
46853
|
static bestCartOffer(catalog: CartCatalog, order: CartOrder, currency: string): StorefrontOffer | undefined;
|
|
@@ -46776,6 +46860,54 @@ declare class CartUtils {
|
|
|
46776
46860
|
* line discounted to a tenth of its price is worth less than 10% of a full-price one.
|
|
46777
46861
|
*/
|
|
46778
46862
|
static cartOfferValue(catalog: CartCatalog, order: CartOrder, offer: StorefrontOffer, currency: string, context?: OfferConditionContext): number;
|
|
46863
|
+
/**
|
|
46864
|
+
* The item-scope offer worth attaching to a single line, or `undefined` when none is.
|
|
46865
|
+
*
|
|
46866
|
+
* Ranked by what it would actually take off this line rather than by percentage, the same way
|
|
46867
|
+
* `bestCartOffer` ranks a cart: a flat amount off can beat a bigger-looking percentage on a cheap
|
|
46868
|
+
* line, and the other way round on an expensive one.
|
|
46869
|
+
*
|
|
46870
|
+
* `unavailableOfferIds` are offers the rest of the cart has already claimed. An offer is only ever
|
|
46871
|
+
* good for one line, since the cart treats an offer held by any line as in use. So a caller walking
|
|
46872
|
+
* the cart must reserve each one as it goes, or two lines would both count on the same offer and
|
|
46873
|
+
* the API would honour it once. `assignItemOffers` does that bookkeeping for a whole cart.
|
|
46874
|
+
*/
|
|
46875
|
+
static bestItemOffer(catalog: CartCatalog, item: LineItem, currency: string, context: OfferConditionContext, unavailableOfferIds?: ReadonlySet<string>): StorefrontOffer | undefined;
|
|
46876
|
+
/**
|
|
46877
|
+
* Which item-scope offer to attach to which line, for the lines not already carrying one.
|
|
46878
|
+
*
|
|
46879
|
+
* Chosen for what the pairings are worth together rather than by cart order. An offer is only good
|
|
46880
|
+
* for one line, so walking the cart and taking the best offer for each line in turn hands a
|
|
46881
|
+
* multi-target offer to whichever line the buyer happened to add first, which is arbitrary and can
|
|
46882
|
+
* be the cheapest one. A buyer claiming these from the upsell cards would have placed them where
|
|
46883
|
+
* they are worth most, so that is what this does.
|
|
46884
|
+
*
|
|
46885
|
+
* Lines already holding an offer are left alone and their offers reserved: an offer on a line is
|
|
46886
|
+
* intent, whether the buyer's from the upsell or the API's from a refreshed order, and this is not
|
|
46887
|
+
* the place to second-guess it.
|
|
46888
|
+
*/
|
|
46889
|
+
static assignItemOffers(catalog: CartCatalog, order: CartOrder, currency: string, context?: OfferConditionContext): {
|
|
46890
|
+
itemId: string;
|
|
46891
|
+
offerId: string;
|
|
46892
|
+
}[];
|
|
46893
|
+
/**
|
|
46894
|
+
* The pairings worth the most together, given each offer can only be spent once.
|
|
46895
|
+
*
|
|
46896
|
+
* Taking the most valuable pairing first is not enough: with one offer worth 100 on line A and 99 on
|
|
46897
|
+
* line B, and a second offer worth 98 on line A alone, claiming the 100 strands the second offer and
|
|
46898
|
+
* saves 100, where putting the first offer on B and the second on A saves 197. The pairings have to
|
|
46899
|
+
* be chosen as a set.
|
|
46900
|
+
*
|
|
46901
|
+
* Walked line by line, memoised on which offers are still free. The candidates have already been
|
|
46902
|
+
* through targeting and eligibility, so in a real cart there are a handful; past `searchableOffers`
|
|
46903
|
+
* distinct offers it takes the most valuable pairing first instead, which is never worse than
|
|
46904
|
+
* applying nothing.
|
|
46905
|
+
*/
|
|
46906
|
+
private static maximalItemOfferAssignment;
|
|
46907
|
+
private static mostValuableItemOfferPairings;
|
|
46908
|
+
private static readonly searchableOffers;
|
|
46909
|
+
private static itemOfferCandidates;
|
|
46910
|
+
private static itemOfferUnitDiscount;
|
|
46779
46911
|
private static unitPriceAfterItemOffer;
|
|
46780
46912
|
}
|
|
46781
46913
|
|
|
@@ -46947,4 +47079,4 @@ declare class MoonbaseClient {
|
|
|
46947
47079
|
orders: OrderEndpoints;
|
|
46948
47080
|
}
|
|
46949
47081
|
|
|
46950
|
-
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, 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, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
|
|
47082
|
+
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, 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, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
|
package/dist/index.d.ts
CHANGED
|
@@ -26,12 +26,47 @@ interface IStore {
|
|
|
26
26
|
set: <TItem>(key: string, item: TItem) => void;
|
|
27
27
|
remove: (key: string) => void;
|
|
28
28
|
listen: <TItem>(key: string, callback: (item: TItem | null) => void) => void;
|
|
29
|
+
/**
|
|
30
|
+
* True once any storage operation has failed and the store has fallen back to
|
|
31
|
+
* memory. Optional so custom stores don't have to implement it.
|
|
32
|
+
*/
|
|
33
|
+
readonly isDegraded?: boolean;
|
|
29
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether `localStorage` can be reached at all.
|
|
37
|
+
*
|
|
38
|
+
* Deliberately *not* a write probe. Writability is not the right question here,
|
|
39
|
+
* because `LocalStorageStore` degrades per operation when a write fails, so a
|
|
40
|
+
* storage that reads fine but is at quota is still worth using: it is holding the
|
|
41
|
+
* buyer's existing session, and refusing it would throw away a perfectly readable
|
|
42
|
+
* sign-in and send them back to the login form. The only thing that makes
|
|
43
|
+
* `localStorage` unusable is not being able to touch it, which is what Firefox
|
|
44
|
+
* does (`SecurityError` from the property getter) when the buyer has blocked
|
|
45
|
+
* cookies and site data. That is why even the truthiness check sits inside a
|
|
46
|
+
* `try`.
|
|
47
|
+
*/
|
|
48
|
+
declare function isLocalStorageAvailable(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* `localStorage`-backed store that degrades to memory instead of throwing.
|
|
51
|
+
*
|
|
52
|
+
* Storage can start failing at any point in a session, not just at construction:
|
|
53
|
+
* the origin hits quota, an extension clears site data, the profile's storage
|
|
54
|
+
* file goes corrupt. Since this is where the auth tokens live, an unhandled
|
|
55
|
+
* throw here surfaces as a failed sign-in for a buyer whose credentials were
|
|
56
|
+
* accepted. So every operation falls back to an in-memory copy. The session
|
|
57
|
+
* keeps working; it just stops surviving a reload.
|
|
58
|
+
*/
|
|
30
59
|
declare class LocalStorageStore implements IStore {
|
|
60
|
+
private readonly onDegraded?;
|
|
61
|
+
private readonly fallback;
|
|
62
|
+
private degraded;
|
|
63
|
+
constructor(onDegraded?: ((err: unknown) => void) | undefined);
|
|
64
|
+
get isDegraded(): boolean;
|
|
31
65
|
get<TItem>(key: string): TItem | null;
|
|
32
66
|
set<TItem>(key: string, item: TItem): void;
|
|
33
67
|
remove(key: string): void;
|
|
34
68
|
listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
|
|
69
|
+
private reportDegraded;
|
|
35
70
|
}
|
|
36
71
|
declare class InMemoryStore implements IStore {
|
|
37
72
|
private readonly store;
|
|
@@ -47,6 +82,7 @@ type IdentityWithExpiry = Identity & {
|
|
|
47
82
|
};
|
|
48
83
|
interface ITokenStore {
|
|
49
84
|
get user(): User | null;
|
|
85
|
+
get isPersistent(): boolean;
|
|
50
86
|
getAccessToken: () => Promise<string | null>;
|
|
51
87
|
setUser: (user: Identity | User) => User | null;
|
|
52
88
|
clear: () => void;
|
|
@@ -57,15 +93,26 @@ declare class TokenStore implements ITokenStore {
|
|
|
57
93
|
private refreshTimeoutId;
|
|
58
94
|
private refreshPromise;
|
|
59
95
|
private readonly store;
|
|
96
|
+
private readonly logger;
|
|
60
97
|
static readonly storageKey = "moonbase_auth";
|
|
61
98
|
constructor(configuration: MoonbaseConfiguration);
|
|
62
99
|
get user(): User | null;
|
|
100
|
+
get isPersistent(): boolean;
|
|
63
101
|
getAccessToken(): Promise<string | null>;
|
|
64
102
|
setUser(user: Identity | User): IdentityWithExpiry | null;
|
|
65
103
|
clear(): null;
|
|
66
104
|
private get isExpired();
|
|
105
|
+
/**
|
|
106
|
+
* Start a refresh and hold it so concurrent callers join it rather than firing
|
|
107
|
+
* their own. The slot is cleared as soon as it settles: a retained promise
|
|
108
|
+
* would hand every later expiry the same stale access token, and a rejected one
|
|
109
|
+
* that stayed put would re-throw on every subsequent request (including the
|
|
110
|
+
* anonymous ones) for the rest of the session.
|
|
111
|
+
*/
|
|
112
|
+
private startRefresh;
|
|
67
113
|
private refreshTokens;
|
|
68
114
|
private handleStorageUpdate;
|
|
115
|
+
private warnAboutStorage;
|
|
69
116
|
}
|
|
70
117
|
|
|
71
118
|
type HttpMethods = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
@@ -1682,6 +1729,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1682
1729
|
releaseDescription: z.ZodOptional<z.ZodString>;
|
|
1683
1730
|
downloadsNeedsUser: z.ZodBoolean;
|
|
1684
1731
|
downloadsNeedsOwnership: z.ZodBoolean;
|
|
1732
|
+
downloadsNeedsGroupMembership: z.ZodBoolean;
|
|
1733
|
+
downloadsAllowed: z.ZodBoolean;
|
|
1685
1734
|
downloads: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1686
1735
|
name: z.ZodString;
|
|
1687
1736
|
key: z.ZodString;
|
|
@@ -1749,6 +1798,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1749
1798
|
currentVersion: string | null;
|
|
1750
1799
|
downloadsNeedsUser: boolean;
|
|
1751
1800
|
downloadsNeedsOwnership: boolean;
|
|
1801
|
+
downloadsNeedsGroupMembership: boolean;
|
|
1802
|
+
downloadsAllowed: boolean;
|
|
1752
1803
|
description?: string | null | undefined;
|
|
1753
1804
|
tagline?: string | null | undefined;
|
|
1754
1805
|
website?: string | undefined;
|
|
@@ -1783,6 +1834,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1783
1834
|
currentVersion: string | null;
|
|
1784
1835
|
downloadsNeedsUser: boolean;
|
|
1785
1836
|
downloadsNeedsOwnership: boolean;
|
|
1837
|
+
downloadsNeedsGroupMembership: boolean;
|
|
1838
|
+
downloadsAllowed: boolean;
|
|
1786
1839
|
description?: string | null | undefined;
|
|
1787
1840
|
tagline?: string | null | undefined;
|
|
1788
1841
|
website?: string | undefined;
|
|
@@ -1850,6 +1903,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1850
1903
|
currentVersion: string | null;
|
|
1851
1904
|
downloadsNeedsUser: boolean;
|
|
1852
1905
|
downloadsNeedsOwnership: boolean;
|
|
1906
|
+
downloadsNeedsGroupMembership: boolean;
|
|
1907
|
+
downloadsAllowed: boolean;
|
|
1853
1908
|
description?: string | null | undefined;
|
|
1854
1909
|
tagline?: string | null | undefined;
|
|
1855
1910
|
website?: string | undefined;
|
|
@@ -1903,6 +1958,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
1903
1958
|
currentVersion: string | null;
|
|
1904
1959
|
downloadsNeedsUser: boolean;
|
|
1905
1960
|
downloadsNeedsOwnership: boolean;
|
|
1961
|
+
downloadsNeedsGroupMembership: boolean;
|
|
1962
|
+
downloadsAllowed: boolean;
|
|
1906
1963
|
description?: string | null | undefined;
|
|
1907
1964
|
tagline?: string | null | undefined;
|
|
1908
1965
|
website?: string | undefined;
|
|
@@ -2450,6 +2507,8 @@ declare const productSummarySchema: z.ZodObject<{
|
|
|
2450
2507
|
releaseDescription: z.ZodOptional<z.ZodString>;
|
|
2451
2508
|
downloadsNeedsUser: z.ZodBoolean;
|
|
2452
2509
|
downloadsNeedsOwnership: z.ZodBoolean;
|
|
2510
|
+
downloadsNeedsGroupMembership: z.ZodBoolean;
|
|
2511
|
+
downloadsAllowed: z.ZodBoolean;
|
|
2453
2512
|
downloads: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2454
2513
|
name: z.ZodString;
|
|
2455
2514
|
key: z.ZodString;
|
|
@@ -2517,6 +2576,8 @@ declare const productSummarySchema: z.ZodObject<{
|
|
|
2517
2576
|
currentVersion: string | null;
|
|
2518
2577
|
downloadsNeedsUser: boolean;
|
|
2519
2578
|
downloadsNeedsOwnership: boolean;
|
|
2579
|
+
downloadsNeedsGroupMembership: boolean;
|
|
2580
|
+
downloadsAllowed: boolean;
|
|
2520
2581
|
description?: string | null | undefined;
|
|
2521
2582
|
tagline?: string | null | undefined;
|
|
2522
2583
|
website?: string | undefined;
|
|
@@ -2551,6 +2612,8 @@ declare const productSummarySchema: z.ZodObject<{
|
|
|
2551
2612
|
currentVersion: string | null;
|
|
2552
2613
|
downloadsNeedsUser: boolean;
|
|
2553
2614
|
downloadsNeedsOwnership: boolean;
|
|
2615
|
+
downloadsNeedsGroupMembership: boolean;
|
|
2616
|
+
downloadsAllowed: boolean;
|
|
2554
2617
|
description?: string | null | undefined;
|
|
2555
2618
|
tagline?: string | null | undefined;
|
|
2556
2619
|
website?: string | undefined;
|
|
@@ -22703,15 +22766,25 @@ type LineItem = z.infer<typeof openOrderLineItem>;
|
|
|
22703
22766
|
type ProductLineItem = z.infer<typeof openProductLineItem>;
|
|
22704
22767
|
type BundleLineItem = z.infer<typeof openBundleLineItem>;
|
|
22705
22768
|
|
|
22769
|
+
interface CheckoutUrlOptions {
|
|
22770
|
+
/** Where to send the buyer once the checkout is done with them. */
|
|
22771
|
+
returnUrl?: string;
|
|
22772
|
+
/**
|
|
22773
|
+
* Whether checkout will be rendered in the overlay iframe rather than as a
|
|
22774
|
+
* full-page redirect. Tells the backend whether a checkout login token is
|
|
22775
|
+
* worth minting: the returned `hostedCheckoutUrl` only carries one when this
|
|
22776
|
+
* is not `false`. Say `false` whenever you intend to redirect, so a day-long
|
|
22777
|
+
* credential is never minted for a URL that will not use it.
|
|
22778
|
+
*/
|
|
22779
|
+
embedded?: boolean;
|
|
22780
|
+
}
|
|
22706
22781
|
declare class OrderEndpoints {
|
|
22707
22782
|
private api;
|
|
22708
22783
|
constructor(api: MoonbaseApi);
|
|
22709
22784
|
get(orderId: string, options?: {
|
|
22710
22785
|
abort?: AbortSignal;
|
|
22711
22786
|
finalize?: boolean;
|
|
22712
|
-
checkout?:
|
|
22713
|
-
returnUrl?: string;
|
|
22714
|
-
};
|
|
22787
|
+
checkout?: CheckoutUrlOptions;
|
|
22715
22788
|
}): Promise<{
|
|
22716
22789
|
id: string;
|
|
22717
22790
|
status: OrderStatus.Completed;
|
|
@@ -24102,9 +24175,7 @@ declare class OrderEndpoints {
|
|
|
24102
24175
|
offerId?: string;
|
|
24103
24176
|
replaced?: string[];
|
|
24104
24177
|
})[];
|
|
24105
|
-
}, checkout?:
|
|
24106
|
-
returnUrl?: string;
|
|
24107
|
-
}, utm?: UrchinTrackingModule): Promise<OpenOrder>;
|
|
24178
|
+
}, checkout?: CheckoutUrlOptions, utm?: UrchinTrackingModule): Promise<OpenOrder>;
|
|
24108
24179
|
addBillingDetails(orderId: string, details: {
|
|
24109
24180
|
name: string;
|
|
24110
24181
|
email: string;
|
|
@@ -46733,6 +46804,18 @@ declare class OfferUtils {
|
|
|
46733
46804
|
static progress(offer: StorefrontOffer, context: Order | OfferConditionContext): OfferProgress | null;
|
|
46734
46805
|
private static evaluate;
|
|
46735
46806
|
static relevantTargets(offer: StorefrontOffer, cartItems: LineItem[]): StorefrontOfferTarget[];
|
|
46807
|
+
/**
|
|
46808
|
+
* Whether every item an offer targets is already in the cart, so the offer has no upsell left to
|
|
46809
|
+
* show.
|
|
46810
|
+
*
|
|
46811
|
+
* This is the set of offers the cart hides: a card inviting the buyer to add what they have already
|
|
46812
|
+
* added says nothing, so it is dropped. Which makes it exactly the set whose discount nothing can
|
|
46813
|
+
* currently claim: an offer is only good for one line, and there is no card left to spend it from.
|
|
46814
|
+
*
|
|
46815
|
+
* An offer with no targets names nothing and so is never in this set.
|
|
46816
|
+
*/
|
|
46817
|
+
static allTargetsInCart(offer: StorefrontOffer, cartItems: LineItem[]): boolean;
|
|
46818
|
+
private static targetInCart;
|
|
46736
46819
|
static targetedVariations(target: StorefrontOfferTarget): PricingVariation[];
|
|
46737
46820
|
static relevantTargetVariations(offer: StorefrontOffer, cartItems: LineItem[]): {
|
|
46738
46821
|
target: StorefrontProduct | StorefrontBundle;
|
|
@@ -46764,6 +46847,7 @@ declare class CartUtils {
|
|
|
46764
46847
|
static measure(catalog: CartCatalog, items: LineItem[], currency: string): Money | undefined;
|
|
46765
46848
|
static conditionContext(catalog: CartCatalog, order: CartOrder, currency: string): OfferConditionContext;
|
|
46766
46849
|
static cartOfferAppliesToLine(offer: StorefrontOffer, item: LineItem): boolean;
|
|
46850
|
+
static offerTargetsLine(offer: StorefrontOffer, item: LineItem): boolean;
|
|
46767
46851
|
static appliedCartOffer(catalog: CartCatalog, order: CartOrder, context: OfferConditionContext): StorefrontOffer | undefined;
|
|
46768
46852
|
static total(catalog: CartCatalog, order: CartOrder, currency: string): CartTotal;
|
|
46769
46853
|
static bestCartOffer(catalog: CartCatalog, order: CartOrder, currency: string): StorefrontOffer | undefined;
|
|
@@ -46776,6 +46860,54 @@ declare class CartUtils {
|
|
|
46776
46860
|
* line discounted to a tenth of its price is worth less than 10% of a full-price one.
|
|
46777
46861
|
*/
|
|
46778
46862
|
static cartOfferValue(catalog: CartCatalog, order: CartOrder, offer: StorefrontOffer, currency: string, context?: OfferConditionContext): number;
|
|
46863
|
+
/**
|
|
46864
|
+
* The item-scope offer worth attaching to a single line, or `undefined` when none is.
|
|
46865
|
+
*
|
|
46866
|
+
* Ranked by what it would actually take off this line rather than by percentage, the same way
|
|
46867
|
+
* `bestCartOffer` ranks a cart: a flat amount off can beat a bigger-looking percentage on a cheap
|
|
46868
|
+
* line, and the other way round on an expensive one.
|
|
46869
|
+
*
|
|
46870
|
+
* `unavailableOfferIds` are offers the rest of the cart has already claimed. An offer is only ever
|
|
46871
|
+
* good for one line, since the cart treats an offer held by any line as in use. So a caller walking
|
|
46872
|
+
* the cart must reserve each one as it goes, or two lines would both count on the same offer and
|
|
46873
|
+
* the API would honour it once. `assignItemOffers` does that bookkeeping for a whole cart.
|
|
46874
|
+
*/
|
|
46875
|
+
static bestItemOffer(catalog: CartCatalog, item: LineItem, currency: string, context: OfferConditionContext, unavailableOfferIds?: ReadonlySet<string>): StorefrontOffer | undefined;
|
|
46876
|
+
/**
|
|
46877
|
+
* Which item-scope offer to attach to which line, for the lines not already carrying one.
|
|
46878
|
+
*
|
|
46879
|
+
* Chosen for what the pairings are worth together rather than by cart order. An offer is only good
|
|
46880
|
+
* for one line, so walking the cart and taking the best offer for each line in turn hands a
|
|
46881
|
+
* multi-target offer to whichever line the buyer happened to add first, which is arbitrary and can
|
|
46882
|
+
* be the cheapest one. A buyer claiming these from the upsell cards would have placed them where
|
|
46883
|
+
* they are worth most, so that is what this does.
|
|
46884
|
+
*
|
|
46885
|
+
* Lines already holding an offer are left alone and their offers reserved: an offer on a line is
|
|
46886
|
+
* intent, whether the buyer's from the upsell or the API's from a refreshed order, and this is not
|
|
46887
|
+
* the place to second-guess it.
|
|
46888
|
+
*/
|
|
46889
|
+
static assignItemOffers(catalog: CartCatalog, order: CartOrder, currency: string, context?: OfferConditionContext): {
|
|
46890
|
+
itemId: string;
|
|
46891
|
+
offerId: string;
|
|
46892
|
+
}[];
|
|
46893
|
+
/**
|
|
46894
|
+
* The pairings worth the most together, given each offer can only be spent once.
|
|
46895
|
+
*
|
|
46896
|
+
* Taking the most valuable pairing first is not enough: with one offer worth 100 on line A and 99 on
|
|
46897
|
+
* line B, and a second offer worth 98 on line A alone, claiming the 100 strands the second offer and
|
|
46898
|
+
* saves 100, where putting the first offer on B and the second on A saves 197. The pairings have to
|
|
46899
|
+
* be chosen as a set.
|
|
46900
|
+
*
|
|
46901
|
+
* Walked line by line, memoised on which offers are still free. The candidates have already been
|
|
46902
|
+
* through targeting and eligibility, so in a real cart there are a handful; past `searchableOffers`
|
|
46903
|
+
* distinct offers it takes the most valuable pairing first instead, which is never worse than
|
|
46904
|
+
* applying nothing.
|
|
46905
|
+
*/
|
|
46906
|
+
private static maximalItemOfferAssignment;
|
|
46907
|
+
private static mostValuableItemOfferPairings;
|
|
46908
|
+
private static readonly searchableOffers;
|
|
46909
|
+
private static itemOfferCandidates;
|
|
46910
|
+
private static itemOfferUnitDiscount;
|
|
46779
46911
|
private static unitPriceAfterItemOffer;
|
|
46780
46912
|
}
|
|
46781
46913
|
|
|
@@ -46947,4 +47079,4 @@ declare class MoonbaseClient {
|
|
|
46947
47079
|
orders: OrderEndpoints;
|
|
46948
47080
|
}
|
|
46949
47081
|
|
|
46950
|
-
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, 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, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
|
|
47082
|
+
export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CartCatalog, type CartOrder, type CartTotal, type CartTotalCondition, CartUtils, 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, type ImageFit, type ImageFormat, type ImageTransform, ImageUtils, InMemoryStore, type License, LicenseStatus, type LineItem, type LineItemTotal, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, type OfferConditionContext, type OfferProgress, type OfferScope, OfferUtils, type OpenOrder, type Order, OrderStatus, type OrderTotal, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type PromotionDisplay, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontOfferTarget, type StorefrontProduct, type StorefrontPromotion, type StorefrontPromotionCta, type StorefrontPromotionTarget, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, imageWidths, isLocalStorageAvailable, isPromotionDisplay, isTransformableImageUrl, maxImageDimension, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, promotionDisplays, resolveUtm, schemas, utmToObject };
|