@swishapp/sdk 0.80.3 → 0.89.1

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.
@@ -2,18 +2,13 @@ import { Item } from "@swishapp/api-client";
2
2
  import * as v from "valibot";
3
3
  import { GetSaveIntentDataQuery, GetSaveIntentDataWithVariantQuery } from "../../storefront-api/storefront-api-client";
4
4
  import { IntentHandler } from "../intent-handler";
5
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
5
+ import { IntentResponse, SuccessIntentResponse } from "../types";
6
6
  export declare const CreateItemIntentDataSchema: v.ObjectSchema<{
7
7
  readonly productId: v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>]>, v.NumberSchema<undefined>], undefined>, v.TransformAction<string | number, number>, v.NumberSchema<undefined>]>;
8
8
  readonly variantId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>]>, v.NumberSchema<undefined>], undefined>, v.TransformAction<any, number>, v.NumberSchema<undefined>]>, undefined>;
9
9
  readonly quantity: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
10
10
  readonly tags: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
11
11
  }, undefined>;
12
- export interface CreateItemIntent extends IntentBase {
13
- action: "create";
14
- type: "swish/Item";
15
- data: CreateItemIntentData;
16
- }
17
12
  export interface CreateItemIntentData extends Omit<CreateItemIntentDataValidated, "productId" | "variantId"> {
18
13
  productId: number | string;
19
14
  variantId?: number | string;
@@ -24,6 +19,6 @@ export type CreateItemSuccessResponse = SuccessIntentResponse<{
24
19
  product: GetSaveIntentDataQuery["product"];
25
20
  variant: GetSaveIntentDataWithVariantQuery["variant"];
26
21
  }>;
27
- export declare class CreateItemHandler extends IntentHandler<CreateItemIntent> {
28
- invoke(intent: CreateItemIntent): Promise<IntentResponse<CreateItemIntent>>;
22
+ export declare class CreateItemHandler extends IntentHandler<"create:item"> {
23
+ invoke(data: CreateItemIntentData): Promise<IntentResponse<"create:item">>;
29
24
  }
@@ -1,13 +1,10 @@
1
1
  import { List } from "@swishapp/api-client";
2
2
  import { IntentHandler } from "../intent-handler";
3
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
4
- export interface CreateListIntent extends IntentBase {
5
- action: "create";
6
- type: "swish/List";
7
- }
3
+ import { IntentResponse, SuccessIntentResponse } from "../types";
4
+ export type CreateListIntentData = void;
8
5
  export type CreateListSuccessResponse = SuccessIntentResponse<{
9
6
  list: List;
10
7
  }>;
11
- export declare class CreateListHandler extends IntentHandler<CreateListIntent> {
12
- invoke(intent: CreateListIntent): Promise<IntentResponse<CreateListIntent>>;
8
+ export declare class CreateListHandler extends IntentHandler<"create:list"> {
9
+ invoke(data?: CreateListIntentData): Promise<IntentResponse<"create:list">>;
13
10
  }
@@ -1,18 +1,13 @@
1
1
  import * as v from "valibot";
2
2
  import { IntentHandler } from "../intent-handler";
3
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
3
+ import { IntentResponse, SuccessIntentResponse } from "../types";
4
4
  export declare const DeleteItemIntentDataSchema: v.ObjectSchema<{
5
5
  readonly itemId: v.StringSchema<undefined>;
6
6
  }, undefined>;
7
- export interface DeleteItemIntent extends IntentBase {
8
- action: "delete";
9
- type: "swish/Item";
10
- data: DeleteItemIntentData;
11
- }
12
7
  export type DeleteItemIntentData = v.InferOutput<typeof DeleteItemIntentDataSchema>;
13
8
  export type DeleteItemSuccessResponse = SuccessIntentResponse<{
14
9
  itemId: string;
15
10
  }>;
16
- export declare class DeleteItemHandler extends IntentHandler<DeleteItemIntent> {
17
- invoke(intent: DeleteItemIntent): Promise<IntentResponse<DeleteItemIntent>>;
11
+ export declare class DeleteItemHandler extends IntentHandler<"delete:item"> {
12
+ invoke(data: DeleteItemIntentData): Promise<IntentResponse<"delete:item">>;
18
13
  }
@@ -1,18 +1,13 @@
1
1
  import * as v from "valibot";
2
2
  import { IntentHandler } from "../intent-handler";
3
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
3
+ import { IntentResponse, SuccessIntentResponse } from "../types";
4
4
  export declare const DeleteListIntentDataSchema: v.ObjectSchema<{
5
5
  readonly listId: v.StringSchema<undefined>;
6
6
  }, undefined>;
7
- export interface DeleteListIntent extends IntentBase {
8
- action: "delete";
9
- type: "swish/List";
10
- data: DeleteListIntentData;
11
- }
12
7
  export type DeleteListIntentData = v.InferOutput<typeof DeleteListIntentDataSchema>;
13
8
  export type DeleteListSuccessResponse = SuccessIntentResponse<{
14
9
  listId: string;
15
10
  }>;
16
- export declare class DeleteListHandler extends IntentHandler<DeleteListIntent> {
17
- invoke(intent: DeleteListIntent): Promise<IntentResponse<DeleteListIntent>>;
11
+ export declare class DeleteListHandler extends IntentHandler<"delete:list"> {
12
+ invoke(data: DeleteListIntentData): Promise<IntentResponse<"delete:list">>;
18
13
  }
@@ -2,16 +2,10 @@ import { ItemDetail } from "@swishapp/api-client";
2
2
  import * as v from "valibot";
3
3
  import { GetSaveIntentDataQuery, GetSaveIntentDataWithVariantQuery } from "../../storefront-api/storefront-api-client";
4
4
  import { IntentHandler } from "../intent-handler";
5
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
6
- import { DeleteItemIntent } from "./delete-item-handler";
5
+ import { IntentResponse, SuccessIntentResponse } from "../types";
7
6
  export declare const EditItemListsIntentDataSchema: v.ObjectSchema<{
8
7
  readonly itemId: v.StringSchema<undefined>;
9
8
  }, undefined>;
10
- export interface EditItemListsIntent extends IntentBase {
11
- action: "edit";
12
- type: "swish/ItemLists";
13
- data: EditItemListsIntentData;
14
- }
15
9
  export interface EditItemListsIntentData extends EditItemListsIntentDataValidated {
16
10
  }
17
11
  export type EditItemListsSuccessResponse = SuccessIntentResponse<{
@@ -20,6 +14,6 @@ export type EditItemListsSuccessResponse = SuccessIntentResponse<{
20
14
  variant: GetSaveIntentDataWithVariantQuery["variant"];
21
15
  }>;
22
16
  export type EditItemListsIntentDataValidated = v.InferOutput<typeof EditItemListsIntentDataSchema>;
23
- export declare class EditItemListsHandler extends IntentHandler<EditItemListsIntent> {
24
- invoke(intent: EditItemListsIntent, skipEvents?: boolean): Promise<IntentResponse<EditItemListsIntent | DeleteItemIntent>>;
17
+ export declare class EditItemListsHandler extends IntentHandler<"edit:item-lists" | "delete:item"> {
18
+ invoke(data: EditItemListsIntentData): Promise<IntentResponse<"edit:item-lists" | "delete:item">>;
25
19
  }
@@ -2,17 +2,12 @@ import { Item } from "@swishapp/api-client";
2
2
  import * as v from "valibot";
3
3
  import { GetSaveIntentDataQuery, GetSaveIntentDataWithVariantQuery } from "../../storefront-api/storefront-api-client";
4
4
  import { IntentHandler } from "../intent-handler";
5
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
5
+ import { IntentResponse, SuccessIntentResponse } from "../types";
6
6
  export declare const EditItemVariantIntentDataSchema: v.ObjectSchema<{
7
7
  readonly itemId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>]>, undefined>;
8
8
  readonly productId: v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>]>, v.NumberSchema<undefined>], undefined>, v.TransformAction<string | number, number>, v.NumberSchema<undefined>]>;
9
9
  readonly variantId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, string>]>, v.NumberSchema<undefined>], undefined>, v.TransformAction<string | number, number>, v.NumberSchema<undefined>]>, undefined>;
10
10
  }, undefined>;
