@occluze/tether 0.6.8 → 0.7.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 -11
- package/dist/esm/astro.js +2 -2
- package/dist/esm/chunks/account-UIPWJQ3Y.js +1 -0
- package/dist/esm/chunks/account-pages-6ROA6Y4V.js +1 -0
- package/dist/esm/chunks/analytics-2V632IRV.js +1 -0
- package/dist/esm/chunks/chunk-4GCXM764.js +1 -0
- package/dist/esm/chunks/chunk-56FCLJJD.js +1 -0
- package/dist/esm/chunks/chunk-5Z5O3767.js +1 -0
- package/dist/esm/chunks/chunk-6OZJCAGZ.js +1 -0
- package/dist/esm/chunks/chunk-A5SYCVQM.js +1 -0
- package/dist/esm/chunks/chunk-BA4LQJJQ.js +1 -0
- package/dist/esm/chunks/chunk-BFTZR4OB.js +4 -0
- package/dist/esm/chunks/chunk-C5JYQCWH.js +1 -0
- package/dist/esm/chunks/chunk-E5YO6274.js +1 -0
- package/dist/esm/chunks/chunk-MPDWM2NN.js +1 -0
- package/dist/esm/chunks/chunk-T44MUL4Y.js +1 -0
- package/dist/esm/chunks/chunk-YLUULATY.js +1 -0
- package/dist/esm/chunks/diagnose-3FEKRIEK.js +14 -0
- package/dist/esm/chunks/extras-6POFBNOP.js +1 -0
- package/dist/esm/chunks/markets-ui-FD6NI2OG.js +1 -0
- package/dist/esm/chunks/search-UJ73YBQ5.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/server.js +2 -2
- package/dist/presets/barba.esm.js +19 -23
- package/dist/tether.account-pages.js +320 -365
- package/dist/tether.account-pages.min.js +1 -1
- package/dist/tether.account.js +242 -491
- package/dist/tether.account.min.js +1 -1
- package/dist/tether.analytics.js +66 -88
- package/dist/tether.analytics.min.js +1 -1
- package/dist/tether.diagnose.js +36 -33
- package/dist/tether.diagnose.min.js +2 -2
- package/dist/tether.extras.js +28 -36
- package/dist/tether.extras.min.js +1 -1
- package/dist/tether.js +1270 -894
- package/dist/tether.markets.js +73 -90
- package/dist/tether.markets.min.js +1 -1
- package/dist/tether.min.js +0 -0
- package/dist/tether.min.js.map +4 -4
- package/dist/tether.search.js +44 -68
- package/dist/tether.search.min.js +1 -1
- package/dist/types/server/src/shared/account-orders.d.ts +44 -0
- package/dist/types/server/src/shared/account-routes.d.ts +153 -0
- package/dist/types/server/src/shared/api-versions.d.ts +13 -0
- package/dist/types/server/src/shared/error-message.d.ts +2 -0
- package/dist/types/server/src/shared/json.d.ts +25 -0
- package/dist/types/server/src/shared/market-codes.d.ts +16 -0
- package/dist/types/src/account/addresses-view.d.ts +5 -0
- package/dist/types/src/account/answers.d.ts +40 -0
- package/dist/types/src/account/markup.d.ts +19 -0
- package/dist/types/src/account/operations.d.ts +41 -0
- package/dist/types/src/account/order-lines.d.ts +13 -0
- package/dist/types/src/account/order-list.d.ts +12 -0
- package/dist/types/src/account/order-page.d.ts +6 -0
- package/dist/types/src/account/page-answers.d.ts +182 -0
- package/dist/types/src/account/page-events.d.ts +2 -0
- package/dist/types/src/account/server-client.d.ts +60 -0
- package/dist/types/src/account/subscriptions-view.d.ts +2 -0
- package/dist/types/src/account-api.d.ts +18 -0
- package/dist/types/src/account-marks.d.ts +15 -0
- package/dist/types/src/account-pages.d.ts +8 -0
- package/dist/types/src/account.d.ts +64 -0
- package/dist/types/src/amounts.d.ts +12 -0
- package/dist/types/src/analytics-shopify.d.ts +41 -0
- package/dist/types/src/analytics.d.ts +2 -0
- package/dist/types/src/api-version.d.ts +28 -0
- package/dist/types/src/astro.d.ts +42 -0
- package/dist/types/src/cart/cart-shape.d.ts +43 -0
- package/dist/types/src/cart/checkout.d.ts +16 -0
- package/dist/types/src/cart/drawer.d.ts +18 -0
- package/dist/types/src/cart/mutations.d.ts +79 -0
- package/dist/types/src/cart/render.d.ts +17 -0
- package/dist/types/src/cart/store.d.ts +182 -0
- package/dist/types/src/cart.d.ts +106 -0
- package/dist/types/src/client.d.ts +100 -0
- package/dist/types/src/collection.d.ts +25 -0
- package/dist/types/src/config-sections.d.ts +40 -0
- package/dist/types/src/config.d.ts +185 -0
- package/dist/types/src/controls/cart-controls.d.ts +2 -0
- package/dist/types/src/controls/discount.d.ts +2 -0
- package/dist/types/src/controls/extras.d.ts +5 -0
- package/dist/types/src/controls/navigation.d.ts +12 -0
- package/dist/types/src/diagnose-markup.d.ts +19 -0
- package/dist/types/src/diagnose.d.ts +60 -0
- package/dist/types/src/dom.d.ts +75 -0
- package/dist/types/src/extras.d.ts +21 -0
- package/dist/types/src/fragments.d.ts +158 -0
- package/dist/types/src/globals.d.ts +15 -0
- package/dist/types/src/images.d.ts +20 -0
- package/dist/types/src/index.d.ts +167 -0
- package/dist/types/src/initial.d.ts +56 -0
- package/dist/types/src/lazy.d.ts +28 -0
- package/dist/types/src/loader.d.ts +84 -0
- package/dist/types/src/market-codes.d.ts +6 -0
- package/dist/types/src/markets-ui.d.ts +32 -0
- package/dist/types/src/markets.d.ts +72 -0
- package/dist/types/src/markup.d.ts +131 -0
- package/dist/types/src/mounting.d.ts +46 -0
- package/dist/types/src/page-market.d.ts +27 -0
- package/dist/types/src/presets/barba.d.ts +56 -0
- package/dist/types/src/product-events.d.ts +2 -0
- package/dist/types/src/product-render.d.ts +17 -0
- package/dist/types/src/product-shape.d.ts +88 -0
- package/dist/types/src/product-state.d.ts +110 -0
- package/dist/types/src/product.d.ts +66 -0
- package/dist/types/src/repeaters.d.ts +16 -0
- package/dist/types/src/search.d.ts +33 -0
- package/dist/types/src/selling-plans.d.ts +64 -0
- package/dist/types/src/server.d.ts +88 -0
- package/dist/types/src/shopify-values.d.ts +46 -0
- package/dist/types/src/status.d.ts +33 -0
- package/dist/types/src/storage.d.ts +12 -0
- package/dist/types/src/store-html.d.ts +39 -0
- package/dist/types/src/storefront/catalog.d.ts +38 -0
- package/dist/types/src/storefront/json-ld.d.ts +20 -0
- package/dist/types/src/variant-render.d.ts +14 -0
- package/package.json +24 -23
- package/src/account/addresses-view.ts +58 -0
- package/src/account/answers.ts +79 -0
- package/src/account/markup.ts +36 -0
- package/src/account/operations.ts +145 -0
- package/src/account/{order-lines.js → order-lines.ts} +20 -41
- package/src/account/order-list.ts +107 -0
- package/src/account/order-page.ts +137 -0
- package/src/account/page-answers.ts +317 -0
- package/src/account/{page-events.js → page-events.ts} +55 -90
- package/src/account/server-client.ts +183 -0
- package/src/account/{subscriptions-view.js → subscriptions-view.ts} +25 -68
- package/src/account-api.ts +98 -0
- package/src/account-marks.ts +35 -0
- package/src/{account-pages.js → account-pages.ts} +29 -37
- package/src/account.ts +284 -0
- package/src/amounts.ts +64 -0
- package/src/{analytics-shopify.js → analytics-shopify.ts} +112 -107
- package/src/analytics.ts +315 -0
- package/src/{api-version.js → api-version.ts} +25 -31
- package/src/{astro.js → astro.ts} +110 -104
- package/src/cart/cart-shape.ts +25 -0
- package/src/cart/checkout.ts +101 -0
- package/src/cart/{drawer.js → drawer.ts} +18 -31
- package/src/cart/mutations.ts +237 -0
- package/src/cart/{render.js → render.ts} +68 -96
- package/src/cart/store.ts +279 -0
- package/src/{cart.js → cart.ts} +82 -128
- package/src/client.ts +391 -0
- package/src/{collection.js → collection.ts} +30 -38
- package/src/config-sections.ts +284 -0
- package/src/config.ts +480 -0
- package/src/controls/{cart-controls.js → cart-controls.ts} +22 -54
- package/src/controls/{discount.js → discount.ts} +13 -34
- package/src/controls/{extras.js → extras.ts} +15 -24
- package/src/controls/{navigation.js → navigation.ts} +24 -30
- package/src/{diagnose-markup.js → diagnose-markup.ts} +37 -72
- package/src/{diagnose.js → diagnose.ts} +95 -96
- package/src/dom.ts +268 -0
- package/src/{extras.js → extras.ts} +43 -52
- package/src/fragments.ts +261 -0
- package/src/globals.d.ts +15 -0
- package/src/{images.js → images.ts} +30 -43
- package/src/index.ts +415 -0
- package/src/initial.ts +101 -0
- package/src/lazy-iife.ts +197 -0
- package/src/lazy.ts +42 -0
- package/src/{loader.js → loader.ts} +149 -123
- package/src/market-codes.ts +6 -0
- package/src/{markets-ui.js → markets-ui.ts} +91 -68
- package/src/markets.ts +246 -0
- package/src/markup.ts +127 -0
- package/src/{mounting.js → mounting.ts} +88 -101
- package/src/{page-market.js → page-market.ts} +32 -38
- package/src/part-integrity.ts +7 -0
- package/src/parts/account-pages.ts +7 -0
- package/src/parts/account.ts +7 -0
- package/src/parts/analytics.ts +7 -0
- package/src/parts/diagnose.ts +7 -0
- package/src/parts/extras.ts +7 -0
- package/src/parts/markets.ts +7 -0
- package/src/parts/search.ts +7 -0
- package/src/presets/barba.ts +194 -0
- package/src/{product-events.js → product-events.ts} +33 -48
- package/src/{product-render.js → product-render.ts} +38 -77
- package/src/product-shape.ts +49 -0
- package/src/product-state.ts +318 -0
- package/src/{product.js → product.ts} +90 -126
- package/src/{repeaters.js → repeaters.ts} +40 -52
- package/src/{search.js → search.ts} +85 -103
- package/src/selling-plans.ts +145 -0
- package/src/server.ts +211 -0
- package/src/{shopify-values.js → shopify-values.ts} +24 -22
- package/src/{status.js → status.ts} +34 -54
- package/src/storage.ts +34 -0
- package/src/store-html.ts +359 -0
- package/src/storefront/catalog.ts +196 -0
- package/src/storefront/{json-ld.js → json-ld.ts} +45 -68
- package/src/{variant-render.js → variant-render.ts} +24 -50
- package/dist/esm/chunks/account-C3NP6HFB.js +0 -1
- package/dist/esm/chunks/account-pages-WLK374FO.js +0 -1
- package/dist/esm/chunks/analytics-G3SAWMNL.js +0 -1
- package/dist/esm/chunks/chunk-27PJJZGC.js +0 -1
- package/dist/esm/chunks/chunk-2FSXS55U.js +0 -1
- package/dist/esm/chunks/chunk-FCSWQDVV.js +0 -1
- package/dist/esm/chunks/chunk-FOMSMIAM.js +0 -1
- package/dist/esm/chunks/chunk-GZJTCLLW.js +0 -1
- package/dist/esm/chunks/chunk-HEQILZVR.js +0 -1
- package/dist/esm/chunks/chunk-JOOEXYF3.js +0 -4
- package/dist/esm/chunks/chunk-MPTQYLSM.js +0 -1
- package/dist/esm/chunks/chunk-NEHZ37TU.js +0 -3
- package/dist/esm/chunks/chunk-V74KGEJF.js +0 -1
- package/dist/esm/chunks/chunk-VT4CDUJJ.js +0 -1
- package/dist/esm/chunks/chunk-YJLWX2HK.js +0 -1
- package/dist/esm/chunks/diagnose-6VVGZNTY.js +0 -14
- package/dist/esm/chunks/extras-GJVRDFM3.js +0 -1
- package/dist/esm/chunks/markets-ui-UNB4PTA7.js +0 -1
- package/dist/esm/chunks/search-OU75RNQL.js +0 -1
- package/src/account/addresses-view.js +0 -92
- package/src/account/browser-session.js +0 -359
- package/src/account/markup.js +0 -48
- package/src/account/operations.js +0 -180
- package/src/account/order-list.js +0 -91
- package/src/account/order-page.js +0 -192
- package/src/account/server-client.js +0 -172
- package/src/account/shared.js +0 -111
- package/src/account/shopify-auth.js +0 -150
- package/src/account-api.js +0 -118
- package/src/account-links.js +0 -35
- package/src/account.js +0 -342
- package/src/amounts.js +0 -36
- package/src/analytics.js +0 -352
- package/src/cart/checkout.js +0 -97
- package/src/cart/mutations.js +0 -234
- package/src/cart/store.js +0 -326
- package/src/client.js +0 -267
- package/src/config.js +0 -349
- package/src/dom.js +0 -287
- package/src/fragments.js +0 -237
- package/src/index.js +0 -353
- package/src/initial.js +0 -87
- package/src/lazy-iife.js +0 -116
- package/src/lazy.js +0 -39
- package/src/market-codes.js +0 -35
- package/src/markets.js +0 -334
- package/src/markup.js +0 -64
- package/src/parts/account-pages.js +0 -6
- package/src/parts/account.js +0 -6
- package/src/parts/analytics.js +0 -6
- package/src/parts/diagnose.js +0 -6
- package/src/parts/extras.js +0 -6
- package/src/parts/markets.js +0 -6
- package/src/parts/search.js +0 -6
- package/src/presets/barba.js +0 -190
- package/src/product-state.js +0 -318
- package/src/selling-plans.js +0 -154
- package/src/server.js +0 -215
- package/src/store-html.js +0 -0
- package/src/storefront/catalog.js +0 -199
- package/types/astro.d.ts +0 -28
- package/types/barba.d.ts +0 -16
- package/types/index.d.ts +0 -577
- package/types/server.d.ts +0 -182
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type OrderState = 'loading' | 'ready' | 'not-found' | 'error';
|
|
2
|
+
/** Every state but `ready`, which shows with the order. */
|
|
3
|
+
export declare function showOrderState(el: HTMLElement, state: Exclude<OrderState, 'ready'>): void;
|
|
4
|
+
/** Loads and renders the order `el` names. A failure is reported and shows the error state. */
|
|
5
|
+
export declare function renderOrder(el: HTMLElement): Promise<void>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { AccountImage, AccountOrderLine } from '../../server/src/shared/account-orders.js';
|
|
2
|
+
import type { Money } from '../shopify-values.js';
|
|
3
|
+
/** An address as the documents select it. */
|
|
4
|
+
export interface MailingAddress {
|
|
5
|
+
id: string | null;
|
|
6
|
+
firstName: string | null;
|
|
7
|
+
lastName: string | null;
|
|
8
|
+
company: string | null;
|
|
9
|
+
address1: string | null;
|
|
10
|
+
address2: string | null;
|
|
11
|
+
city: string | null;
|
|
12
|
+
province: string | null;
|
|
13
|
+
zoneCode: string | null;
|
|
14
|
+
zip: string | null;
|
|
15
|
+
country: string | null;
|
|
16
|
+
countryCode: string | null;
|
|
17
|
+
phoneNumber: string | null;
|
|
18
|
+
/** One line per entry. */
|
|
19
|
+
formatted: string[];
|
|
20
|
+
}
|
|
21
|
+
/** One of the customer's saved addresses. */
|
|
22
|
+
export type AccountAddress = MailingAddress & {
|
|
23
|
+
id: string;
|
|
24
|
+
};
|
|
25
|
+
export type CustomerAddress = AccountAddress & {
|
|
26
|
+
isDefault: boolean;
|
|
27
|
+
};
|
|
28
|
+
interface ReturnReason {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string | null;
|
|
31
|
+
handle: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** A line of the order page's document. */
|
|
34
|
+
export type OrderDetailLine = AccountOrderLine & {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string | null;
|
|
37
|
+
sku: string | null;
|
|
38
|
+
price: Money | null;
|
|
39
|
+
totalPrice: Money | null;
|
|
40
|
+
suggestedReturnReasonDefinitions: {
|
|
41
|
+
nodes: ReturnReason[];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
interface Tracking {
|
|
45
|
+
company: string | null;
|
|
46
|
+
number: string | null;
|
|
47
|
+
url: string | null;
|
|
48
|
+
}
|
|
49
|
+
export interface Fulfillment {
|
|
50
|
+
id: string | null;
|
|
51
|
+
status: string | null;
|
|
52
|
+
createdAt: string | null;
|
|
53
|
+
estimatedDeliveryAt: string | null;
|
|
54
|
+
latestShipmentStatus: string | null;
|
|
55
|
+
trackingInformation: Tracking[];
|
|
56
|
+
}
|
|
57
|
+
interface ReturnableLine {
|
|
58
|
+
quantity: number;
|
|
59
|
+
lineItem: {
|
|
60
|
+
id: string;
|
|
61
|
+
} | null;
|
|
62
|
+
}
|
|
63
|
+
/** A return Shopify opened. */
|
|
64
|
+
export interface OpenedReturn {
|
|
65
|
+
id: string;
|
|
66
|
+
status: string | null;
|
|
67
|
+
}
|
|
68
|
+
/** The order page's document. */
|
|
69
|
+
export interface OrderDetail {
|
|
70
|
+
id: string;
|
|
71
|
+
name: string | null;
|
|
72
|
+
number: number | null;
|
|
73
|
+
processedAt: string | null;
|
|
74
|
+
cancelledAt: string | null;
|
|
75
|
+
financialStatus: string | null;
|
|
76
|
+
fulfillmentStatus: string | null;
|
|
77
|
+
statusPageUrl: string | null;
|
|
78
|
+
requiresShipping: boolean | null;
|
|
79
|
+
totalPrice: Money | null;
|
|
80
|
+
subtotal: Money | null;
|
|
81
|
+
totalShipping: Money | null;
|
|
82
|
+
totalTax: Money | null;
|
|
83
|
+
shippingAddress: MailingAddress | null;
|
|
84
|
+
billingAddress: MailingAddress | null;
|
|
85
|
+
lineItems: {
|
|
86
|
+
nodes: OrderDetailLine[];
|
|
87
|
+
};
|
|
88
|
+
fulfillments: {
|
|
89
|
+
nodes: Fulfillment[];
|
|
90
|
+
};
|
|
91
|
+
returnInformation: {
|
|
92
|
+
returnableLineItems: {
|
|
93
|
+
nodes: ReturnableLine[];
|
|
94
|
+
};
|
|
95
|
+
} | null;
|
|
96
|
+
returns: {
|
|
97
|
+
nodes: OpenedReturn[];
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export interface SubscriptionLine {
|
|
101
|
+
id: string | null;
|
|
102
|
+
name: string | null;
|
|
103
|
+
title: string | null;
|
|
104
|
+
variantTitle: string | null;
|
|
105
|
+
quantity: number;
|
|
106
|
+
sku: string | null;
|
|
107
|
+
currentPrice: Money | null;
|
|
108
|
+
lineDiscountedPrice: Money | null;
|
|
109
|
+
image: AccountImage | null;
|
|
110
|
+
}
|
|
111
|
+
interface BillingCycle {
|
|
112
|
+
cycleIndex: number | null;
|
|
113
|
+
skipped: boolean;
|
|
114
|
+
billingAttemptExpectedDate: string | null;
|
|
115
|
+
}
|
|
116
|
+
/** The subscriptions document. */
|
|
117
|
+
export interface SubscriptionContract {
|
|
118
|
+
id: string;
|
|
119
|
+
/** `ACTIVE`, `PAUSED`, `CANCELLED`, `EXPIRED` or `FAILED`. */
|
|
120
|
+
status: string | null;
|
|
121
|
+
nextBillingDate: string | null;
|
|
122
|
+
currencyCode: string | null;
|
|
123
|
+
deliveryPrice: Money | null;
|
|
124
|
+
deliveryPolicy: {
|
|
125
|
+
interval: string | null;
|
|
126
|
+
intervalCount: {
|
|
127
|
+
count: number;
|
|
128
|
+
} | null;
|
|
129
|
+
} | null;
|
|
130
|
+
lines: {
|
|
131
|
+
nodes: SubscriptionLine[];
|
|
132
|
+
};
|
|
133
|
+
upcomingBillingCycles: {
|
|
134
|
+
nodes: BillingCycle[];
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export interface Profile {
|
|
138
|
+
firstName: string | null;
|
|
139
|
+
lastName: string | null;
|
|
140
|
+
}
|
|
141
|
+
/** What a subscription action changed: the contract (pause, resume, cancel) or its next billing cycle (skip, unskip). */
|
|
142
|
+
export type SubscriptionChange = {
|
|
143
|
+
contract: {
|
|
144
|
+
id: string | null;
|
|
145
|
+
status: string | null;
|
|
146
|
+
};
|
|
147
|
+
} | {
|
|
148
|
+
billingCycle: {
|
|
149
|
+
cycleIndex: number | null;
|
|
150
|
+
skipped: boolean;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
/** @throws {TetherError} Without an id. */
|
|
154
|
+
export declare const toAccountAddress: (value: unknown) => AccountAddress;
|
|
155
|
+
/**
|
|
156
|
+
* @param value The addresses operation's list, each address with the `isDefault` it adds.
|
|
157
|
+
* @throws {TetherError} For an address without an id.
|
|
158
|
+
*/
|
|
159
|
+
export declare const toCustomerAddresses: (value: unknown) => CustomerAddress[];
|
|
160
|
+
/**
|
|
161
|
+
* @param value The order operation's `order`.
|
|
162
|
+
* @returns `null` when the customer has no such order.
|
|
163
|
+
* @throws {TetherError} For an order, line, reason or return without an id.
|
|
164
|
+
*/
|
|
165
|
+
export declare function toOrderDetail(value: unknown): OrderDetail | null;
|
|
166
|
+
/**
|
|
167
|
+
* @param value The subscriptions operation's list.
|
|
168
|
+
* @throws {TetherError} For a contract without an id.
|
|
169
|
+
*/
|
|
170
|
+
export declare const toSubscriptionContracts: (value: unknown) => SubscriptionContract[];
|
|
171
|
+
/**
|
|
172
|
+
* @param result The subscription operation's result.
|
|
173
|
+
* @throws {TetherError} With neither a contract nor a billing cycle.
|
|
174
|
+
*/
|
|
175
|
+
export declare function toSubscriptionChange(result: Record<string, unknown>): SubscriptionChange;
|
|
176
|
+
/** @throws {TetherError} Without an id. */
|
|
177
|
+
export declare function toReturn(value: unknown): OpenedReturn;
|
|
178
|
+
/** @throws {TetherError} Without an id. */
|
|
179
|
+
export declare const toDeletedId: (value: unknown) => string;
|
|
180
|
+
/** @param value The profile operation's `customer`. */
|
|
181
|
+
export declare const toProfile: (value: unknown) => Profile;
|
|
182
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { AccountCustomer } from './answers.js';
|
|
2
|
+
/** The Worker's answer, or a 401: the session cookie is missing, has expired, or Shopify ended the login. */
|
|
3
|
+
export type ServerAnswer = {
|
|
4
|
+
kind: 'answer';
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'logged-out';
|
|
8
|
+
};
|
|
9
|
+
type ServerLogin = {
|
|
10
|
+
loggedIn: true;
|
|
11
|
+
customer: AccountCustomer;
|
|
12
|
+
} | {
|
|
13
|
+
loggedIn: false;
|
|
14
|
+
};
|
|
15
|
+
export interface ServerRequest {
|
|
16
|
+
method?: 'GET' | 'POST';
|
|
17
|
+
body?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One request to the Worker, with the session cookie. A POST carries the header the Worker requires against
|
|
21
|
+
* cross-site forms.
|
|
22
|
+
*
|
|
23
|
+
* @throws {TetherError} `NOT_CONFIGURED` without `account.server`, `INVALID` for refused input, `HTTP_<status>` for
|
|
24
|
+
* any other failure but a 401, with the Worker's `userErrors`; `NETWORK` when the Worker can't be reached.
|
|
25
|
+
*/
|
|
26
|
+
export declare function serverFetch(path: string, { method, body }?: ServerRequest): Promise<ServerAnswer>;
|
|
27
|
+
/**
|
|
28
|
+
* Who is logged in, asked once and then kept; the "may be logged in" hint follows the answer.
|
|
29
|
+
*
|
|
30
|
+
* @throws {TetherError} When the Worker can't be reached or fails: that says nothing about the login.
|
|
31
|
+
*/
|
|
32
|
+
export declare function serverLogin(): Promise<ServerLogin>;
|
|
33
|
+
/** @returns True when the Worker last said a customer is logged in. */
|
|
34
|
+
export declare const isServerLoggedIn: () => boolean;
|
|
35
|
+
/** Asks the Worker again on the next `serverLogin()`, after a change of the customer's data. */
|
|
36
|
+
export declare function forgetServerLogin(): void;
|
|
37
|
+
/**
|
|
38
|
+
* To the Worker's login, which comes back to `returnTo` with `?account=<outcome>`. The cart is linked later, at
|
|
39
|
+
* checkout, through the Worker's protected `POST /cart`.
|
|
40
|
+
*
|
|
41
|
+
* @throws {TetherError} `NOT_CONFIGURED` without `account.server`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function serverLoginRedirect({ returnTo, locale }: {
|
|
44
|
+
returnTo: string;
|
|
45
|
+
locale?: string | undefined;
|
|
46
|
+
}): void;
|
|
47
|
+
/**
|
|
48
|
+
* The logged-in customer's checkout, for `Cart.setCheckoutResolver`: the Worker links the cart to the customer and
|
|
49
|
+
* answers with its checkout URL.
|
|
50
|
+
*
|
|
51
|
+
* @returns `null` when nobody is logged in or the Worker linked no cart, so the cart's own checkout URL is used.
|
|
52
|
+
* @throws {TetherError} When the Worker fails; the cart reports it and checks out without the login.
|
|
53
|
+
*/
|
|
54
|
+
export declare function serverCheckoutUrl(): Promise<string | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Ends the session at the Worker, which also unlinks the cart, then goes on to Shopify's logout when the Worker says
|
|
57
|
+
* where. Sends `tether:account-logout`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function serverLogout(returnTo: string): Promise<'redirected' | 'stayed'>;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Parts } from './lazy.js';
|
|
2
|
+
type AccountPart = Parts['account'];
|
|
3
|
+
type AccountResult<Name extends keyof AccountPart> = Awaited<ReturnType<AccountPart[Name]>>;
|
|
4
|
+
type AccountFunction<Name extends keyof AccountPart> = (...args: Parameters<AccountPart[Name]>) => Promise<AccountResult<Name>>;
|
|
5
|
+
type AccountApi = {
|
|
6
|
+
[Name in keyof AccountPart]: AccountFunction<Name>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Loads the account part and mounts it on `root`, when accounts are configured and the page needs them: account
|
|
10
|
+
* markup in `root`, a login coming back from the Worker (`?account=`), or the "may be logged in" hint.
|
|
11
|
+
*/
|
|
12
|
+
export declare function mountAccountIfUsed(root: ParentNode): void;
|
|
13
|
+
/**
|
|
14
|
+
* `Tether.account`: the account part's functions, each loading the part on first call. A plain object, so `await
|
|
15
|
+
* Tether.account` and `Object.keys(Tether.account)` behave as for any object.
|
|
16
|
+
*/
|
|
17
|
+
export declare const accountApi: AccountApi;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the Worker's login redirect says in `?account=`: `in` after a login, `expired` when the login took too long,
|
|
3
|
+
* `error` when it failed.
|
|
4
|
+
*/
|
|
5
|
+
type LoginOutcome = 'in' | 'expired' | 'error';
|
|
6
|
+
/** The "may be logged in" hint's key: it makes the core load the part on the next page, and holds no secret. */
|
|
7
|
+
export declare const hintKey: () => string;
|
|
8
|
+
/**
|
|
9
|
+
* Removes the customer tokens and pending login that Tether 0.6's browser-mode accounts kept in this browser. The
|
|
10
|
+
* session held a refresh token with the customer's full scope, so it must not stay behind once accounts run through
|
|
11
|
+
* the Worker. TODO: remove in 0.8.0, when no visitor's browser still holds a 0.6 session.
|
|
12
|
+
*/
|
|
13
|
+
export declare function forgetBrowserModeTokens(): void;
|
|
14
|
+
export declare const isLoginOutcome: (value: string | null) => value is LoginOutcome;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { setup, order, updateProfile, addresses, saveAddress, deleteAddress, subscriptions, subscriptionAction, requestReturn, } from './account/operations.js';
|
|
2
|
+
/** Renders the order page, profile form, addresses and subscriptions in `root`: only what it has. */
|
|
3
|
+
export declare function renderPages(root?: ParentNode): Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* The error state of every account page in `root`, for when nobody can say whether a customer is logged in (the
|
|
6
|
+
* Worker or Shopify can't be reached).
|
|
7
|
+
*/
|
|
8
|
+
export declare function showUnavailable(root: ParentNode): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { AccountCustomer } from './account/answers.js';
|
|
2
|
+
import type { AccountOrder } from '../server/src/shared/account-orders.js';
|
|
3
|
+
import type { AddressFields, ReturnLine } from './account/operations.js';
|
|
4
|
+
import type { AccountAddress, CustomerAddress, OpenedReturn, OrderDetail, Profile, SubscriptionChange, SubscriptionContract } from './account/page-answers.js';
|
|
5
|
+
import type { SubscriptionAction } from '../server/src/shared/account-routes.js';
|
|
6
|
+
/** @returns True when the Worker last said a customer is logged in; false before it has been asked. */
|
|
7
|
+
export declare const isLoggedIn: () => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Through the Worker to Shopify's login page; the visitor comes back to `returnTo`.
|
|
10
|
+
*
|
|
11
|
+
* @throws {TetherError} `NOT_CONFIGURED` without `account.server`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function login({ returnTo, locale, }?: {
|
|
14
|
+
returnTo?: string;
|
|
15
|
+
locale?: string;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* @returns The logged-in customer, `null` when nobody is.
|
|
19
|
+
* @throws {TetherError} When the Worker can't be reached or fails.
|
|
20
|
+
*/
|
|
21
|
+
export declare function customer(): Promise<AccountCustomer | null>;
|
|
22
|
+
/**
|
|
23
|
+
* @param options `first`: a whole number from 1 to `MAX_ORDER_COUNT`.
|
|
24
|
+
* @returns The customer's most recent orders, newest first; none when nobody is logged in.
|
|
25
|
+
* @throws {TetherError} `INVALID` for another `first`, which is refused before any request; else when the Worker or
|
|
26
|
+
* Shopify can't answer.
|
|
27
|
+
*/
|
|
28
|
+
export declare function orders({ first }?: {
|
|
29
|
+
first?: number;
|
|
30
|
+
}): Promise<AccountOrder[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Logs out here and at Shopify, and unlinks the cart. Sends `tether:account-logout`.
|
|
33
|
+
*
|
|
34
|
+
* @param options `returnTo`: where Shopify sends the visitor afterwards.
|
|
35
|
+
*/
|
|
36
|
+
export declare function logout({ returnTo, }?: {
|
|
37
|
+
returnTo?: string;
|
|
38
|
+
}): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Fills the account markup in `root`: what shows when logged in or out, the customer, their orders, and the account
|
|
41
|
+
* pages.
|
|
42
|
+
*/
|
|
43
|
+
export declare function render(root?: ParentNode): Promise<void>;
|
|
44
|
+
/** One of the customer's orders, in full (lines, totals, addresses, fulfillments, returns). */
|
|
45
|
+
export declare const order: (id: string | number) => Promise<OrderDetail | null>;
|
|
46
|
+
export declare const updateProfile: (fields?: {
|
|
47
|
+
firstName?: string;
|
|
48
|
+
lastName?: string;
|
|
49
|
+
}) => Promise<Profile>;
|
|
50
|
+
export declare const addresses: () => Promise<CustomerAddress[]>;
|
|
51
|
+
/** Creates an address, or updates the one with `id`. */
|
|
52
|
+
export declare const saveAddress: (address: AddressFields | null, options?: {
|
|
53
|
+
id?: string;
|
|
54
|
+
isDefault?: boolean;
|
|
55
|
+
}) => Promise<AccountAddress>;
|
|
56
|
+
export declare const deleteAddress: (id: string) => Promise<string>;
|
|
57
|
+
export declare const subscriptions: () => Promise<SubscriptionContract[]>;
|
|
58
|
+
export declare const subscriptionAction: (id: string | number, action: SubscriptionAction) => Promise<SubscriptionChange>;
|
|
59
|
+
export declare const requestReturn: (orderId: string | number, lines: ReturnLine[]) => Promise<OpenedReturn>;
|
|
60
|
+
/**
|
|
61
|
+
* Called by the core on mount: on the first one, finishes a login that's coming back and lets the Worker link the
|
|
62
|
+
* cart at checkout; then fills the page.
|
|
63
|
+
*/
|
|
64
|
+
export declare function mountAccount(root?: ParentNode): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arithmetic on Shopify's money amounts, which are decimal strings (`'27.50'`). Comparisons go digit by digit, as
|
|
3
|
+
* integers of the smallest unit present, so two amounts that differ only past float precision aren't misjudged. Sums
|
|
4
|
+
* and differences are taken in the currency's own smallest unit, so JPY stays whole and KWD keeps its three digits.
|
|
5
|
+
*/
|
|
6
|
+
import type { Money } from './shopify-values.js';
|
|
7
|
+
/** @returns True when both are decimal numbers and `amount` is the larger one. */
|
|
8
|
+
export declare function isGreaterAmount(amount: string | null | undefined, other: string | null | undefined): boolean;
|
|
9
|
+
/** @returns The amount in the currency's smallest unit (cents, yen, fils), rounded to a whole one. */
|
|
10
|
+
export declare function toMinorUnits(money: Money): number;
|
|
11
|
+
/** @returns The amount written with the currency's own number of digits. */
|
|
12
|
+
export declare function fromMinorUnits(minorUnits: number, currencyCode: string): Money;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type EventPayload = Record<string, unknown>;
|
|
2
|
+
interface TrackingValues {
|
|
3
|
+
uniqueToken: string;
|
|
4
|
+
visitToken: string;
|
|
5
|
+
}
|
|
6
|
+
interface DestinationContext {
|
|
7
|
+
getTrackingValues: () => TrackingValues;
|
|
8
|
+
}
|
|
9
|
+
type Subscriber = (payload: EventPayload, context: DestinationContext) => void;
|
|
10
|
+
type Subscribe = (event: string, subscriber: Subscriber) => () => void;
|
|
11
|
+
interface BusConfig {
|
|
12
|
+
shop: {
|
|
13
|
+
shopId: string;
|
|
14
|
+
channel: 'headless';
|
|
15
|
+
};
|
|
16
|
+
consent: {
|
|
17
|
+
mode: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** What shopify.js registers. */
|
|
21
|
+
interface DestinationSpec {
|
|
22
|
+
name: string;
|
|
23
|
+
setup?: (api: {
|
|
24
|
+
subscribe: Subscribe;
|
|
25
|
+
getConfig: () => BusConfig;
|
|
26
|
+
}) => unknown;
|
|
27
|
+
}
|
|
28
|
+
/** Hydrogen's `window.Shopify.analytics`. */
|
|
29
|
+
export interface AnalyticsBus {
|
|
30
|
+
getConfig: () => BusConfig;
|
|
31
|
+
publish: (event: string, payload?: EventPayload) => void;
|
|
32
|
+
addDestination: (destination: DestinationSpec) => () => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sets up `window.Shopify` for Shopify's scripts and loads them.
|
|
36
|
+
*
|
|
37
|
+
* @param isProductPage Asked by Shopify's script for the page template.
|
|
38
|
+
* @returns The bus, the page's own when a theme already set one up.
|
|
39
|
+
*/
|
|
40
|
+
export declare function startShopifyAnalytics(isProductPage: () => boolean): Promise<AnalyticsBus>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shopify API versions are quarterly (YYYY-01, -04, -07, -10) and supported for 12 months. Tether pins a dated version
|
|
3
|
+
* and never targets `unstable` (it changes without notice). Used by the config, the diagnose part and the release
|
|
4
|
+
* scripts.
|
|
5
|
+
*/
|
|
6
|
+
import type { ApiVersion } from '../server/src/shared/api-versions.js';
|
|
7
|
+
export interface ApiVersionStatus {
|
|
8
|
+
version: string;
|
|
9
|
+
/** Released and still supported. */
|
|
10
|
+
ok: boolean;
|
|
11
|
+
/** What to do about it, for people. */
|
|
12
|
+
note: string;
|
|
13
|
+
/** Months of support left, rounded; negative once support ended. */
|
|
14
|
+
monthsLeft?: number;
|
|
15
|
+
/** The version after this one. */
|
|
16
|
+
next?: string;
|
|
17
|
+
}
|
|
18
|
+
/** @returns True for a dated version such as `2026-07`. */
|
|
19
|
+
export declare const isQuarterlyVersion: (version: unknown) => version is ApiVersion;
|
|
20
|
+
/**
|
|
21
|
+
* `'2026-07'` → `'2026-10'`, `'2026-10'` → `'2027-01'`.
|
|
22
|
+
*
|
|
23
|
+
* @param steps Quarters ahead.
|
|
24
|
+
* @throws {Error} When `version` isn't a quarterly version.
|
|
25
|
+
*/
|
|
26
|
+
export declare function nextApiVersion(version: string, steps?: number): string;
|
|
27
|
+
/** The support window of `version`, relative to `now`. */
|
|
28
|
+
export declare function apiVersionStatus(version: string, now?: Date): ApiVersionStatus;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TetherOptions } from './config.js';
|
|
2
|
+
import type { StorefrontOptions } from './server.js';
|
|
3
|
+
interface AstroLogger {
|
|
4
|
+
warn: (message: string) => void;
|
|
5
|
+
}
|
|
6
|
+
/** The argument of Astro's `astro:config:setup` hook. */
|
|
7
|
+
interface AstroConfigSetup {
|
|
8
|
+
injectScript: (stage: 'head-inline' | 'page', content: string) => void;
|
|
9
|
+
/** `dev`, `build`, `preview` or `sync`. */
|
|
10
|
+
command: string;
|
|
11
|
+
config: {
|
|
12
|
+
root?: URL;
|
|
13
|
+
};
|
|
14
|
+
logger: AstroLogger;
|
|
15
|
+
addWatchFile?: (path: string) => void;
|
|
16
|
+
/** Takes a partial Astro config. A method, so that Astro's own `DeepPartial<AstroConfig>` parameter fits. */
|
|
17
|
+
updateConfig?(config: {
|
|
18
|
+
env?: {
|
|
19
|
+
schema?: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
}): unknown;
|
|
22
|
+
}
|
|
23
|
+
/** The config options a page can be handed as JSON: all but the functions. */
|
|
24
|
+
type SerializableOptions = {
|
|
25
|
+
[Key in keyof TetherOptions as Exclude<TetherOptions[Key], null | undefined> extends (...args: never[]) => unknown ? never : Key]?: TetherOptions[Key];
|
|
26
|
+
};
|
|
27
|
+
/** `createStorefront()`'s own options that a config shared with it may hold, which the page leaves out. */
|
|
28
|
+
type ServerOnlyOptions = Pick<StorefrontOptions, 'siteUrl' | 'pageSize'>;
|
|
29
|
+
/** Tether's serializable config and the storefront's own options, plus the integration's own options. */
|
|
30
|
+
interface TetherAstroOptions extends SerializableOptions, ServerOnlyOptions {
|
|
31
|
+
/** Add the Tether script to every page (default true). */
|
|
32
|
+
inject?: boolean;
|
|
33
|
+
/** Files that restart the dev server when they change. */
|
|
34
|
+
watch?: string[] | null;
|
|
35
|
+
}
|
|
36
|
+
export type { TetherAstroOptions, AstroConfigSetup };
|
|
37
|
+
export default function tether(options?: TetherAstroOptions): {
|
|
38
|
+
name: string;
|
|
39
|
+
hooks: {
|
|
40
|
+
'astro:config:setup': (setup: AstroConfigSetup) => Promise<void>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const CART: {
|
|
2
|
+
readonly id: "string";
|
|
3
|
+
readonly checkoutUrl: "string";
|
|
4
|
+
readonly totalQuantity: "number";
|
|
5
|
+
readonly attributes: readonly ["object"];
|
|
6
|
+
readonly discountCodes: readonly ["object"];
|
|
7
|
+
readonly cost: {
|
|
8
|
+
readonly totalAmount: {
|
|
9
|
+
readonly amount: "string";
|
|
10
|
+
readonly currencyCode: "string";
|
|
11
|
+
};
|
|
12
|
+
readonly subtotalAmount: {
|
|
13
|
+
readonly amount: "string";
|
|
14
|
+
readonly currencyCode: "string";
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
readonly lines: {
|
|
18
|
+
readonly nodes: readonly [{
|
|
19
|
+
readonly id: "string";
|
|
20
|
+
readonly quantity: "number";
|
|
21
|
+
readonly attributes: readonly ["object"];
|
|
22
|
+
readonly cost: {
|
|
23
|
+
readonly totalAmount: {
|
|
24
|
+
readonly amount: "string";
|
|
25
|
+
readonly currencyCode: "string";
|
|
26
|
+
};
|
|
27
|
+
readonly subtotalAmount: {
|
|
28
|
+
readonly amount: "string";
|
|
29
|
+
readonly currencyCode: "string";
|
|
30
|
+
};
|
|
31
|
+
readonly amountPerQuantity: {
|
|
32
|
+
readonly amount: "string";
|
|
33
|
+
readonly currencyCode: "string";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly merchandise: {
|
|
37
|
+
readonly id: "string";
|
|
38
|
+
readonly selectedOptions: readonly ["object"];
|
|
39
|
+
readonly product: "object";
|
|
40
|
+
};
|
|
41
|
+
}];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CheckoutTarget } from '../config.js';
|
|
2
|
+
/**
|
|
3
|
+
* The logged-in customer's checkout URL for the cart; `null` when nobody is logged in, so the cart's own checkout URL
|
|
4
|
+
* is used.
|
|
5
|
+
*/
|
|
6
|
+
type CheckoutResolver = () => Promise<string | null>;
|
|
7
|
+
/** Sets the account part's checkout URL, or clears it with `null`. A URL it answers opens checkout logged in. */
|
|
8
|
+
export declare function setCheckoutResolver(resolver: CheckoutResolver | null): void;
|
|
9
|
+
/**
|
|
10
|
+
* Goes to Shopify's checkout. With `_blank` the tab opens inside the click (Safari blocks `window.open` after an
|
|
11
|
+
* await) and gets its URL once there is one.
|
|
12
|
+
*
|
|
13
|
+
* @returns The checkout URL, `null` with nothing to check out or after a reported failure.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkout(target?: CheckoutTarget): Promise<string | null>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Every cart drawer on the page. */
|
|
2
|
+
export declare const drawers: () => HTMLElement[];
|
|
3
|
+
/** True while a drawer, or the drawer-less cart, is open. */
|
|
4
|
+
export declare function isOpen(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* `aria-expanded` on the open buttons, and dialog semantics on the drawers unless their markup has its own. A closed
|
|
7
|
+
* drawer is hidden from screen readers and, with `cartFocus`, out of the Tab order (inert), like a closed dialog.
|
|
8
|
+
*/
|
|
9
|
+
export declare function syncDrawerAria(open: boolean): void;
|
|
10
|
+
/** Opens every drawer except `tether-cart-drawer="manual"` ones, which the site opens itself. */
|
|
11
|
+
export declare function openCart(): void;
|
|
12
|
+
export declare function closeCart(): void;
|
|
13
|
+
export declare function toggleCart(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Keeps Tab inside the open drawer (`cartFocus`): from the last focusable element it wraps to the first, with Shift
|
|
16
|
+
* from the first to the last, and from outside the drawer it goes in. For a document `keydown` listener.
|
|
17
|
+
*/
|
|
18
|
+
export declare function trapFocus(event: KeyboardEvent): void;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { AttributeValue } from '../dom.js';
|
|
2
|
+
import type { ShopifyCart, Attribute } from './store.js';
|
|
3
|
+
export type Attributes = Record<string, AttributeValue> | {
|
|
4
|
+
key: string | number;
|
|
5
|
+
value?: AttributeValue;
|
|
6
|
+
}[];
|
|
7
|
+
/** A line to add, in any of the shapes `Cart.add` takes. */
|
|
8
|
+
export interface LineSpec {
|
|
9
|
+
variantId?: string | number;
|
|
10
|
+
merchandiseId?: string | number;
|
|
11
|
+
id?: string | number;
|
|
12
|
+
quantity?: number | string;
|
|
13
|
+
sellingPlanId?: string | number | null;
|
|
14
|
+
sellingPlan?: string | number | null;
|
|
15
|
+
attributes?: Attributes | null;
|
|
16
|
+
}
|
|
17
|
+
/** Shopify's `CartLineInput`. */
|
|
18
|
+
export interface CartLineInput {
|
|
19
|
+
merchandiseId: string;
|
|
20
|
+
quantity: number;
|
|
21
|
+
sellingPlanId?: string;
|
|
22
|
+
attributes?: Attribute[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @returns True when `error` says Shopify doesn't have the cart, false for any other failure (the network, the token,
|
|
26
|
+
* a line it refused), after which the saved cart is still good.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isCartGone(error: unknown): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* @param input A variant id, or a line.
|
|
31
|
+
* @param quantity For a variant id.
|
|
32
|
+
* @param options For a variant id.
|
|
33
|
+
* @throws {TetherError} `ERROR` without a variant id.
|
|
34
|
+
*/
|
|
35
|
+
export declare function toLineInput(input: string | number | LineSpec | null | undefined, quantity?: number, options?: Omit<LineSpec, 'variantId' | 'quantity'>): CartLineInput;
|
|
36
|
+
/** A mutation on the saved cart. */
|
|
37
|
+
interface CartMutation {
|
|
38
|
+
/** The mutation, e.g. `cartLinesAdd`. */
|
|
39
|
+
name: string;
|
|
40
|
+
/** Its variable definitions besides `$cartId`. */
|
|
41
|
+
args: string;
|
|
42
|
+
/** Its arguments besides `cartId`. */
|
|
43
|
+
inner: string;
|
|
44
|
+
variables: Record<string, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* The `CartInput` of a new cart that does what the mutation asks, when there is no cart (or Shopify no longer has
|
|
47
|
+
* it); `null` leaves the visitor without a cart instead.
|
|
48
|
+
*/
|
|
49
|
+
createInput: Record<string, unknown> | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Runs a mutation on the saved cart, or creates a cart from `createInput` when there is none to change.
|
|
53
|
+
*
|
|
54
|
+
* @returns The changed cart; `null` without a cart and without a `createInput`.
|
|
55
|
+
* @throws {TetherError} For a failed request or Shopify's user errors; also when the cart is gone and there is no
|
|
56
|
+
* `createInput` (the saved cart is forgotten first).
|
|
57
|
+
*/
|
|
58
|
+
export declare function mutateCart({ name, args, inner, variables, createInput, }: CartMutation): Promise<ShopifyCart | null>;
|
|
59
|
+
/** @returns The cart, `null` when Shopify doesn't have it (expired or checked out). */
|
|
60
|
+
export declare function fetchCart(id: string): Promise<ShopifyCart | null>;
|
|
61
|
+
/** @returns The cart's current checkout URL, `null` when Shopify doesn't have the cart. */
|
|
62
|
+
export declare function fetchCheckoutUrl(id: string): Promise<string | null>;
|
|
63
|
+
/** A change to one line, for `updateLine`. */
|
|
64
|
+
export interface LinePatch {
|
|
65
|
+
/** 0 or less removes the line. */
|
|
66
|
+
quantity?: number;
|
|
67
|
+
/** `null` switches the line back to one-time purchase. */
|
|
68
|
+
sellingPlanId?: string | number | null;
|
|
69
|
+
attributes?: Attributes;
|
|
70
|
+
merchandiseId?: string | number;
|
|
71
|
+
variantId?: string | number;
|
|
72
|
+
}
|
|
73
|
+
/** @returns Shopify's `CartLineUpdateInput`. */
|
|
74
|
+
export declare function toLineUpdate(lineId: string, patch: number | LinePatch): Record<string, unknown>;
|
|
75
|
+
export declare const updateLines: (lines: Record<string, unknown>[]) => Promise<ShopifyCart | null>;
|
|
76
|
+
export declare const removeLines: (lineIds: string[]) => Promise<ShopifyCart | null>;
|
|
77
|
+
/** @returns The cart once `lineId` has `target` (0 removes it). */
|
|
78
|
+
export declare const setLineQuantity: (lineId: string, target: number) => Promise<ShopifyCart | null>;
|
|
79
|
+
export {};
|