@magicstoreai/storefront-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,371 @@
1
+ // src/client.ts
2
+ import createClient from "openapi-fetch";
3
+
4
+ // src/errors.ts
5
+ var CODE_BY_STATUS = {
6
+ 400: "BAD_REQUEST",
7
+ 401: "UNAUTHENTICATED",
8
+ 403: "FORBIDDEN",
9
+ 404: "NOT_FOUND",
10
+ 405: "METHOD_NOT_ALLOWED",
11
+ 413: "PAYLOAD_TOO_LARGE",
12
+ 422: "VALIDATION_FAILED",
13
+ 429: "RATE_LIMITED",
14
+ 503: "SERVICE_UNAVAILABLE"
15
+ };
16
+ var MagicStoreError = class _MagicStoreError extends Error {
17
+ name = "MagicStoreError";
18
+ /** HTTP status; `0` when no answer arrived. */
19
+ status;
20
+ /** An API `code` (open to new values), or `NETWORK_ERROR` / `ABORTED`. */
21
+ code;
22
+ /** Localized, safe to show to a customer — when the API sent one. */
23
+ detail;
24
+ /** Per-field failures on `VALIDATION_FAILED` and per-line conflicts. */
25
+ errors;
26
+ /** `X-Request-Id` of the call. Quote it when reporting a problem. */
27
+ requestId;
28
+ /** Seconds to wait before trying again (`Retry-After`), when the API said. */
29
+ retryAfter;
30
+ /** The key a money-moving call was sent with: retry with the same one. */
31
+ idempotencyKey;
32
+ /** The problem document as received, when there was one. */
33
+ problem;
34
+ constructor(init) {
35
+ super(init.message, init.cause === void 0 ? void 0 : { cause: init.cause });
36
+ this.status = init.status;
37
+ this.code = init.code;
38
+ this.detail = init.detail;
39
+ this.errors = init.errors ?? [];
40
+ this.requestId = init.requestId;
41
+ this.retryAfter = init.retryAfter;
42
+ this.idempotencyKey = init.idempotencyKey;
43
+ this.problem = init.problem;
44
+ }
45
+ /** From a non-2xx answer. A body that is not a problem document still yields a code. */
46
+ static fromResponse(response, body, context) {
47
+ const problem = isRecord(body) ? body : void 0;
48
+ const code = typeof problem?.code === "string" ? problem.code : CODE_BY_STATUS[response.status] ?? (response.status >= 500 ? "INTERNAL_ERROR" : "BAD_REQUEST");
49
+ const requestId = (typeof problem?.requestId === "string" ? problem.requestId : void 0) ?? response.headers.get("X-Request-Id") ?? context.requestId;
50
+ return new _MagicStoreError({
51
+ status: response.status,
52
+ code,
53
+ message: problem?.title ?? `${response.status} ${code}`,
54
+ detail: problem?.detail,
55
+ errors: Array.isArray(problem?.errors) ? problem.errors : void 0,
56
+ requestId,
57
+ retryAfter: retryAfterSeconds(response),
58
+ idempotencyKey: context.idempotencyKey,
59
+ problem
60
+ });
61
+ }
62
+ /** No answer: the request never completed. */
63
+ static fromFailure(cause, context) {
64
+ return new _MagicStoreError({
65
+ status: 0,
66
+ code: context.aborted ? "ABORTED" : "NETWORK_ERROR",
67
+ message: context.aborted ? "The request was aborted." : "The request did not complete.",
68
+ requestId: context.requestId,
69
+ idempotencyKey: context.idempotencyKey,
70
+ cause
71
+ });
72
+ }
73
+ };
74
+ function retryAfterSeconds(response) {
75
+ const value = response.headers.get("Retry-After");
76
+ if (value === null) {
77
+ return void 0;
78
+ }
79
+ const seconds = Number(value);
80
+ return Number.isFinite(seconds) && seconds >= 0 ? seconds : void 0;
81
+ }
82
+ function isRecord(value) {
83
+ return typeof value === "object" && value !== null && !Array.isArray(value);
84
+ }
85
+
86
+ // src/generated/operations.ts
87
+ var API_VERSION = "2.0.0-alpha.1";
88
+ var operationTable = {
89
+ analyticsEventsStore: { method: "POST", path: "/analytics/events", idempotencyKey: false, customer: false, pagination: null },
90
+ authClick: { method: "POST", path: "/auth/click", idempotencyKey: false, customer: false, pagination: null },
91
+ authOq: { method: "POST", path: "/auth/oq", idempotencyKey: false, customer: false, pagination: null },
92
+ authOtp: { method: "POST", path: "/auth/otp", idempotencyKey: false, customer: false, pagination: null },
93
+ authOtpVerification: { method: "POST", path: "/auth/otp/verification", idempotencyKey: false, customer: false, pagination: null },
94
+ authTelegram: { method: "POST", path: "/auth/telegram", idempotencyKey: false, customer: false, pagination: null },
95
+ authTokenDestroy: { method: "DELETE", path: "/auth/token", idempotencyKey: false, customer: true, pagination: null },
96
+ authTokenRefresh: { method: "POST", path: "/auth/token/refresh", idempotencyKey: false, customer: false, pagination: null },
97
+ cartsAttributes: { method: "PUT", path: "/carts/{id}/attributes", idempotencyKey: false, customer: false, pagination: null },
98
+ cartsBuyerIdentity: { method: "PUT", path: "/carts/{id}/buyer-identity", idempotencyKey: false, customer: true, pagination: null },
99
+ cartsDiscountCodes: { method: "PUT", path: "/carts/{id}/discount-codes", idempotencyKey: false, customer: false, pagination: null },
100
+ cartsGift: { method: "PUT", path: "/carts/{id}/gift", idempotencyKey: false, customer: false, pagination: null },
101
+ cartsLinesDestroy: { method: "DELETE", path: "/carts/{id}/lines/{lineId}", idempotencyKey: false, customer: false, pagination: null },
102
+ cartsLinesStore: { method: "POST", path: "/carts/{id}/lines", idempotencyKey: false, customer: false, pagination: null },
103
+ cartsLinesUpdate: { method: "PATCH", path: "/carts/{id}/lines/{lineId}", idempotencyKey: false, customer: false, pagination: null },
104
+ cartsNote: { method: "PUT", path: "/carts/{id}/note", idempotencyKey: false, customer: false, pagination: null },
105
+ cartsPoints: { method: "PUT", path: "/carts/{id}/points", idempotencyKey: false, customer: true, pagination: null },
106
+ cartsShow: { method: "GET", path: "/carts/{id}", idempotencyKey: false, customer: false, pagination: null },
107
+ cartsStore: { method: "POST", path: "/carts", idempotencyKey: false, customer: false, pagination: null },
108
+ chatConversationsCustomer: { method: "PUT", path: "/chat/conversations/{id}/customer", idempotencyKey: false, customer: true, pagination: null },
109
+ chatConversationsIndex: { method: "GET", path: "/chat/conversations", idempotencyKey: false, customer: true, pagination: "offset" },
110
+ chatConversationsMessagesIndex: { method: "GET", path: "/chat/conversations/{id}/messages", idempotencyKey: false, customer: false, pagination: "cursor" },
111
+ chatConversationsMessagesStore: { method: "POST", path: "/chat/conversations/{id}/messages", idempotencyKey: false, customer: false, pagination: null },
112
+ chatConversationsOperatorRequest: { method: "PUT", path: "/chat/conversations/{id}/operator-request", idempotencyKey: false, customer: false, pagination: null },
113
+ chatConversationsReadMarker: { method: "PUT", path: "/chat/conversations/{id}/read-marker", idempotencyKey: false, customer: false, pagination: null },
114
+ chatConversationsShow: { method: "GET", path: "/chat/conversations/{id}", idempotencyKey: false, customer: false, pagination: null },
115
+ chatConversationsStore: { method: "POST", path: "/chat/conversations", idempotencyKey: false, customer: false, pagination: null },
116
+ checkoutsCompletion: { method: "POST", path: "/checkouts/{id}/completion", idempotencyKey: true, customer: false, pagination: null },
117
+ checkoutsContact: { method: "PUT", path: "/checkouts/{id}/contact", idempotencyKey: false, customer: false, pagination: null },
118
+ checkoutsDeliveryOption: { method: "PUT", path: "/checkouts/{id}/delivery-option", idempotencyKey: false, customer: false, pagination: null },
119
+ checkoutsDeliveryOptions: { method: "GET", path: "/checkouts/{id}/delivery-options", idempotencyKey: false, customer: false, pagination: null },
120
+ checkoutsPaymentMethod: { method: "PUT", path: "/checkouts/{id}/payment-method", idempotencyKey: false, customer: false, pagination: null },
121
+ checkoutsPaymentMethods: { method: "GET", path: "/checkouts/{id}/payment-methods", idempotencyKey: false, customer: false, pagination: null },
122
+ checkoutsPickupLocation: { method: "PUT", path: "/checkouts/{id}/pickup-location", idempotencyKey: false, customer: false, pagination: null },
123
+ checkoutsShippingAddress: { method: "PUT", path: "/checkouts/{id}/shipping-address", idempotencyKey: false, customer: false, pagination: null },
124
+ checkoutsShow: { method: "GET", path: "/checkouts/{id}", idempotencyKey: false, customer: false, pagination: null },
125
+ checkoutsStore: { method: "POST", path: "/checkouts", idempotencyKey: false, customer: false, pagination: null },
126
+ collectionsFilters: { method: "GET", path: "/collections/{handle}/filters", idempotencyKey: false, customer: false, pagination: null },
127
+ collectionsIndex: { method: "GET", path: "/collections", idempotencyKey: false, customer: false, pagination: "offset" },
128
+ collectionsProducts: { method: "GET", path: "/collections/{handle}/products", idempotencyKey: false, customer: false, pagination: "offset" },
129
+ collectionsShow: { method: "GET", path: "/collections/{handle}", idempotencyKey: false, customer: false, pagination: null },
130
+ collectionsTree: { method: "GET", path: "/collections/tree", idempotencyKey: false, customer: false, pagination: null },
131
+ contacts: { method: "GET", path: "/contacts", idempotencyKey: false, customer: false, pagination: null },
132
+ customerAddressesDestroy: { method: "DELETE", path: "/customer/addresses/{addressId}", idempotencyKey: false, customer: true, pagination: null },
133
+ customerAddressesIndex: { method: "GET", path: "/customer/addresses", idempotencyKey: false, customer: true, pagination: null },
134
+ customerAddressesShow: { method: "GET", path: "/customer/addresses/{addressId}", idempotencyKey: false, customer: true, pagination: null },
135
+ customerAddressesStore: { method: "POST", path: "/customer/addresses", idempotencyKey: false, customer: true, pagination: null },
136
+ customerAddressesUpdate: { method: "PUT", path: "/customer/addresses/{addressId}", idempotencyKey: false, customer: true, pagination: null },
137
+ customerAmbassadorPayoutsIndex: { method: "GET", path: "/customer/ambassador/payouts", idempotencyKey: false, customer: true, pagination: "offset" },
138
+ customerAmbassadorPayoutsShow: { method: "GET", path: "/customer/ambassador/payouts/{payoutId}", idempotencyKey: false, customer: true, pagination: null },
139
+ customerAmbassadorPayoutsStore: { method: "POST", path: "/customer/ambassador/payouts", idempotencyKey: true, customer: true, pagination: null },
140
+ customerAmbassadorReferrals: { method: "GET", path: "/customer/ambassador/referrals", idempotencyKey: false, customer: true, pagination: "offset" },
141
+ customerAmbassadorShow: { method: "GET", path: "/customer/ambassador", idempotencyKey: false, customer: true, pagination: null },
142
+ customerAmbassadorStats: { method: "GET", path: "/customer/ambassador/stats", idempotencyKey: false, customer: true, pagination: null },
143
+ customerDeletionRequest: { method: "POST", path: "/customer/deletion-request", idempotencyKey: false, customer: true, pagination: null },
144
+ customerOrdersCancellation: { method: "POST", path: "/customer/orders/{id}/cancellation", idempotencyKey: false, customer: true, pagination: null },
145
+ customerOrdersIndex: { method: "GET", path: "/customer/orders", idempotencyKey: false, customer: true, pagination: "offset" },
146
+ customerOrdersReorder: { method: "POST", path: "/customer/orders/{id}/reorder", idempotencyKey: false, customer: true, pagination: null },
147
+ customerOrdersShow: { method: "GET", path: "/customer/orders/{id}", idempotencyKey: false, customer: true, pagination: null },
148
+ customerPhoneVerification: { method: "POST", path: "/customer/phone-verification", idempotencyKey: false, customer: true, pagination: null },
149
+ customerPreOrdersIndex: { method: "GET", path: "/customer/pre-orders", idempotencyKey: false, customer: true, pagination: "offset" },
150
+ customerPreOrdersShow: { method: "GET", path: "/customer/pre-orders/{id}", idempotencyKey: false, customer: true, pagination: null },
151
+ customerReferralInvitees: { method: "GET", path: "/customer/referral/invitees", idempotencyKey: false, customer: true, pagination: "offset" },
152
+ customerReferralShow: { method: "GET", path: "/customer/referral", idempotencyKey: false, customer: true, pagination: null },
153
+ customerReviewsAwaiting: { method: "GET", path: "/customer/reviews/awaiting", idempotencyKey: false, customer: true, pagination: null },
154
+ customerReviewsIndex: { method: "GET", path: "/customer/reviews", idempotencyKey: false, customer: true, pagination: "offset" },
155
+ customerRewardsDiscountCodesIndex: { method: "GET", path: "/customer/rewards/discount-codes", idempotencyKey: false, customer: true, pagination: "offset" },
156
+ customerRewardsDiscountCodesShow: { method: "GET", path: "/customer/rewards/discount-codes/{id}", idempotencyKey: false, customer: true, pagination: null },
157
+ customerRewardsRedemptionsStore: { method: "POST", path: "/customer/rewards/redemptions", idempotencyKey: true, customer: true, pagination: null },
158
+ customerShow: { method: "GET", path: "/customer", idempotencyKey: false, customer: true, pagination: null },
159
+ customerUpdate: { method: "PATCH", path: "/customer", idempotencyKey: false, customer: true, pagination: null },
160
+ customerWalletActivities: { method: "GET", path: "/customer/wallet/activities", idempotencyKey: false, customer: true, pagination: "offset" },
161
+ customerWalletShow: { method: "GET", path: "/customer/wallet", idempotencyKey: false, customer: true, pagination: null },
162
+ customerWishlistAdd: { method: "PUT", path: "/customer/wishlist/{productId}", idempotencyKey: false, customer: true, pagination: null },
163
+ customerWishlistIndex: { method: "GET", path: "/customer/wishlist", idempotencyKey: false, customer: true, pagination: "offset" },
164
+ customerWishlistRemove: { method: "DELETE", path: "/customer/wishlist/{productId}", idempotencyKey: false, customer: true, pagination: null },
165
+ home: { method: "GET", path: "/home", idempotencyKey: false, customer: false, pagination: null },
166
+ locationsIndex: { method: "GET", path: "/locations", idempotencyKey: false, customer: false, pagination: null },
167
+ mediaUploadsStore: { method: "POST", path: "/media/uploads", idempotencyKey: false, customer: true, pagination: null },
168
+ menusShow: { method: "GET", path: "/menus/{handle}", idempotencyKey: false, customer: false, pagination: null },
169
+ ordersPayment: { method: "GET", path: "/orders/{id}/payment", idempotencyKey: false, customer: false, pagination: null },
170
+ ordersPaymentLink: { method: "POST", path: "/orders/{id}/payment-link", idempotencyKey: true, customer: false, pagination: null },
171
+ pagesIndex: { method: "GET", path: "/pages", idempotencyKey: false, customer: false, pagination: null },
172
+ pagesShow: { method: "GET", path: "/pages/{handle}", idempotencyKey: false, customer: false, pagination: null },
173
+ ping: { method: "GET", path: "/ping", idempotencyKey: false, customer: false, pagination: null },
174
+ preOrdersStore: { method: "POST", path: "/pre-orders", idempotencyKey: false, customer: false, pagination: null },
175
+ productsIndex: { method: "GET", path: "/products", idempotencyKey: false, customer: false, pagination: "offset" },
176
+ productsRecommendations: { method: "GET", path: "/products/{handle}/recommendations", idempotencyKey: false, customer: false, pagination: null },
177
+ productsReviews: { method: "GET", path: "/products/{handle}/reviews", idempotencyKey: false, customer: false, pagination: "offset" },
178
+ productsShow: { method: "GET", path: "/products/{handle}", idempotencyKey: false, customer: false, pagination: null },
179
+ realtimeAuthorizationsStore: { method: "POST", path: "/realtime/authorizations", idempotencyKey: false, customer: false, pagination: null },
180
+ reelsIndex: { method: "GET", path: "/reels", idempotencyKey: false, customer: false, pagination: "offset" },
181
+ referralProgram: { method: "GET", path: "/referral-program", idempotencyKey: false, customer: false, pagination: null },
182
+ reviewsLike: { method: "PUT", path: "/reviews/{id}/like", idempotencyKey: false, customer: true, pagination: null },
183
+ reviewsSite: { method: "GET", path: "/reviews/site", idempotencyKey: false, customer: false, pagination: "offset" },
184
+ reviewsSiteStore: { method: "POST", path: "/reviews/site", idempotencyKey: false, customer: true, pagination: null },
185
+ reviewsStore: { method: "POST", path: "/reviews", idempotencyKey: false, customer: true, pagination: null },
186
+ reviewsUnlike: { method: "DELETE", path: "/reviews/{id}/like", idempotencyKey: false, customer: true, pagination: null },
187
+ rewardsEarningRules: { method: "GET", path: "/rewards/earning-rules", idempotencyKey: false, customer: false, pagination: null },
188
+ rewardsSpendingRules: { method: "GET", path: "/rewards/spending-rules", idempotencyKey: false, customer: false, pagination: null },
189
+ search: { method: "GET", path: "/search", idempotencyKey: false, customer: false, pagination: "offset" },
190
+ searchFilters: { method: "GET", path: "/search/filters", idempotencyKey: false, customer: false, pagination: null },
191
+ searchSuggestions: { method: "GET", path: "/search/suggestions", idempotencyKey: false, customer: false, pagination: null },
192
+ searchTrending: { method: "GET", path: "/search/trending", idempotencyKey: false, customer: false, pagination: null },
193
+ shop: { method: "GET", path: "/shop", idempotencyKey: false, customer: false, pagination: null },
194
+ sitemap: { method: "GET", path: "/sitemap", idempotencyKey: false, customer: false, pagination: "offset" },
195
+ themeSectionSchema: { method: "GET", path: "/theme/section-schema", idempotencyKey: false, customer: false, pagination: null }
196
+ };
197
+
198
+ // src/pagination.ts
199
+ async function* paginate(call, operationId, style, [input, options]) {
200
+ const base = input ?? {};
201
+ let query = { ...base.query };
202
+ for (; ; ) {
203
+ const args = [{ ...base, query }, options];
204
+ const body = await call(operationId, ...args);
205
+ for (const item of body.data ?? []) {
206
+ yield item;
207
+ }
208
+ if (style === "offset") {
209
+ const pagination = body.meta?.pagination;
210
+ if (!pagination?.hasNextPage) {
211
+ return;
212
+ }
213
+ query = { ...query, page: pagination.page + 1 };
214
+ } else {
215
+ const cursor = body.meta?.cursor;
216
+ if (!cursor?.hasNextPage || cursor.next === null) {
217
+ return;
218
+ }
219
+ query = { ...query, cursor: cursor.next };
220
+ }
221
+ }
222
+ }
223
+
224
+ // src/client.ts
225
+ var RETRYABLE_STATUS = (status) => status === 429 || status >= 500;
226
+ function createStorefrontClient(options) {
227
+ const baseUrl = resolveBaseUrl(options);
228
+ const fetchImpl = options.fetch ?? globalThis.fetch;
229
+ const retry = options.retry === false ? null : {
230
+ retries: options.retry?.retries ?? 2,
231
+ baseDelayMs: options.retry?.baseDelayMs ?? 300,
232
+ maxDelayMs: options.retry?.maxDelayMs ?? 1e4
233
+ };
234
+ const transport = createClient({
235
+ baseUrl,
236
+ // Resolved on each call: a test (or an app) may swap the global fetch later.
237
+ fetch: (request) => fetchImpl(request)
238
+ });
239
+ async function call(operationId, ...[input, requestOptions]) {
240
+ const operation = operationTable[operationId];
241
+ if (operation === void 0) {
242
+ throw new TypeError(`Unknown Storefront API operation: ${String(operationId)}`);
243
+ }
244
+ const request = input ?? {};
245
+ const perCall = requestOptions ?? {};
246
+ const requestId = perCall.requestId ?? randomId();
247
+ const idempotencyKey = operation.idempotencyKey ? perCall.idempotencyKey ?? randomId() : void 0;
248
+ const headers = await buildHeaders(request, perCall, requestId, idempotencyKey);
249
+ const tries = operation.method === "GET" && retry !== null ? retry.retries + 1 : 1;
250
+ for (let attempt = 1; ; attempt++) {
251
+ let result;
252
+ try {
253
+ result = await transport.request(
254
+ operation.method,
255
+ operation.path,
256
+ {
257
+ params: { path: request.path, query: request.query },
258
+ body: request.body,
259
+ headers,
260
+ signal: perCall.signal
261
+ }
262
+ );
263
+ } catch (cause) {
264
+ const aborted = perCall.signal?.aborted === true;
265
+ if (!aborted && attempt < tries) {
266
+ await sleep(backoff(attempt, retry), perCall.signal);
267
+ continue;
268
+ }
269
+ throw MagicStoreError.fromFailure(cause, { requestId, idempotencyKey, aborted });
270
+ }
271
+ const { response } = result;
272
+ if (response.ok) {
273
+ return response.status === 204 ? void 0 : result.data;
274
+ }
275
+ const error = MagicStoreError.fromResponse(response, result.error, {
276
+ requestId,
277
+ idempotencyKey
278
+ });
279
+ if (attempt < tries && RETRYABLE_STATUS(response.status)) {
280
+ const wait = error.retryAfter !== void 0 ? error.retryAfter * 1e3 : backoff(attempt, retry);
281
+ if (wait <= retry.maxDelayMs) {
282
+ await sleep(wait, perCall.signal);
283
+ continue;
284
+ }
285
+ }
286
+ throw error;
287
+ }
288
+ }
289
+ async function buildHeaders(request, perCall, requestId, idempotencyKey) {
290
+ const headers = { Accept: "application/json", ...options.headers };
291
+ if (options.storefrontToken) {
292
+ headers["X-Storefront-Token"] = options.storefrontToken;
293
+ }
294
+ const locale = perCall.locale ?? options.locale;
295
+ if (locale) {
296
+ headers["Accept-Language"] = locale;
297
+ }
298
+ const token = perCall.customerToken !== void 0 ? perCall.customerToken : await readToken(options.customerToken);
299
+ if (token) {
300
+ headers["Authorization"] = `Bearer ${token}`;
301
+ }
302
+ for (const [name, value] of Object.entries(request.header ?? {})) {
303
+ if (value !== void 0 && value !== null) {
304
+ headers[name] = String(value);
305
+ }
306
+ }
307
+ headers["X-Request-Id"] = requestId;
308
+ if (idempotencyKey !== void 0) {
309
+ headers["Idempotency-Key"] = idempotencyKey;
310
+ }
311
+ return { ...headers, ...perCall.headers };
312
+ }
313
+ const client = { call };
314
+ client.paginate = (operationId, ...args) => paginate(call, operationId, operationTable[operationId].pagination, args);
315
+ for (const operationId of Object.keys(operationTable)) {
316
+ client[operationId] = (...args) => call(operationId, ...args);
317
+ }
318
+ return client;
319
+ }
320
+ function operationInput(_operationId, input) {
321
+ return input;
322
+ }
323
+ function resolveBaseUrl(options) {
324
+ if (options.baseUrl) {
325
+ return options.baseUrl.replace(/\/+$/, "");
326
+ }
327
+ if (options.shopDomain) {
328
+ const host = options.shopDomain.replace(/^https?:\/\//, "").replace(/\/+$/, "");
329
+ return `https://${host}/api/v2/storefront`;
330
+ }
331
+ throw new TypeError("createStorefrontClient needs a shopDomain or a baseUrl.");
332
+ }
333
+ async function readToken(source) {
334
+ if (typeof source === "function") {
335
+ return await source() ?? null;
336
+ }
337
+ return source ?? null;
338
+ }
339
+ function randomId() {
340
+ return globalThis.crypto.randomUUID();
341
+ }
342
+ function backoff(attempt, retry) {
343
+ const ceiling = Math.min(retry.maxDelayMs, retry.baseDelayMs * 2 ** (attempt - 1));
344
+ return Math.round(Math.random() * ceiling);
345
+ }
346
+ function sleep(ms, signal) {
347
+ return new Promise((resolve, reject) => {
348
+ if (signal?.aborted) {
349
+ reject(signal.reason);
350
+ return;
351
+ }
352
+ const timer = setTimeout(() => {
353
+ signal?.removeEventListener("abort", onAbort);
354
+ resolve();
355
+ }, ms);
356
+ const onAbort = () => {
357
+ clearTimeout(timer);
358
+ reject(signal?.reason);
359
+ };
360
+ signal?.addEventListener("abort", onAbort, { once: true });
361
+ });
362
+ }
363
+ export {
364
+ API_VERSION,
365
+ MagicStoreError,
366
+ createStorefrontClient,
367
+ operationInput,
368
+ operationTable,
369
+ retryAfterSeconds
370
+ };
371
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/errors.ts","../src/generated/operations.ts","../src/pagination.ts"],"sourcesContent":["import createClient from 'openapi-fetch';\nimport { MagicStoreError } from './errors';\nimport { operationTable } from './generated/operations';\nimport type { paths } from './generated/schema';\nimport { paginate } from './pagination';\nimport type {\n OperationArgs,\n OperationId,\n OperationInput,\n OperationMethods,\n OperationResult,\n PageItem,\n PaginatedOperationId,\n RequestOptions,\n} from './types';\n\n/** A customer access token, or where to read it from on every call (it rotates hourly). */\nexport type CustomerTokenSource =\n string | null | (() => string | null | undefined | Promise<string | null | undefined>);\n\nexport interface RetryOptions {\n /** Retries after the first try. Default 2. */\n retries?: number;\n /** First backoff; doubled per retry, with jitter. Default 300 ms. */\n baseDelayMs?: number;\n /** Longest wait between tries — a longer `Retry-After` is not waited out. Default 10 s. */\n maxDelayMs?: number;\n}\n\nexport interface StorefrontClientOptions {\n /** The shop's storefront domain, e.g. `shop.example.uz` → `https://shop.example.uz/api/v2/storefront`. */\n shopDomain?: string;\n /** The full API base URL, instead of `shopDomain`. */\n baseUrl?: string;\n /** `X-Storefront-Token` — identifies the shop when the host is not one of its domains. */\n storefrontToken?: string;\n /** Default language (`Accept-Language`); the shop's default when omitted. */\n locale?: string;\n /** The signed-in customer, sent as `Authorization: Bearer` when present. */\n customerToken?: CustomerTokenSource;\n /**\n * Retry policy for `GET`s answered `429` or `5xx`, or not answered at all. Writes are never\n * retried by the client. `false` turns retries off.\n */\n retry?: RetryOptions | false;\n /** A `fetch` implementation; the global one by default. */\n fetch?: typeof globalThis.fetch;\n /** Headers sent on every call. */\n headers?: Record<string, string>;\n}\n\nexport type StorefrontClient = OperationMethods & {\n /** Calls an operation by its `operationId` — what every named method does. */\n call<K extends OperationId>(\n operationId: K,\n ...args: OperationArgs<K>\n ): Promise<OperationResult<K>>;\n /**\n * Every item of a paginated operation, page after page (`page` for offset operations,\n * `cursor` for feeds). Stops when the API says there is no next page.\n */\n paginate<K extends PaginatedOperationId>(\n operationId: K,\n ...args: OperationArgs<K>\n ): AsyncGenerator<PageItem<K>, void, undefined>;\n};\n\ninterface OperationRequest {\n path?: Record<string, unknown>;\n query?: Record<string, unknown>;\n header?: Record<string, unknown>;\n body?: unknown;\n}\n\nconst RETRYABLE_STATUS = (status: number): boolean => status === 429 || status >= 500;\n\nexport function createStorefrontClient(options: StorefrontClientOptions): StorefrontClient {\n const baseUrl = resolveBaseUrl(options);\n const fetchImpl = options.fetch ?? globalThis.fetch;\n const retry =\n options.retry === false\n ? null\n : {\n retries: options.retry?.retries ?? 2,\n baseDelayMs: options.retry?.baseDelayMs ?? 300,\n maxDelayMs: options.retry?.maxDelayMs ?? 10_000,\n };\n\n const transport = createClient<paths>({\n baseUrl,\n // Resolved on each call: a test (or an app) may swap the global fetch later.\n fetch: (request) => fetchImpl(request),\n });\n\n async function call<K extends OperationId>(\n operationId: K,\n ...[input, requestOptions]: OperationArgs<K>\n ): Promise<OperationResult<K>> {\n const operation = operationTable[operationId];\n if (operation === undefined) {\n throw new TypeError(`Unknown Storefront API operation: ${String(operationId)}`);\n }\n\n const request = (input ?? {}) as OperationRequest;\n const perCall: RequestOptions = requestOptions ?? {};\n const requestId = perCall.requestId ?? randomId();\n const idempotencyKey = operation.idempotencyKey\n ? (perCall.idempotencyKey ?? randomId())\n : undefined;\n const headers = await buildHeaders(request, perCall, requestId, idempotencyKey);\n const tries = operation.method === 'GET' && retry !== null ? retry.retries + 1 : 1;\n\n for (let attempt = 1; ; attempt++) {\n let result: { data?: unknown; error?: unknown; response: Response };\n try {\n result = await transport.request(\n operation.method as never,\n operation.path as never,\n {\n params: { path: request.path, query: request.query },\n body: request.body,\n headers,\n signal: perCall.signal,\n } as never,\n );\n } catch (cause) {\n const aborted = perCall.signal?.aborted === true;\n if (!aborted && attempt < tries) {\n await sleep(backoff(attempt, retry!), perCall.signal);\n continue;\n }\n throw MagicStoreError.fromFailure(cause, { requestId, idempotencyKey, aborted });\n }\n\n const { response } = result;\n if (response.ok) {\n return (response.status === 204 ? undefined : result.data) as OperationResult<K>;\n }\n\n const error = MagicStoreError.fromResponse(response, result.error, {\n requestId,\n idempotencyKey,\n });\n if (attempt < tries && RETRYABLE_STATUS(response.status)) {\n const wait =\n error.retryAfter !== undefined ? error.retryAfter * 1000 : backoff(attempt, retry!);\n if (wait <= retry!.maxDelayMs) {\n await sleep(wait, perCall.signal);\n continue;\n }\n }\n throw error;\n }\n }\n\n async function buildHeaders(\n request: OperationRequest,\n perCall: RequestOptions,\n requestId: string,\n idempotencyKey: string | undefined,\n ): Promise<Record<string, string>> {\n const headers: Record<string, string> = { Accept: 'application/json', ...options.headers };\n\n if (options.storefrontToken) {\n headers['X-Storefront-Token'] = options.storefrontToken;\n }\n const locale = perCall.locale ?? options.locale;\n if (locale) {\n headers['Accept-Language'] = locale;\n }\n const token =\n perCall.customerToken !== undefined\n ? perCall.customerToken\n : await readToken(options.customerToken);\n if (token) {\n headers['Authorization'] = `Bearer ${token}`;\n }\n for (const [name, value] of Object.entries(request.header ?? {})) {\n if (value !== undefined && value !== null) {\n headers[name] = String(value);\n }\n }\n headers['X-Request-Id'] = requestId;\n if (idempotencyKey !== undefined) {\n headers['Idempotency-Key'] = idempotencyKey;\n }\n\n return { ...headers, ...perCall.headers };\n }\n\n const client = { call } as StorefrontClient;\n client.paginate = <K extends PaginatedOperationId>(operationId: K, ...args: OperationArgs<K>) =>\n paginate(call, operationId, operationTable[operationId].pagination, args);\n\n for (const operationId of Object.keys(operationTable) as OperationId[]) {\n (client as unknown as Record<string, unknown>)[operationId] = (\n ...args: OperationArgs<typeof operationId>\n ) => call(operationId, ...args);\n }\n\n return client;\n}\n\n/** For callers that build an input apart from the call. */\nexport function operationInput<K extends OperationId>(\n _operationId: K,\n input: OperationInput<K>,\n): OperationInput<K> {\n return input;\n}\n\nfunction resolveBaseUrl(options: StorefrontClientOptions): string {\n if (options.baseUrl) {\n return options.baseUrl.replace(/\\/+$/, '');\n }\n if (options.shopDomain) {\n const host = options.shopDomain.replace(/^https?:\\/\\//, '').replace(/\\/+$/, '');\n return `https://${host}/api/v2/storefront`;\n }\n throw new TypeError('createStorefrontClient needs a shopDomain or a baseUrl.');\n}\n\nasync function readToken(source: CustomerTokenSource | undefined): Promise<string | null> {\n if (typeof source === 'function') {\n return (await source()) ?? null;\n }\n return source ?? null;\n}\n\nfunction randomId(): string {\n return globalThis.crypto.randomUUID();\n}\n\n/** Exponential backoff with full jitter: a random wait up to base × 2^(attempt-1), capped. */\nfunction backoff(attempt: number, retry: Required<RetryOptions>): number {\n const ceiling = Math.min(retry.maxDelayMs, retry.baseDelayMs * 2 ** (attempt - 1));\n return Math.round(Math.random() * ceiling);\n}\n\nfunction sleep(ms: number, signal: AbortSignal | undefined): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(signal.reason);\n return;\n }\n const timer = setTimeout(() => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n const onAbort = (): void => {\n clearTimeout(timer);\n reject(signal?.reason);\n };\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n","import type { Problem, ProblemCode } from './types';\n\n/** No answer at all: the network failed, or the call was aborted. Never sent by the API. */\nexport type ClientErrorCode = 'NETWORK_ERROR' | 'ABORTED';\n\nexport type MagicStoreErrorCode = ProblemCode | ClientErrorCode;\n\n/** One failed rule on a validation failure or a per-line conflict. */\nexport type ProblemFieldError = NonNullable<Problem['errors']>[number];\n\nconst CODE_BY_STATUS: Record<number, ProblemCode> = {\n 400: 'BAD_REQUEST',\n 401: 'UNAUTHENTICATED',\n 403: 'FORBIDDEN',\n 404: 'NOT_FOUND',\n 405: 'METHOD_NOT_ALLOWED',\n 413: 'PAYLOAD_TOO_LARGE',\n 422: 'VALIDATION_FAILED',\n 429: 'RATE_LIMITED',\n 503: 'SERVICE_UNAVAILABLE',\n};\n\n/**\n * Every failed call. `code` is what to branch on — never the message, which is localized.\n *\n * ```ts\n * try {\n * await client.checkoutsCompletion({ path: { id } });\n * } catch (error) {\n * if (error instanceof MagicStoreError && error.code === 'CHECKOUT_NOT_READY') { … }\n * }\n * ```\n */\nexport class MagicStoreError extends Error {\n override readonly name = 'MagicStoreError';\n\n /** HTTP status; `0` when no answer arrived. */\n readonly status: number;\n\n /** An API `code` (open to new values), or `NETWORK_ERROR` / `ABORTED`. */\n readonly code: MagicStoreErrorCode | (string & {});\n\n /** Localized, safe to show to a customer — when the API sent one. */\n readonly detail: string | undefined;\n\n /** Per-field failures on `VALIDATION_FAILED` and per-line conflicts. */\n readonly errors: ProblemFieldError[];\n\n /** `X-Request-Id` of the call. Quote it when reporting a problem. */\n readonly requestId: string;\n\n /** Seconds to wait before trying again (`Retry-After`), when the API said. */\n readonly retryAfter: number | undefined;\n\n /** The key a money-moving call was sent with: retry with the same one. */\n readonly idempotencyKey: string | undefined;\n\n /** The problem document as received, when there was one. */\n readonly problem: Partial<Problem> | undefined;\n\n constructor(init: {\n status: number;\n code: MagicStoreErrorCode | (string & {});\n message: string;\n requestId: string;\n detail?: string | undefined;\n errors?: ProblemFieldError[] | undefined;\n retryAfter?: number | undefined;\n idempotencyKey?: string | undefined;\n problem?: Partial<Problem> | undefined;\n cause?: unknown;\n }) {\n super(init.message, init.cause === undefined ? undefined : { cause: init.cause });\n this.status = init.status;\n this.code = init.code;\n this.detail = init.detail;\n this.errors = init.errors ?? [];\n this.requestId = init.requestId;\n this.retryAfter = init.retryAfter;\n this.idempotencyKey = init.idempotencyKey;\n this.problem = init.problem;\n }\n\n /** From a non-2xx answer. A body that is not a problem document still yields a code. */\n static fromResponse(\n response: Response,\n body: unknown,\n context: { requestId: string; idempotencyKey?: string | undefined },\n ): MagicStoreError {\n const problem = isRecord(body) ? (body as Partial<Problem>) : undefined;\n const code =\n typeof problem?.code === 'string'\n ? problem.code\n : (CODE_BY_STATUS[response.status] ??\n (response.status >= 500 ? 'INTERNAL_ERROR' : 'BAD_REQUEST'));\n const requestId =\n (typeof problem?.requestId === 'string' ? problem.requestId : undefined) ??\n response.headers.get('X-Request-Id') ??\n context.requestId;\n\n return new MagicStoreError({\n status: response.status,\n code,\n message: problem?.title ?? `${response.status} ${code}`,\n detail: problem?.detail,\n errors: Array.isArray(problem?.errors) ? problem.errors : undefined,\n requestId,\n retryAfter: retryAfterSeconds(response),\n idempotencyKey: context.idempotencyKey,\n problem,\n });\n }\n\n /** No answer: the request never completed. */\n static fromFailure(\n cause: unknown,\n context: { requestId: string; idempotencyKey?: string | undefined; aborted: boolean },\n ): MagicStoreError {\n return new MagicStoreError({\n status: 0,\n code: context.aborted ? 'ABORTED' : 'NETWORK_ERROR',\n message: context.aborted ? 'The request was aborted.' : 'The request did not complete.',\n requestId: context.requestId,\n idempotencyKey: context.idempotencyKey,\n cause,\n });\n }\n}\n\n/** `Retry-After` as delta-seconds (the API never sends an HTTP date). */\nexport function retryAfterSeconds(response: Response): number | undefined {\n const value = response.headers.get('Retry-After');\n if (value === null) {\n return undefined;\n }\n const seconds = Number(value);\n return Number.isFinite(seconds) && seconds >= 0 ? seconds : undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","// Generated by scripts/generate-operations.mjs from spec/storefront-v2.json — do not edit.\n// Storefront API 2.0.0-alpha.1, 107 operations.\n\nexport const API_VERSION = '2.0.0-alpha.1';\n\nexport const operationTable = {\n analyticsEventsStore: { method: 'POST', path: '/analytics/events', idempotencyKey: false, customer: false, pagination: null },\n authClick: { method: 'POST', path: '/auth/click', idempotencyKey: false, customer: false, pagination: null },\n authOq: { method: 'POST', path: '/auth/oq', idempotencyKey: false, customer: false, pagination: null },\n authOtp: { method: 'POST', path: '/auth/otp', idempotencyKey: false, customer: false, pagination: null },\n authOtpVerification: { method: 'POST', path: '/auth/otp/verification', idempotencyKey: false, customer: false, pagination: null },\n authTelegram: { method: 'POST', path: '/auth/telegram', idempotencyKey: false, customer: false, pagination: null },\n authTokenDestroy: { method: 'DELETE', path: '/auth/token', idempotencyKey: false, customer: true, pagination: null },\n authTokenRefresh: { method: 'POST', path: '/auth/token/refresh', idempotencyKey: false, customer: false, pagination: null },\n cartsAttributes: { method: 'PUT', path: '/carts/{id}/attributes', idempotencyKey: false, customer: false, pagination: null },\n cartsBuyerIdentity: { method: 'PUT', path: '/carts/{id}/buyer-identity', idempotencyKey: false, customer: true, pagination: null },\n cartsDiscountCodes: { method: 'PUT', path: '/carts/{id}/discount-codes', idempotencyKey: false, customer: false, pagination: null },\n cartsGift: { method: 'PUT', path: '/carts/{id}/gift', idempotencyKey: false, customer: false, pagination: null },\n cartsLinesDestroy: { method: 'DELETE', path: '/carts/{id}/lines/{lineId}', idempotencyKey: false, customer: false, pagination: null },\n cartsLinesStore: { method: 'POST', path: '/carts/{id}/lines', idempotencyKey: false, customer: false, pagination: null },\n cartsLinesUpdate: { method: 'PATCH', path: '/carts/{id}/lines/{lineId}', idempotencyKey: false, customer: false, pagination: null },\n cartsNote: { method: 'PUT', path: '/carts/{id}/note', idempotencyKey: false, customer: false, pagination: null },\n cartsPoints: { method: 'PUT', path: '/carts/{id}/points', idempotencyKey: false, customer: true, pagination: null },\n cartsShow: { method: 'GET', path: '/carts/{id}', idempotencyKey: false, customer: false, pagination: null },\n cartsStore: { method: 'POST', path: '/carts', idempotencyKey: false, customer: false, pagination: null },\n chatConversationsCustomer: { method: 'PUT', path: '/chat/conversations/{id}/customer', idempotencyKey: false, customer: true, pagination: null },\n chatConversationsIndex: { method: 'GET', path: '/chat/conversations', idempotencyKey: false, customer: true, pagination: 'offset' },\n chatConversationsMessagesIndex: { method: 'GET', path: '/chat/conversations/{id}/messages', idempotencyKey: false, customer: false, pagination: 'cursor' },\n chatConversationsMessagesStore: { method: 'POST', path: '/chat/conversations/{id}/messages', idempotencyKey: false, customer: false, pagination: null },\n chatConversationsOperatorRequest: { method: 'PUT', path: '/chat/conversations/{id}/operator-request', idempotencyKey: false, customer: false, pagination: null },\n chatConversationsReadMarker: { method: 'PUT', path: '/chat/conversations/{id}/read-marker', idempotencyKey: false, customer: false, pagination: null },\n chatConversationsShow: { method: 'GET', path: '/chat/conversations/{id}', idempotencyKey: false, customer: false, pagination: null },\n chatConversationsStore: { method: 'POST', path: '/chat/conversations', idempotencyKey: false, customer: false, pagination: null },\n checkoutsCompletion: { method: 'POST', path: '/checkouts/{id}/completion', idempotencyKey: true, customer: false, pagination: null },\n checkoutsContact: { method: 'PUT', path: '/checkouts/{id}/contact', idempotencyKey: false, customer: false, pagination: null },\n checkoutsDeliveryOption: { method: 'PUT', path: '/checkouts/{id}/delivery-option', idempotencyKey: false, customer: false, pagination: null },\n checkoutsDeliveryOptions: { method: 'GET', path: '/checkouts/{id}/delivery-options', idempotencyKey: false, customer: false, pagination: null },\n checkoutsPaymentMethod: { method: 'PUT', path: '/checkouts/{id}/payment-method', idempotencyKey: false, customer: false, pagination: null },\n checkoutsPaymentMethods: { method: 'GET', path: '/checkouts/{id}/payment-methods', idempotencyKey: false, customer: false, pagination: null },\n checkoutsPickupLocation: { method: 'PUT', path: '/checkouts/{id}/pickup-location', idempotencyKey: false, customer: false, pagination: null },\n checkoutsShippingAddress: { method: 'PUT', path: '/checkouts/{id}/shipping-address', idempotencyKey: false, customer: false, pagination: null },\n checkoutsShow: { method: 'GET', path: '/checkouts/{id}', idempotencyKey: false, customer: false, pagination: null },\n checkoutsStore: { method: 'POST', path: '/checkouts', idempotencyKey: false, customer: false, pagination: null },\n collectionsFilters: { method: 'GET', path: '/collections/{handle}/filters', idempotencyKey: false, customer: false, pagination: null },\n collectionsIndex: { method: 'GET', path: '/collections', idempotencyKey: false, customer: false, pagination: 'offset' },\n collectionsProducts: { method: 'GET', path: '/collections/{handle}/products', idempotencyKey: false, customer: false, pagination: 'offset' },\n collectionsShow: { method: 'GET', path: '/collections/{handle}', idempotencyKey: false, customer: false, pagination: null },\n collectionsTree: { method: 'GET', path: '/collections/tree', idempotencyKey: false, customer: false, pagination: null },\n contacts: { method: 'GET', path: '/contacts', idempotencyKey: false, customer: false, pagination: null },\n customerAddressesDestroy: { method: 'DELETE', path: '/customer/addresses/{addressId}', idempotencyKey: false, customer: true, pagination: null },\n customerAddressesIndex: { method: 'GET', path: '/customer/addresses', idempotencyKey: false, customer: true, pagination: null },\n customerAddressesShow: { method: 'GET', path: '/customer/addresses/{addressId}', idempotencyKey: false, customer: true, pagination: null },\n customerAddressesStore: { method: 'POST', path: '/customer/addresses', idempotencyKey: false, customer: true, pagination: null },\n customerAddressesUpdate: { method: 'PUT', path: '/customer/addresses/{addressId}', idempotencyKey: false, customer: true, pagination: null },\n customerAmbassadorPayoutsIndex: { method: 'GET', path: '/customer/ambassador/payouts', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerAmbassadorPayoutsShow: { method: 'GET', path: '/customer/ambassador/payouts/{payoutId}', idempotencyKey: false, customer: true, pagination: null },\n customerAmbassadorPayoutsStore: { method: 'POST', path: '/customer/ambassador/payouts', idempotencyKey: true, customer: true, pagination: null },\n customerAmbassadorReferrals: { method: 'GET', path: '/customer/ambassador/referrals', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerAmbassadorShow: { method: 'GET', path: '/customer/ambassador', idempotencyKey: false, customer: true, pagination: null },\n customerAmbassadorStats: { method: 'GET', path: '/customer/ambassador/stats', idempotencyKey: false, customer: true, pagination: null },\n customerDeletionRequest: { method: 'POST', path: '/customer/deletion-request', idempotencyKey: false, customer: true, pagination: null },\n customerOrdersCancellation: { method: 'POST', path: '/customer/orders/{id}/cancellation', idempotencyKey: false, customer: true, pagination: null },\n customerOrdersIndex: { method: 'GET', path: '/customer/orders', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerOrdersReorder: { method: 'POST', path: '/customer/orders/{id}/reorder', idempotencyKey: false, customer: true, pagination: null },\n customerOrdersShow: { method: 'GET', path: '/customer/orders/{id}', idempotencyKey: false, customer: true, pagination: null },\n customerPhoneVerification: { method: 'POST', path: '/customer/phone-verification', idempotencyKey: false, customer: true, pagination: null },\n customerPreOrdersIndex: { method: 'GET', path: '/customer/pre-orders', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerPreOrdersShow: { method: 'GET', path: '/customer/pre-orders/{id}', idempotencyKey: false, customer: true, pagination: null },\n customerReferralInvitees: { method: 'GET', path: '/customer/referral/invitees', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerReferralShow: { method: 'GET', path: '/customer/referral', idempotencyKey: false, customer: true, pagination: null },\n customerReviewsAwaiting: { method: 'GET', path: '/customer/reviews/awaiting', idempotencyKey: false, customer: true, pagination: null },\n customerReviewsIndex: { method: 'GET', path: '/customer/reviews', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerRewardsDiscountCodesIndex: { method: 'GET', path: '/customer/rewards/discount-codes', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerRewardsDiscountCodesShow: { method: 'GET', path: '/customer/rewards/discount-codes/{id}', idempotencyKey: false, customer: true, pagination: null },\n customerRewardsRedemptionsStore: { method: 'POST', path: '/customer/rewards/redemptions', idempotencyKey: true, customer: true, pagination: null },\n customerShow: { method: 'GET', path: '/customer', idempotencyKey: false, customer: true, pagination: null },\n customerUpdate: { method: 'PATCH', path: '/customer', idempotencyKey: false, customer: true, pagination: null },\n customerWalletActivities: { method: 'GET', path: '/customer/wallet/activities', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerWalletShow: { method: 'GET', path: '/customer/wallet', idempotencyKey: false, customer: true, pagination: null },\n customerWishlistAdd: { method: 'PUT', path: '/customer/wishlist/{productId}', idempotencyKey: false, customer: true, pagination: null },\n customerWishlistIndex: { method: 'GET', path: '/customer/wishlist', idempotencyKey: false, customer: true, pagination: 'offset' },\n customerWishlistRemove: { method: 'DELETE', path: '/customer/wishlist/{productId}', idempotencyKey: false, customer: true, pagination: null },\n home: { method: 'GET', path: '/home', idempotencyKey: false, customer: false, pagination: null },\n locationsIndex: { method: 'GET', path: '/locations', idempotencyKey: false, customer: false, pagination: null },\n mediaUploadsStore: { method: 'POST', path: '/media/uploads', idempotencyKey: false, customer: true, pagination: null },\n menusShow: { method: 'GET', path: '/menus/{handle}', idempotencyKey: false, customer: false, pagination: null },\n ordersPayment: { method: 'GET', path: '/orders/{id}/payment', idempotencyKey: false, customer: false, pagination: null },\n ordersPaymentLink: { method: 'POST', path: '/orders/{id}/payment-link', idempotencyKey: true, customer: false, pagination: null },\n pagesIndex: { method: 'GET', path: '/pages', idempotencyKey: false, customer: false, pagination: null },\n pagesShow: { method: 'GET', path: '/pages/{handle}', idempotencyKey: false, customer: false, pagination: null },\n ping: { method: 'GET', path: '/ping', idempotencyKey: false, customer: false, pagination: null },\n preOrdersStore: { method: 'POST', path: '/pre-orders', idempotencyKey: false, customer: false, pagination: null },\n productsIndex: { method: 'GET', path: '/products', idempotencyKey: false, customer: false, pagination: 'offset' },\n productsRecommendations: { method: 'GET', path: '/products/{handle}/recommendations', idempotencyKey: false, customer: false, pagination: null },\n productsReviews: { method: 'GET', path: '/products/{handle}/reviews', idempotencyKey: false, customer: false, pagination: 'offset' },\n productsShow: { method: 'GET', path: '/products/{handle}', idempotencyKey: false, customer: false, pagination: null },\n realtimeAuthorizationsStore: { method: 'POST', path: '/realtime/authorizations', idempotencyKey: false, customer: false, pagination: null },\n reelsIndex: { method: 'GET', path: '/reels', idempotencyKey: false, customer: false, pagination: 'offset' },\n referralProgram: { method: 'GET', path: '/referral-program', idempotencyKey: false, customer: false, pagination: null },\n reviewsLike: { method: 'PUT', path: '/reviews/{id}/like', idempotencyKey: false, customer: true, pagination: null },\n reviewsSite: { method: 'GET', path: '/reviews/site', idempotencyKey: false, customer: false, pagination: 'offset' },\n reviewsSiteStore: { method: 'POST', path: '/reviews/site', idempotencyKey: false, customer: true, pagination: null },\n reviewsStore: { method: 'POST', path: '/reviews', idempotencyKey: false, customer: true, pagination: null },\n reviewsUnlike: { method: 'DELETE', path: '/reviews/{id}/like', idempotencyKey: false, customer: true, pagination: null },\n rewardsEarningRules: { method: 'GET', path: '/rewards/earning-rules', idempotencyKey: false, customer: false, pagination: null },\n rewardsSpendingRules: { method: 'GET', path: '/rewards/spending-rules', idempotencyKey: false, customer: false, pagination: null },\n search: { method: 'GET', path: '/search', idempotencyKey: false, customer: false, pagination: 'offset' },\n searchFilters: { method: 'GET', path: '/search/filters', idempotencyKey: false, customer: false, pagination: null },\n searchSuggestions: { method: 'GET', path: '/search/suggestions', idempotencyKey: false, customer: false, pagination: null },\n searchTrending: { method: 'GET', path: '/search/trending', idempotencyKey: false, customer: false, pagination: null },\n shop: { method: 'GET', path: '/shop', idempotencyKey: false, customer: false, pagination: null },\n sitemap: { method: 'GET', path: '/sitemap', idempotencyKey: false, customer: false, pagination: 'offset' },\n themeSectionSchema: { method: 'GET', path: '/theme/section-schema', idempotencyKey: false, customer: false, pagination: null },\n} as const;\n","import type {\n OperationArgs,\n OperationId,\n OperationResult,\n PageItem,\n PaginatedOperationId,\n} from './types';\n\ntype Call = <K extends OperationId>(\n operationId: K,\n ...args: OperationArgs<K>\n) => Promise<OperationResult<K>>;\n\ninterface PageBody {\n data?: unknown[];\n meta?: {\n pagination?: { page: number; hasNextPage: boolean };\n cursor?: { next: string | null; hasNextPage: boolean };\n };\n}\n\nexport async function* paginate<K extends PaginatedOperationId>(\n call: Call,\n operationId: K,\n style: 'offset' | 'cursor',\n [input, options]: OperationArgs<K>,\n): AsyncGenerator<PageItem<K>, void, undefined> {\n const base = (input ?? {}) as { query?: Record<string, unknown> };\n let query: Record<string, unknown> = { ...base.query };\n\n for (;;) {\n const args = [{ ...base, query }, options] as unknown as OperationArgs<K>;\n const body = (await call(operationId, ...args)) as unknown as PageBody;\n\n for (const item of body.data ?? []) {\n yield item as PageItem<K>;\n }\n\n if (style === 'offset') {\n const pagination = body.meta?.pagination;\n if (!pagination?.hasNextPage) {\n return;\n }\n query = { ...query, page: pagination.page + 1 };\n } else {\n const cursor = body.meta?.cursor;\n if (!cursor?.hasNextPage || cursor.next === null) {\n return;\n }\n query = { ...query, cursor: cursor.next };\n }\n }\n}\n"],"mappings":";AAAA,OAAO,kBAAkB;;;ACUzB,IAAM,iBAA8C;AAAA,EAClD,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACP;AAaO,IAAM,kBAAN,MAAM,yBAAwB,MAAM;AAAA,EACvB,OAAO;AAAA;AAAA,EAGhB;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA,EAET,YAAY,MAWT;AACD,UAAM,KAAK,SAAS,KAAK,UAAU,SAAY,SAAY,EAAE,OAAO,KAAK,MAAM,CAAC;AAChF,SAAK,SAAS,KAAK;AACnB,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK;AACnB,SAAK,SAAS,KAAK,UAAU,CAAC;AAC9B,SAAK,YAAY,KAAK;AACtB,SAAK,aAAa,KAAK;AACvB,SAAK,iBAAiB,KAAK;AAC3B,SAAK,UAAU,KAAK;AAAA,EACtB;AAAA;AAAA,EAGA,OAAO,aACL,UACA,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Q,EAAE;AAAA,EAC3C;AACA,MAAI,QAAQ,YAAY;AACtB,UAAM,OAAO,QAAQ,WAAW,QAAQ,gBAAgB,EAAE,EAAE,QAAQ,QAAQ,EAAE;AAC9E,WAAO,WAAW,IAAI;AAAA,EACxB;AACA,QAAM,IAAI,UAAU,yDAAyD;AAC/E;AAEA,eAAe,UAAU,QAAiE;AACxF,MAAI,OAAO,WAAW,YAAY;AAChC,WAAQ,MAAM,OAAO,KAAM;AAAA,EAC7B;AACA,SAAO,UAAU;AACnB;AAEA,SAAS,WAAmB;AAC1B,SAAO,WAAW,OAAO,WAAW;AACtC;AAGA,SAAS,QAAQ,SAAiB,OAAuC;AACvE,QAAM,UAAU,KAAK,IAAI,MAAM,YAAY,MAAM,cAAc,MAAM,UAAU,EAAE;AACjF,SAAO,KAAK,MAAM,KAAK,OAAO,IAAI,OAAO;AAC3C;AAEA,SAAS,MAAM,IAAY,QAAgD;AACzE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,QAAQ,SAAS;AACnB,aAAO,OAAO,MAAM;AACpB;AAAA,IACF;AACA,UAAM,QAAQ,WAAW,MAAM;AAC7B,cAAQ,oBAAoB,SAAS,OAAO;AAC5C,cAAQ;AAAA,IACV,GAAG,EAAE;AACL,UAAM,UAAU,MAAY;AAC1B,mBAAa,KAAK;AAClB,aAAO,QAAQ,MAAM;AAAA,IACvB;AACA,YAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AAAA,EAC3D,CAAC;AACH;","names":[]}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@magicstoreai/storefront-client",
3
+ "version": "0.1.0",
4
+ "description": "Typed client for the MagicStore Storefront API v2 — Node, edge and browser",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "devDependencies": {
22
+ "@types/node": "^26.6.2",
23
+ "openapi-typescript": "^7.13.0",
24
+ "tsup": "^8.5.1",
25
+ "typescript": "5.9.3",
26
+ "vitest": "^5.0.1"
27
+ },
28
+ "dependencies": {
29
+ "openapi-fetch": "^0.17.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "generate": "openapi-typescript ../../spec/storefront-v2.json -o src/generated/schema.ts && node scripts/generate-operations.mjs",
36
+ "build": "tsup",
37
+ "test": "vitest run",
38
+ "typecheck": "tsc --noEmit"
39
+ }
40
+ }