@nosto/nosto-react 0.4.3 → 1.0.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/src/types.ts CHANGED
@@ -6,6 +6,7 @@ declare global {
6
6
  nostojs: {
7
7
  (callback: (api: NostoClient) => void): void
8
8
  q?: unknown[]
9
+
9
10
  }
10
11
  }
11
12
  }
@@ -13,161 +14,851 @@ declare global {
13
14
  /**
14
15
  * @group Types
15
16
  */
16
- export interface Affinity {
17
- name: string
18
- score: number
17
+ export interface NostoClient {
18
+ setAutoLoad(autoload: boolean): void
19
+ defaultSession(): Session
20
+ placements: {
21
+ getPlacements(): string[]
22
+ injectCampaigns(recommendations: Record<string, unknown>): void
23
+ }
19
24
  }
20
25
 
21
26
  /**
22
27
  * @group Types
23
28
  */
24
- export interface SessionAction {
25
- setPlacements(placements: string[]): SessionAction
26
- load(): Promise<{
27
- affinities: Record<string, Affinity[]>
28
- geo_location?: string[]
29
- page_views: number
30
- recommendations: Recommendation[]
31
- }>
29
+ export interface Recommendation {
30
+ result_id: string
31
+ products: Product[]
32
+ result_type: string
33
+ title: string
34
+ div_id: string
35
+ source_product_ids: string[]
36
+ params: unknown
32
37
  }
33
38
 
39
+ // copied from client script d.ts export
40
+ declare const eventTypes: readonly ["vp", "lp", "dp", "rp", "bp", "vc", "or", "is", "cp", "ec", "es", "gc", "src", "cpr", "pl", "cc", "con"]
41
+ declare type EventType = typeof eventTypes[number]
42
+
34
43
  /**
35
44
  * @group Types
36
45
  */
37
- export interface NostoSession {
38
- setCart(cart?: Cart): NostoSession
39
- setCustomer(customer?: Customer): NostoSession
40
- setResponseMode(mode: string): NostoSession
41
- setVariation(variation?: string): NostoSession
42
- addOrder(order: { purchase: Purchase }): SessionAction
43
- viewCategory(category: string): SessionAction
44
- viewProduct(product: string): SessionAction
45
- viewFrontPage(): SessionAction
46
- viewNotFound(): SessionAction
47
- viewOther(): SessionAction
48
- viewSearch(query: string): SessionAction
49
- viewCart(): SessionAction
46
+ export interface CartItem {
47
+ name: string
48
+ price_currency_code: string
49
+ product_id: string
50
+ quantity: number
51
+ sku_id?: string
52
+ unit_price: number
50
53
  }
51
54
 
52
55
  /**
53
56
  * @group Types
54
57
  */
55
- export interface NostoClient {
56
- setAutoLoad(autoload: boolean): NostoClient
57
- defaultSession(): NostoSession
58
- placements: {
59
- getPlacements(): string[]
60
- injectCampaigns(recommendations: Record<string, Recommendation>): void
61
- }
58
+ export interface ConversionItem {
59
+ name: string
60
+ price_currency_code: string
61
+ product_id: string
62
+ quantity?: number
63
+ sku_id?: string
64
+ unit_price?: number
62
65
  }
63
66
 
64
67
  /**
65
68
  * @group Types
66
69
  */
67
- export interface Recommendation {
68
- result_id: string
69
- products: Product[]
70
- result_type: string
71
- title: string
72
- div_id: string
73
- source_product_ids: string[]
74
- params: unknown
70
+ export interface CustomerAffinityResponse {
71
+ discount: number
72
+ top_brands: CustomerAffinityResponseItem[]
73
+ top_categories: CustomerAffinityResponseItem[]
74
+ top_product_types: CustomerAffinityResponseItem[]
75
+ top_skus: {
76
+ [index: string]: CustomerAffinityResponseItem[]
77
+ }
75
78
  }
76
79
 
77
80
  /**
78
81
  * @group Types
79
82
  */
80
- export interface Item {
81
- name: string
82
- price_currency_code: string
83
- product_id: string
84
- quantity: number
85
- sku_id: string
86
- unit_price: number
83
+ export interface CustomerAffinityResponseItem {
84
+ name: string
85
+ score: number
87
86
  }
88
87
 
89
88
  /**
90
89
  * @group Types
91
90
  */
92
- export interface Cart {
93
- items: Item[]
91
+ export interface OrderCustomer {
92
+ country: string
93
+ email?: string
94
+ first_name?: string
95
+ last_name?: string
96
+ newsletter: string
97
+ order_number: string
98
+ phone: string
99
+ post_code: string
100
+ type: string
94
101
  }
95
102
 
96
103
  /**
97
104
  * @group Types
98
105
  */
99
106
  export interface Customer {
100
- customer_reference: string
101
- email: string
102
- first_name: string
103
- last_name: string
104
- newsletter: boolean
107
+ customer_reference?: string
108
+ email: string
109
+ first_name: string
110
+ hcid?: string
111
+ last_name: string
112
+ newsletter?: boolean
113
+ order_number?: string
114
+ source?: string
115
+ source_id?: string
116
+ type?: string
117
+ }
118
+
119
+ /**
120
+ * @group Types
121
+ */
122
+ export interface Order {
123
+ created_at?: Date
124
+ external_order_ref: string
125
+ info?: OrderCustomer
126
+ items: ConversionItem[]
127
+ order_status?: string
128
+ order_status_label?: string
129
+ payment_provider: string
105
130
  }
106
131
 
107
132
  /**
108
133
  * @group Types
109
134
  */
110
- export interface Buyer {
111
- first_name: string
112
- last_name: string
113
- email: string
114
- type: string
115
- newsletter: boolean
135
+ export type PageType = "front" | "category" | "product" | "cart" | "search" | "notfound" | "order" | "other" | "checkout"
136
+
137
+ /**
138
+ * @group Types
139
+ */
140
+ export type RenderMode = "HTML" | "SIMPLE" | "JSON_170x170" | "JSON_100_X_100" | "JSON_90x70" | "JSON_50x50" | "JSON_30x30" | "JSON_100x140" | "JSON_200x200" | "JSON_400x400" | "JSON_750x750" | "JSON_10_MAX_SQUARE" | "JSON_200x200_SQUARE" | "JSON_400x400_SQUARE" | "JSON_750x750_SQUARE" | "JSON_ORIGINAL" | "VERSION_SOURCE"
141
+
142
+ /**
143
+ * @group Types
144
+ */
145
+ interface PluginMetadata {
146
+ mainModule?: string
147
+ cmpModule?: string
148
+ msiModule?: string
116
149
  }
117
150
 
118
151
  /**
119
152
  * @group Types
120
153
  */
121
- export interface Purchase {
122
- number: string
123
- info: Buyer
124
- items: Item[]
154
+ export interface Cart {
155
+ hcid?: string
156
+ items: CartItem[]
125
157
  }
126
158
 
127
159
  /**
128
160
  * @group Types
129
161
  */
130
- export interface SKU {
131
- id: string
132
- name: string
133
- price: number
134
- listPrice?: number
135
- url: URL
136
- imageUrl: URL
137
- gtin?: string
138
- availability: "InStock" | "OutOfStock"
139
- customFields?: { [key: string]: string }
162
+ export type Product = {
163
+ product_id: string
164
+ selected_sku_id?: string
140
165
  }
141
166
 
142
167
  /**
143
168
  * @group Types
144
169
  */
145
- export interface Product {
146
- alternateImageUrls?: URL[]
147
- availability: "InStock" | "OutOfStock"
148
- brand?: string
149
- category: string[]
150
- categoryIds?: string[]
151
- description: string
152
- googleCategory?: string
153
- condition?: string
154
- gender?: string
155
- ageGroup?: string
156
- gtin?: string
157
- imageUrl: URL
158
- listPrice?: number
159
- name: string
160
- price: number
161
- ratingValue?: number
162
- reviewCount?: number
163
- priceCurrencyCode: string
164
- productId: string
165
- tags1?: string[]
166
- tags2?: string[]
167
- tags3?: string[]
168
- thumbUrl?: URL
169
- url: URL
170
- customFields?: { [key: string]: string }
171
- variationId?: string
172
- skus?: SKU[]
170
+ export interface Data<ProductType extends Product = Product> {
171
+ cart: Cart | undefined
172
+ customer: Customer | undefined
173
+ variation: string | undefined
174
+ restoreLink: string | undefined
175
+ products: ProductType[]
176
+ order: Order | undefined
177
+ searchTerms: string[] | undefined
178
+ categories: string[] | undefined
179
+ categoryIds: string[] | undefined
180
+ parentCategoryIds: string[] | undefined
181
+ tags: string[] | undefined
182
+ customFields: Record<string, string[]> | undefined
183
+ elements: string[] | undefined
184
+ pageType: PageType | undefined
185
+ sortOrder: string | undefined
186
+ pluginVersion: PluginMetadata | undefined
187
+ }
188
+
189
+ /**
190
+ * @group Types
191
+ */
192
+ export interface RecommendationRequestFlags {
193
+ skipPageViews?: boolean
194
+ trackEvents?: boolean
195
+ skipEvents?: boolean
196
+ reloadCart?: boolean
197
+ }
198
+
199
+ /**
200
+ * @group Types
201
+ */
202
+ export interface Session {
203
+ /**
204
+ * Sets the information about the user's current shopping cart. It the user
205
+ * does not have any items in his shopping cart, you can pass <code>null<code>.
206
+ * Passing <code>null<code> will nullify the user's shopping cart on Nosto's
207
+ * end. You must also pass in the shopping cart content in it's entirety as
208
+ * partial content are not supported.
209
+ *
210
+ * @example
211
+ * nostojs(api => api
212
+ * .defaultSession()
213
+ * .setCart({
214
+ * items: [
215
+ * product_id: "101",
216
+ * sku_id: "101-S",
217
+ * name: "Shoe",
218
+ * unit_price: 34.99
219
+ * price_currency_code: "EUR"
220
+ * ]
221
+ * })
222
+ * .viewCart()
223
+ * .setPlacements(["free-shipper"])
224
+ * .update()
225
+ * .then(data => console.log(data)))
226
+ *
227
+ * @public
228
+ * @param {Cart|undefined} cart the details of the user's shopping cart contents
229
+ * @returns {Session} the current session
230
+ */
231
+ setCart(cart: Cart | undefined): Session
232
+ /**
233
+ * Sets the information about the currently logged in customer. If the current
234
+ * customer is not provided, you will not be able to leverage features such as
235
+ * triggered emails. While it is recommended to always provide the details of
236
+ * the currently logged in customer, it may be omitted if there are concerns
237
+ * about privacy or compliance.
238
+ *
239
+ * @example
240
+ * nostojs(api => api
241
+ * .defaultSession()
242
+ * .setCustomer({
243
+ * first_name: "Mridang",
244
+ * last_name: "Agarwalla",
245
+ * email: "mridang@nosto.com",
246
+ * newsletter: false,
247
+ * customer_reference: "5e3d4a9c-cf58-11ea-87d0-0242ac130003"
248
+ * })
249
+ * .viewCart()
250
+ * .setPlacements(["free-shipper"])
251
+ * .load()
252
+ * .then(data => console.log(data)))
253
+ *
254
+ * @public
255
+ * @param {Customer} customer the details of the currently logged in customer
256
+ * @returns {Session} the current session
257
+ */
258
+ setCustomer(customer: Customer | undefined): Session
259
+ /**
260
+ * Sets the current variation identifier for the session. A variation identifier
261
+ * identifies the current currency (or the current customer group). If your site
262
+ * uses multi-currency, you must provide the ISO code current currency being viewed.
263
+ *
264
+ * @example
265
+ * nostojs(api => api
266
+ * .defaultSession()
267
+ * .setVariation("GBP")
268
+ * .viewCart()
269
+ * .setPlacements(["free-shipper"])
270
+ * .load()
271
+ * .then(data => console.log(data)))
272
+ *
273
+ * @public
274
+ * @param {String} variation the case-sensitive identifier of the current variation
275
+ * @returns {Session} the current session
276
+ */
277
+ setVariation(variation: string): Session
278
+ /**
279
+ * Sets the restore link for the current session. Restore links can be leveraged
280
+ * in email campaigns. Restore links allow the the user to restore the cart
281
+ * contents in a single click.
282
+ * <br/><br/>
283
+ * Read more about
284
+ * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link}
285
+ *
286
+ * @example
287
+ * nostojs(api => api
288
+ * .defaultSession()
289
+ * .setRestoreLink("https://jeans.com/session/restore?sid=6bdb69d5-ed15-4d92")
290
+ * .viewCart()
291
+ * .setPlacements(["free-shipper"])
292
+ * .load()
293
+ * .then(data => console.log(data)))
294
+ *
295
+ * @public
296
+ * @param {String} restoreLink the secure URL to restore the user's current session
297
+ * @returns {Session} the current session
298
+ */
299
+ setRestoreLink(restoreLink: string): Session
300
+ /**
301
+ * Sets the response type to HTML or JSON_ORIGINAL. This denotes the preferred
302
+ * response type of the recommendation result.
303
+ * If you would like to access the raw recommendation data in <code>JSON</code> form, specify
304
+ * <code>JSON</code>. When you specify JSON, you will need to template the result yourself.
305
+ * If you require a more simplified approach, specify <code>HTML</code>. When you specify
306
+ * <code>HTML</code>, you get back HTML blobs, that you may simply inject into
307
+ * you placements.
308
+ *
309
+ * @example
310
+ * nostojs(api => api
311
+ * .defaultSession()
312
+ * .setResponseMode("HTML")
313
+ * .viewCart()
314
+ * .setPlacements(["free-shipper"])
315
+ * .load()
316
+ * .then(data => console.log(data)))
317
+ *
318
+ * @public
319
+ * @param {String} mode the response mode for the recommendation data
320
+ * @returns {Session} the current session
321
+ */
322
+ setResponseMode(mode: RenderMode): Session
323
+ /**
324
+ * Create a new action for a front page. This should be used when the user
325
+ * visits the home page.
326
+ * <br/><br/>
327
+ * You must invoke [the load method]{@link Action#load} on the resultant
328
+ * action in order for the request to be made.
329
+ * <br/><br/>
330
+ * You do not need to specify the page-type explicitly as it is inferred
331
+ * from the action.
332
+ *
333
+ * @example
334
+ * nostojs(api => api
335
+ * .defaultSession()
336
+ * .viewFrontPage()
337
+ * .setPlacements(["best-seller"])
338
+ * .load()
339
+ * .then(data => console.log(data)))
340
+ *
341
+ *
342
+ * @public
343
+ * @returns {Action} the action instance to load content or track events.
344
+ */
345
+ viewFrontPage(): Action
346
+ /**
347
+ * Create a new action for a cart page. This should be used on all cart and
348
+ * checkout pages. If your site has a multi-step checkout, it is recommended
349
+ * that you send this event on each checkout page.
350
+ * <br/><br/>
351
+ * You must invoke [the load method]{@link Action#load} on the resultant
352
+ * action in order for the request to be made.
353
+ * <br/><br/>
354
+ * You do not need to specify the page-type explicitly as it is inferred
355
+ * from the action.
356
+ *
357
+ * @example
358
+ * nostojs(api => api
359
+ * .defaultSession()
360
+ * .viewCart()
361
+ * .setPlacements(["free-shipper"])
362
+ * .load()
363
+ * .then(data => console.log(data)))
364
+ *
365
+ * @public
366
+ * @returns {Action} the action instance to load content or track events.
367
+ */
368
+ viewCart(): Action
369
+ /**
370
+ * Create a new action for a not found page. This should be used only on 404
371
+ * pages.
372
+ * <br/><br/>
373
+ * You must invoke [the load method]{@link Action#load} on the resultant
374
+ * action in order for the request to be made.
375
+ * <br/><br/>
376
+ * You do not need to specify the page-type explicitly as it is inferred
377
+ * from the action.
378
+ *
379
+ * @example
380
+ * nostojs(api => api
381
+ * .defaultSession()
382
+ * .viewNotFound()
383
+ * .setPlacements(["best-seller"])
384
+ * .load()
385
+ * .then(data => console.log(data)))
386
+ *
387
+ * @public
388
+ * @returns {Action} the action instance to load content or track events.
389
+ */
390
+ viewNotFound(): Action
391
+ /**
392
+ * Create a new action for a product page. This must be used only when a
393
+ * product is being viewed. In case a specific SKU of the product is being viewed, use viewProductSku instead.
394
+ * <br/><br/>
395
+ * You must invoke [the load method]{@link Action#load} on the resultant
396
+ * action in order for the request to be made.
397
+ * <br/><br/>
398
+ * You do not need to specify the page-type explicitly as it is inferred
399
+ * from the action.
400
+ *
401
+ * @example
402
+ * nostojs(api => api
403
+ * .defaultSession()
404
+ * .viewProduct("101")
405
+ * .setCategories(["/men/trousers"])
406
+ * .setRef("123", "example_reco_id")
407
+ * .setPlacements(["cross-seller"])
408
+ * .load()
409
+ * .then(data => console.log(data)))
410
+ *
411
+ * @public
412
+ * @param product
413
+ * @returns {Action} the action instance to load content or track events.
414
+ */
415
+ viewProduct(product: string | Product): Action
416
+ /**
417
+ * Create a new action for a product page when a specific SKU has been chosen. This must be used only when a
418
+ * product and specific SKU is being viewed.
419
+ * <br/><br/>
420
+ * You must invoke [the load method]{@link Action#load} on the resultant
421
+ * action in order for the request to be made.
422
+ * <br/><br/>
423
+ * You do not need to specify the page-type explicitly as it is inferred
424
+ * from the action.
425
+ *
426
+ * @example
427
+ * nostojs(api => api
428
+ * .defaultSession()
429
+ * .viewProductSku("101", "101-sku-1")
430
+ * .setCategories(["/men/trousers"])
431
+ * .setRef("123", "example_reco_id")
432
+ * .setPlacements(["cross-seller"])
433
+ * .load()
434
+ * .then(data => console.log(data)))
435
+ *
436
+ * @public
437
+ * @param productId
438
+ * @param skuId
439
+ * @returns {Action} the action instance to load content or track events.
440
+ */
441
+ viewProductSku(productId: string, skuId: string): Action
442
+ /**
443
+ * Create a new action for a category page. This should be used on all
444
+ * category, collection of brand pages.
445
+ * <br/><br/>
446
+ * You must invoke [the load method]{@link Action#load} on the resultant
447
+ * action in order for the request to be made.
448
+ * <br/><br/>
449
+ * You do not need to specify the page-type explicitly as it is inferred
450
+ * from the action.
451
+ *
452
+ * @example
453
+ * nostojs(api => api
454
+ * .defaultSession()
455
+ * .viewCategory("/men/shoes")
456
+ * .setPlacements(["category123"])
457
+ * .load()
458
+ * .then(data => console.log(data)))
459
+ *
460
+ * @public
461
+ * @param {Array<String>} categories
462
+ * @returns {Action} the action instance to load content or track events.
463
+ */
464
+ viewCategory(...categories: string[]): Action
465
+ /**
466
+ * Create a new action for a tag page. This should be used only on tag pages.
467
+ * <br/><br/>
468
+ * You must invoke [the load method]{@link Action#load} on the resultant
469
+ * action in order for the request to be made.
470
+ * <br/><br/>
471
+ * You do not need to specify the page-type explicitly as it is inferred
472
+ * from the action.
473
+ * Note: tags are not case-sensitive.
474
+ *
475
+ * @example
476
+ * nostojs(api => api
477
+ * .defaultSession()
478
+ * .viewTag("colourful")
479
+ * .load()
480
+ * .then(data => console.log(data)))
481
+ *
482
+ * @public
483
+ * @deprecated as this is an advanced action with a limited a use case
484
+ * @param {Array<String>} tags the set of the tags being viewed.
485
+ * @returns {Action} the action instance to load content or track events.
486
+ */
487
+ viewTag(...tags: string[]): Action
488
+ /**
489
+ * Create a new action with custom fields.
490
+ * <br/><br/>
491
+ * You must invoke [the load method]{@link Action#load} on the resultant
492
+ * action in order for the request to be made.
493
+ * <br/><br/>
494
+ * You do not need to specify the page-type explicitly as it is inferred
495
+ * from the action.
496
+ * Note: tags are not case-sensitive.
497
+ *
498
+ * @example
499
+ * nostojs(api => api
500
+ * .defaultSession()
501
+ * .viewCustomField({material: "cotton"})
502
+ * .load()
503
+ * .then(data => console.log(data)))
504
+ *
505
+ * @public
506
+ * @deprecated as this is an advanced action with a limited a use case
507
+ * @param {Object} customFields custom fields being viewed.
508
+ * @returns {Action} the action instance to load content or track events.
509
+ */
510
+ viewCustomField(customFields: Record<string, string[]>): Action
511
+ /**
512
+ * Create a new action for a search page. This should be used only
513
+ * on search pages. A search page action requires you to pass the search
514
+ * term. For example, if the user search for "black shoes", you must pass
515
+ * in "black shoes" and not an encoded version such as "black+shoes".
516
+ * <br/><br/>
517
+ * You must invoke [the load method]{@link Action#load} on the resultant
518
+ * action in order for the request to be made.
519
+ * <br/><br/>
520
+ * You do not need to specify the page-type explicitly as it is inferred
521
+ * from the action.
522
+ * Search terms are not case-sensitive.
523
+ *
524
+ * @example
525
+ * nostojs(api => api
526
+ * .defaultSession()
527
+ * .viewSearch("black shoes")
528
+ * .load()
529
+ * .then(data => console.log(data)))
530
+ *
531
+ * @public
532
+ * @param {Array.<String>} searchTerms the non-encoded search terms
533
+ * @returns {Action} the action instance to load content or track events.
534
+ */
535
+ viewSearch(...searchTerms: string[]): Action
536
+ /**
537
+ * Create a new action for a general page. This should be used only on
538
+ * pages that don't have a corresponding action. For example, if the user
539
+ * is viewing a page such as a "Contact Us" page, you should use the viewOther
540
+ * action.
541
+ * <br/><br/>
542
+ * You must invoke [the load method]{@link Action#load} on the resultant
543
+ * action in order for the request to be made.
544
+ * <br/><br/>
545
+ * You do not need to specify the page-type explicitly as it is inferred
546
+ * from the action.
547
+ *
548
+ * @example
549
+ * nostojs(api => api
550
+ * .defaultSession()
551
+ * .viewOther()
552
+ * .load()
553
+ * .then(data => console.log(data)))
554
+ *
555
+ * @public
556
+ * @returns {Action} the action instance to load content or track events.
557
+ */
558
+ viewOther(): Action
559
+ /**
560
+ * Create a new action for an order page. This should only be used on order
561
+ * confirmation / thank you pages.
562
+ * <br/><br/>
563
+ * You do not need to specify the page-type explicitly as it is inferred
564
+ * from the action.
565
+ * <br/><br/>
566
+ * You must invoke [the load method]{@link Action#load} on the resultant
567
+ * action in order for the request to be made.
568
+ *
569
+ * @example
570
+ * nostojs(api => {
571
+ * api.defaultSession()
572
+ * .addOrder({
573
+ * external_order_ref: "145000006",
574
+ * info: {
575
+ * order_number: "195",
576
+ * email: "mridang@nosto.com",
577
+ * first_name: "Mridang",
578
+ * last_name: "Agarwalla",
579
+ * type: "order",
580
+ * newsletter: true
581
+ * },
582
+ * items: [{
583
+ * product_id: "406",
584
+ * sku_id: "243",
585
+ * name: "Linen Blazer (White, S)",
586
+ * quantity: 1,
587
+ * unit_price: 455,
588
+ * price_currency_code: "EUR"
589
+ * }]
590
+ * })
591
+ * .setPlacements(["order-related"])
592
+ * .load()
593
+ * .then(data => {
594
+ * console.log(data.recommendations)
595
+ * })
596
+ * })
597
+ * @public
598
+ * @param {Order} order the information about the order that was placed
599
+ * @returns {Action} the action instance to load content or track events.
600
+ */
601
+ addOrder(order: Order): Action
602
+ /**
603
+ * Creates an action to report that product was added to the shopping cart,
604
+ * e.g. from the recommendation slot with "Add to cart" button.
605
+ * <p>
606
+ * You must invoke [the load method]{@link Action#load} on the resultant
607
+ * action in order for the request to be made.
608
+ *
609
+ *
610
+ * @example
611
+ * nostojs(api => api
612
+ * .defaultSession()
613
+ * .reportAddToCart("123", "reco-slot-1")
614
+ * .load()
615
+ * .then(data => console.log(data)))
616
+ *
617
+ * @public
618
+ * @param product
619
+ * @param element
620
+ * @returns {Action} the action instance to load content or track events.
621
+ */
622
+ reportAddToCart(product: string, element: string): Action
623
+ /**
624
+ * @example
625
+ * nostojs(api => api
626
+ * .defaultSession()
627
+ * .recordAttribution("vp", "12345678", "123456")
628
+ * .done()
629
+ * .then(data => console.log(data))
630
+ * @param { EventType } type
631
+ * @param { String } target
632
+ * @param { String | undefined } [ref]
633
+ * @param { String | undefined } [refSrc]
634
+ * @return { Object }
635
+ *
636
+ */
637
+ recordAttribution(type: EventType, target: string, ref: string, refSrc: string): object
638
+ }
639
+
640
+ /**
641
+ * @group Types
642
+ */
643
+ export interface Action {
644
+ /**
645
+ * Handles click attribution for product recommendations.
646
+ * This can be called when reporting a product view
647
+ * to signal that the view is a result of a click on a recommendation.
648
+ *
649
+ * @public
650
+ * @param {String} productId currently viewed product's product id
651
+ * @param {String} reference value of result_id from the recommendation response that was clicked
652
+ * @return {Action}
653
+ */
654
+ setRef(productId: string, reference: string): Action
655
+ /**
656
+ * Allows you to provide an additional recommender hint that a product is being
657
+ * viewed.
658
+ * <br/><br/>
659
+ * You must invoke [the load method]{@link Action#load} on the resultant
660
+ * action in order for the request to be made.
661
+ *
662
+ * @public
663
+ * @param {String} product the identifier of the product being viewed
664
+ * @return {Action} the instance of the action
665
+ */
666
+ setProduct(product: string | Product): Action
667
+ /**
668
+ * @deprecated
669
+ * @param {Array<String>} products
670
+ * @return {Action}
671
+ */
672
+ setProducts(products: (string | Product)[]): Action
673
+ /**
674
+ * Sets the information about the user's current shopping cart. It the user
675
+ * does not have any items in his shopping cart, you can pass <code>null<code>.
676
+ * Passing <code>null<code> will nullify the user's shopping cart on Nosto's
677
+ * end. You must also pass in the shopping cart content in it's entirety as
678
+ * partial content are not supported.
679
+ * <br/><br/>
680
+ * It is not recommended to pass the current cart contents to an action but
681
+ * instead use the the session
682
+ * <br/><br/>
683
+ * You must invoke [the load method]{@link Action#load} on the resultant
684
+ * action in order for the request to be made.
685
+ *
686
+ * @see {@link Session#setCart}
687
+ * @return {Action}
688
+ */
689
+ setCart(cart: Cart): Action
690
+ /**
691
+ * Sets the information about the currently logged in customer. If the current
692
+ * customer is not provided, you will not be able to leverage features such as
693
+ * triggered emails. While it is recommended to always provide the details of
694
+ * the currently logged in customer, it may be omitted if there are concerns
695
+ * about privacy or compliance.
696
+ * <br/><br/>
697
+ * It is not recommended to pass the current customer details to an action but
698
+ * instead use the the session
699
+ * <br/><br/>
700
+ * You must invoke [the load method]{@link Action#load} on the resultant
701
+ * action in order for the request to be made.
702
+ *
703
+ * @see {@link Session#setCustomer}
704
+ * @public
705
+ * @param {Customer} customer the details of the currently logged in customer
706
+ * @return {Action}
707
+ */
708
+ setCustomer(customer: Customer): Action
709
+ /**
710
+ * @param {Order} order
711
+ * @return {Action}
712
+ */
713
+ setOrder(order: Order): Action
714
+ /**
715
+ * <br/><br/>
716
+ * You must invoke [the load method]{@link Action#load} on the resultant
717
+ * action in order for the request to be made.
718
+ *
719
+ * @public
720
+ * @param searchTerms
721
+ * @return {Action}
722
+ */
723
+ setSearchTerms(searchTerms: string[]): Action
724
+ /**
725
+ * <br/><br/>
726
+ * You must invoke [the load method]{@link Action#load} on the resultant
727
+ * action in order for the request to be made.
728
+ *
729
+ * @public
730
+ * @param {Array<String>} categories
731
+ * @return {Action}
732
+ */
733
+ setCategories(categories: string[]): Action
734
+ /**
735
+ * <br/><br/>
736
+ * You must invoke [the load method]{@link Action#load} on the resultant
737
+ * action in order for the request to be made.
738
+ *
739
+ * @public
740
+ * @param {Array<String>} categoryIds
741
+ * @return {Action}
742
+ */
743
+ setCategoryIds(categoryIds: string[]): Action
744
+ /**
745
+ * <br/><br/>
746
+ * You must invoke [the load method]{@link Action#load} on the resultant
747
+ * action in order for the request to be made.
748
+ *
749
+ * @public
750
+ * @param {Array<String>} parentCategoryIds
751
+ * @return {Action}
752
+ */
753
+ setParentCategoryIds(parentCategoryIds: string[]): Action
754
+ /**
755
+ * <br/><br/>
756
+ * You must invoke [the load method]{@link Action#load} on the resultant
757
+ * action in order for the request to be made.
758
+ *
759
+ * @public
760
+ * @param tags
761
+ * @return {Action}
762
+ */
763
+ setTags(tags: string[]): Action
764
+ /**
765
+ * <br/><br/>
766
+ * You must invoke [the load method]{@link Action#load} on the resultant
767
+ * action in order for the request to be made.
768
+ *
769
+ * @public
770
+ * @param customFields
771
+ * @return {Action}
772
+ */
773
+ setCustomFields(customFields: Record<string, string[]>): Action
774
+ /**
775
+ * Sets the current variation identifier for the session. A variation identifier
776
+ * identifies the current currency (or the current customer group). If your site
777
+ * uses multi-currency, you must provide the ISO code current currency being viewed.
778
+ * <br/><br/>
779
+ * It is not recommended to pass the variation identifier to an action but
780
+ * instead use the the session.
781
+ * <br/><br/>
782
+ * You must invoke [the load method]{@link Action#load} on the resultant
783
+ * action in order for the request to be made.
784
+ *
785
+ * @see {@link Session#setVariation}
786
+ * @public
787
+ * @param {String} variation the case-sensitive identifier of the current variation
788
+ * @return {Action}
789
+ */
790
+ setVariation(variation: string): Action
791
+ /**
792
+ * <br/><br/>
793
+ * You must invoke [the load method]{@link Action#load} on the resultant
794
+ * action in order for the request to be made.
795
+ *
796
+ * @public
797
+ * @param {Array.<String>} placements
798
+ * @return {Action}
799
+ */
800
+ setPlacements(placements: string[]): Action
801
+ /**
802
+ * Sets the restore link for the current session. Restore links can be leveraged
803
+ * in email campaigns. Restore links allow the the user to restore the cart
804
+ * contents in a single click.
805
+ * <br/><br/>
806
+ * Read more about
807
+ * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link}
808
+ * <br/><br/>
809
+ * It is not recommended to pass the restore link to an action but instead use the the
810
+ * session.
811
+ * <br/><br/>
812
+ * You must invoke [the load method]{@link Action#load} on the resultant
813
+ * action in order for the request to be made.
814
+ *
815
+ * @see {@link Session#setRestoreLink}
816
+ * @public
817
+ * @param {String} restoreLink the secure URL to restore the user's current session
818
+ * @return {Action}
819
+ */
820
+ setRestoreLink(restoreLink: string): Action
821
+ /**
822
+ * Sets the identifier of the current page type to the current request. The different
823
+ * page types are product, front, search, cart, order, category, notfound and other.
824
+ * <br/><br/>
825
+ * You must invoke [the load method]{@link Action#load} on the resultant
826
+ * action in order for the request to be made.
827
+ * <br/><br/>
828
+ * It is not recommended to pass the page type to an action but instead use the the
829
+ * session.
830
+ * <br/><br/>
831
+ * You must invoke [the load method]{@link Action#load} on the resultant
832
+ * action in order for the request to be made.
833
+ *
834
+ * @see {@link Session#viewFrontPage} for when a front or home page is being viewed
835
+ * @see {@link Session#viewCart} for when a cart or checkout page is being viewed
836
+ * @see {@link Session#viewNotFound} for when a not-found or 404 page is being viewed
837
+ * @see {@link Session#viewProduct} for when a product page is being viewed
838
+ * @see {@link Session#viewCategory} for when a category, collection or brand page is being viewed
839
+ * @see {@link Session#viewTag} for when a tag page is being viewed
840
+ * @see {@link Session#viewSearch} for when a search page is being viewed
841
+ * @see {@link Session#viewOther} for when a miscellaneous page is being viewed
842
+ * @public
843
+ */
844
+ setPageType(pageType: PageType): Action
845
+ /**
846
+ * @public
847
+ * @return {Object}
848
+ */
849
+ dumpData(): Data
850
+ update(): unknown
851
+ load(flags?: RecommendationRequestFlags): Promise<ActionResponse>
852
+ }
853
+
854
+ export interface ActionResponse {
855
+ recommendations: Record<string, unknown>
856
+ campaigns?: {
857
+ recommendations: Record<string, unknown>
858
+ content: Record<string, unknown>
859
+ }
860
+ page_views: number
861
+ geo_location: string[]
862
+ affinities: CustomerAffinityResponse
863
+ cmpid: string
173
864
  }