@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.
- package/README.md +50 -0
- package/dist/ajax-api/ajax-api-client.d.ts +81 -0
- package/dist/ajax-api/ajax-api-publisher.d.ts +9 -0
- package/dist/cache/fetch-cache.d.ts +87 -0
- package/dist/dom/dom-utils.d.ts +16 -0
- package/dist/events/event-bus.d.ts +7 -0
- package/dist/index.d.ts +8 -0
- package/dist/state/index.d.ts +4 -0
- package/dist/state/item-context-signal.d.ts +11 -0
- package/dist/state/item-count-signal.d.ts +7 -0
- package/dist/state/item-state-signal.d.ts +19 -0
- package/dist/state/swish-query-signals.d.ts +21 -0
- package/dist/storefront-api/load-product-card-data.d.ts +15 -0
- package/dist/storefront-api/load-product-detail-data.d.ts +15 -0
- package/dist/storefront-api/load-product-id.d.ts +11 -0
- package/dist/storefront-api/load-product-images.d.ts +20 -0
- package/dist/storefront-api/load-product-options.d.ts +13 -0
- package/dist/storefront-api/load-product-recommendations.d.ts +17 -0
- package/dist/storefront-api/load-selected-variant.d.ts +14 -0
- package/dist/storefront-api/queries/fragments.d.ts +7 -0
- package/dist/storefront-api/queries/index.d.ts +14 -0
- package/dist/storefront-api/storefront-api-client.d.ts +67 -0
- package/dist/storefront-api/types/storefront.generated.d.ts +461 -0
- package/dist/storefront-api/types/storefront.types.d.ts +8460 -0
- package/dist/swish-api/items-batch-loader.d.ts +4 -0
- package/dist/swish-api/swish-api-client.d.ts +43 -0
- package/dist/swish-api/swish-api-publisher.d.ts +8 -0
- package/dist/swish-ui/swish-ui-element.d.ts +9 -0
- package/dist/swish-ui/swish-ui-utils.d.ts +112 -0
- package/dist/swish.d.ts +124 -0
- package/dist/swish.js +403 -0
- package/dist/types.d.ts +57 -0
- package/dist/utils/shop-bridge.d.ts +26 -0
- package/dist/utils/shopify-gid.d.ts +2 -0
- package/dist/utils/shopify-url-utils.d.ts +13 -0
- package/package.json +60 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
import type { SwishApi } from "./swish-api-client";
|
|
3
|
+
import type { Item, PaginatedApiResponse } from "@swishapp/api-client";
|
|
4
|
+
export declare const createItemsBatchLoader: (apiClient: SwishApi) => DataLoader<string, PaginatedApiResponse<Item>, string>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ApiResponse, Item, ItemControllerFindData, ItemDetail, ListControllerFindData, ListDetail, PaginatedApiResponse, SwishClientConfig } from "@swishapp/api-client";
|
|
2
|
+
export interface SwishApiConfig extends SwishClientConfig {
|
|
3
|
+
loadProfile?: () => string | undefined;
|
|
4
|
+
storeProfile?: (profile: string) => void;
|
|
5
|
+
deleteProfile?: () => void;
|
|
6
|
+
responseInterceptor?: (response: Response, request: Request) => Promise<void> | void;
|
|
7
|
+
}
|
|
8
|
+
export declare class SwishApi {
|
|
9
|
+
private readonly cache;
|
|
10
|
+
private readonly apiClient;
|
|
11
|
+
private readonly config;
|
|
12
|
+
private readonly itemsLoader;
|
|
13
|
+
constructor(config: SwishApiConfig, cacheKeyPrefix: string);
|
|
14
|
+
private processProfileHeader;
|
|
15
|
+
get items(): {
|
|
16
|
+
list: (query?: ItemControllerFindData["query"], options?: {
|
|
17
|
+
batch?: boolean;
|
|
18
|
+
}) => Promise<PaginatedApiResponse<Item>>;
|
|
19
|
+
findById: (itemId: string) => Promise<ApiResponse<ItemDetail>>;
|
|
20
|
+
create: (items: import("@swishapp/api-client").CreateItemInput) => Promise<ApiResponse<Item>>;
|
|
21
|
+
delete: (itemIds: import("@swishapp/api-client").DeleteItemsInput["itemIds"]) => Promise<ApiResponse<unknown>>;
|
|
22
|
+
updateById: (itemId: string, body: import("@swishapp/api-client").UpdateItemInput) => Promise<ApiResponse<Item>>;
|
|
23
|
+
deleteById: (itemId: string) => Promise<ApiResponse<unknown>>;
|
|
24
|
+
setListsById: (itemId: string, listIds: import("@swishapp/api-client").SetItemListsInput["listIds"]) => Promise<ApiResponse<ItemDetail>>;
|
|
25
|
+
count: () => Promise<ApiResponse<import("@swishapp/api-client").ItemCount>>;
|
|
26
|
+
};
|
|
27
|
+
get lists(): {
|
|
28
|
+
list: (query?: ListControllerFindData["query"]) => Promise<PaginatedApiResponse<ListDetail>>;
|
|
29
|
+
findById: (listId: string) => Promise<ApiResponse<ListDetail>>;
|
|
30
|
+
create: (list: import("@swishapp/api-client").CreateListInput) => Promise<ApiResponse<import("@swishapp/api-client").List>>;
|
|
31
|
+
updateById: (listId: string, body: import("@swishapp/api-client").UpdateListInput) => Promise<ApiResponse<import("@swishapp/api-client").List>>;
|
|
32
|
+
deleteById: (listId: string) => Promise<ApiResponse<unknown>>;
|
|
33
|
+
orderItems: (listId: string, itemIds: import("@swishapp/api-client").SetListItemsOrderInput["itemIds"]) => Promise<ApiResponse<import("@swishapp/api-client").List>>;
|
|
34
|
+
addItemsToList: (listId: string, itemIds: import("@swishapp/api-client").AddItemsToListInput["itemIds"]) => Promise<ApiResponse<ListDetail>>;
|
|
35
|
+
removeItemFromList: (listId: string, itemId: string) => Promise<ApiResponse<unknown>>;
|
|
36
|
+
};
|
|
37
|
+
get profiles(): {
|
|
38
|
+
customerAccountsVersion: () => Promise<ApiResponse<import("@swishapp/api-client").AccountsVersionResult>>;
|
|
39
|
+
createToken: (body?: import("@swishapp/api-client").CreateProfileTokenInput) => Promise<ApiResponse<import("@swishapp/api-client").CreateProfileTokenResult>>;
|
|
40
|
+
identify: (body: import("@swishapp/api-client").IdentifyProfileInput) => Promise<ApiResponse<import("@swishapp/api-client").IdentifyProfileResult>>;
|
|
41
|
+
};
|
|
42
|
+
clearCache(): Promise<void>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EventBus, EventName } from "../events/event-bus";
|
|
2
|
+
export declare class SwishApiPublisher {
|
|
3
|
+
private readonly eventBus;
|
|
4
|
+
private readonly eventMap;
|
|
5
|
+
constructor(eventBus: EventBus);
|
|
6
|
+
processFetchResponse(response: Response, request: Request): Promise<void>;
|
|
7
|
+
getEventName(method: string, status: number, url: string): EventName | undefined;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Ref<T> {
|
|
2
|
+
current: T;
|
|
3
|
+
}
|
|
4
|
+
export declare class SwishUiElement extends HTMLElement {
|
|
5
|
+
constructor();
|
|
6
|
+
private componentRef;
|
|
7
|
+
getComponentRef: <TComponent = unknown>() => Ref<TComponent>;
|
|
8
|
+
setComponentRef: <TComponent = unknown>(ref: Ref<TComponent>) => void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { SwishUiManifest, SwishUiOptions } from "../types";
|
|
2
|
+
import type { ShopBridge } from "../utils/shop-bridge";
|
|
3
|
+
import type { Ref, SwishUiElement } from "./swish-ui-element";
|
|
4
|
+
import "../utils/shop-bridge";
|
|
5
|
+
import { Item, ItemDetail } from "@swishapp/api-client";
|
|
6
|
+
import { GetProductCardDataWithVariantQuery, GetSelectedVariantQuery } from "../storefront-api/storefront-api-client";
|
|
7
|
+
export interface Notifications {
|
|
8
|
+
pushNotification(notification: Notification): string;
|
|
9
|
+
removeNotification(id: string): void;
|
|
10
|
+
clearAllNotifications(): void;
|
|
11
|
+
}
|
|
12
|
+
export interface Notification {
|
|
13
|
+
title?: string;
|
|
14
|
+
text: string;
|
|
15
|
+
image?: string;
|
|
16
|
+
action?: {
|
|
17
|
+
label: string;
|
|
18
|
+
url?: string;
|
|
19
|
+
onAction?: () => void;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare const setConfig: (opts: SwishUiOptions) => void;
|
|
23
|
+
export declare const hideModal: (element: string | HTMLElement) => Promise<void>;
|
|
24
|
+
export declare const showModal: (element: string | HTMLElement) => Promise<void>;
|
|
25
|
+
export declare const showSignIn: (options?: {
|
|
26
|
+
returnTo?: string;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
export interface UnsaveAlertOptions {
|
|
29
|
+
itemId: string;
|
|
30
|
+
onSubmit?: (data: UnsaveAlertSubmitData) => void;
|
|
31
|
+
onCancel?: () => void;
|
|
32
|
+
}
|
|
33
|
+
export interface UnsaveAlertSubmitData {
|
|
34
|
+
itemId: string;
|
|
35
|
+
}
|
|
36
|
+
export declare const showUnsaveAlert: (options: UnsaveAlertOptions) => Promise<void>;
|
|
37
|
+
export declare const showDeleteListAlert: (options: {
|
|
38
|
+
listId: string;
|
|
39
|
+
onSubmit?: () => void;
|
|
40
|
+
onCancel?: () => void;
|
|
41
|
+
}) => Promise<void>;
|
|
42
|
+
export declare const showDrawer: () => Promise<void>;
|
|
43
|
+
export declare const showListMenu: (options: {
|
|
44
|
+
listId: string;
|
|
45
|
+
onClose?: (data: {
|
|
46
|
+
reason: string;
|
|
47
|
+
}) => void;
|
|
48
|
+
}) => Promise<void>;
|
|
49
|
+
export interface ListSelectOptions {
|
|
50
|
+
itemId: string;
|
|
51
|
+
onSubmit?: (data: ListSelectSubmitData) => void | Promise<void>;
|
|
52
|
+
onClose?: () => void;
|
|
53
|
+
onUnsave?: (data: UnsaveAlertSubmitData) => void;
|
|
54
|
+
}
|
|
55
|
+
export type ListSelectProduct = Exclude<GetProductCardDataWithVariantQuery["product"], undefined | null>;
|
|
56
|
+
export type ListSelectVariant = Exclude<GetProductCardDataWithVariantQuery["variant"], undefined | null>;
|
|
57
|
+
export interface ListSelectSubmitData {
|
|
58
|
+
item: ItemDetail;
|
|
59
|
+
product: ListSelectProduct;
|
|
60
|
+
variant?: ListSelectVariant;
|
|
61
|
+
}
|
|
62
|
+
export declare const showListSelect: (options: ListSelectOptions) => Promise<void>;
|
|
63
|
+
export declare const showNotification: (options: {
|
|
64
|
+
title?: string;
|
|
65
|
+
text: string;
|
|
66
|
+
image?: string;
|
|
67
|
+
action?: {
|
|
68
|
+
label: string;
|
|
69
|
+
url?: string;
|
|
70
|
+
onAction?: () => void;
|
|
71
|
+
};
|
|
72
|
+
}) => Promise<void>;
|
|
73
|
+
export declare const hideAllNotifications: () => Promise<void>;
|
|
74
|
+
export interface VariantSelectOptions {
|
|
75
|
+
productId?: string;
|
|
76
|
+
productHandle?: string;
|
|
77
|
+
variantId?: string;
|
|
78
|
+
displayType?: "rows" | "pills";
|
|
79
|
+
action?: "none" | "save";
|
|
80
|
+
onSubmit: (data: VariantSelectSubmitData) => void;
|
|
81
|
+
}
|
|
82
|
+
export type VariantSelectProduct = Exclude<GetSelectedVariantQuery["product"], undefined | null>;
|
|
83
|
+
export type VariantSelectVariant = Exclude<VariantSelectProduct["variantBySelectedOptions"], undefined | null>;
|
|
84
|
+
export interface VariantSelectSubmitData {
|
|
85
|
+
item: Item;
|
|
86
|
+
product: VariantSelectProduct;
|
|
87
|
+
variant: VariantSelectVariant;
|
|
88
|
+
}
|
|
89
|
+
export declare const showVariantSelect: (options?: VariantSelectOptions) => Promise<void>;
|
|
90
|
+
export declare const showListEditor: <TData = unknown>(options?: {
|
|
91
|
+
listId?: string;
|
|
92
|
+
variantId?: string;
|
|
93
|
+
onSubmit: (data: TData) => void | Promise<void>;
|
|
94
|
+
}) => Promise<void>;
|
|
95
|
+
export declare const initShopBridge: ({ onShopModalOpen, }: {
|
|
96
|
+
onShopModalOpen: () => void;
|
|
97
|
+
}) => Promise<ShopBridge>;
|
|
98
|
+
export declare const loadManifest: () => Promise<SwishUiManifest>;
|
|
99
|
+
export interface RequireUiComponentOptions<TComponent> {
|
|
100
|
+
instance?: string;
|
|
101
|
+
listeners?: Record<string, (event: Event | CustomEvent) => void>;
|
|
102
|
+
onHydrated?: (ref: Ref<TComponent>) => void;
|
|
103
|
+
}
|
|
104
|
+
export declare const requireUiComponent: <TComponent = unknown>(name: string, options?: RequireUiComponentOptions<TComponent>) => Promise<SwishUiElement>;
|
|
105
|
+
export declare const insertComponent: <T extends HTMLElement = SwishUiElement>({ name, instance, template, position, refElement, }: {
|
|
106
|
+
name: string;
|
|
107
|
+
instance?: string;
|
|
108
|
+
template: string;
|
|
109
|
+
position: InsertPosition;
|
|
110
|
+
refElement: HTMLElement;
|
|
111
|
+
}) => Promise<T>;
|
|
112
|
+
export declare const queryComponent: <T extends HTMLElement = SwishUiElement>(name: string, instance?: string) => T;
|
package/dist/swish.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { SwishAppOptions, SwishEmbedData } from "./types";
|
|
2
|
+
import { AjaxApiClient } from "./ajax-api/ajax-api-client";
|
|
3
|
+
import { createElementLocator, createLocationObserver } from "./dom/dom-utils";
|
|
4
|
+
import { EventBus } from "./events/event-bus";
|
|
5
|
+
import { effect, signal } from "./state";
|
|
6
|
+
import { StorefrontApiClient } from "./storefront-api/storefront-api-client";
|
|
7
|
+
import { SwishApi } from "./swish-api/swish-api-client";
|
|
8
|
+
export declare const VERSION: string;
|
|
9
|
+
export declare const swishEmbedData: SwishEmbedData;
|
|
10
|
+
export declare const swishApp: (options: SwishAppOptions) => Promise<SwishApp>;
|
|
11
|
+
export declare class SwishApp {
|
|
12
|
+
private readonly swishApi;
|
|
13
|
+
private readonly swishApiPublisher;
|
|
14
|
+
private readonly storefrontApi;
|
|
15
|
+
private readonly ajaxApi;
|
|
16
|
+
private readonly ajaxApiPublisher;
|
|
17
|
+
private readonly options;
|
|
18
|
+
readonly events: EventBus;
|
|
19
|
+
constructor(options: SwishAppOptions);
|
|
20
|
+
get customer(): {
|
|
21
|
+
id: string | null;
|
|
22
|
+
email: string | null;
|
|
23
|
+
firstName: string | null;
|
|
24
|
+
lastName: string | null;
|
|
25
|
+
b2b: boolean | null;
|
|
26
|
+
};
|
|
27
|
+
get localization(): {
|
|
28
|
+
country: string;
|
|
29
|
+
language: string;
|
|
30
|
+
market: number;
|
|
31
|
+
};
|
|
32
|
+
get shopifyRoutes(): {
|
|
33
|
+
accountUrl: string;
|
|
34
|
+
accountLoginUrl: string;
|
|
35
|
+
rootUrl: string;
|
|
36
|
+
};
|
|
37
|
+
get api(): SwishApi;
|
|
38
|
+
get storefront(): StorefrontApiClient;
|
|
39
|
+
get ajax(): AjaxApiClient;
|
|
40
|
+
get shopUrl(): string;
|
|
41
|
+
readonly ui: {
|
|
42
|
+
showSignIn: (options?: {
|
|
43
|
+
returnTo?: string;
|
|
44
|
+
}) => Promise<void>;
|
|
45
|
+
showVariantSelect: (options?: import(".").VariantSelectOptions) => Promise<void>;
|
|
46
|
+
initShopBridge: ({ onShopModalOpen, }: {
|
|
47
|
+
onShopModalOpen: () => void;
|
|
48
|
+
}) => Promise<import(".").ShopBridge>;
|
|
49
|
+
showNotification: (options: {
|
|
50
|
+
title?: string;
|
|
51
|
+
text: string;
|
|
52
|
+
image?: string;
|
|
53
|
+
action?: {
|
|
54
|
+
label: string;
|
|
55
|
+
url?: string;
|
|
56
|
+
onAction?: () => void;
|
|
57
|
+
};
|
|
58
|
+
}) => Promise<void>;
|
|
59
|
+
hideAllNotifications: () => Promise<void>;
|
|
60
|
+
showListSelect: (options: import(".").ListSelectOptions) => Promise<void>;
|
|
61
|
+
showDrawer: () => Promise<void>;
|
|
62
|
+
showListEditor: <TData = unknown>(options?: {
|
|
63
|
+
listId?: string;
|
|
64
|
+
variantId?: string;
|
|
65
|
+
onSubmit: (data: TData) => void | Promise<void>;
|
|
66
|
+
}) => Promise<void>;
|
|
67
|
+
showUnsaveAlert: (options: import(".").UnsaveAlertOptions) => Promise<void>;
|
|
68
|
+
hideModal: (element: string | HTMLElement) => Promise<void>;
|
|
69
|
+
showModal: (element: string | HTMLElement) => Promise<void>;
|
|
70
|
+
showListMenu: (options: {
|
|
71
|
+
listId: string;
|
|
72
|
+
onClose?: (data: {
|
|
73
|
+
reason: string;
|
|
74
|
+
}) => void;
|
|
75
|
+
}) => Promise<void>;
|
|
76
|
+
showDeleteListAlert: (options: {
|
|
77
|
+
listId: string;
|
|
78
|
+
onSubmit?: () => void;
|
|
79
|
+
onCancel?: () => void;
|
|
80
|
+
}) => Promise<void>;
|
|
81
|
+
};
|
|
82
|
+
readonly dom: {
|
|
83
|
+
createElementLocator: typeof createElementLocator;
|
|
84
|
+
createQueryParamsObserver: typeof createLocationObserver;
|
|
85
|
+
};
|
|
86
|
+
readonly state: {
|
|
87
|
+
itemContext: (source?: HTMLElement) => import("@preact/signals-core").Signal<import("./state").ItemContext>;
|
|
88
|
+
itemState: (context: import("@preact/signals-core").Signal<import("./state").ItemContext>) => import("@preact/signals-core").ReadonlySignal<{
|
|
89
|
+
error: import("@swishapp/api-client").ApiError | null;
|
|
90
|
+
status: string;
|
|
91
|
+
savedItemId: string | null;
|
|
92
|
+
loading: boolean;
|
|
93
|
+
submitting: boolean;
|
|
94
|
+
saved: boolean;
|
|
95
|
+
saving: boolean;
|
|
96
|
+
unsaving: boolean;
|
|
97
|
+
}> & {
|
|
98
|
+
save: () => Promise<void>;
|
|
99
|
+
unsave: () => void;
|
|
100
|
+
update: () => void;
|
|
101
|
+
toggle: () => Promise<void>;
|
|
102
|
+
};
|
|
103
|
+
itemCount: () => import("@preact/signals-core").ReadonlySignal<{
|
|
104
|
+
count: number;
|
|
105
|
+
loading: boolean;
|
|
106
|
+
error: import("@swishapp/api-client").ApiError | null;
|
|
107
|
+
}>;
|
|
108
|
+
swishQuery: <TResponse extends import("@swishapp/api-client").ApiResponse<any> | import("@swishapp/api-client").PaginatedApiResponse<any>, TVariables>(fetch: import("./state/swish-query-signals").FetchFn<TResponse, TVariables>, options?: {
|
|
109
|
+
variables?: import("@preact/signals-core").Signal<TVariables>;
|
|
110
|
+
skip?: import("@preact/signals-core").Signal<boolean>;
|
|
111
|
+
refetch?: import(".").EventName[];
|
|
112
|
+
}) => {
|
|
113
|
+
data: import("@preact/signals-core").Signal<(TResponse extends {
|
|
114
|
+
data: infer D;
|
|
115
|
+
} ? D : never) | null>;
|
|
116
|
+
pageInfo: import("@preact/signals-core").Signal<import("@swishapp/api-client").PageInfo | null>;
|
|
117
|
+
error: import("@preact/signals-core").Signal<import("@swishapp/api-client").ApiError | null>;
|
|
118
|
+
loading: import("@preact/signals-core").Signal<boolean>;
|
|
119
|
+
refetching: import("@preact/signals-core").ReadonlySignal<boolean>;
|
|
120
|
+
};
|
|
121
|
+
effect: typeof effect;
|
|
122
|
+
signal: typeof signal;
|
|
123
|
+
};
|
|
124
|
+
}
|