webc-miam 5.1.0 → 6.0.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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * An interface used to represent a product when Miam synchronizes the client's cart with
3
+ * Miam's basket, and need to compare products present in each one.
4
+ */
5
+ export interface ComparableProduct {
6
+ /**
7
+ * Id of the product in the client's database (called ext-id on Miam's end).
8
+ */
9
+ id: string;
10
+ /**
11
+ * When client side sends an array of ComparableProduct to Miam, the SDK expects quantities
12
+ * to match the quantity of each product in the cart of the client.
13
+ *
14
+ * When Miam sends an array of ComparableProducts to the client, quantities represent the quantity
15
+ * of products to add to the client's cart, and as such can be negatives if products need to be
16
+ * removed from the cart.
17
+ */
18
+ quantity: number;
19
+ /**
20
+ * The client can add attributes if they need when sending ComparableProducts to the SDK.
21
+ * Miam will send the attributes back if changes are to be made about those products.
22
+ */
23
+ additionalInfos?: any;
24
+ }
@@ -0,0 +1,246 @@
1
+ import { Observable } from 'rxjs';
2
+ import { ComparableProduct } from './comparable-product';
3
+
4
+ export interface MiamInterface {
5
+ /**
6
+ * Method to call when the user begins the payment procedure (typically when they click
7
+ * on a "Confirm my cart" button)
8
+ * @param totalPrice the total price of your basket (can be a floating or integer number)
9
+ */
10
+ paymentStarted: (totalPrice: number) => void;
11
+
12
+ // ---------------------------------------------------------------------------------------------------
13
+
14
+ analytics: {
15
+ /**
16
+ * Initialize Analytics
17
+ *
18
+ * @param domain Plausible domain
19
+ * @param optimizeKey Google Optimize key
20
+ */
21
+ init: (domain: string, optimizeKey: string) => void;
22
+ };
23
+
24
+ // ---------------------------------------------------------------------------------------------------
25
+
26
+ basket: {
27
+ /**
28
+ * Emits true when Miam's basket has succesfully loaded for the first time.
29
+ * Does not emit anything before or after that.
30
+ */
31
+ basketIsReady$: Observable<boolean>;
32
+ /**
33
+ * Fetch the first GroceriesList & Basket early (before any action requires it on Miam's
34
+ * side), so you can start the basket-sync earlier
35
+ */
36
+ initialize: () => void;
37
+ /**
38
+ * If you have different price tables (or pricebooks) for the same point of sale, you can call this
39
+ * method to make Miam know on which pricebook you are using
40
+ * For example, prices can be different depending on if the user chose home delivery or drive-in
41
+ */
42
+ updatePricebook: (pricebookName: string) => void,
43
+ };
44
+
45
+ basketSync: {
46
+ /**
47
+ * The callback parameter is called when Miam's basket changes to update the user's cart accordingly
48
+ *
49
+ * @param pushProductsToBasket a method that updates the user's cart with the pruducts passed in parameter, by adding
50
+ * products if their quantity is positive, and removing them if their quantity is negative
51
+ */
52
+ definePushProductsToBasket: (pushProductsToBasket: (products: ComparableProduct[]) => void) => void;
53
+ /**
54
+ * Call to notify Miam that the user's cart has been updated
55
+ *
56
+ * @param comparableProducts The products in the user's cart
57
+ */
58
+ retailerBasketChanged: (comparableProducts: ComparableProduct[]) => void;
59
+ /**
60
+ * Call to notify Miam that the user's cart was paid
61
+ * Miam then refreshes the groceries-list and basket for the next user's cart
62
+ *
63
+ * @param total The total price of the cart paid
64
+ */
65
+ handlePayment: (total: number) => void
66
+ };
67
+
68
+ // ---------------------------------------------------------------------------------------------------
69
+
70
+ features: {
71
+ /**
72
+ * Call to enable recipes to display a video instead of their picture, if there is a video for the recipe
73
+ */
74
+ enableVideoRecipes: () => void;
75
+ /**
76
+ * Call to enable the catalog to display articles, if their are packages that contain any articles
77
+ */
78
+ enableArticlesInCatalog: () => void;
79
+ /**
80
+ * Call to authorize Miam to ask for user preferences the first time users view the recipe catalog
81
+ */
82
+ enableUserPreferences: () => void;
83
+ /**
84
+ * Call to enable tags displaying on recipe-details
85
+ */
86
+ enableTagsOnRecipes: () => void;
87
+ /**
88
+ * Call to enable personal recipes on recipe-catalog
89
+ */
90
+ enablePersonalRecipes: () => void;
91
+ };
92
+
93
+ // ---------------------------------------------------------------------------------------------------
94
+
95
+ hook: {
96
+ /**
97
+ * Set up a callback which Miam will call before adding a recipe to the user's cart
98
+ *
99
+ * @param callback a method that will be called passing two parameters :
100
+ * - isLogged, true if the user is logged (according to Miam, see user.loadWithExtId for more)
101
+ * - isPosValid true if the PointOfSale is recognized by Miam
102
+ * Typically you might want to use this to show your connexion page if the user tries to add a recipe while logged out
103
+ * or to show your point of sale picker if the user has not chosen one
104
+ */
105
+ setHookCallback: (callback: (isLogged, isPosValid) => boolean) => void;
106
+ };
107
+
108
+ // ---------------------------------------------------------------------------------------------------
109
+
110
+ list: {
111
+ /**
112
+ * Resets Miam's GroceriesList & empties all products & recipes added by the user
113
+ * /!\ We heavily recommend not to use this method outside of the web console for testing purposes /!\
114
+ */
115
+ reset: () => void;
116
+ /**
117
+ * Adds a recipe to Miam's basket
118
+ * /!\ We heavily recommend not to use this method outside of the web console for testing purposes /!\
119
+ */
120
+ addRecipe: (recipeId: string, guests: number) => Observable<object>;
121
+ /**
122
+ * Returns an observable that will emit true if the recipe passed in parameter is in Miam's GroceriesList
123
+ */
124
+ hasRecipe: (recipeId: string) => Observable<boolean>;
125
+ };
126
+
127
+ // ---------------------------------------------------------------------------------------------------
128
+
129
+ pos: {
130
+ /**
131
+ * Call to inform Miam of the point of sale the user is currently on. Do not forget to call the method
132
+ * if it changes after user loads the page
133
+ *
134
+ * @param extId the id of the PointOfSale in client's database
135
+ */
136
+ loadWithExtId: (extId) => void;
137
+ };
138
+
139
+ // ---------------------------------------------------------------------------------------------------
140
+
141
+ recipes: {
142
+ /**
143
+ * An observable that emits a value when the recipe-modal is closed
144
+ */
145
+ hidden: Observable<boolean>;
146
+ /**
147
+ * If called with a parameter to true, recipe-details will show a picture next to the ingredients
148
+ */
149
+ shouldDisplayIngredientPicturesOnRecipeCards: (should: boolean) => void;
150
+ /**
151
+ * Call with an url of a picture to change the default picture displayed if an ingredient doesn't have a picture
152
+ * and if ingredients picture have been enabled with recipes.shouldDisplayIngredientPicturesOnRecipeCards(true)
153
+ */
154
+ setDefaultIngredientPicture: (url: string) => void;
155
+ /**
156
+ * Override default labels for difficulty levels
157
+ *
158
+ * @param levels The list of labels to override for each difficulty (difficulties are respectively 1: Easy, 2: Medium, 3: Hard)
159
+ * example : [{value: 1, label: "Beginner"}] to update the label of easy recipes to "Beginner"
160
+ */
161
+ setDifficultyLevels: (levels: { value: number, label: string }[]) => void;
162
+
163
+ // /**
164
+ // * /!\ DEPRECATED: DO NOT USE /!\
165
+ // */
166
+ // setRecipesPrimaryButtonActions: (display: boolean, addToBasket: boolean) => void;
167
+ // /**
168
+ // * /!\ DEPRECATED: DO NOT USE /!\
169
+ // */
170
+ // setSuggestionsPrimaryButtonActions: (display: boolean, addToBasket: boolean) => void;
171
+ /**
172
+ * If called, adding a recipe to Miam's basket will display a confirmation toaster
173
+ */
174
+ showConfirmationToaster: () => void;
175
+ };
176
+
177
+ // ---------------------------------------------------------------------------------------------------
178
+
179
+ router: {
180
+ /**
181
+ * Inform Miam of the url where the catalog is for the redirection link of recipe-details
182
+ */
183
+ setRecipeCatalogUrl: (url: string) => void;
184
+ /**
185
+ * Inform Miam of the url where the onboarding section of the catalog should redirect
186
+ */
187
+ setRecipeInfoLink: (url: string) => void;
188
+ };
189
+
190
+ // ---------------------------------------------------------------------------------------------------
191
+
192
+ supplier: {
193
+ /**
194
+ * Call to inform Miam of the supplier the user is currently on. Do not forget to call the method
195
+ * if it changes after user loads the page (should not happen escept in very specific cases)
196
+ *
197
+ * @param supplierId the Supplier id in Miam's database
198
+ */
199
+ load: (supplierId: number | string) => void;
200
+ };
201
+
202
+ // ---------------------------------------------------------------------------------------------------
203
+
204
+ user: {
205
+ /**
206
+ * Call to inform Miam of the id of the user.
207
+ *
208
+ * @param id a string unique identifier to the user
209
+ * @param forbidProfiling if set to true, desactivate personalized content (personalized recipes & products)
210
+ * @param initBasket DEPRECATED - if set to true, fetch the GroceriesList & Basket of the user (recommanded as
211
+ * it saves time later)
212
+ */
213
+ loadWithExtId: (id: string, forbidProfiling: boolean, initBasket: boolean) => Observable<object>;
214
+ /**
215
+ * Call to inform Miam that the user has logged out
216
+ */
217
+ reset: () => void;
218
+ /**
219
+ * If your website has a "favorite products" feature, you can pass the ids of all products
220
+ * which the user has marked as favorites, so they can be prioritized when adding a recipe
221
+ * to their cart, if one of them is returned as a matching product for the recipe.
222
+ *
223
+ * @param favoriteProductIds an array of product ids, passed as string
224
+ */
225
+ setFavoriteItems: (favoriteProductIds: string[]) => Observable<object>;
226
+ };
227
+
228
+ // ---------------------------------------------------------------------------------------------------
229
+
230
+ view: {
231
+ /**
232
+ * Call to notify Miam of the scrollable element of the client's page, if it is not <body>
233
+ * This is necessary to prevent the page to scroll in the backgroud when Miam opens a popup/modal/drawer
234
+ */
235
+ setGlobalScrollableElement: (element: HTMLElement) => void;
236
+ };
237
+
238
+ // ---------------------------------------------------------------------------------------------------
239
+
240
+ /**
241
+ * Override two times will not be considered (DEPRECATED)
242
+ * @param icon have to be a knowed icon name see section 'Custom icons' in read me
243
+ * @param url of the new icon
244
+ */
245
+ overrideIcon: (icon, url: string) => void;
246
+ }