@swishapp/sdk 0.52.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.
Files changed (36) hide show
  1. package/README.md +50 -0
  2. package/dist/ajax-api/ajax-api-client.d.ts +81 -0
  3. package/dist/ajax-api/ajax-api-publisher.d.ts +9 -0
  4. package/dist/cache/fetch-cache.d.ts +87 -0
  5. package/dist/dom/dom-utils.d.ts +16 -0
  6. package/dist/events/event-bus.d.ts +7 -0
  7. package/dist/index.d.ts +8 -0
  8. package/dist/state/index.d.ts +4 -0
  9. package/dist/state/item-context-signal.d.ts +11 -0
  10. package/dist/state/item-count-signal.d.ts +7 -0
  11. package/dist/state/item-state-signal.d.ts +19 -0
  12. package/dist/state/swish-query-signals.d.ts +21 -0
  13. package/dist/storefront-api/load-product-card-data.d.ts +15 -0
  14. package/dist/storefront-api/load-product-detail-data.d.ts +15 -0
  15. package/dist/storefront-api/load-product-id.d.ts +11 -0
  16. package/dist/storefront-api/load-product-images.d.ts +20 -0
  17. package/dist/storefront-api/load-product-options.d.ts +13 -0
  18. package/dist/storefront-api/load-product-recommendations.d.ts +17 -0
  19. package/dist/storefront-api/load-selected-variant.d.ts +14 -0
  20. package/dist/storefront-api/queries/fragments.d.ts +7 -0
  21. package/dist/storefront-api/queries/index.d.ts +14 -0
  22. package/dist/storefront-api/storefront-api-client.d.ts +67 -0
  23. package/dist/storefront-api/types/storefront.generated.d.ts +461 -0
  24. package/dist/storefront-api/types/storefront.types.d.ts +8460 -0
  25. package/dist/swish-api/items-batch-loader.d.ts +4 -0
  26. package/dist/swish-api/swish-api-client.d.ts +43 -0
  27. package/dist/swish-api/swish-api-publisher.d.ts +8 -0
  28. package/dist/swish-ui/swish-ui-element.d.ts +9 -0
  29. package/dist/swish-ui/swish-ui-utils.d.ts +112 -0
  30. package/dist/swish.d.ts +124 -0
  31. package/dist/swish.js +403 -0
  32. package/dist/types.d.ts +57 -0
  33. package/dist/utils/shop-bridge.d.ts +26 -0
  34. package/dist/utils/shopify-gid.d.ts +2 -0
  35. package/dist/utils/shopify-url-utils.d.ts +13 -0
  36. package/package.json +60 -0
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Swish SDK
2
+
3
+ JavaScript library for integrating Swish on a Shopify web store (themes and headless stacks).
4
+
5
+ ## Installation
6
+
7
+ To load the Swish app, you can either activate the Swish embed through your theme editor or install it via NPM. We recommend using the app embed for most scenarios. For headless stacks, NPM is necessary.
8
+
9
+ ## With Swish embed
10
+
11
+ Make sure to activate the Swish embed in the theme editor!
12
+
13
+ ```html
14
+ <script type="module">
15
+ const swishApp = () =>
16
+ new Promise((r) => {
17
+ window.swish
18
+ ? r(window.swish)
19
+ : document.addEventListener("swish-ready", () => r(window.swish));
20
+ });
21
+
22
+ const swish = await swishApp();
23
+
24
+ const { data } = await swish.api.items.list();
25
+ </script>
26
+ ```
27
+
28
+ ## Code only
29
+
30
+ ```ts
31
+ import { swishApp } from "/apps/wishlist/assets/sdk/swish.js";
32
+
33
+ const swish = await swishApp({
34
+ proxy: {
35
+ baseUrl: "/apps/wishlist",
36
+ },
37
+ });
38
+
39
+ const { data } = await swish.api.items.list();
40
+ ```
41
+
42
+ # Headless stacks
43
+
44
+ The Swish SDK requires a proxy service that operates on the same domain as the store. This service facilitates the loading of additional resources and ensures secure communication with the Swish API.
45
+
46
+ Please use the [Node.js library](https://www.npmjs.com/package/@swishapp/node) to implement the app proxy.
47
+
48
+ ## Documentation
49
+
50
+ For more information visit [Swish DEV docs](https://developers.swish.app/libraries/sdk).
@@ -0,0 +1,81 @@
1
+ export interface AjaxConfig {
2
+ storeDomain: string;
3
+ fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
4
+ responseInterceptor?: (response: Response, request: Request) => Promise<void> | void;
5
+ }
6
+ export interface CartLineItem {
7
+ id: number;
8
+ properties: Record<string, string> | null;
9
+ quantity: number;
10
+ variant_id: number;
11
+ key: string;
12
+ title: string;
13
+ price: number;
14
+ original_price: number;
15
+ discounted_price: number;
16
+ line_price: number;
17
+ original_line_price: number;
18
+ total_discount: number;
19
+ discounts: any[];
20
+ sku: string;
21
+ grams: number;
22
+ vendor: string;
23
+ taxable: boolean;
24
+ product_id: number;
25
+ gift_card: boolean;
26
+ final_price: number;
27
+ final_line_price: number;
28
+ url: string;
29
+ image: string;
30
+ handle: string;
31
+ requires_shipping: boolean;
32
+ product_type: string;
33
+ product_title: string;
34
+ product_description: string;
35
+ variant_title: string;
36
+ variant_options: string[];
37
+ line_level_discount_allocations: any[];
38
+ }
39
+ export interface Cart {
40
+ token: string;
41
+ note: string | null;
42
+ attributes: Record<string, string>;
43
+ original_total_price: number;
44
+ total_price: number;
45
+ total_discount: number;
46
+ total_weight: number;
47
+ item_count: number;
48
+ items: CartLineItem[];
49
+ requires_shipping: boolean;
50
+ currency: string;
51
+ items_subtotal_price: number;
52
+ cart_level_discount_applications: any[];
53
+ }
54
+ export interface AddToCartItem {
55
+ id: string;
56
+ quantity: number;
57
+ }
58
+ export interface AddToCartRequest {
59
+ items: AddToCartItem[];
60
+ }
61
+ export interface AddToCartResponse {
62
+ items: CartLineItem[];
63
+ }
64
+ export interface CartError {
65
+ message: string;
66
+ status: string;
67
+ description: string;
68
+ }
69
+ export declare class AjaxApiClient {
70
+ private config;
71
+ private readonly cache;
72
+ constructor(config: AjaxConfig);
73
+ patchFetch(): void;
74
+ private getFetchRequest;
75
+ private getBaseUrl;
76
+ fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
77
+ private request;
78
+ fetchCart(): Promise<Cart>;
79
+ addToCart(request: AddToCartRequest): Promise<AddToCartResponse>;
80
+ clearCache(): Promise<void>;
81
+ }
@@ -0,0 +1,9 @@
1
+ import { EventBus } from "../events/event-bus";
2
+ import { EventName } from "../events/event-bus";
3
+ export declare class AjaxApiPublisher {
4
+ private readonly eventBus;
5
+ private readonly eventMap;
6
+ constructor(eventBus: EventBus);
7
+ processFetchResponse(response: Response, request: Request): Promise<void>;
8
+ getEventName(url: string): EventName | null;
9
+ }
@@ -0,0 +1,87 @@
1
+ export declare enum CacheControl {
2
+ None = "no-cache",
3
+ Minimal = "max-age=3, stale-while-revalidate=0",// 3 seconds, no stale
4
+ Short = "max-age=60, stale-while-revalidate=3600",// 1 minute, 1 hour stale
5
+ Long = "max-age=3600, stale-while-revalidate=86400"
6
+ }
7
+ export declare class FetchCache {
8
+ private readonly cacheName;
9
+ private readonly defaultCacheControl;
10
+ private readonly revalidationPromises;
11
+ private readonly inFlightRequests;
12
+ private readonly keyPrefix;
13
+ constructor(cacheName: string, defaultCacheControl: CacheControl | string, keyPrefix?: string);
14
+ /**
15
+ * Get a cached response by key
16
+ */
17
+ get(key: string): Promise<Response | undefined>;
18
+ /**
19
+ * Set a cached response with the specified policy
20
+ */
21
+ set(key: string, response: Response, cacheControl: CacheControl | string): Promise<void>;
22
+ /**
23
+ * Set a cached response from a fetch request
24
+ */
25
+ fetchWithCache(input: string | URL | Request, init?: RequestInit, cacheControl?: CacheControl | string): Promise<Response>;
26
+ /**
27
+ * Delete a specific cache entry
28
+ */
29
+ delete(key: string): Promise<boolean>;
30
+ /**
31
+ * Clear all cache entries
32
+ */
33
+ clear(): Promise<void>;
34
+ /**
35
+ * Get all cache keys
36
+ */
37
+ keys(): Promise<string[]>;
38
+ /**
39
+ * Check if a key exists in cache
40
+ */
41
+ has(key: string): Promise<boolean>;
42
+ /**
43
+ * Get cache statistics
44
+ */
45
+ getStats(): Promise<{
46
+ total: number;
47
+ }>;
48
+ /**
49
+ * Remove all expired entries from the cache
50
+ */
51
+ cleanupExpiredEntries(): Promise<{
52
+ removed: number;
53
+ remaining: number;
54
+ }>;
55
+ /**
56
+ * Get the cache key from fetch args
57
+ */
58
+ getCacheKey(input: string | URL | globalThis.Request, init?: RequestInit): Promise<string>;
59
+ /**
60
+ * Get the url from the fetch input
61
+ */
62
+ getInputUrl(input: string | URL | globalThis.Request): string;
63
+ /**
64
+ * Check if a response has expired based on its Cache-Control header
65
+ */
66
+ private isExpired;
67
+ /**
68
+ * Check if a response is stale but can be revalidated
69
+ */
70
+ private isStaleButRevalidatable;
71
+ /**
72
+ * Revalidate a cached response in the background
73
+ */
74
+ private revalidateInBackground;
75
+ /**
76
+ * Parse max-age value from Cache-Control header
77
+ */
78
+ private parseMaxAge;
79
+ /**
80
+ * Parse stale-while-revalidate value from Cache-Control header
81
+ */
82
+ private parseStaleWhileRevalidate;
83
+ /**
84
+ * Create a cacheable response with appropriate headers based on policy
85
+ */
86
+ private createCacheableResponse;
87
+ }
@@ -0,0 +1,16 @@
1
+ export declare function waitForDOM(): Promise<Node>;
2
+ export interface CreateElementLocatorArgs {
3
+ onElementFound: (element: Element) => void;
4
+ selector: string;
5
+ observerOptions?: IntersectionObserverInit;
6
+ }
7
+ export declare function createElementLocator({ onElementFound, selector, observerOptions, }: CreateElementLocatorArgs): MutationObserver;
8
+ export interface CreateLocationObserverArgs {
9
+ onLocationChange: (location: Location) => void;
10
+ }
11
+ export declare function createLocationObserver({ onLocationChange, }: CreateLocationObserverArgs): () => void;
12
+ export interface CreateHrefObserverArgs {
13
+ element: HTMLAnchorElement;
14
+ onHrefChange: (href: string) => void;
15
+ }
16
+ export declare function createHrefObserver({ element, onHrefChange, }: CreateHrefObserverArgs): () => void;
@@ -0,0 +1,7 @@
1
+ export type EventName = "cart-add" | "cart-update" | "cart-change" | "cart-clear" | "item-create" | "item-update" | "item-delete" | "item-lists-update" | "list-create" | "list-update" | "list-delete";
2
+ export declare class EventBus {
3
+ private readonly eventBus;
4
+ subscribe(type: EventName | EventName[], callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): () => void;
5
+ unsubscribe(type: EventName, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
6
+ publish(type: EventName, detail: any): void;
7
+ }
@@ -0,0 +1,8 @@
1
+ export type * from "@swishapp/api-client";
2
+ export type * from "./ajax-api/ajax-api-client";
3
+ export type { EventName } from "./events/event-bus";
4
+ export type * from "./storefront-api/storefront-api-client";
5
+ export { SwishApp } from "./swish";
6
+ export type { Ref, SwishUiElement } from "./swish-ui/swish-ui-element";
7
+ export type { Notification, Notifications, UnsaveAlertSubmitData, ListSelectSubmitData, VariantSelectSubmitData, UnsaveAlertOptions, ListSelectOptions, VariantSelectOptions, } from "./swish-ui/swish-ui-utils";
8
+ export type { ShopBridge } from "./utils/shop-bridge";
@@ -0,0 +1,4 @@
1
+ export { signal, effect } from "@preact/signals-core";
2
+ export * from "./item-context-signal";
3
+ export * from "./item-state-signal";
4
+ export * from "./item-count-signal";
@@ -0,0 +1,11 @@
1
+ import { SwishApp } from "../swish";
2
+ export interface ItemContext {
3
+ loading: boolean;
4
+ productHandle?: string;
5
+ productId?: string;
6
+ variantId?: string;
7
+ itemId?: string;
8
+ skipVariantSelect?: boolean;
9
+ defaultVariantId?: string;
10
+ }
11
+ export declare const itemContextSignal: (swish: SwishApp) => (source?: HTMLElement) => import("@preact/signals-core").Signal<ItemContext>;
@@ -0,0 +1,7 @@
1
+ import { ApiError } from "@swishapp/api-client";
2
+ import { SwishApp } from "../swish";
3
+ export declare const itemCountSignal: (swish: SwishApp) => () => import("@preact/signals-core").ReadonlySignal<{
4
+ count: number;
5
+ loading: boolean;
6
+ error: ApiError | null;
7
+ }>;
@@ -0,0 +1,19 @@
1
+ import { Signal } from "@preact/signals-core";
2
+ import { ApiError } from "@swishapp/api-client";
3
+ import { ItemContext } from "./item-context-signal";
4
+ import { SwishApp } from "../swish";
5
+ export declare const itemStateSignal: (swish: SwishApp) => (context: Signal<ItemContext>) => import("@preact/signals-core").ReadonlySignal<{
6
+ error: ApiError | null;
7
+ status: string;
8
+ savedItemId: string | null;
9
+ loading: boolean;
10
+ submitting: boolean;
11
+ saved: boolean;
12
+ saving: boolean;
13
+ unsaving: boolean;
14
+ }> & {
15
+ save: () => Promise<void>;
16
+ unsave: () => void;
17
+ update: () => void;
18
+ toggle: () => Promise<void>;
19
+ };
@@ -0,0 +1,21 @@
1
+ import { ApiError, ApiResponse, PageInfo, PaginatedApiResponse } from "@swishapp/api-client";
2
+ import { EventName } from "../events/event-bus";
3
+ import { SwishApp } from "../swish";
4
+ import { Signal } from "@preact/signals-core";
5
+ export type FetchFn<TResponse, TVariables> = (variables?: TVariables) => Promise<TResponse>;
6
+ type DataOf<T> = T extends {
7
+ data: infer D;
8
+ } ? D : never;
9
+ type AnyApiResponse = ApiResponse<any> | PaginatedApiResponse<any>;
10
+ export declare const swishQuerySignals: (swish: SwishApp) => <TResponse extends AnyApiResponse, TVariables>(fetch: FetchFn<TResponse, TVariables>, options?: {
11
+ variables?: Signal<TVariables>;
12
+ skip?: Signal<boolean>;
13
+ refetch?: EventName[];
14
+ }) => {
15
+ data: Signal<DataOf<TResponse> | null>;
16
+ pageInfo: Signal<PageInfo | null>;
17
+ error: Signal<ApiError | null>;
18
+ loading: Signal<boolean>;
19
+ refetching: import("@preact/signals-core").ReadonlySignal<boolean>;
20
+ };
21
+ export {};
@@ -0,0 +1,15 @@
1
+ import { StorefrontApiClient, StorefrontApiResponse } from "./storefront-api-client";
2
+ import type { GetProductCardDataQuery, GetProductCardDataWithVariantQuery } from "./types/storefront.generated";
3
+ import type { HasMetafieldsIdentifier } from "./types/storefront.types";
4
+ export type LoadProductCardDataResponse = StorefrontApiResponse<GetProductCardDataQuery | GetProductCardDataWithVariantQuery>;
5
+ export type { GetProductCardDataQueryVariables } from "./types/storefront.generated";
6
+ export interface LoadProductCardDataArgs {
7
+ productId?: string;
8
+ variantId?: string;
9
+ productMetafields?: HasMetafieldsIdentifier[];
10
+ variantMetafields?: HasMetafieldsIdentifier[];
11
+ }
12
+ export declare const loadProductCardData: (client: StorefrontApiClient, { productId, variantId, productMetafields, variantMetafields, }: LoadProductCardDataArgs) => Promise<{
13
+ data: GetProductCardDataQuery | GetProductCardDataWithVariantQuery | undefined;
14
+ errors: import("@shopify/graphql-client").ResponseErrors | null;
15
+ }>;
@@ -0,0 +1,15 @@
1
+ import { StorefrontApiClient, StorefrontApiResponse } from "./storefront-api-client";
2
+ import type { GetProductDetailDataQuery, GetProductDetailDataWithVariantQuery } from "./types/storefront.generated";
3
+ import type { HasMetafieldsIdentifier } from "./types/storefront.types";
4
+ export type LoadProductDetailDataResponse = StorefrontApiResponse<GetProductDetailDataQuery | GetProductDetailDataWithVariantQuery>;
5
+ export type { GetProductDetailDataQueryVariables } from "./types/storefront.generated";
6
+ export interface LoadProductDetailDataArgs {
7
+ productId?: string;
8
+ variantId?: string;
9
+ productMetafields?: HasMetafieldsIdentifier[];
10
+ variantMetafields?: HasMetafieldsIdentifier[];
11
+ }
12
+ export declare const loadProductDetailData: (client: StorefrontApiClient, { productId, variantId, productMetafields, variantMetafields, }: LoadProductDetailDataArgs) => Promise<{
13
+ data: GetProductDetailDataQuery | GetProductDetailDataWithVariantQuery | undefined;
14
+ errors: import("@shopify/graphql-client").ResponseErrors | null;
15
+ }>;
@@ -0,0 +1,11 @@
1
+ import { StorefrontApiClient, StorefrontApiResponse } from "./storefront-api-client";
2
+ import type { GetProductIdByHandleQuery } from "./types/storefront.generated";
3
+ export type LoadProductIdResponse = StorefrontApiResponse<GetProductIdByHandleQuery>;
4
+ export type { GetProductIdByHandleQueryVariables } from "./types/storefront.generated";
5
+ export interface LoadProductIdArgs {
6
+ productHandle?: string;
7
+ }
8
+ export declare const loadProductId: (client: StorefrontApiClient, { productHandle }: LoadProductIdArgs) => Promise<{
9
+ data: GetProductIdByHandleQuery | undefined;
10
+ errors: import("@shopify/graphql-client").ResponseErrors | null;
11
+ }>;
@@ -0,0 +1,20 @@
1
+ import { StorefrontApiClient, StorefrontApiResponse } from "./storefront-api-client";
2
+ export type LoadProductImagesResponse = StorefrontApiResponse<{
3
+ id: string;
4
+ altText: string;
5
+ url: string;
6
+ }[]>;
7
+ export type { GetProductImagesByIdQueryVariables } from "./types/storefront.generated";
8
+ export interface LoadProductImagesArgs {
9
+ items: {
10
+ productId: number;
11
+ variantId?: number | null;
12
+ }[];
13
+ }
14
+ export declare const loadProductImages: (client: StorefrontApiClient, { items }: LoadProductImagesArgs) => Promise<{
15
+ data: (Pick<import("./types/storefront.types").Image, "id" | "altText" | "url" | "thumbhash"> | undefined)[];
16
+ error: null;
17
+ } | {
18
+ data: null;
19
+ error: Error;
20
+ }>;
@@ -0,0 +1,13 @@
1
+ import { StorefrontApiClient, StorefrontApiResponse } from "./storefront-api-client";
2
+ import type { GetProductOptionsQuery, GetProductOptionsWithVariantQuery } from "./types/storefront.generated";
3
+ export type LoadProductOptionsResponse = StorefrontApiResponse<GetProductOptionsQuery | GetProductOptionsWithVariantQuery>;
4
+ export type { GetProductOptionsQueryVariables } from "./types/storefront.generated";
5
+ export interface LoadProductOptionsArgs {
6
+ productId?: string;
7
+ variantId?: string;
8
+ productHandle?: string;
9
+ }
10
+ export declare const loadProductOptions: (client: StorefrontApiClient, { productId, productHandle, variantId }: LoadProductOptionsArgs) => Promise<{
11
+ data: GetProductOptionsQuery | GetProductOptionsWithVariantQuery | undefined;
12
+ errors: import("@shopify/graphql-client").ResponseErrors | null;
13
+ }>;
@@ -0,0 +1,17 @@
1
+ import { StorefrontApiClient, StorefrontApiResponse } from "./storefront-api-client";
2
+ import type { HasMetafieldsIdentifier, Product, ProductRecommendationIntent } from "./types/storefront.types";
3
+ export type LoadProductRecommendationsResponse = StorefrontApiResponse<{
4
+ productRecommendations?: Product[] | null;
5
+ }>;
6
+ export interface LoadProductRecommendationsArgs {
7
+ productId?: string;
8
+ productHandle?: string;
9
+ intent?: ProductRecommendationIntent;
10
+ productMetafields?: HasMetafieldsIdentifier[];
11
+ }
12
+ export declare const loadProductRecommendations: (client: StorefrontApiClient, { productId, productHandle, intent, productMetafields, }: LoadProductRecommendationsArgs) => Promise<{
13
+ data: {
14
+ productRecommendations?: Product[] | null;
15
+ } | undefined;
16
+ errors: import("@shopify/graphql-client").ResponseErrors | null;
17
+ }>;
@@ -0,0 +1,14 @@
1
+ import { StorefrontApiClient, StorefrontApiResponse } from "./storefront-api-client";
2
+ import type { SelectedOptionInput } from "./types/storefront.types";
3
+ import type { GetSelectedVariantQuery } from "./types/storefront.generated";
4
+ export type LoadSelectedVariantResponse = StorefrontApiResponse<GetSelectedVariantQuery>;
5
+ export type { GetSelectedVariantQueryVariables } from "./types/storefront.generated";
6
+ export interface LoadSelectedVariantArgs {
7
+ productId?: string;
8
+ productHandle?: string;
9
+ selectedOptions: SelectedOptionInput[];
10
+ }
11
+ export declare const loadSelectedVariant: (client: StorefrontApiClient, { productId, productHandle, selectedOptions }: LoadSelectedVariantArgs) => Promise<{
12
+ data: GetSelectedVariantQuery | undefined;
13
+ errors: import("@shopify/graphql-client").ResponseErrors | null;
14
+ }>;
@@ -0,0 +1,7 @@
1
+ export declare const PRODUCT_IMAGE_FIELDS = "\n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n";
2
+ export declare const PRODUCT_CARD_DATA_FIELDS = "\n fragment productCardDataFields on Product {\n id\n availableForSale\n category {\n id\n name\n }\n compareAtPriceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n ...productImageFields\n }\n isGiftCard\n onlineStoreUrl\n description\n handle\n priceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n productType\n tags\n title\n variantsCount {\n count\n }\n # totalInventory\n metafields(identifiers: $productMetafields) {\n key\n namespace\n value\n }\n }\n";
3
+ export declare const PRODUCT_VARIANT_DATA_FIELDS = "\n fragment productVariantDataFields on ProductVariant {\n id\n availableForSale\n compareAtPrice {\n amount\n currencyCode\n }\n currentlyNotInStock\n image {\n ...productImageFields\n }\n price {\n amount\n currencyCode\n }\n # quantityAvailable\n selectedOptions {\n name\n value\n }\n sku\n title\n metafields(identifiers: $variantMetafields) {\n key\n namespace\n value\n }\n }\n";
4
+ export declare const PRODUCT_OPTIONS_VARIANT_FIELDS = "\n fragment productOptionsVariantFields on ProductVariant {\n id\n selectedOptions {\n name\n value\n }\n }\n";
5
+ export declare const SELECTED_VARIANT_FIELDS = "\n fragment selectedVariantFields on Product {\n id\n title\n handle\n featuredImage {\n ...productImageFields\n }\n variantBySelectedOptions(selectedOptions: $selectedOptions) {\n id\n availableForSale\n compareAtPrice {\n amount\n currencyCode\n }\n currentlyNotInStock\n image {\n ...productImageFields\n }\n price {\n amount\n currencyCode\n }\n title\n selectedOptions {\n name\n value\n }\n }\n }\n";
6
+ export declare const PRODUCT_OPTIONS_FIELDS = "\n fragment productOptionsFields on Product {\n id\n title\n featuredImage {\n ...productImageFields\n }\n encodedVariantAvailability\n encodedVariantExistence\n variantsCount {\n count\n precision\n }\n options {\n id\n name\n optionValues {\n name\n swatch {\n color\n image {\n previewImage {\n url\n }\n }\n }\n firstSelectableVariant {\n id\n image {\n ...productImageFields\n }\n }\n }\n }\n }\n";
7
+ export declare const PRODUCT_IMAGES_FIELDS = "\n fragment productImagesFields on Product {\n images(first: 20) {\n nodes {\n ...productImageFields\n }\n }\n }\n";
@@ -0,0 +1,14 @@
1
+ export declare const GET_PRODUCT_CARD_DATA_BY_ID = "\n query GetProductCardData(\n $productId: ID!\n $productMetafields: [HasMetafieldsIdentifier!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(id: $productId) {\n ...productCardDataFields\n }\n }\n \n fragment productCardDataFields on Product {\n id\n availableForSale\n category {\n id\n name\n }\n compareAtPriceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n ...productImageFields\n }\n isGiftCard\n onlineStoreUrl\n description\n handle\n priceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n productType\n tags\n title\n variantsCount {\n count\n }\n # totalInventory\n metafields(identifiers: $productMetafields) {\n key\n namespace\n value\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
2
+ export declare const GET_PRODUCT_CARD_DATA_BY_ID_WITH_VARIANT = "\n query GetProductCardDataWithVariant(\n $productId: ID!\n $variantId: ID!\n $productMetafields: [HasMetafieldsIdentifier!]!\n $variantMetafields: [HasMetafieldsIdentifier!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(id: $productId) {\n ...productCardDataFields\n }\n variant: node(id: $variantId) {\n ...productVariantDataFields\n }\n }\n \n fragment productCardDataFields on Product {\n id\n availableForSale\n category {\n id\n name\n }\n compareAtPriceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n ...productImageFields\n }\n isGiftCard\n onlineStoreUrl\n description\n handle\n priceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n productType\n tags\n title\n variantsCount {\n count\n }\n # totalInventory\n metafields(identifiers: $productMetafields) {\n key\n namespace\n value\n }\n }\n\n \n fragment productVariantDataFields on ProductVariant {\n id\n availableForSale\n compareAtPrice {\n amount\n currencyCode\n }\n currentlyNotInStock\n image {\n ...productImageFields\n }\n price {\n amount\n currencyCode\n }\n # quantityAvailable\n selectedOptions {\n name\n value\n }\n sku\n title\n metafields(identifiers: $variantMetafields) {\n key\n namespace\n value\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
3
+ export declare const GET_PRODUCT_OPTIONS_BY_ID = "\n query GetProductOptions(\n $productId: ID!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(id: $productId) {\n ...productOptionsFields\n }\n }\n \n fragment productOptionsFields on Product {\n id\n title\n featuredImage {\n ...productImageFields\n }\n encodedVariantAvailability\n encodedVariantExistence\n variantsCount {\n count\n precision\n }\n options {\n id\n name\n optionValues {\n name\n swatch {\n color\n image {\n previewImage {\n url\n }\n }\n }\n firstSelectableVariant {\n id\n image {\n ...productImageFields\n }\n }\n }\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
4
+ export declare const GET_PRODUCT_OPTIONS_BY_HANDLE = "\n query GetProductOptionsByHandle(\n $handle: String!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(handle: $handle) {\n ...productOptionsFields\n }\n }\n \n fragment productOptionsFields on Product {\n id\n title\n featuredImage {\n ...productImageFields\n }\n encodedVariantAvailability\n encodedVariantExistence\n variantsCount {\n count\n precision\n }\n options {\n id\n name\n optionValues {\n name\n swatch {\n color\n image {\n previewImage {\n url\n }\n }\n }\n firstSelectableVariant {\n id\n image {\n ...productImageFields\n }\n }\n }\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
5
+ export declare const GET_PRODUCT_OPTIONS_BY_ID_WITH_VARIANT = "\n query GetProductOptionsWithVariant(\n $productId: ID!\n $variantId: ID!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(id: $productId) {\n ...productOptionsFields\n }\n variant: node(id: $variantId) {\n ...productOptionsVariantFields\n }\n }\n \n fragment productOptionsFields on Product {\n id\n title\n featuredImage {\n ...productImageFields\n }\n encodedVariantAvailability\n encodedVariantExistence\n variantsCount {\n count\n precision\n }\n options {\n id\n name\n optionValues {\n name\n swatch {\n color\n image {\n previewImage {\n url\n }\n }\n }\n firstSelectableVariant {\n id\n image {\n ...productImageFields\n }\n }\n }\n }\n }\n\n \n fragment productOptionsVariantFields on ProductVariant {\n id\n selectedOptions {\n name\n value\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
6
+ export declare const GET_PRODUCT_OPTIONS_BY_HANDLE_WITH_VARIANT = "\n query GetProductOptionsByHandleWithVariant(\n $handle: String!\n $variantId: ID!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(handle: $handle) {\n ...productOptionsFields\n }\n variant: node(id: $variantId) {\n ...productOptionsVariantFields\n }\n }\n \n fragment productOptionsFields on Product {\n id\n title\n featuredImage {\n ...productImageFields\n }\n encodedVariantAvailability\n encodedVariantExistence\n variantsCount {\n count\n precision\n }\n options {\n id\n name\n optionValues {\n name\n swatch {\n color\n image {\n previewImage {\n url\n }\n }\n }\n firstSelectableVariant {\n id\n image {\n ...productImageFields\n }\n }\n }\n }\n }\n\n \n fragment productOptionsVariantFields on ProductVariant {\n id\n selectedOptions {\n name\n value\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
7
+ export declare const GET_SELECTED_VARIANT = "\n query GetSelectedVariant(\n $productId: ID!\n $selectedOptions: [SelectedOptionInput!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(id: $productId) {\n ...selectedVariantFields\n }\n }\n \n fragment selectedVariantFields on Product {\n id\n title\n handle\n featuredImage {\n ...productImageFields\n }\n variantBySelectedOptions(selectedOptions: $selectedOptions) {\n id\n availableForSale\n compareAtPrice {\n amount\n currencyCode\n }\n currentlyNotInStock\n image {\n ...productImageFields\n }\n price {\n amount\n currencyCode\n }\n title\n selectedOptions {\n name\n value\n }\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
8
+ export declare const GET_SELECTED_VARIANT_BY_HANDLE = "\n query GetSelectedVariantByHandle(\n $handle: String!\n $selectedOptions: [SelectedOptionInput!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(handle: $handle) {\n ...selectedVariantFields\n }\n }\n \n fragment selectedVariantFields on Product {\n id\n title\n handle\n featuredImage {\n ...productImageFields\n }\n variantBySelectedOptions(selectedOptions: $selectedOptions) {\n id\n availableForSale\n compareAtPrice {\n amount\n currencyCode\n }\n currentlyNotInStock\n image {\n ...productImageFields\n }\n price {\n amount\n currencyCode\n }\n title\n selectedOptions {\n name\n value\n }\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
9
+ export declare const GET_PRODUCT_DETAIL_DATA_BY_ID = "\n query GetProductDetailData(\n $productId: ID!\n $productMetafields: [HasMetafieldsIdentifier!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(id: $productId) {\n ...productCardDataFields\n ...productOptionsFields\n ...productImagesFields\n }\n }\n \n fragment productCardDataFields on Product {\n id\n availableForSale\n category {\n id\n name\n }\n compareAtPriceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n ...productImageFields\n }\n isGiftCard\n onlineStoreUrl\n description\n handle\n priceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n productType\n tags\n title\n variantsCount {\n count\n }\n # totalInventory\n metafields(identifiers: $productMetafields) {\n key\n namespace\n value\n }\n }\n\n \n fragment productOptionsFields on Product {\n id\n title\n featuredImage {\n ...productImageFields\n }\n encodedVariantAvailability\n encodedVariantExistence\n variantsCount {\n count\n precision\n }\n options {\n id\n name\n optionValues {\n name\n swatch {\n color\n image {\n previewImage {\n url\n }\n }\n }\n firstSelectableVariant {\n id\n image {\n ...productImageFields\n }\n }\n }\n }\n }\n\n \n fragment productImagesFields on Product {\n images(first: 20) {\n nodes {\n ...productImageFields\n }\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
10
+ export declare const GET_PRODUCT_DETAIL_DATA_BY_ID_WITH_VARIANT = "\n query GetProductDetailDataWithVariant(\n $productId: ID!\n $variantId: ID!\n $productMetafields: [HasMetafieldsIdentifier!]!\n $variantMetafields: [HasMetafieldsIdentifier!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n product(id: $productId) {\n ...productCardDataFields\n ...productOptionsFields\n ...productImagesFields\n }\n variant: node(id: $variantId) {\n ...productVariantDataFields\n }\n }\n \n fragment productCardDataFields on Product {\n id\n availableForSale\n category {\n id\n name\n }\n compareAtPriceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n ...productImageFields\n }\n isGiftCard\n onlineStoreUrl\n description\n handle\n priceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n productType\n tags\n title\n variantsCount {\n count\n }\n # totalInventory\n metafields(identifiers: $productMetafields) {\n key\n namespace\n value\n }\n }\n\n \n fragment productOptionsFields on Product {\n id\n title\n featuredImage {\n ...productImageFields\n }\n encodedVariantAvailability\n encodedVariantExistence\n variantsCount {\n count\n precision\n }\n options {\n id\n name\n optionValues {\n name\n swatch {\n color\n image {\n previewImage {\n url\n }\n }\n }\n firstSelectableVariant {\n id\n image {\n ...productImageFields\n }\n }\n }\n }\n }\n\n \n fragment productVariantDataFields on ProductVariant {\n id\n availableForSale\n compareAtPrice {\n amount\n currencyCode\n }\n currentlyNotInStock\n image {\n ...productImageFields\n }\n price {\n amount\n currencyCode\n }\n # quantityAvailable\n selectedOptions {\n name\n value\n }\n sku\n title\n metafields(identifiers: $variantMetafields) {\n key\n namespace\n value\n }\n }\n\n \n fragment productImagesFields on Product {\n images(first: 20) {\n nodes {\n ...productImageFields\n }\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
11
+ export declare const GET_PRODUCT_IMAGES_BY_ID = "\n query GetProductImagesById(\n $ids: [ID!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n nodes(ids: $ids) {\n ... on Product {\n featuredImage {\n ...productImageFields\n }\n }\n ... on ProductVariant {\n image {\n ...productImageFields\n }\n product {\n featuredImage {\n ...productImageFields\n }\n }\n }\n }\n }\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
12
+ export declare const GET_PRODUCT_RECOMMENDATIONS_BY_ID = "\n query GetProductRecommendationsById(\n $productId: ID!\n $intent: ProductRecommendationIntent\n $productMetafields: [HasMetafieldsIdentifier!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n productRecommendations(productId: $productId, intent: $intent) {\n ...productCardDataFields\n }\n }\n \n fragment productCardDataFields on Product {\n id\n availableForSale\n category {\n id\n name\n }\n compareAtPriceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n ...productImageFields\n }\n isGiftCard\n onlineStoreUrl\n description\n handle\n priceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n productType\n tags\n title\n variantsCount {\n count\n }\n # totalInventory\n metafields(identifiers: $productMetafields) {\n key\n namespace\n value\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
13
+ export declare const GET_PRODUCT_RECOMMENDATIONS_BY_HANDLE = "\n query GetProductRecommendationsByHandle(\n $handle: String!\n $intent: ProductRecommendationIntent\n $productMetafields: [HasMetafieldsIdentifier!]!\n $country: CountryCode!\n $language: LanguageCode!\n ) @inContext(country: $country, language: $language) {\n productRecommendations(productHandle: $handle, intent: $intent) {\n ...productCardDataFields\n }\n }\n \n fragment productCardDataFields on Product {\n id\n availableForSale\n category {\n id\n name\n }\n compareAtPriceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n featuredImage {\n ...productImageFields\n }\n isGiftCard\n onlineStoreUrl\n description\n handle\n priceRange {\n maxVariantPrice {\n amount\n currencyCode\n }\n minVariantPrice {\n amount\n currencyCode\n }\n }\n productType\n tags\n title\n variantsCount {\n count\n }\n # totalInventory\n metafields(identifiers: $productMetafields) {\n key\n namespace\n value\n }\n }\n\n \n fragment productImageFields on Image {\n id\n altText\n url\n thumbhash\n }\n\n";
14
+ export declare const GET_PRODUCT_ID_BY_HANDLE = "\n query GetProductIdByHandle($handle: String!) {\n product(handle: $handle) {\n id\n }\n }\n";
@@ -0,0 +1,67 @@
1
+ import type { ResponseErrors } from "@shopify/graphql-client";
2
+ import { LoadProductCardDataArgs } from "./load-product-card-data";
3
+ import { LoadProductDetailDataArgs } from "./load-product-detail-data";
4
+ import { LoadProductImagesArgs } from "./load-product-images";
5
+ import { LoadProductOptionsArgs } from "./load-product-options";
6
+ import { LoadSelectedVariantArgs } from "./load-selected-variant";
7
+ import { LoadProductRecommendationsArgs } from "./load-product-recommendations";
8
+ import { LoadProductIdArgs } from "./load-product-id";
9
+ export * from "./load-product-card-data";
10
+ export * from "./load-product-options";
11
+ export * from "./load-selected-variant";
12
+ export * from "./types/storefront.generated";
13
+ export * from "./load-product-recommendations";
14
+ export interface StorefrontApiResponse<TData> {
15
+ data: TData;
16
+ errors: ResponseErrors;
17
+ }
18
+ export declare const API_VERSION = "2025-07";
19
+ export interface StorefrontConfig {
20
+ storeDomain: string;
21
+ accessToken: string;
22
+ }
23
+ export declare class StorefrontApiClient {
24
+ private client;
25
+ private readonly shortCache;
26
+ private readonly longCache;
27
+ constructor(config: StorefrontConfig);
28
+ fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
29
+ query: <TData, TVariables extends Record<string, unknown>>(query: string, variables: TVariables) => Promise<{
30
+ data: (TData extends undefined ? any : TData) | undefined;
31
+ errors: ResponseErrors | null;
32
+ }>;
33
+ loadProductOptions: (args: LoadProductOptionsArgs) => Promise<{
34
+ data: import("./storefront-api-client").GetProductOptionsQuery | import("./storefront-api-client").GetProductOptionsWithVariantQuery | undefined;
35
+ errors: ResponseErrors | null;
36
+ }>;
37
+ loadSelectedVariant: (args: LoadSelectedVariantArgs) => Promise<{
38
+ data: import("./storefront-api-client").GetSelectedVariantQuery | undefined;
39
+ errors: ResponseErrors | null;
40
+ }>;
41
+ loadProductCardData: (args: LoadProductCardDataArgs) => Promise<{
42
+ data: import("./storefront-api-client").GetProductCardDataQuery | import("./storefront-api-client").GetProductCardDataWithVariantQuery | undefined;
43
+ errors: ResponseErrors | null;
44
+ }>;
45
+ loadProductDetailData: (args: LoadProductDetailDataArgs) => Promise<{
46
+ data: import("./storefront-api-client").GetProductDetailDataQuery | import("./storefront-api-client").GetProductDetailDataWithVariantQuery | undefined;
47
+ errors: ResponseErrors | null;
48
+ }>;
49
+ loadProductImages: (args: LoadProductImagesArgs) => Promise<{
50
+ data: (Pick<import("./types/storefront.types").Image, "id" | "altText" | "url" | "thumbhash"> | undefined)[];
51
+ error: null;
52
+ } | {
53
+ data: null;
54
+ error: Error;
55
+ }>;
56
+ loadProductRecommendations: (args: LoadProductRecommendationsArgs) => Promise<{
57
+ data: {
58
+ productRecommendations?: import("./types/storefront.types").Product[] | null;
59
+ } | undefined;
60
+ errors: ResponseErrors | null;
61
+ }>;
62
+ loadProductId: (args: LoadProductIdArgs) => Promise<{
63
+ data: import("./storefront-api-client").GetProductIdByHandleQuery | undefined;
64
+ errors: ResponseErrors | null;
65
+ }>;
66
+ clearCache(): Promise<void>;
67
+ }