@nosto/nosto-react 0.5.0 → 2.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,923 @@ declare global {
13
14
  /**
14
15
  * @group Types
15
16
  */
16
- export interface Affinity {
17
+ export interface NostoClient {
18
+ setAutoLoad(autoload: boolean): void
19
+ defaultSession(): Session
20
+ listen(event: string, callback: (data: unknown) => void): void
21
+ placements: {
22
+ getPlacements(): string[]
23
+ injectCampaigns(recommendations: Record<string, unknown>): void
24
+ }
25
+ }
26
+
27
+ /**
28
+ * @group Types
29
+ */
30
+ export interface Recommendation {
31
+ result_id: string
32
+ products: PushedProduct[]
33
+ result_type: string
34
+ title: string
35
+ div_id: string
36
+ source_product_ids: string[]
37
+ params: unknown
38
+ }
39
+
40
+ export interface PushedProduct {
41
+ age_group?: string
42
+ alternate_image_urls: string[]
43
+ availability: string
44
+ brand?: string
45
+ category: string[]
46
+ category_id: string[]
47
+ condition?: string
48
+ custom_fields: { [index: string]: string }
49
+ date_published?: Date
50
+ description?: string
51
+ gender?: string
52
+ google_category?: string
53
+ gtin?: string
54
+ image_url?: string
55
+ inventory_level?: number
56
+ list_price?: number
57
+ name: string
58
+ parent_category_id: string[]
59
+ price: number
60
+ price_currency_code: string
61
+ product_id: string
62
+ rating_value?: number
63
+ review_count?: number
64
+ skus: PushedProductSKU[]
65
+ source_updated?: Date
66
+ supplier_cost?: number
67
+ tags1: string[]
68
+ tags2: string[]
69
+ tags3: string[]
70
+ thumb_url?: string
71
+ unit_pricing_base_measure?: number
72
+ unit_pricing_measure?: number
73
+ unit_pricing_unit?: string
74
+ update_received?: Date
75
+ url: string
76
+ variation_id?: string
77
+ variations: { [index: string]: PushedVariation }
78
+ }
79
+
80
+ export interface PushedProductSKU extends NostoSku { }
81
+
82
+ export interface PushedVariation extends NostoVariant { }
83
+
84
+
85
+ export interface NostoSku extends Sku {
86
+ inventory_level?: number
87
+ }
88
+
89
+ export interface NostoVariant {
90
+ availability: string
91
+ available: boolean
92
+ discounted: boolean
93
+ list_price?: number
94
+ price: number
95
+ price_currency_code: string
96
+ price_text?: string
97
+ }
98
+
99
+ export interface Sku {
100
+ availability: string
101
+ custom_fields: { [index: string]: string }
102
+ gtin?: string
103
+ id: string
104
+ image_url?: string
105
+ list_price?: number
17
106
  name: string
18
- score: number
107
+ price: number
108
+ url?: string
19
109
  }
20
110
 
111
+ // 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]
114
+
21
115
  /**
22
116
  * @group Types
23
117
  */
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
- }>
118
+ 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
32
125
  }
33
126
 
34
127
  /**
35
128
  * @group Types
36
129
  */
37
- export interface NostoClientSession {
38
- setCart(cart?: Cart): NostoClientSession
39
- setCustomer(customer?: Customer): NostoClientSession
40
- setResponseMode(mode: string): NostoClientSession
41
- setVariation(variation?: string): NostoClientSession
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
130
+ 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
50
137
  }
51
138
 
52
139
  /**
53
140
  * @group Types
54
141
  */
55
- export interface NostoClient {
56
- setAutoLoad(autoload: boolean): NostoClient
57
- defaultSession(): NostoClientSession
58
- placements: {
59
- getPlacements(): string[]
60
- injectCampaigns(recommendations: Record<string, Recommendation>): void
61
- }
142
+ 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
+ }
62
150
  }
63
151
 
64
152
  /**
65
153
  * @group Types
66
154
  */
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
155
+ export interface CustomerAffinityResponseItem {
156
+ name: string
157
+ score: number
75
158
  }
76
159
 
77
160
  /**
78
161
  * @group Types
79
162
  */
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
163
+ 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
173
+ }
174
+
175
+ /**
176
+ * @group Types
177
+ */
178
+ 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
189
+ }
190
+
191
+ /**
192
+ * @group Types
193
+ */
194
+ 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
202
+ }
203
+
204
+ /**
205
+ * @group Types
206
+ */
207
+ export type PageType = "front" | "category" | "product" | "cart" | "search" | "notfound" | "order" | "other" | "checkout"
208
+
209
+ /**
210
+ * @group Types
211
+ */
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"
213
+
214
+ /**
215
+ * @group Types
216
+ */
217
+ interface PluginMetadata {
218
+ mainModule?: string
219
+ cmpModule?: string
220
+ msiModule?: string
87
221
  }
88
222
 
89
223
  /**
90
224
  * @group Types
91
225
  */
92
226
  export interface Cart {
93
- items: Item[]
227
+ hcid?: string
228
+ items: CartItem[]
94
229
  }
95
230
 
96
231
  /**
97
232
  * @group Types
98
233
  */
99
- export interface Customer {
100
- customer_reference: string
101
- email: string
102
- first_name: string
103
- last_name: string
104
- newsletter: boolean
234
+ export type Product = {
235
+ product_id: string
236
+ selected_sku_id?: string
105
237
  }
106
238
 
107
239
  /**
108
240
  * @group Types
109
241
  */
110
- export interface Buyer {
111
- first_name: string
112
- last_name: string
113
- email: string
114
- type: string
115
- newsletter: boolean
242
+ 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
116
259
  }
117
260
 
118
261
  /**
119
262
  * @group Types
120
263
  */
121
- export interface Purchase {
122
- number: string
123
- info: Buyer
124
- items: Item[]
264
+ export interface RecommendationRequestFlags {
265
+ skipPageViews?: boolean
266
+ trackEvents?: boolean
267
+ skipEvents?: boolean
268
+ reloadCart?: boolean
125
269
  }
126
270
 
127
271
  /**
128
272
  * @group Types
129
273
  */
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 }
274
+ 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
140
710
  }
141
711
 
142
712
  /**
143
713
  * @group Types
144
714
  */
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[]
715
+ 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>
924
+ }
925
+
926
+ export interface ActionResponse {
927
+ 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
173
936
  }