@brytdesigns/shopify-utils 1.2.21 → 3.0.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/effect/Actions/bridge.js +71 -0
- package/dist/effect/Actions/bridge.js.map +1 -0
- package/dist/effect/Actions/errors.js +46 -0
- package/dist/effect/Actions/errors.js.map +1 -0
- package/dist/effect/Actions/index.js +23 -0
- package/dist/effect/Actions/index.js.map +1 -0
- package/dist/effect/Actions/service.js +127 -0
- package/dist/effect/Actions/service.js.map +1 -0
- package/dist/effect/Actions/trampoline.js +26 -0
- package/dist/effect/Actions/trampoline.js.map +1 -0
- package/dist/effect/Ajax/Sections/index.js +2 -4
- package/dist/effect/Ajax/Sections/schema.js +28 -39
- package/dist/effect/Ajax/Sections/schema.js.map +1 -1
- package/dist/effect/Ajax/Window/data/AllowedRouteOrigins.js +75 -0
- package/dist/effect/Ajax/Window/data/AllowedRouteOrigins.js.map +1 -0
- package/dist/effect/Ajax/Window/data/ShopifyRoutes.js +86 -37
- package/dist/effect/Ajax/Window/data/ShopifyRoutes.js.map +1 -1
- package/dist/effect/Ajax/Window/data/StorefrontClientConfig.js +14 -13
- package/dist/effect/Ajax/Window/data/StorefrontClientConfig.js.map +1 -1
- package/dist/effect/Ajax/Window/data/StorefrontOrigin.js +32 -0
- package/dist/effect/Ajax/Window/data/StorefrontOrigin.js.map +1 -0
- package/dist/effect/Ajax/Window/data/index.js +15 -5
- package/dist/effect/Ajax/Window/data/index.js.map +1 -1
- package/dist/effect/Ajax/Window/index.js +2 -4
- package/dist/effect/Ajax/index.js +13 -3
- package/dist/effect/Ajax/index.js.map +1 -1
- package/dist/effect/Logging/index.js +13 -10
- package/dist/effect/Logging/index.js.map +1 -1
- package/dist/effect/Resource/data.js +20 -30
- package/dist/effect/Resource/data.js.map +1 -1
- package/dist/effect/Resource/index.js +14 -3
- package/dist/effect/Resource/index.js.map +1 -1
- package/dist/effect/Resource/schema.js +45 -45
- package/dist/effect/Resource/schema.js.map +1 -1
- package/dist/effect/_virtual/_rolldown/runtime.js +13 -0
- package/dist/effect/index.d.ts +383 -65
- package/dist/effect/index.js +5 -8
- package/dist/main/_virtual/_rolldown/runtime.js +13 -0
- package/dist/main/actions.js +78 -0
- package/dist/main/actions.js.map +1 -0
- package/dist/main/effect/Actions/bridge.js +65 -0
- package/dist/main/effect/Actions/bridge.js.map +1 -0
- package/dist/main/effect/Actions/errors.js +46 -0
- package/dist/main/effect/Actions/errors.js.map +1 -0
- package/dist/main/effect/Actions/index.js +4 -0
- package/dist/main/effect/Actions/service.js +127 -0
- package/dist/main/effect/Actions/service.js.map +1 -0
- package/dist/main/effect/Actions/trampoline.js +26 -0
- package/dist/main/effect/Actions/trampoline.js.map +1 -0
- package/dist/main/effect/Ajax/Sections/index.js +1 -4
- package/dist/main/effect/Ajax/Sections/schema.js +11 -41
- package/dist/main/effect/Ajax/Sections/schema.js.map +1 -1
- package/dist/main/effect/Ajax/Window/data/AllowedRouteOrigins.js +18 -0
- package/dist/main/effect/Ajax/Window/data/AllowedRouteOrigins.js.map +1 -0
- package/dist/main/effect/Ajax/Window/data/ShopifyRoutes.js +37 -37
- package/dist/main/effect/Ajax/Window/data/ShopifyRoutes.js.map +1 -1
- package/dist/main/effect/Ajax/Window/data/StorefrontClientConfig.js +3 -14
- package/dist/main/effect/Ajax/Window/data/StorefrontClientConfig.js.map +1 -1
- package/dist/main/effect/Ajax/Window/data/StorefrontOrigin.js +6 -0
- package/dist/main/effect/Ajax/Window/data/StorefrontOrigin.js.map +1 -0
- package/dist/main/effect/Ajax/Window/data/index.js +4 -6
- package/dist/main/effect/Ajax/Window/index.js +1 -4
- package/dist/main/effect/Ajax/index.js +2 -4
- package/dist/main/effect/Logging/index.js +2 -13
- package/dist/main/effect/Resource/data.js +20 -30
- package/dist/main/effect/Resource/data.js.map +1 -1
- package/dist/main/effect/Resource/index.js +3 -4
- package/dist/main/effect/Resource/schema.js +45 -45
- package/dist/main/effect/Resource/schema.js.map +1 -1
- package/dist/main/effect/index.js +4 -8
- package/dist/main/index.d.ts +351 -11
- package/dist/main/index.js +3 -3
- package/dist/main/resources/index.js +8 -7
- package/dist/main/resources/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/effect/Ajax/Sections/index.js.map +0 -1
- package/dist/effect/Ajax/Window/data/types.js +0 -3
- package/dist/effect/Ajax/Window/data/types.js.map +0 -1
- package/dist/effect/Ajax/Window/index.js.map +0 -1
- package/dist/effect/index.js.map +0 -1
- package/dist/index.d.ts +0 -77
- package/dist/jsdelivr/effect/Ajax/Sections/index.js +0 -4
- package/dist/jsdelivr/effect/Ajax/Sections/index.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Sections/schema.js +0 -20
- package/dist/jsdelivr/effect/Ajax/Sections/schema.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/data/ShopifyRoutes.js +0 -38
- package/dist/jsdelivr/effect/Ajax/Window/data/ShopifyRoutes.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/data/StorefrontClientConfig.js +0 -16
- package/dist/jsdelivr/effect/Ajax/Window/data/StorefrontClientConfig.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/data/index.js +0 -6
- package/dist/jsdelivr/effect/Ajax/Window/data/index.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/data/types.js +0 -3
- package/dist/jsdelivr/effect/Ajax/Window/data/types.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/Window/index.js +0 -4
- package/dist/jsdelivr/effect/Ajax/Window/index.js.map +0 -1
- package/dist/jsdelivr/effect/Ajax/index.js +0 -4
- package/dist/jsdelivr/effect/Ajax/index.js.map +0 -1
- package/dist/jsdelivr/effect/Logging/index.js +0 -13
- package/dist/jsdelivr/effect/Logging/index.js.map +0 -1
- package/dist/jsdelivr/effect/Resource/data.js +0 -17
- package/dist/jsdelivr/effect/Resource/data.js.map +0 -1
- package/dist/jsdelivr/effect/Resource/index.js +0 -4
- package/dist/jsdelivr/effect/Resource/index.js.map +0 -1
- package/dist/jsdelivr/effect/Resource/schema.js +0 -47
- package/dist/jsdelivr/effect/Resource/schema.js.map +0 -1
- package/dist/jsdelivr/effect/index.js +0 -8
- package/dist/jsdelivr/effect/index.js.map +0 -1
- package/dist/jsdelivr/index.js +0 -3
- package/dist/jsdelivr/index.js.map +0 -1
- package/dist/jsdelivr/resources/index.js +0 -9
- package/dist/jsdelivr/resources/index.js.map +0 -1
- package/dist/main/effect/Ajax/Sections/index.js.map +0 -1
- package/dist/main/effect/Ajax/Window/data/index.js.map +0 -1
- package/dist/main/effect/Ajax/Window/data/types.js +0 -3
- package/dist/main/effect/Ajax/Window/data/types.js.map +0 -1
- package/dist/main/effect/Ajax/Window/index.js.map +0 -1
- package/dist/main/effect/Ajax/index.js.map +0 -1
- package/dist/main/effect/Logging/index.js.map +0 -1
- package/dist/main/effect/Resource/index.js.map +0 -1
- package/dist/main/effect/index.js.map +0 -1
- package/dist/main/index.js.map +0 -1
package/dist/effect/index.d.ts
CHANGED
|
@@ -1,13 +1,363 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
import * as Cause from 'effect/Cause';
|
|
4
|
+
import * as Context from 'effect/Context';
|
|
3
5
|
import * as Data from 'effect/Data';
|
|
4
6
|
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Layer from 'effect/Layer';
|
|
5
8
|
import * as LogLevel from 'effect/LogLevel';
|
|
6
|
-
import { ParseError } from 'effect/ParseResult';
|
|
7
9
|
import * as Schema from 'effect/Schema';
|
|
10
|
+
import * as Scope from 'effect/Scope';
|
|
8
11
|
|
|
12
|
+
declare const toAsyncCallback: <Args extends ReadonlyArray<unknown>, A, E, R>(services: Context.Context<R>, f: (...args: Args) => Effect.Effect<A, E, R>) => (...args: Args) => Promise<A>;
|
|
13
|
+
declare const toSyncCallback: <Args extends ReadonlyArray<unknown>, A, R>(services: Context.Context<R>, f: (...args: Args) => Effect.Effect<A, never, R>, onAbnormal: (cause: Cause.Cause<never>) => A) => (...args: Args) => A;
|
|
14
|
+
declare const fromPromiseThunk: <A, E>(thunk: () => Promise<A>, onReject: (cause: unknown) => E) => Effect.Effect<A, E>;
|
|
15
|
+
/** Every action exposed on `window.Shopify.actions`. */
|
|
16
|
+
export type ActionName = "getCart" | "updateCart" | "openCart";
|
|
17
|
+
/**
|
|
18
|
+
* Only `updateCart` and `openCart` are `ActionFunction`s — `getCart` is a bare
|
|
19
|
+
* callable with no `configure()` / `isDefault()`.
|
|
20
|
+
*/
|
|
21
|
+
export type ConfigurableActionName = Exclude<ActionName, "getCart">;
|
|
22
|
+
declare const ActionsUnavailableError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{
|
|
23
|
+
readonly [P in keyof A as P extends "_tag" ? never : P]: A[P];
|
|
24
|
+
}>) => import("effect/Cause").YieldableError & {
|
|
25
|
+
readonly _tag: "@brytdesigns/shopify-utils/ActionsUnavailableError";
|
|
26
|
+
} & Readonly<A>;
|
|
27
|
+
declare class ActionsUnavailableError extends ActionsUnavailableError_base<{
|
|
28
|
+
readonly action: ActionName;
|
|
29
|
+
readonly message: string;
|
|
30
|
+
}> {
|
|
31
|
+
constructor(options: {
|
|
32
|
+
readonly action: ActionName;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
declare const ActionConfigurationRejectedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{
|
|
36
|
+
readonly [P in keyof A as P extends "_tag" ? never : P]: A[P];
|
|
37
|
+
}>) => import("effect/Cause").YieldableError & {
|
|
38
|
+
readonly _tag: "@brytdesigns/shopify-utils/ActionConfigurationRejectedError";
|
|
39
|
+
} & Readonly<A>;
|
|
40
|
+
declare class ActionConfigurationRejectedError extends ActionConfigurationRejectedError_base<{
|
|
41
|
+
readonly action: ConfigurableActionName;
|
|
42
|
+
readonly message: string;
|
|
43
|
+
}> {
|
|
44
|
+
constructor(options: {
|
|
45
|
+
readonly action: ConfigurableActionName;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
declare const ActionInvocationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{
|
|
49
|
+
readonly [P in keyof A as P extends "_tag" ? never : P]: A[P];
|
|
50
|
+
}>) => import("effect/Cause").YieldableError & {
|
|
51
|
+
readonly _tag: "@brytdesigns/shopify-utils/ActionInvocationError";
|
|
52
|
+
} & Readonly<A>;
|
|
53
|
+
declare class ActionInvocationError extends ActionInvocationError_base<{
|
|
54
|
+
readonly action: ActionName;
|
|
55
|
+
readonly cause: unknown;
|
|
56
|
+
readonly message: string;
|
|
57
|
+
}> {
|
|
58
|
+
constructor(options: {
|
|
59
|
+
readonly action: ActionName;
|
|
60
|
+
readonly cause: unknown;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// -----------------------------------------------------------------------------
|
|
64
|
+
// VENDORED FILE — DO NOT EDIT BY HAND.
|
|
65
|
+
//
|
|
66
|
+
// Source: https://cdn.shopify.com/storefront/standard-actions.d.ts
|
|
67
|
+
// Vendored: 2026-08-13
|
|
68
|
+
// Upstream version (see `// version:` line below): 977e4f914dd2b3eca85ad01dee81c2c96eb1b2e5
|
|
69
|
+
// sha256 (upstream body only, i.e. everything below this header):
|
|
70
|
+
// 2f0fc044f35999cd09550b8b68620077601d1409817edae16745e600417788e7
|
|
71
|
+
//
|
|
72
|
+
// Everything below this header is the upstream file byte-for-byte. To diff
|
|
73
|
+
// against a future revision:
|
|
74
|
+
//
|
|
75
|
+
// curl -sSL https://cdn.shopify.com/storefront/standard-actions.d.ts \
|
|
76
|
+
// | diff - <(tail -n +25 shopify/utils/src/types/standard-actions.d.ts)
|
|
77
|
+
//
|
|
78
|
+
// There is NO npm package for this. Shopify injects the runtime on every Liquid
|
|
79
|
+
// storefront as `window.Shopify.actions`; a module build for import maps lives
|
|
80
|
+
// at https://cdn.shopify.com/storefront/standard-actions.js. Do not add a
|
|
81
|
+
// dependency — import types via the `@theme/standard-actions` alias
|
|
82
|
+
// (see tsconfig.json `paths`), which is marked `external` in tsup.config.ts.
|
|
83
|
+
//
|
|
84
|
+
// This file is excluded from Biome in the root biome.json so formatting/lint
|
|
85
|
+
// never rewrites upstream content and pollutes the diff.
|
|
86
|
+
// -----------------------------------------------------------------------------
|
|
87
|
+
// version: 977e4f914dd2b3eca85ad01dee81c2c96eb1b2e5
|
|
88
|
+
export interface Price {
|
|
89
|
+
amount: string;
|
|
90
|
+
currencyCode: string;
|
|
91
|
+
}
|
|
92
|
+
export interface CartDiscountCode {
|
|
93
|
+
applicable: boolean;
|
|
94
|
+
code: string;
|
|
95
|
+
}
|
|
96
|
+
export interface CartCost {
|
|
97
|
+
totalAmount: Price;
|
|
98
|
+
}
|
|
99
|
+
export interface CartLine {
|
|
100
|
+
id: string;
|
|
101
|
+
quantity: number;
|
|
102
|
+
cost: CartCost;
|
|
103
|
+
}
|
|
104
|
+
export interface CartMutationUserError {
|
|
105
|
+
code?: string;
|
|
106
|
+
field?: string[];
|
|
107
|
+
message: string;
|
|
108
|
+
}
|
|
109
|
+
export interface CartMutationWarning {
|
|
110
|
+
code?: string;
|
|
111
|
+
message: string;
|
|
112
|
+
target?: string;
|
|
113
|
+
}
|
|
114
|
+
declare const CART_UPDATE_CONTEXTS: readonly [
|
|
115
|
+
"product",
|
|
116
|
+
"cart",
|
|
117
|
+
"dialog",
|
|
118
|
+
"standard-action"
|
|
119
|
+
];
|
|
120
|
+
export type CartUpdateContext = (typeof CART_UPDATE_CONTEXTS)[number];
|
|
121
|
+
declare const CART_UPDATE_ACTIONS: readonly [
|
|
122
|
+
"add",
|
|
123
|
+
"remove",
|
|
124
|
+
"update"
|
|
125
|
+
];
|
|
126
|
+
export type CartUpdateAction = (typeof CART_UPDATE_ACTIONS)[number];
|
|
127
|
+
export type ActionArgs<P, O = void> = [
|
|
128
|
+
P
|
|
129
|
+
] extends [
|
|
130
|
+
void
|
|
131
|
+
] ? [
|
|
132
|
+
options?: O
|
|
133
|
+
] : [
|
|
134
|
+
Extract<P, void>
|
|
135
|
+
] extends [
|
|
136
|
+
never
|
|
137
|
+
] ? [
|
|
138
|
+
payload: P,
|
|
139
|
+
options?: O
|
|
140
|
+
] : [
|
|
141
|
+
payload?: Exclude<P, void>,
|
|
142
|
+
options?: O
|
|
143
|
+
];
|
|
144
|
+
export type UpdateCartUserError = CartMutationUserError;
|
|
145
|
+
export type UpdateCartWarning = CartMutationWarning;
|
|
146
|
+
export interface CartAttributeInput {
|
|
147
|
+
key: string;
|
|
148
|
+
value: string;
|
|
149
|
+
}
|
|
150
|
+
export interface StorefrontCartLinesConnection {
|
|
151
|
+
nodes: CartLine[];
|
|
152
|
+
}
|
|
153
|
+
export interface StorefrontCartSummary {
|
|
154
|
+
id: string;
|
|
155
|
+
totalQuantity: number;
|
|
156
|
+
cost: CartCost;
|
|
157
|
+
lines: StorefrontCartLinesConnection;
|
|
158
|
+
discountCodes: CartDiscountCode[];
|
|
159
|
+
}
|
|
160
|
+
export type UpdateCartEventTargetMeta = {
|
|
161
|
+
type: "shopify:cart:lines-update";
|
|
162
|
+
action: CartUpdateAction;
|
|
163
|
+
} | {
|
|
164
|
+
type: "shopify:cart:note-update" | "shopify:cart:attributes-update" | "shopify:cart:discount-update" | "shopify:cart:error";
|
|
165
|
+
};
|
|
166
|
+
export interface CartLineInput {
|
|
167
|
+
/**
|
|
168
|
+
* Existing-line id from SFAPI or the AJAX cart API.
|
|
169
|
+
* CartLine GIDs keep or receive a `?cart=` suffix automatically when the cart id is known.
|
|
170
|
+
* Present = update/remove; absent = add.
|
|
171
|
+
*/
|
|
172
|
+
id?: string;
|
|
173
|
+
/** ProductVariant GID or raw variant id. Required for add. */
|
|
174
|
+
merchandiseId?: string;
|
|
175
|
+
/** Set to 0 to remove. */
|
|
176
|
+
quantity: number;
|
|
177
|
+
/** Line item-level custom attributes */
|
|
178
|
+
attributes?: CartAttributeInput[];
|
|
179
|
+
/** Selling plan GID or raw selling plan id. */
|
|
180
|
+
sellingPlanId?: string;
|
|
181
|
+
}
|
|
182
|
+
export interface UpdateCartPayload {
|
|
183
|
+
/** Cart GID or raw cart token. If omitted, discovered from the cart cookie. */
|
|
184
|
+
cartId?: string;
|
|
185
|
+
lines?: CartLineInput[];
|
|
186
|
+
note?: string;
|
|
187
|
+
discountCodes?: string[];
|
|
188
|
+
/** Cart-level custom attributes */
|
|
189
|
+
attributes?: CartAttributeInput[];
|
|
190
|
+
}
|
|
191
|
+
export interface UpdateCartResult {
|
|
192
|
+
cart: StorefrontCartSummary;
|
|
193
|
+
userErrors?: UpdateCartUserError[];
|
|
194
|
+
warnings?: UpdateCartWarning[];
|
|
195
|
+
detail?: Record<string, any>;
|
|
196
|
+
}
|
|
197
|
+
export interface UpdateCartOptions {
|
|
198
|
+
signal?: AbortSignal;
|
|
199
|
+
event?: {
|
|
200
|
+
detail?: Record<string, any>;
|
|
201
|
+
context?: CartUpdateContext;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export interface GetCartPayload {
|
|
205
|
+
/** Cart GID or raw cart token. If omitted, discovered from the browser cookie. */
|
|
206
|
+
cartId?: string;
|
|
207
|
+
}
|
|
208
|
+
export interface GetCartResult {
|
|
209
|
+
cart: StorefrontCartSummary | null;
|
|
210
|
+
detail?: Record<string, any>;
|
|
211
|
+
}
|
|
212
|
+
export interface GetCartOptions {
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The default handler, lifted into Effect-land.
|
|
217
|
+
*
|
|
218
|
+
* Handlers receive this rather than a pre-computed result so they keep the full
|
|
219
|
+
* range of the upstream contract: run the default, wrap it, retry it, race it,
|
|
220
|
+
* or skip it entirely and synthesise a result.
|
|
221
|
+
*/
|
|
222
|
+
export type DefaultHandler<A> = Effect.Effect<A, ActionInvocationError>;
|
|
223
|
+
/**
|
|
224
|
+
* An action handler written in Effect.
|
|
225
|
+
*
|
|
226
|
+
* The returned Effect's success value is what the action resolves with, and its
|
|
227
|
+
* failure becomes a rejected promise for Shopify.
|
|
228
|
+
*
|
|
229
|
+
* Note that `E` is checked but never surfaces to the fiber that called
|
|
230
|
+
* `configure` — the handler runs long afterwards, when a shopper triggers the
|
|
231
|
+
* action, so its failure has nowhere to go but the promise Shopify awaits. If
|
|
232
|
+
* you want handler failures observed, observe them inside the handler.
|
|
233
|
+
*/
|
|
234
|
+
export type Handler<P, A, O, E, R> = (defaultHandler: DefaultHandler<A>, ...args: ActionArgs<P, O>) => Effect.Effect<A, E, R>;
|
|
235
|
+
/**
|
|
236
|
+
* Resolves the element that `shopify:cart:*` events are dispatched from.
|
|
237
|
+
*
|
|
238
|
+
* The error channel is `never` on purpose. Shopify calls this synchronously and
|
|
239
|
+
* uses the return value immediately, so there is nowhere for a failure to go —
|
|
240
|
+
* handle errors inside the Effect and fall back to an element or `null`.
|
|
241
|
+
*
|
|
242
|
+
* For the same reason this Effect must complete synchronously. Anything that
|
|
243
|
+
* suspends (`Effect.sleep`, an HTTP call, an async service) cannot produce a
|
|
244
|
+
* value in time and is reported as `null` with a logged defect, which makes
|
|
245
|
+
* Shopify dispatch on `document`. If you need async work, resolve it ahead of
|
|
246
|
+
* time into a `Ref` and read the `Ref` here.
|
|
247
|
+
*/
|
|
248
|
+
export type EventTargetResolver<R> = (meta: UpdateCartEventTargetMeta) => Effect.Effect<EventTarget | null, never, R>;
|
|
249
|
+
export interface UpdateCartConfiguration<E, R> {
|
|
250
|
+
readonly eventTarget: EventTargetResolver<R>;
|
|
251
|
+
/** Optional: routing events without changing cart behaviour is valid. */
|
|
252
|
+
readonly handler?: Handler<UpdateCartPayload, UpdateCartResult, UpdateCartOptions, E, R>;
|
|
253
|
+
}
|
|
254
|
+
export interface OpenCartConfiguration<E, R> {
|
|
255
|
+
/**
|
|
256
|
+
* Required, unlike `updateCart`'s. `openCart` has no event target, so a
|
|
257
|
+
* configuration without a handler would claim the one-shot upstream slot
|
|
258
|
+
* while contributing nothing — locking everyone else out for the life of
|
|
259
|
+
* the page in exchange for default behaviour.
|
|
260
|
+
*/
|
|
261
|
+
readonly handler: Handler<void, void, void, E, R>;
|
|
262
|
+
}
|
|
263
|
+
export interface ShopifyStorefrontActionsImpl {
|
|
264
|
+
/**
|
|
265
|
+
* Read the current cart. `getCart` is a bare callable upstream — it has no
|
|
266
|
+
* `configure()`, so there is no `configureGetCart`.
|
|
267
|
+
*/
|
|
268
|
+
readonly getCart: (payload?: GetCartPayload, options?: GetCartOptions) => Effect.Effect<GetCartResult, ActionsUnavailableError | ActionInvocationError>;
|
|
269
|
+
readonly updateCart: (payload: UpdateCartPayload, options?: UpdateCartOptions) => Effect.Effect<UpdateCartResult, ActionsUnavailableError | ActionInvocationError>;
|
|
270
|
+
readonly openCart: Effect.Effect<void, ActionsUnavailableError | ActionInvocationError>;
|
|
271
|
+
/**
|
|
272
|
+
* Install an Effect-based `updateCart` configuration for the lifetime of the
|
|
273
|
+
* enclosing `Scope`.
|
|
274
|
+
*
|
|
275
|
+
* The `R` of the supplied Effects flows out into the returned Effect's
|
|
276
|
+
* requirements, so the services your handler needs stay explicit and must be
|
|
277
|
+
* provided before this runs — they are captured, not smuggled.
|
|
278
|
+
*
|
|
279
|
+
* Calling this more than once rebinds rather than failing: we claim the
|
|
280
|
+
* upstream slot once and swap our own configuration behind it. A
|
|
281
|
+
* `ActionConfigurationRejectedError` therefore means one specific thing —
|
|
282
|
+
* something outside this library claimed the action first.
|
|
283
|
+
*
|
|
284
|
+
* For page-lifetime registration, build it into a layer with
|
|
285
|
+
* `Layer.effectDiscard(Actions.configureUpdateCart({ ... }))` so the
|
|
286
|
+
* registration lives exactly as long as the runtime does.
|
|
287
|
+
*/
|
|
288
|
+
readonly configureUpdateCart: <E, R>(config: UpdateCartConfiguration<E, R>) => Effect.Effect<void, ActionsUnavailableError | ActionConfigurationRejectedError, R | Scope.Scope>;
|
|
289
|
+
readonly configureOpenCart: <E, R>(config: OpenCartConfiguration<E, R>) => Effect.Effect<void, ActionsUnavailableError | ActionConfigurationRejectedError, R | Scope.Scope>;
|
|
290
|
+
/**
|
|
291
|
+
* Upstream's own notion: `true` until the action's slot is claimed.
|
|
292
|
+
*
|
|
293
|
+
* Because the slot can never be released, this stays `false` once we have
|
|
294
|
+
* claimed it, even after every configuration has been deactivated.
|
|
295
|
+
*/
|
|
296
|
+
readonly isDefault: (action: ConfigurableActionName) => Effect.Effect<boolean, ActionsUnavailableError>;
|
|
297
|
+
}
|
|
298
|
+
declare const ShopifyStorefrontActions_base: Context.ServiceClass<ShopifyStorefrontActions, "@brytdesigns/shopify-utils/ShopifyStorefrontActions", ShopifyStorefrontActionsImpl>;
|
|
299
|
+
declare class ShopifyStorefrontActions extends ShopifyStorefrontActions_base {
|
|
300
|
+
}
|
|
301
|
+
declare const layer: Layer.Layer<ShopifyStorefrontActions, never, never>;
|
|
302
|
+
declare const getCart: (payload?: GetCartPayload, options?: GetCartOptions) => Effect.Effect<GetCartResult, ActionsUnavailableError | ActionInvocationError, ShopifyStorefrontActions>;
|
|
303
|
+
declare const updateCart: (payload: UpdateCartPayload, options?: UpdateCartOptions) => Effect.Effect<UpdateCartResult, ActionsUnavailableError | ActionInvocationError, ShopifyStorefrontActions>;
|
|
304
|
+
declare const openCart: Effect.Effect<void, ActionsUnavailableError | ActionInvocationError, ShopifyStorefrontActions>;
|
|
305
|
+
declare const configureUpdateCart: <E, R>(config: UpdateCartConfiguration<E, R>) => Effect.Effect<void, ActionsUnavailableError | ActionConfigurationRejectedError, Scope.Scope | ShopifyStorefrontActions | R>;
|
|
306
|
+
declare const configureOpenCart: <E, R>(config: OpenCartConfiguration<E, R>) => Effect.Effect<void, ActionsUnavailableError | ActionConfigurationRejectedError, Scope.Scope | ShopifyStorefrontActions | R>;
|
|
307
|
+
declare const isDefault: (action: ConfigurableActionName) => Effect.Effect<boolean, ActionsUnavailableError, ShopifyStorefrontActions>;
|
|
308
|
+
export type Input = typeof Input;
|
|
309
|
+
declare const Input: Schema.Struct<{
|
|
310
|
+
readonly sections: Schema.optional<Schema.decodeTo<Schema.String, Schema.$Array<Schema.String>, never, never>>;
|
|
311
|
+
readonly sections_url: Schema.optional<Schema.String>;
|
|
312
|
+
}>;
|
|
313
|
+
export type UniqueKeys<T extends string> = T extends `${infer K},${infer Rest}` ? K | UniqueKeys<Rest> : T;
|
|
314
|
+
declare function makeResponseSchema<const T extends string>(input: T): Schema.$Record<Schema.Literals<UniqueKeys<T>[]>, Schema.NullOr<Schema.decodeTo<Schema.instanceOf<Element, Element>, Schema.String, never, never>>>;
|
|
315
|
+
declare const Origins: Context.Reference<readonly string[]>;
|
|
316
|
+
declare const layer$1: (origins: readonly string[]) => Layer.Layer<never>;
|
|
317
|
+
export interface IShopifyRoutes {
|
|
318
|
+
readonly account_addresses_url: string;
|
|
319
|
+
readonly account_login_url: string;
|
|
320
|
+
readonly account_logout_url: string;
|
|
321
|
+
readonly account_recover_url: string;
|
|
322
|
+
readonly account_register_url: string;
|
|
323
|
+
readonly account_url: string;
|
|
324
|
+
readonly all_products_collection_url: string;
|
|
325
|
+
readonly product_url: string;
|
|
326
|
+
readonly products_url: string;
|
|
327
|
+
readonly cart_add_url: string;
|
|
328
|
+
readonly cart_change_url: string;
|
|
329
|
+
readonly cart_clear_url: string;
|
|
330
|
+
readonly cart_update_url: string;
|
|
331
|
+
readonly cart_url: string;
|
|
332
|
+
readonly collections_url: string;
|
|
333
|
+
readonly predictive_search_url: string;
|
|
334
|
+
readonly product_recommendations_url: string;
|
|
335
|
+
readonly root_url: string;
|
|
336
|
+
readonly search_url: string;
|
|
337
|
+
readonly storefront_login_url: string;
|
|
338
|
+
}
|
|
339
|
+
export interface IStorefrontClientConfig {
|
|
340
|
+
readonly accessToken: string;
|
|
341
|
+
readonly shopName: string;
|
|
342
|
+
apiVersion: string;
|
|
343
|
+
}
|
|
344
|
+
declare const Defaults: IShopifyRoutes;
|
|
345
|
+
declare class ShopifyRoutes extends Data.Class<IShopifyRoutes> {
|
|
346
|
+
constructor();
|
|
347
|
+
}
|
|
348
|
+
declare const make: () => ShopifyRoutes;
|
|
349
|
+
declare const Routes: Context.Reference<IShopifyRoutes>;
|
|
350
|
+
declare const layer$2: (routes: IShopifyRoutes) => Layer.Layer<never>;
|
|
351
|
+
declare class StorefrontClientConfig extends Data.Class<IStorefrontClientConfig> {
|
|
352
|
+
constructor();
|
|
353
|
+
}
|
|
354
|
+
declare const make$1: () => StorefrontClientConfig;
|
|
355
|
+
declare const Origin: Context.Reference<string>;
|
|
356
|
+
declare const layer$3: (origin: string) => Layer.Layer<never>;
|
|
357
|
+
declare const filterLevelOrNever: <A, E, R>(level: LogLevel.LogLevel, effect: Effect.Effect<A, E, R>) => Effect.Effect<A | undefined, E, R>;
|
|
358
|
+
declare const makeNamespacedLogSpan: (prefix: string) => (label: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
9
359
|
export type Type = Schema.Schema.Type<typeof Type>;
|
|
10
|
-
declare const Type: Schema.
|
|
360
|
+
declare const Type: Schema.Literals<readonly [
|
|
11
361
|
"Cart",
|
|
12
362
|
"Collection",
|
|
13
363
|
"Customer",
|
|
@@ -42,89 +392,57 @@ declare const Type: Schema.Literal<[
|
|
|
42
392
|
"StaffMember",
|
|
43
393
|
"Theme"
|
|
44
394
|
]>;
|
|
45
|
-
export type GID = Schema.
|
|
46
|
-
declare const GID: Schema.
|
|
47
|
-
export type ID = Schema.
|
|
48
|
-
declare const ID: Schema.Union<[
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
395
|
+
export type GID = Schema.Codec.Encoded<typeof GID>;
|
|
396
|
+
declare const GID: Schema.String;
|
|
397
|
+
export type ID = Schema.Codec.Encoded<typeof ID>;
|
|
398
|
+
declare const ID: Schema.Union<readonly [
|
|
399
|
+
Schema.Number,
|
|
400
|
+
Schema.NumberFromString,
|
|
401
|
+
Schema.String
|
|
52
402
|
]>;
|
|
53
403
|
export type FormatOptions<T extends ID, R extends Type> = {
|
|
54
404
|
id: T;
|
|
55
405
|
type: R;
|
|
56
406
|
};
|
|
57
|
-
declare const format: <const T extends ID, const R extends Type>({ id, type, }: FormatOptions<T, R>) => Effect.Effect<`gid://shopify/${R}/${T}`,
|
|
58
|
-
declare const parse: (input: string) => Effect.Effect<string | number,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
readonly account_logout_url: string;
|
|
63
|
-
readonly account_recover_url: string;
|
|
64
|
-
readonly account_register_url: string;
|
|
65
|
-
readonly account_url: string;
|
|
66
|
-
readonly all_products_collection_url: string;
|
|
67
|
-
readonly product_url: string;
|
|
68
|
-
readonly products_url: string;
|
|
69
|
-
readonly cart_add_url: string;
|
|
70
|
-
readonly cart_change_url: string;
|
|
71
|
-
readonly cart_clear_url: string;
|
|
72
|
-
readonly cart_update_url: string;
|
|
73
|
-
readonly cart_url: string;
|
|
74
|
-
readonly collections_url: string;
|
|
75
|
-
readonly predictive_search_url: string;
|
|
76
|
-
readonly product_recommendations_url: string;
|
|
77
|
-
readonly root_url: string;
|
|
78
|
-
readonly search_url: string;
|
|
79
|
-
readonly storefront_login_url: string;
|
|
407
|
+
declare const format: <const T extends ID, const R extends Type>({ id, type, }: FormatOptions<T, R>) => Effect.Effect<`gid://shopify/${R}/${T}`, Schema.SchemaError, never>;
|
|
408
|
+
declare const parse: (input: string) => Effect.Effect<string | number, Schema.SchemaError, never>;
|
|
409
|
+
|
|
410
|
+
declare namespace Bridge {
|
|
411
|
+
export { fromPromiseThunk, toAsyncCallback, toSyncCallback };
|
|
80
412
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
readonly shopName: string;
|
|
84
|
-
apiVersion: string;
|
|
413
|
+
declare namespace Resource {
|
|
414
|
+
export { GID, ID, Type, format, parse };
|
|
85
415
|
}
|
|
86
|
-
declare
|
|
87
|
-
|
|
88
|
-
constructor();
|
|
416
|
+
declare namespace Sections {
|
|
417
|
+
export { Input, makeResponseSchema };
|
|
89
418
|
}
|
|
90
|
-
declare
|
|
91
|
-
|
|
92
|
-
constructor();
|
|
419
|
+
declare namespace StorefrontOrigin {
|
|
420
|
+
export { Origin, layer$3 as layer };
|
|
93
421
|
}
|
|
94
|
-
declare
|
|
95
|
-
export
|
|
96
|
-
declare const Input: Schema.Struct<{
|
|
97
|
-
sections: Schema.optional<Schema.transform<Schema.Array$<typeof Schema.String>, typeof Schema.String>>;
|
|
98
|
-
sections_url: Schema.optional<typeof Schema.String>;
|
|
99
|
-
}>;
|
|
100
|
-
export type UniqueKeys<T extends string> = T extends `${infer K},${infer Rest}` ? K | UniqueKeys<Rest> : T;
|
|
101
|
-
declare function makeResponseSchema<const T extends string>(input: T): Schema.Record$<Schema.SchemaClass<UniqueKeys<T>, UniqueKeys<T>, never>, Schema.NullOr<Schema.transformOrFail<typeof Schema.String, Schema.instanceOf<Element>, never>>>;
|
|
102
|
-
declare const filterLevelOrNever: <A, E, R>(level: LogLevel.LogLevel, effect: Effect.Effect<A, E, R>) => Effect.Effect<A | undefined, E, R>;
|
|
103
|
-
declare const makeNamespacedLogSpan: (prefix: string) => (label: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
104
|
-
|
|
105
|
-
declare namespace StorefrontClientConfig$1 {
|
|
106
|
-
export { StorefrontClientConfig, make$1 as make };
|
|
422
|
+
declare namespace AllowedRouteOrigins {
|
|
423
|
+
export { Origins, layer$1 as layer };
|
|
107
424
|
}
|
|
108
425
|
declare namespace ShopifyRoutes$1 {
|
|
109
|
-
export { Defaults, ShopifyRoutes, make };
|
|
110
|
-
}
|
|
111
|
-
declare namespace Window$1 {
|
|
112
|
-
export { ShopifyRoutes$1 as ShopifyRoutes, StorefrontClientConfig$1 as StorefrontClientConfig };
|
|
426
|
+
export { Defaults, Routes, ShopifyRoutes, layer$2 as layer, make };
|
|
113
427
|
}
|
|
114
|
-
declare namespace
|
|
115
|
-
export {
|
|
428
|
+
declare namespace StorefrontClientConfig$1 {
|
|
429
|
+
export { StorefrontClientConfig, make$1 as make };
|
|
116
430
|
}
|
|
117
|
-
declare namespace
|
|
118
|
-
export {
|
|
431
|
+
declare namespace Window$1 {
|
|
432
|
+
export { AllowedRouteOrigins, ShopifyRoutes$1 as ShopifyRoutes, StorefrontClientConfig$1 as StorefrontClientConfig, StorefrontOrigin };
|
|
119
433
|
}
|
|
120
|
-
declare namespace
|
|
121
|
-
export {
|
|
434
|
+
declare namespace Actions {
|
|
435
|
+
export { ActionConfigurationRejectedError, ActionInvocationError, ActionName, ActionsUnavailableError, Bridge, CartAttributeInput, CartCost, CartDiscountCode, CartLine, CartLineInput, CartMutationUserError, CartMutationWarning, CartUpdateAction, CartUpdateContext, ConfigurableActionName, DefaultHandler, EventTargetResolver, GetCartOptions, GetCartPayload, GetCartResult, Handler, OpenCartConfiguration, Price, ShopifyStorefrontActions, ShopifyStorefrontActionsImpl, StorefrontCartLinesConnection, StorefrontCartSummary, UpdateCartConfiguration, UpdateCartEventTargetMeta, UpdateCartOptions, UpdateCartPayload, UpdateCartResult, UpdateCartUserError, UpdateCartWarning, configureOpenCart, configureUpdateCart, getCart, isDefault, layer, openCart, updateCart };
|
|
122
436
|
}
|
|
123
437
|
declare namespace Ajax {
|
|
124
438
|
export { Sections, Window$1 as Window };
|
|
125
439
|
}
|
|
440
|
+
declare namespace Logging {
|
|
441
|
+
export { filterLevelOrNever, makeNamespacedLogSpan };
|
|
442
|
+
}
|
|
126
443
|
|
|
127
444
|
export {
|
|
445
|
+
Actions,
|
|
128
446
|
Ajax,
|
|
129
447
|
Logging,
|
|
130
448
|
Resource,
|
package/dist/effect/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { index_js$1 as Logging };
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { Actions_exports } from "./Actions/index.js";
|
|
2
|
+
import { Ajax_exports } from "./Ajax/index.js";
|
|
3
|
+
import { Logging_exports } from "./Logging/index.js";
|
|
4
|
+
import { Resource_exports } from "./Resource/index.js";
|
|
5
|
+
export { Actions_exports as Actions, Ajax_exports as Ajax, Logging_exports as Logging, Resource_exports as Resource };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { ActionConfigurationRejectedError, ActionInvocationError, ActionsUnavailableError } from "./effect/Actions/errors.js";
|
|
3
|
+
import { configureOpenCart as configureOpenCart$1, configureUpdateCart as configureUpdateCart$1, getCart as getCart$1, isDefault as isDefault$1, layer, openCart as openCart$1, updateCart as updateCart$1 } from "./effect/Actions/service.js";
|
|
4
|
+
import "./effect/index.js";
|
|
5
|
+
import * as Cause from "effect/Cause";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Exit from "effect/Exit";
|
|
8
|
+
import * as Scope from "effect/Scope";
|
|
9
|
+
//#region src/actions.ts
|
|
10
|
+
var actions_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
ActionConfigurationRejectedError: () => ActionConfigurationRejectedError,
|
|
12
|
+
ActionInvocationError: () => ActionInvocationError,
|
|
13
|
+
ActionsUnavailableError: () => ActionsUnavailableError,
|
|
14
|
+
configureOpenCart: () => configureOpenCart,
|
|
15
|
+
configureUpdateCart: () => configureUpdateCart,
|
|
16
|
+
getCart: () => getCart,
|
|
17
|
+
isDefault: () => isDefault,
|
|
18
|
+
openCart: () => openCart,
|
|
19
|
+
updateCart: () => updateCart
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Run to a promise that rejects with the failure itself.
|
|
23
|
+
*
|
|
24
|
+
* `Effect.runPromise` rejects with a `FiberFailure` wrapping the error, which
|
|
25
|
+
* would force a plain-JS caller to understand Effect internals to get at their
|
|
26
|
+
* own tagged error. Squashing the cause means `catch (e)` sees the
|
|
27
|
+
* `ActionsUnavailableError` directly and `instanceof` behaves as expected.
|
|
28
|
+
*/
|
|
29
|
+
var settle = async (effect) => {
|
|
30
|
+
const exit = await Effect.runPromiseExit(Effect.provide(effect, layer));
|
|
31
|
+
if (Exit.isSuccess(exit)) return exit.value;
|
|
32
|
+
throw Cause.squash(exit.cause);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Run a scoped configuration and hand back its teardown.
|
|
36
|
+
*
|
|
37
|
+
* The scope is deliberately not closed on success — the configuration must
|
|
38
|
+
* outlive this call. It is closed if configuring fails, so a failed attempt
|
|
39
|
+
* leaves nothing registered.
|
|
40
|
+
*/
|
|
41
|
+
var runScoped = async (effect) => {
|
|
42
|
+
const scope = Effect.runSync(Scope.make());
|
|
43
|
+
const dispose = () => Effect.runPromise(Scope.close(scope, Exit.void));
|
|
44
|
+
const exit = await Effect.runPromiseExit(effect.pipe(Scope.provide(scope), Effect.provide(layer)));
|
|
45
|
+
if (Exit.isFailure(exit)) {
|
|
46
|
+
await dispose();
|
|
47
|
+
throw Cause.squash(exit.cause);
|
|
48
|
+
}
|
|
49
|
+
return dispose;
|
|
50
|
+
};
|
|
51
|
+
/** Read the current cart. */
|
|
52
|
+
var getCart = (payload, options) => settle(getCart$1(payload, options));
|
|
53
|
+
/** Mutate the cart through Shopify's action, honouring any configuration. */
|
|
54
|
+
var updateCart = (payload, options) => settle(updateCart$1(payload, options));
|
|
55
|
+
/** Open the cart through Shopify's action. */
|
|
56
|
+
var openCart = () => settle(openCart$1);
|
|
57
|
+
/** Upstream's own notion: `true` until the action's slot is claimed. */
|
|
58
|
+
var isDefault = (action) => settle(isDefault$1(action));
|
|
59
|
+
/**
|
|
60
|
+
* Install an `updateCart` configuration, resolving to its teardown.
|
|
61
|
+
*
|
|
62
|
+
* Calling this again rebinds rather than failing. A rejection with
|
|
63
|
+
* `ActionConfigurationRejectedError` means something outside this library
|
|
64
|
+
* claimed the action first.
|
|
65
|
+
*/
|
|
66
|
+
var configureUpdateCart = (config = {}) => {
|
|
67
|
+
const { eventTarget, handler } = config;
|
|
68
|
+
return runScoped(configureUpdateCart$1({
|
|
69
|
+
eventTarget: (meta) => Effect.sync(() => eventTarget?.(meta) ?? null),
|
|
70
|
+
...handler === void 0 ? {} : { handler: (defaultAction, payload, options) => Effect.promise(() => handler(() => Effect.runPromise(defaultAction), payload, options)) }
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
/** Install an `openCart` configuration, resolving to its teardown. */
|
|
74
|
+
var configureOpenCart = (config) => runScoped(configureOpenCart$1({ handler: (defaultAction) => Effect.promise(() => config.handler(() => Effect.runPromise(defaultAction))) }));
|
|
75
|
+
//#endregion
|
|
76
|
+
export { ActionConfigurationRejectedError, ActionInvocationError, ActionsUnavailableError, actions_exports, configureOpenCart, configureUpdateCart, getCart, isDefault, openCart, updateCart };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../../src/actions.ts"],"sourcesContent":["import * as Cause from \"effect/Cause\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as Scope from \"effect/Scope\";\n\nimport { Actions } from \"./effect/index.js\";\n\n/**\n * Promise-based access to Shopify's storefront cart actions, for consumers that\n * are not written in Effect.\n *\n * This is a facade over `./effect`'s `Actions`, not a reimplementation, so it\n * inherits the behaviour that matters: the one-shot upstream `configure()` slot\n * is claimed once and rebound thereafter, a missing runtime is distinguishable\n * from a refused configuration, and a configuration can be torn down.\n *\n * Errors arrive as rejections carrying the same tagged error instances the\n * Effect API fails with, so `instanceof ActionsUnavailableError` still works.\n */\n\nexport type Dispose = () => Promise<void>;\n\nexport type UpdateCartHandler = (\n\tdefaultHandler: () => Promise<Actions.UpdateCartResult>,\n\tpayload: Actions.UpdateCartPayload,\n\toptions?: Actions.UpdateCartOptions,\n) => Promise<Actions.UpdateCartResult>;\n\nexport type OpenCartHandler = (\n\tdefaultHandler: () => Promise<void>,\n) => Promise<void>;\n\nexport interface UpdateCartConfiguration {\n\t/**\n\t * Chooses the element `shopify:cart:*` events dispatch from. Returning\n\t * `null` — the default — leaves Shopify dispatching on `document`.\n\t *\n\t * Must be synchronous: Shopify uses the return value immediately.\n\t */\n\treadonly eventTarget?: (\n\t\tmeta: Actions.UpdateCartEventTargetMeta,\n\t) => EventTarget | null;\n\treadonly handler?: UpdateCartHandler;\n}\n\nexport interface OpenCartConfiguration {\n\treadonly handler: OpenCartHandler;\n}\n\n/**\n * Run to a promise that rejects with the failure itself.\n *\n * `Effect.runPromise` rejects with a `FiberFailure` wrapping the error, which\n * would force a plain-JS caller to understand Effect internals to get at their\n * own tagged error. Squashing the cause means `catch (e)` sees the\n * `ActionsUnavailableError` directly and `instanceof` behaves as expected.\n */\nconst settle = async <A, E>(\n\teffect: Effect.Effect<A, E, Actions.ShopifyStorefrontActions>,\n): Promise<A> => {\n\tconst exit = await Effect.runPromiseExit(\n\t\tEffect.provide(effect, Actions.layer),\n\t);\n\n\tif (Exit.isSuccess(exit)) return exit.value;\n\n\tthrow Cause.squash(exit.cause);\n};\n\n/**\n * Run a scoped configuration and hand back its teardown.\n *\n * The scope is deliberately not closed on success — the configuration must\n * outlive this call. It is closed if configuring fails, so a failed attempt\n * leaves nothing registered.\n */\nconst runScoped = async <E>(\n\teffect: Effect.Effect<\n\t\tvoid,\n\t\tE,\n\t\tActions.ShopifyStorefrontActions | Scope.Scope\n\t>,\n): Promise<Dispose> => {\n\tconst scope = Effect.runSync(Scope.make());\n\tconst dispose = () => Effect.runPromise(Scope.close(scope, Exit.void));\n\n\tconst exit = await Effect.runPromiseExit(\n\t\teffect.pipe(Scope.provide(scope), Effect.provide(Actions.layer)),\n\t);\n\n\tif (Exit.isFailure(exit)) {\n\t\tawait dispose();\n\t\tthrow Cause.squash(exit.cause);\n\t}\n\n\treturn dispose;\n};\n\n/** Read the current cart. */\nexport const getCart = (\n\tpayload?: Actions.GetCartPayload,\n\toptions?: Actions.GetCartOptions,\n): Promise<Actions.GetCartResult> => settle(Actions.getCart(payload, options));\n\n/** Mutate the cart through Shopify's action, honouring any configuration. */\nexport const updateCart = (\n\tpayload: Actions.UpdateCartPayload,\n\toptions?: Actions.UpdateCartOptions,\n): Promise<Actions.UpdateCartResult> =>\n\tsettle(Actions.updateCart(payload, options));\n\n/** Open the cart through Shopify's action. */\nexport const openCart = (): Promise<void> => settle(Actions.openCart);\n\n/** Upstream's own notion: `true` until the action's slot is claimed. */\nexport const isDefault = (\n\taction: Actions.ConfigurableActionName,\n): Promise<boolean> => settle(Actions.isDefault(action));\n\n/**\n * Install an `updateCart` configuration, resolving to its teardown.\n *\n * Calling this again rebinds rather than failing. A rejection with\n * `ActionConfigurationRejectedError` means something outside this library\n * claimed the action first.\n */\nexport const configureUpdateCart = (\n\tconfig: UpdateCartConfiguration = {},\n): Promise<Dispose> => {\n\tconst { eventTarget, handler } = config;\n\n\treturn runScoped(\n\t\tActions.configureUpdateCart({\n\t\t\t// A plain function cannot suspend, so wrapping it here makes the\n\t\t\t// synchronous-only contract impossible to violate from this surface.\n\t\t\teventTarget: (meta) => Effect.sync(() => eventTarget?.(meta) ?? null),\n\t\t\t...(handler === undefined\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\thandler: (defaultAction, payload, options) =>\n\t\t\t\t\t\t\tEffect.promise(() =>\n\t\t\t\t\t\t\t\thandler(\n\t\t\t\t\t\t\t\t\t() => Effect.runPromise(defaultAction),\n\t\t\t\t\t\t\t\t\tpayload,\n\t\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t}),\n\t);\n};\n\n/** Install an `openCart` configuration, resolving to its teardown. */\nexport const configureOpenCart = (\n\tconfig: OpenCartConfiguration,\n): Promise<Dispose> =>\n\trunScoped(\n\t\tActions.configureOpenCart({\n\t\t\thandler: (defaultAction) =>\n\t\t\t\tEffect.promise(() =>\n\t\t\t\t\tconfig.handler(() => Effect.runPromise(defaultAction)),\n\t\t\t\t),\n\t\t}),\n\t);\n\nexport type {\n\tActionName,\n\tConfigurableActionName,\n} from \"./effect/Actions/errors.js\";\nexport {\n\tActionConfigurationRejectedError,\n\tActionInvocationError,\n\tActionsUnavailableError,\n} from \"./effect/Actions/errors.js\";\n\nexport type {\n\tGetCartOptions,\n\tGetCartPayload,\n\tGetCartResult,\n\tUpdateCartEventTargetMeta,\n\tUpdateCartOptions,\n\tUpdateCartPayload,\n\tUpdateCartResult,\n} from \"./effect/Actions/types.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,IAAM,SAAS,OACd,WACgB;CAChB,MAAM,OAAO,MAAM,OAAO,eACzB,OAAO,QAAQ,QAAQ,KAAa,CACrC;CAEA,IAAI,KAAK,UAAU,IAAI,GAAG,OAAO,KAAK;CAEtC,MAAM,MAAM,OAAO,KAAK,KAAK;AAC9B;;;;;;;;AASA,IAAM,YAAY,OACjB,WAKsB;CACtB,MAAM,QAAQ,OAAO,QAAQ,MAAM,KAAK,CAAC;CACzC,MAAM,gBAAgB,OAAO,WAAW,MAAM,MAAM,OAAO,KAAK,IAAI,CAAC;CAErE,MAAM,OAAO,MAAM,OAAO,eACzB,OAAO,KAAK,MAAM,QAAQ,KAAK,GAAG,OAAO,QAAQ,KAAa,CAAC,CAChE;CAEA,IAAI,KAAK,UAAU,IAAI,GAAG;EACzB,MAAM,QAAQ;EACd,MAAM,MAAM,OAAO,KAAK,KAAK;CAC9B;CAEA,OAAO;AACR;;AAGA,IAAa,WACZ,SACA,YACoC,OAAO,UAAgB,SAAS,OAAO,CAAC;;AAG7E,IAAa,cACZ,SACA,YAEA,OAAO,aAAmB,SAAS,OAAO,CAAC;;AAG5C,IAAa,iBAAgC,OAAO,UAAgB;;AAGpE,IAAa,aACZ,WACsB,OAAO,YAAkB,MAAM,CAAC;;;;;;;;AASvD,IAAa,uBACZ,SAAkC,CAAC,MACb;CACtB,MAAM,EAAE,aAAa,YAAY;CAEjC,OAAO,UACN,sBAA4B;EAG3B,cAAc,SAAS,OAAO,WAAW,cAAc,IAAI,KAAK,IAAI;EACpE,GAAI,YAAY,KAAA,IACb,CAAC,IACD,EACA,UAAU,eAAe,SAAS,YACjC,OAAO,cACN,cACO,OAAO,WAAW,aAAa,GACrC,SACA,OACD,CACD,EACF;CACH,CAAC,CACF;AACD;;AAGA,IAAa,qBACZ,WAEA,UACC,oBAA0B,EACzB,UAAU,kBACT,OAAO,cACN,OAAO,cAAc,OAAO,WAAW,aAAa,CAAC,CACtD,EACF,CAAC,CACF"}
|