@nosto/nosto-react 2.2.1 → 2.2.2

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