11
- export interface EditItemVariantIntent extends IntentBase {
12
- action: "edit";
13
- type: "swish/ItemVariant";
14
- data: EditItemVariantIntentData;
15
- }
16
11
  export interface EditItemVariantIntentData extends Omit<EditItemVariantIntentDataValidated, "productId" | "variantId"> {
17
12
  productId: number | string;
18
13
  variantId?: number | string;
@@ -23,6 +18,6 @@ export type EditItemVariantSuccessResponse = SuccessIntentResponse<{
23
18
  product: GetSaveIntentDataQuery["product"];
24
19
  variant: GetSaveIntentDataWithVariantQuery["variant"];
25
20
  }>;
26
- export declare class EditItemVariantHandler extends IntentHandler<EditItemVariantIntent> {
27
- invoke(intent: EditItemVariantIntent, skipEvents?: boolean): Promise<IntentResponse<EditItemVariantIntent>>;
21
+ export declare class EditItemVariantHandler extends IntentHandler<"edit:item-variant"> {
22
+ invoke(data: EditItemVariantIntentData): Promise<IntentResponse<"edit:item-variant">>;
28
23
  }
@@ -1,19 +1,14 @@
1
1
  import { List } from "@swishapp/api-client";
2
2
  import * as v from "valibot";
3
3
  import { IntentHandler } from "../intent-handler";
4
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
4
+ import { IntentResponse, SuccessIntentResponse } from "../types";
5
5
  export declare const EditListIntentDataSchema: v.ObjectSchema<{
6
6
  readonly listId: v.StringSchema<undefined>;
7
7
  }, undefined>;
8
- export interface EditListIntent extends IntentBase {
9
- action: "edit";
10
- type: "swish/List";
11
- data: EditListIntentData;
12
- }
13
8
  export type EditListIntentData = v.InferOutput<typeof EditListIntentDataSchema>;
14
9
  export type EditListSuccessResponse = SuccessIntentResponse<{
15
10
  list: List;
16
11
  }>;
17
- export declare class EditListHandler extends IntentHandler<EditListIntent> {
18
- invoke(intent: EditListIntent): Promise<IntentResponse<EditListIntent>>;
12
+ export declare class EditListHandler extends IntentHandler<"edit:list"> {
13
+ invoke(data: EditListIntentData): Promise<IntentResponse<"edit:list">>;
19
14
  }
@@ -1,10 +1,6 @@
1
1
  import { IntentHandler } from "../intent-handler";
2
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
3
- export interface OpenHomeIntent extends IntentBase {
4
- action: "open";
5
- type: "swish/Home";
6
- }
2
+ import { IntentResponse, SuccessIntentResponse } from "../types";
7
3
  export type OpenHomeSuccessResponse = SuccessIntentResponse<void>;
8
- export declare class OpenHomeHandler extends IntentHandler<OpenHomeIntent> {
9
- invoke(intent: OpenHomeIntent): Promise<IntentResponse<OpenHomeIntent>>;
4
+ export declare class OpenHomeHandler extends IntentHandler<"open:home"> {
5
+ invoke(data?: void): Promise<IntentResponse<"open:home">>;
10
6
  }
@@ -1,18 +1,13 @@
1
1
  import * as v from "valibot";
2
2
  import { IntentHandler } from "../intent-handler";
3
- import { IntentBase, IntentResponse } from "../types";
3
+ import { IntentResponse } from "../types";
4
4
  import { EditListSuccessResponse } from "./edit-list-handler";
5
5
  import { DeleteListSuccessResponse } from "./delete-list-handler";
6
6
  export declare const OpenListMenuIntentDataSchema: v.ObjectSchema<{
7
7
  readonly listId: v.StringSchema<undefined>;
8
8
  }, undefined>;
9
- export interface OpenListMenuIntent extends IntentBase {
10
- action: "open";
11
- type: "swish/ListMenu";
12
- data: OpenListMenuIntentData;
13
- }
14
9
  export type OpenListMenuIntentData = v.InferOutput<typeof OpenListMenuIntentDataSchema>;
15
10
  export type OpenListMenuSuccessResponse = EditListSuccessResponse | DeleteListSuccessResponse;
16
- export declare class OpenListMenuHandler extends IntentHandler<OpenListMenuIntent> {
17
- invoke(intent: OpenListMenuIntent): Promise<IntentResponse<OpenListMenuIntent>>;
11
+ export declare class OpenListMenuHandler extends IntentHandler<"open:list-menu" | "edit:list" | "delete:list"> {
12
+ invoke(data: OpenListMenuIntentData): Promise<IntentResponse<"open:list-menu" | "edit:list" | "delete:list">>;
18
13
  }
@@ -1,18 +1,13 @@
1
1
  import * as v from "valibot";
2
2
  import { QuickBuySubmitData } from "../../swish";
3
3
  import { IntentHandler } from "../intent-handler";
4
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
4
+ import { IntentResponse, SuccessIntentResponse } from "../types";
5
5
  export declare const OpenQuickBuyIntentDataSchema: v.ObjectSchema<{
6
6
  readonly productId: v.StringSchema<undefined>;
7
7
  readonly variantId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
8
8
  }, undefined>;
9
- export interface OpenQuickBuyIntent extends IntentBase {
10
- action: "open";
11
- type: "swish/QuickBuy";
12
- data: OpenQuickBuyIntentData;
13
- }
14
9
  export type OpenQuickBuyIntentData = v.InferOutput<typeof OpenQuickBuyIntentDataSchema>;
15
10
  export type OpenQuickBuySuccessResponse = SuccessIntentResponse<QuickBuySubmitData>;
16
- export declare class OpenQuickBuyHandler extends IntentHandler<OpenQuickBuyIntent> {
17
- invoke(intent: OpenQuickBuyIntent): Promise<IntentResponse<OpenQuickBuyIntent>>;
11
+ export declare class OpenQuickBuyHandler extends IntentHandler<"open:quick-buy"> {
12
+ invoke(data: OpenQuickBuyIntentData): Promise<IntentResponse<"open:quick-buy">>;
18
13
  }
@@ -1,16 +1,11 @@
1
1
  import * as v from "valibot";
2
2
  import { IntentHandler } from "../intent-handler";
3
- import { IntentBase, IntentResponse, SuccessIntentResponse } from "../types";
3
+ import { IntentResponse, SuccessIntentResponse } from "../types";
4
4
  export declare const OpenSignInIntentDataSchema: v.ObjectSchema<{
5
5
  readonly returnTo: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6
6
  }, undefined>;
7
- export interface OpenSignInIntent extends IntentBase {
8
- action: "open";
9
- type: "swish/SignIn";
10
- data: OpenSignInIntentData;
11
- }
12
7
  export type OpenSignInIntentData = v.InferOutput<typeof OpenSignInIntentDataSchema>;
13
8
  export type OpenSignInSuccessResponse = SuccessIntentResponse<void>;
14
- export declare class OpenSignInHandler extends IntentHandler<OpenSignInIntent> {
15
- invoke(intent: OpenSignInIntent): Promise<IntentResponse<OpenSignInIntent>>;
9
+ export declare class OpenSignInHandler extends IntentHandler<"open:sign-in"> {
10
+ invoke(data: OpenSignInIntentData | undefined): Promise<IntentResponse<"open:sign-in">>;
16
11
  }
@@ -0,0 +1,17 @@
1
+ import { IntentHandler } from "../intent-handler";
2
+ import { IntentResponse, IntentToData, SuccessIntentResponse } from "../types";
3
+ import * as v from "valibot";
4
+ export declare const ToastIntentDataSchema: v.ObjectSchema<{
5
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6
+ readonly text: v.StringSchema<undefined>;
7
+ readonly image: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
8
+ readonly action: v.OptionalSchema<v.ObjectSchema<{
9
+ readonly label: v.StringSchema<undefined>;
10
+ readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
11
+ }, undefined>, undefined>;
12
+ }, undefined>;
13
+ export type ToastIntentData = v.InferOutput<typeof ToastIntentDataSchema>;
14
+ export type ToastSuccessResponse = SuccessIntentResponse<void>;
15
+ export declare class ShowToastHandler extends IntentHandler<"show:toast"> {
16
+ invoke(data: IntentToData<"show:toast">): Promise<IntentResponse<"show:toast">>;
17
+ }
@@ -1,6 +1,5 @@
1
- import { CreateItemIntent } from "../handlers/create-item-handler";
2
1
  import { IntentHook } from "../intent-hook";
3
2
  import { IntentResponse } from "../types";
4
- export declare class AfterCreateItemHook extends IntentHook<CreateItemIntent> {
5
- invoke(response: IntentResponse<CreateItemIntent>): Promise<void>;
3
+ export declare class AfterCreateItemHook extends IntentHook<"create:item"> {
4
+ invoke(response: IntentResponse<"create:item">): Promise<void>;
6
5
  }
@@ -1,6 +1,5 @@
1
- import { EditItemListsIntent } from "../handlers/edit-item-lists-handler";
2
1
  import { IntentHook } from "../intent-hook";
3
2
  import { IntentResponse } from "../types";
4
- export declare class AfterEditItemListsHook extends IntentHook<EditItemListsIntent> {
5
- invoke(response: IntentResponse<EditItemListsIntent>): Promise<void>;
3
+ export declare class AfterEditItemListsHook extends IntentHook<"edit:item-lists"> {
4
+ invoke(response: IntentResponse<"edit:item-lists">): Promise<void>;
6
5
  }
@@ -0,0 +1,5 @@
1
+ import { IntentHook } from "../intent-hook";
2
+ import { IntentResponse } from "../types";
3
+ export declare class AfterOpenHomeHook extends IntentHook<"open:home"> {
4
+ invoke(response: IntentResponse<"open:home">): Promise<void>;
5
+ }
@@ -1,12 +1,12 @@
1
1
  import { SwishApp } from "../swish";
2
2
  import { SwishUi } from "../swish-ui/swish-ui";
3
3
  import { IntentOptions } from "./intents";
4
- import { Intent, IntentEventBus, IntentResponse } from "./types";
5
- export declare abstract class IntentHandler<T extends Intent = Intent> {
4
+ import { Intent, IntentEventBus, IntentResponse, IntentToData } from "./types";
5
+ export declare abstract class IntentHandler<I extends Intent = Intent> {
6
6
  protected readonly swish: SwishApp;
7
7
  protected readonly ui: SwishUi;
8
8
  protected readonly eventBus: IntentEventBus;
9
9
  protected readonly options: IntentOptions;
10
10
  constructor(swish: SwishApp, ui: SwishUi, eventBus: IntentEventBus, options: IntentOptions);
11
- abstract invoke(intent: T): Promise<IntentResponse<T>>;
11
+ abstract invoke(data: IntentToData<I>, ...args: any[]): Promise<IntentResponse<I>>;
12
12
  }
@@ -2,10 +2,10 @@ import type { SwishApp } from "../swish";
2
2
  import { SwishUi } from "../swish-ui/swish-ui";
3
3
  import type { IntentOptions } from "./intents";
4
4
  import type { Intent, IntentResponse } from "./types";
5
- export declare abstract class IntentHook<T extends Intent = Intent> {
5
+ export declare abstract class IntentHook<I extends Intent = Intent> {
6
6
  protected readonly swish: SwishApp;
7
7
  protected readonly ui: SwishUi;
8
8
  protected readonly options: IntentOptions;
9
9
  constructor(swish: SwishApp, ui: SwishUi, options: IntentOptions);
10
- abstract invoke(respomse: IntentResponse<T>): Promise<void>;
10
+ abstract invoke(response: IntentResponse<I>): Promise<void>;
11
11
  }
@@ -1,5 +1,5 @@
1
1
  import { SwishApp } from "../swish";
2
- import { Intent, IntentActivity, IntentQuery, IntentQueryWithParams, IntentResponse } from "./types";
2
+ import { Intent, IntentActivity, IntentQueryWithParams, IntentResponse, IntentToData } from "./types";
3
3
  import { SwishUi } from "../swish-ui/swish-ui";
4
4
  export interface IntentOptions {
5
5
  save: {
@@ -20,13 +20,17 @@ export declare class Intents {
20
20
  private readonly ui;
21
21
  private readonly eventBus;
22
22
  private readonly options;
23
+ private readonly handlers;
23
24
  constructor(swish: SwishApp, ui: SwishUi);
24
25
  publishAnalyticsEvent(event: string, data: Record<string, any>): void;
25
- invoke<T extends Intent>(intent: T): Promise<IntentActivity<T>>;
26
- listen(intent: Pick<Intent, "action" | "type">, callback: (response: IntentResponse) => void): () => void;
27
- getIntentQuery(intent: Pick<Intent, "action" | "type">): IntentQuery;
28
- parseIntent(intent: Intent | IntentQuery | IntentQueryWithParams): Intent;
29
- handleIntent<T extends Intent>(intent: T): Promise<IntentResponse<T>>;
26
+ invoke<I extends Intent>(intent: I, ...args: IntentToData<I> extends void ? [] | [undefined] : [IntentToData<I>]): Promise<IntentActivity<I, IntentToData<I>>>;
27
+ listen<I extends Intent>(intent: I, callback: (response: IntentResponse<I>) => void): () => void;
28
+ parseIntentFromString(intentString: Intent | IntentQueryWithParams): {
29
+ intent: Intent;
30
+ data: Record<string, string>;
31
+ };
32
+ parseIntentFromHash(hash: string): Intent | null;
33
+ handleIntent<I extends Intent>(intent: I, data: IntentToData<I>): Promise<IntentResponse<I>>;
30
34
  initIntentHooks(): void;
31
35
  initIntentWatcher(): void;
32
36
  }
@@ -1,72 +1,75 @@
1
- import { CreateItemIntent, CreateItemSuccessResponse } from "./handlers/create-item-handler";
2
- import { DeleteItemIntent, DeleteItemSuccessResponse } from "./handlers/delete-item-handler";
3
- import { EditItemVariantIntent, EditItemVariantSuccessResponse } from "./handlers/edit-item-variant-handler";
4
- import { EditItemListsIntent, EditItemListsSuccessResponse } from "./handlers/edit-item-lists-handler";
5
- import { EditListIntent, EditListSuccessResponse } from "./handlers/edit-list-handler";
6
- import { DeleteListIntent, DeleteListSuccessResponse } from "./handlers/delete-list-handler";
7
- import { CreateListIntent, CreateListSuccessResponse } from "./handlers/create-list-handler";
8
- import { OpenHomeIntent, OpenHomeSuccessResponse } from "./handlers/open-home-handler";
9
- import { OpenListMenuIntent, OpenListMenuSuccessResponse } from "./handlers/open-list-menu-handler";
10
- import { OpenSignInIntent, OpenSignInSuccessResponse } from "./handlers/open-sign-in-handler";
11
- import { OpenQuickBuyIntent, OpenQuickBuySuccessResponse } from "./handlers/open-quick-buy-handler";
12
- export type { DeleteItemSuccessResponse, EditItemVariantSuccessResponse, EditItemListsSuccessResponse, CreateItemSuccessResponse, EditListSuccessResponse, DeleteListSuccessResponse, CreateListSuccessResponse, };
13
- export type IntentAction = "create" | "edit" | "delete" | "open";
14
- export type IntentType = "swish/Item" | "swish/ItemVariant" | "swish/ItemLists" | "swish/List" | "swish/Home" | "swish/ListMenu" | "swish/SignIn" | "swish/QuickBuy";
15
- export type IntentQuery = `${IntentAction}:${IntentType}`;
1
+ import type { CreateItemIntentData, CreateItemSuccessResponse } from "./handlers/create-item-handler";
2
+ import type { DeleteItemIntentData, DeleteItemSuccessResponse } from "./handlers/delete-item-handler";
3
+ import type { EditItemVariantIntentData, EditItemVariantSuccessResponse } from "./handlers/edit-item-variant-handler";
4
+ import type { EditItemListsIntentData, EditItemListsSuccessResponse } from "./handlers/edit-item-lists-handler";
5
+ import type { EditListIntentData, EditListSuccessResponse } from "./handlers/edit-list-handler";
6
+ import type { DeleteListIntentData, DeleteListSuccessResponse } from "./handlers/delete-list-handler";
7
+ import type { CreateListIntentData, CreateListSuccessResponse } from "./handlers/create-list-handler";
8
+ import type { OpenHomeSuccessResponse } from "./handlers/open-home-handler";
9
+ import type { OpenListMenuIntentData, OpenListMenuSuccessResponse } from "./handlers/open-list-menu-handler";
10
+ import type { OpenSignInIntentData, OpenSignInSuccessResponse } from "./handlers/open-sign-in-handler";
11
+ import type { OpenQuickBuyIntentData, OpenQuickBuySuccessResponse } from "./handlers/open-quick-buy-handler";
12
+ import { ToastIntentData, ToastSuccessResponse } from "./handlers/show-toast-handler";
13
+ export type { DeleteItemSuccessResponse, EditItemVariantSuccessResponse, EditItemListsSuccessResponse, CreateItemSuccessResponse, EditListSuccessResponse, DeleteListSuccessResponse, CreateListSuccessResponse, ToastSuccessResponse, };
14
+ export type Intent = "create:item" | "edit:item-variant" | "edit:item-lists" | "delete:item" | "edit:list" | "delete:list" | "create:list" | "open:home" | "open:list-menu" | "open:sign-in" | "open:quick-buy" | "show:toast";
16
15
  export type IntentQueryParam = `${string}=${string}`;
17
- export type IntentQueryWithParams = `${IntentQuery},${IntentQueryParam}`;
18
- export type Intent = CreateItemIntent | EditItemVariantIntent | EditItemListsIntent | DeleteItemIntent | EditListIntent | DeleteListIntent | CreateListIntent | OpenHomeIntent | OpenListMenuIntent | OpenSignInIntent | OpenQuickBuyIntent;
19
- export type IntentResponse<I extends Intent = Intent> = ClosedIntentResponse | ErrorIntentResponse | IntentToSuccessResponse<I>;
20
- export type IntentQueryResponse<I extends IntentQuery = IntentQuery> = ClosedIntentResponse | ErrorIntentResponse | IntentQueryToSuccessResponse<I>;
21
- export type IntentResponseEvent<I extends IntentQuery = IntentQuery> = CustomEvent<IntentQueryResponse<I>>;
22
- export interface IntentActivity<I extends Intent = Intent> {
16
+ export type IntentQueryWithParams = `${Intent},${IntentQueryParam}`;
17
+ export type IntentResponse<I extends Intent = Intent> = ClosedIntentResponse<I> | ErrorIntentResponse<I> | IntentToSuccessResponse<I>;
18
+ export type IntentResponseEvent<I extends Intent = Intent> = CustomEvent<IntentResponse<I>>;
19
+ export interface IntentActivity<I extends Intent = Intent, D = IntentToData<I>> {
23
20
  intent: I;
21
+ data: D;
24
22
  complete: Promise<IntentResponse<I>>;
25
23
  }
26
- export interface IntentResponseBase {
24
+ export interface IntentResponseBase<I extends Intent = Intent> {
25
+ intent: I;
27
26
  code: "ok" | "error" | "closed";
28
27
  }
29
- export interface ClosedIntentResponse extends IntentResponseBase {
28
+ export interface ClosedIntentResponse<I extends Intent = Intent> extends IntentResponseBase<I> {
30
29
  code: "closed";
31
30
  }
32
- export interface ErrorIntentResponse extends IntentResponseBase {
31
+ export interface ErrorIntentResponse<I extends Intent = Intent> extends IntentResponseBase<I> {
33
32
  code: "error";
34
33
  message: string;
35
34
  issues: string[];
36
35
  }
37
- export interface SuccessIntentResponse<T> extends IntentResponseBase {
36
+ export interface SuccessIntentResponse<T, I extends Intent = Intent> extends IntentResponseBase<I> {
38
37
  code: "ok";
39
38
  data: T;
40
39
  }
41
- export interface IntentBase {
42
- action: IntentAction;
43
- type: IntentType;
44
- data?: unknown;
40
+ interface IntentDataMap {
41
+ "create:item": CreateItemIntentData;
42
+ "edit:item-variant": EditItemVariantIntentData;
43
+ "edit:item-lists": EditItemListsIntentData;
44
+ "delete:item": DeleteItemIntentData;
45
+ "edit:list": EditListIntentData;
46
+ "delete:list": DeleteListIntentData;
47
+ "create:list": CreateListIntentData;
48
+ "open:home": void;
49
+ "open:list-menu": OpenListMenuIntentData;
50
+ "open:sign-in": OpenSignInIntentData | undefined;
51
+ "open:quick-buy": OpenQuickBuyIntentData;
52
+ "show:toast": ToastIntentData;
45
53
  }
46
- export interface IntentSuccessResponseMap {
47
- "create:swish/Item": CreateItemSuccessResponse;
48
- "edit:swish/ItemVariant": EditItemVariantSuccessResponse;
49
- "edit:swish/ItemLists": EditItemListsSuccessResponse | DeleteItemSuccessResponse;
50
- "delete:swish/Item": DeleteItemSuccessResponse;
51
- "edit:swish/List": EditListSuccessResponse;
52
- "delete:swish/List": DeleteListSuccessResponse;
53
- "create:swish/List": CreateListSuccessResponse;
54
- "open:swish/Home": OpenHomeSuccessResponse;
55
- "open:swish/ListMenu": OpenListMenuSuccessResponse;
56
- "open:swish/SignIn": OpenSignInSuccessResponse;
57
- "open:swish/QuickBuy": OpenQuickBuySuccessResponse;
54
+ interface IntentSuccessResponseMap {
55
+ "create:item": CreateItemSuccessResponse;
56
+ "edit:item-variant": EditItemVariantSuccessResponse;
57
+ "edit:item-lists": EditItemListsSuccessResponse | DeleteItemSuccessResponse;
58
+ "delete:item": DeleteItemSuccessResponse;
59
+ "edit:list": EditListSuccessResponse;
60
+ "delete:list": DeleteListSuccessResponse;
61
+ "create:list": CreateListSuccessResponse;
62
+ "open:home": OpenHomeSuccessResponse;
63
+ "open:list-menu": OpenListMenuSuccessResponse;
64
+ "open:sign-in": OpenSignInSuccessResponse;
65
+ "open:quick-buy": OpenQuickBuySuccessResponse;
66
+ "show:toast": ToastSuccessResponse;
58
67
  }
59
- export type IntentToSuccessResponse<I extends {
60
- action: IntentAction;
61
- type: IntentType;
62
- }> = I extends {
63
- action: infer A;
64
- type: infer T;
65
- } ? `${Extract<A, string>}:${Extract<T, string>}` extends keyof IntentSuccessResponseMap ? IntentSuccessResponseMap[`${Extract<A, string>}:${Extract<T, string>}`] : never : never;
66
- export type IntentQueryToSuccessResponse<I extends IntentQuery = IntentQuery> = I extends keyof IntentSuccessResponseMap ? IntentSuccessResponseMap[I] : never;
68
+ export type IntentToData<I extends Intent> = I extends keyof IntentDataMap ? IntentDataMap[I] : never;
69
+ export type IntentToSuccessResponse<I extends Intent> = I extends keyof IntentSuccessResponseMap ? IntentSuccessResponseMap[I] : never;
67
70
  export type IntentResposeEvent = CustomEvent<IntentResponse>;
68
71
  export interface IntentEventBus {
69
- addEventListener<I extends IntentQuery = IntentQuery>(type: I, callback: (event: IntentResponseEvent<I>) => void): void;
70
- removeEventListener(type: IntentQuery, callback: (event: IntentResposeEvent) => void): void;
72
+ addEventListener<I extends Intent = Intent>(type: I, callback: (event: IntentResponseEvent<I>) => void): void;
73
+ removeEventListener(type: Intent, callback: (event: IntentResposeEvent) => void): void;
71
74
  dispatchEvent(event: IntentResponseEvent): boolean;
72
75
  }
@@ -32,7 +32,6 @@ export interface SwishUiOptions {
32
32
  version: string;
33
33
  }
34
34
  export interface StorefrontContext {
35
- myshopifyDomain: string;
36
35
  customer: {
37
36
  id: string | null;
38
37
  email: string | null;
@@ -45,9 +44,10 @@ export interface StorefrontContext {
45
44
  language: LanguageCode;
46
45
  market: string;
47
46
  };
47
+ myshopifyDomain: string;
48
+ newCustomAccounts: boolean;
48
49
  routes: {
49
50
  accountUrl: string;
50
- accountLoginUrl: string;
51
51
  rootUrl: string;
52
52
  };
53
53
  }
@@ -1,31 +1,31 @@
1
+ import { StorefrontContext, SwishUiOptions } from "../options/types";
2
+ import "../utils/shop-bridge";
1
3
  import type { ShopBridge } from "../utils/shop-bridge";
2
4
  import type { SwishUiElement } from "./swish-ui-element";
3
- import "../utils/shop-bridge";
4
- import { StorefrontContext, SwishUiOptions } from "../options/types";
5
- import { DeleteListAlertOptions, DrawerOptions, ListMenuOptions, ListSelectOptions, ListDetailPageOptions, SignInOptions, Toast, UnsaveAlertOptions, VariantSelectOptions, QuickBuyOptions, ListEditorOptions, RequireUiComponentOptions } from "./types";
5
+ import { DeleteListAlertOptions, DrawerOptions, ListDetailPageOptions, ListEditorOptions, ListEditorSubmitData, ListMenuOptions, ListMenuResponse, ListSelectOptions, ListSelectResponse, QuickBuyOptions, QuickBuySubmitData, RequireUiComponentOptions, SignInOptions, Toast, UiResponse, UnsaveAlertOptions, UnsaveAlertSubmitData, VariantSelectOptions, VariantSelectSubmitData } from "./types";
6
6
  export declare class SwishUi {
7
7
  private storefrontContext;
8
8
  private swishUiOptions;
9
9
  private inflightModals;
10
- private eventListeners;
11
10
  private scrollLockStyleSheet;
12
11
  private scrollLockRefCount;
13
12
  private scrollPositionBeforeLock;
14
13
  constructor(swishUiOptions: SwishUiOptions, storefrontContext: StorefrontContext);
15
14
  hideModal(element: string | HTMLElement): Promise<void>;
16
15
  showModal(element: string | HTMLElement): Promise<void>;
17
- showSignIn(options?: SignInOptions): Promise<void>;
18
- showUnsaveAlert(options: UnsaveAlertOptions): Promise<void>;
19
- showDeleteListAlert(options: DeleteListAlertOptions): Promise<void>;
20
- showDrawer(options?: DrawerOptions): Promise<void>;
21
- showListMenu(options: ListMenuOptions): Promise<void>;
22
- showListSelect(options: ListSelectOptions): Promise<void>;
16
+ private waitForEvent;
17
+ showSignIn(options?: SignInOptions): Promise<UiResponse<void>>;
18
+ showUnsaveAlert(options: UnsaveAlertOptions): Promise<UiResponse<UnsaveAlertSubmitData>>;
19
+ showDeleteListAlert(options: DeleteListAlertOptions): Promise<UiResponse<void>>;
20
+ showDrawer(options?: DrawerOptions): Promise<UiResponse<void>>;
21
+ showListMenu(options: ListMenuOptions): Promise<ListMenuResponse>;
22
+ showListSelect(options: ListSelectOptions): Promise<ListSelectResponse>;
23
23
  initListDetailPage(options: ListDetailPageOptions, refElement: HTMLElement): Promise<void>;
24
- showToast(toast: Toast): Promise<void>;
24
+ showToast(toast: Toast): Promise<import("./types").ClosedUiResponse | import("./types").SuccessUiResponse<void>>;
25
25
  hideAllToasts(): Promise<void>;
26
- showVariantSelect(options?: VariantSelectOptions): Promise<void>;
27
- showQuickBuy(options?: QuickBuyOptions): Promise<void>;
28
- showListEditor(options?: ListEditorOptions): Promise<void>;
26
+ showVariantSelect(options?: VariantSelectOptions): Promise<UiResponse<VariantSelectSubmitData>>;
27
+ showQuickBuy(options?: QuickBuyOptions): Promise<UiResponse<QuickBuySubmitData>>;
28
+ showListEditor(options?: ListEditorOptions): Promise<UiResponse<ListEditorSubmitData>>;
29
29
  initShopBridge({ onShopModalOpen }: {
30
30
  onShopModalOpen: () => void;
31
31
  }): Promise<ShopBridge>;