@nosto/nosto-react 1.0.0 → 2.1.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/dist/index.d.ts CHANGED
@@ -1,232 +1,6 @@
1
1
  import { Context } from 'react';
2
- import { default as default_2 } from 'react';
3
2
  import { JSX as JSX_2 } from 'react/jsx-runtime';
4
-
5
- /**
6
- * @group Types
7
- */
8
- declare interface Action {
9
- /**
10
- * Handles click attribution for product recommendations.
11
- * This can be called when reporting a product view
12
- * to signal that the view is a result of a click on a recommendation.
13
- *
14
- * @public
15
- * @param {String} productId currently viewed product's product id
16
- * @param {String} reference value of result_id from the recommendation response that was clicked
17
- * @return {Action}
18
- */
19
- setRef(productId: string, reference: string): Action;
20
- /**
21
- * Allows you to provide an additional recommender hint that a product is being
22
- * viewed.
23
- * <br/><br/>
24
- * You must invoke [the load method]{@link Action#load} on the resultant
25
- * action in order for the request to be made.
26
- *
27
- * @public
28
- * @param {String} product the identifier of the product being viewed
29
- * @return {Action} the instance of the action
30
- */
31
- setProduct(product: string | Product): Action;
32
- /**
33
- * @deprecated
34
- * @param {Array<String>} products
35
- * @return {Action}
36
- */
37
- setProducts(products: (string | Product)[]): Action;
38
- /**
39
- * Sets the information about the user's current shopping cart. It the user
40
- * does not have any items in his shopping cart, you can pass <code>null<code>.
41
- * Passing <code>null<code> will nullify the user's shopping cart on Nosto's
42
- * end. You must also pass in the shopping cart content in it's entirety as
43
- * partial content are not supported.
44
- * <br/><br/>
45
- * It is not recommended to pass the current cart contents to an action but
46
- * instead use the the session
47
- * <br/><br/>
48
- * You must invoke [the load method]{@link Action#load} on the resultant
49
- * action in order for the request to be made.
50
- *
51
- * @see {@link Session#setCart}
52
- * @return {Action}
53
- */
54
- setCart(cart: Cart): Action;
55
- /**
56
- * Sets the information about the currently logged in customer. If the current
57
- * customer is not provided, you will not be able to leverage features such as
58
- * triggered emails. While it is recommended to always provide the details of
59
- * the currently logged in customer, it may be omitted if there are concerns
60
- * about privacy or compliance.
61
- * <br/><br/>
62
- * It is not recommended to pass the current customer details to an action but
63
- * instead use the the session
64
- * <br/><br/>
65
- * You must invoke [the load method]{@link Action#load} on the resultant
66
- * action in order for the request to be made.
67
- *
68
- * @see {@link Session#setCustomer}
69
- * @public
70
- * @param {Customer} customer the details of the currently logged in customer
71
- * @return {Action}
72
- */
73
- setCustomer(customer: Customer): Action;
74
- /**
75
- * @param {Order} order
76
- * @return {Action}
77
- */
78
- setOrder(order: Order): Action;
79
- /**
80
- * <br/><br/>
81
- * You must invoke [the load method]{@link Action#load} on the resultant
82
- * action in order for the request to be made.
83
- *
84
- * @public
85
- * @param searchTerms
86
- * @return {Action}
87
- */
88
- setSearchTerms(searchTerms: string[]): Action;
89
- /**
90
- * <br/><br/>
91
- * You must invoke [the load method]{@link Action#load} on the resultant
92
- * action in order for the request to be made.
93
- *
94
- * @public
95
- * @param {Array<String>} categories
96
- * @return {Action}
97
- */
98
- setCategories(categories: string[]): Action;
99
- /**
100
- * <br/><br/>
101
- * You must invoke [the load method]{@link Action#load} on the resultant
102
- * action in order for the request to be made.
103
- *
104
- * @public
105
- * @param {Array<String>} categoryIds
106
- * @return {Action}
107
- */
108
- setCategoryIds(categoryIds: string[]): Action;
109
- /**
110
- * <br/><br/>
111
- * You must invoke [the load method]{@link Action#load} on the resultant
112
- * action in order for the request to be made.
113
- *
114
- * @public
115
- * @param {Array<String>} parentCategoryIds
116
- * @return {Action}
117
- */
118
- setParentCategoryIds(parentCategoryIds: string[]): Action;
119
- /**
120
- * <br/><br/>
121
- * You must invoke [the load method]{@link Action#load} on the resultant
122
- * action in order for the request to be made.
123
- *
124
- * @public
125
- * @param tags
126
- * @return {Action}
127
- */
128
- setTags(tags: string[]): Action;
129
- /**
130
- * <br/><br/>
131
- * You must invoke [the load method]{@link Action#load} on the resultant
132
- * action in order for the request to be made.
133
- *
134
- * @public
135
- * @param customFields
136
- * @return {Action}
137
- */
138
- setCustomFields(customFields: Record<string, string[]>): Action;
139
- /**
140
- * Sets the current variation identifier for the session. A variation identifier
141
- * identifies the current currency (or the current customer group). If your site
142
- * uses multi-currency, you must provide the ISO code current currency being viewed.
143
- * <br/><br/>
144
- * It is not recommended to pass the variation identifier to an action but
145
- * instead use the the session.
146
- * <br/><br/>
147
- * You must invoke [the load method]{@link Action#load} on the resultant
148
- * action in order for the request to be made.
149
- *
150
- * @see {@link Session#setVariation}
151
- * @public
152
- * @param {String} variation the case-sensitive identifier of the current variation
153
- * @return {Action}
154
- */
155
- setVariation(variation: string): Action;
156
- /**
157
- * <br/><br/>
158
- * You must invoke [the load method]{@link Action#load} on the resultant
159
- * action in order for the request to be made.
160
- *
161
- * @public
162
- * @param {Array.<String>} placements
163
- * @return {Action}
164
- */
165
- setPlacements(placements: string[]): Action;
166
- /**
167
- * Sets the restore link for the current session. Restore links can be leveraged
168
- * in email campaigns. Restore links allow the the user to restore the cart
169
- * contents in a single click.
170
- * <br/><br/>
171
- * Read more about
172
- * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link}
173
- * <br/><br/>
174
- * It is not recommended to pass the restore link to an action but instead use the the
175
- * session.
176
- * <br/><br/>
177
- * You must invoke [the load method]{@link Action#load} on the resultant
178
- * action in order for the request to be made.
179
- *
180
- * @see {@link Session#setRestoreLink}
181
- * @public
182
- * @param {String} restoreLink the secure URL to restore the user's current session
183
- * @return {Action}
184
- */
185
- setRestoreLink(restoreLink: string): Action;
186
- /**
187
- * Sets the identifier of the current page type to the current request. The different
188
- * page types are product, front, search, cart, order, category, notfound and other.
189
- * <br/><br/>
190
- * You must invoke [the load method]{@link Action#load} on the resultant
191
- * action in order for the request to be made.
192
- * <br/><br/>
193
- * It is not recommended to pass the page type to an action but instead use the the
194
- * session.
195
- * <br/><br/>
196
- * You must invoke [the load method]{@link Action#load} on the resultant
197
- * action in order for the request to be made.
198
- *
199
- * @see {@link Session#viewFrontPage} for when a front or home page is being viewed
200
- * @see {@link Session#viewCart} for when a cart or checkout page is being viewed
201
- * @see {@link Session#viewNotFound} for when a not-found or 404 page is being viewed
202
- * @see {@link Session#viewProduct} for when a product page is being viewed
203
- * @see {@link Session#viewCategory} for when a category, collection or brand page is being viewed
204
- * @see {@link Session#viewTag} for when a tag page is being viewed
205
- * @see {@link Session#viewSearch} for when a search page is being viewed
206
- * @see {@link Session#viewOther} for when a miscellaneous page is being viewed
207
- * @public
208
- */
209
- setPageType(pageType: PageType): Action;
210
- /**
211
- * @public
212
- * @return {Object}
213
- */
214
- dumpData(): Data;
215
- update(): unknown;
216
- load(flags?: RecommendationRequestFlags): Promise<ActionResponse>;
217
- }
218
-
219
- declare interface ActionResponse {
220
- recommendations: Record<string, unknown>;
221
- campaigns?: {
222
- recommendations: Record<string, unknown>;
223
- content: Record<string, unknown>;
224
- };
225
- page_views: number;
226
- geo_location: string[];
227
- affinities: CustomerAffinityResponse;
228
- cmpid: string;
229
- }
3
+ import { ReactElement } from 'react';
230
4
 
231
5
  declare type AnyFunction = (...args: unknown[]) => unknown;
232
6
 
@@ -278,53 +52,6 @@ export declare interface Customer {
278
52
  type?: string;
279
53
  }
280
54
 
281
- /**
282
- * @group Types
283
- */
284
- declare interface CustomerAffinityResponse {
285
- discount: number;
286
- top_brands: CustomerAffinityResponseItem[];
287
- top_categories: CustomerAffinityResponseItem[];
288
- top_product_types: CustomerAffinityResponseItem[];
289
- top_skus: {
290
- [index: string]: CustomerAffinityResponseItem[];
291
- };
292
- }
293
-
294
- /**
295
- * @group Types
296
- */
297
- declare interface CustomerAffinityResponseItem {
298
- name: string;
299
- score: number;
300
- }
301
-
302
- /**
303
- * @group Types
304
- */
305
- declare interface Data<ProductType extends Product = Product> {
306
- cart: Cart | undefined;
307
- customer: Customer | undefined;
308
- variation: string | undefined;
309
- restoreLink: string | undefined;
310
- products: ProductType[];
311
- order: Order | undefined;
312
- searchTerms: string[] | undefined;
313
- categories: string[] | undefined;
314
- categoryIds: string[] | undefined;
315
- parentCategoryIds: string[] | undefined;
316
- tags: string[] | undefined;
317
- customFields: Record<string, string[]> | undefined;
318
- elements: string[] | undefined;
319
- pageType: PageType | undefined;
320
- sortOrder: string | undefined;
321
- pluginVersion: PluginMetadata | undefined;
322
- }
323
-
324
- declare type EventType = typeof eventTypes[number];
325
-
326
- declare const eventTypes: readonly ["vp", "lp", "dp", "rp", "bp", "vc", "or", "is", "cp", "ec", "es", "gc", "src", "cpr", "pl", "cc", "con"];
327
-
328
55
  /**
329
56
  * You can personalise your cart and checkout pages by using the `Nosto404` component.
330
57
  * The component does not require any props.
@@ -399,18 +126,6 @@ export declare function NostoCheckout(props: {
399
126
  placements?: string[];
400
127
  }): null;
401
128
 
402
- /**
403
- * @group Types
404
- */
405
- declare interface NostoClient {
406
- setAutoLoad(autoload: boolean): void;
407
- defaultSession(): Session;
408
- placements: {
409
- getPlacements(): string[];
410
- injectCampaigns(recommendations: Record<string, unknown>): void;
411
- };
412
- }
413
-
414
129
  /**
415
130
  * @group Essential Functions
416
131
  */
@@ -425,14 +140,7 @@ export declare interface NostoContextType {
425
140
  currentVariation?: string;
426
141
  renderFunction?: AnyFunction;
427
142
  responseMode: RenderMode;
428
- recommendationComponent?: React.ReactElement<{
429
- nostoRecommendation: Recommendation;
430
- }>;
431
- useRenderCampaigns(type: string): {
432
- renderCampaigns(data: unknown, api: NostoClient): void;
433
- pageTypeUpdated: boolean;
434
- };
435
- pageType: string;
143
+ recommendationComponent?: RecommendationComponent;
436
144
  }
437
145
 
438
146
  /**
@@ -583,7 +291,7 @@ export declare function NostoProvider(props: NostoProviderProps): JSX_2.Element;
583
291
  /**
584
292
  * @group Components
585
293
  */
586
- declare interface NostoProviderProps {
294
+ export declare interface NostoProviderProps {
587
295
  /**
588
296
  * Indicates merchant id
589
297
  */
@@ -596,7 +304,10 @@ declare interface NostoProviderProps {
596
304
  * Indicates an url of a server
597
305
  */
598
306
  host?: string;
599
- children: default_2.ReactElement;
307
+ /**
308
+ * children
309
+ */
310
+ children: ReactElement | ReactElement[];
600
311
  /**
601
312
  * Indicates if merchant uses multiple currencies
602
313
  */
@@ -604,9 +315,7 @@ declare interface NostoProviderProps {
604
315
  /**
605
316
  * Recommendation component which holds nostoRecommendation object
606
317
  */
607
- recommendationComponent?: default_2.ReactElement<{
608
- nostoRecommendation: Recommendation;
609
- }>;
318
+ recommendationComponent?: RecommendationComponent;
610
319
  /**
611
320
  * Enables Shopify markets with language and market id
612
321
  */
@@ -614,6 +323,14 @@ declare interface NostoProviderProps {
614
323
  language?: string;
615
324
  marketId?: string | number;
616
325
  };
326
+ /**
327
+ * Load nosto script (should be false if loading the script outside of nosto-react)
328
+ */
329
+ loadScript?: boolean;
330
+ /**
331
+ * Custom script loader
332
+ */
333
+ scriptLoader?: (scriptSrc: string, options?: ScriptLoadOptions) => Promise<void>;
617
334
  }
618
335
 
619
336
  /**
@@ -659,6 +376,20 @@ export declare function NostoSession(props?: {
659
376
  customer?: Customer;
660
377
  }): JSX_2.Element;
661
378
 
379
+ declare interface NostoSku extends Sku {
380
+ inventory_level?: number;
381
+ }
382
+
383
+ declare interface NostoVariant {
384
+ availability: string;
385
+ available: boolean;
386
+ discounted: boolean;
387
+ list_price?: number;
388
+ price: number;
389
+ price_currency_code: string;
390
+ price_text?: string;
391
+ }
392
+
662
393
  /**
663
394
  * @group Types
664
395
  */
@@ -687,20 +418,6 @@ declare interface OrderCustomer {
687
418
  type: string;
688
419
  }
689
420
 
690
- /**
691
- * @group Types
692
- */
693
- declare type PageType = "front" | "category" | "product" | "cart" | "search" | "notfound" | "order" | "other" | "checkout";
694
-
695
- /**
696
- * @group Types
697
- */
698
- declare interface PluginMetadata {
699
- mainModule?: string;
700
- cmpModule?: string;
701
- msiModule?: string;
702
- }
703
-
704
421
  /**
705
422
  * @group Types
706
423
  */
@@ -709,12 +426,62 @@ export declare type Product = {
709
426
  selected_sku_id?: string;
710
427
  };
711
428
 
429
+ declare interface PushedProduct {
430
+ age_group?: string;
431
+ alternate_image_urls: string[];
432
+ availability: string;
433
+ brand?: string;
434
+ category: string[];
435
+ category_id: string[];
436
+ condition?: string;
437
+ custom_fields: {
438
+ [index: string]: string;
439
+ };
440
+ date_published?: Date;
441
+ description?: string;
442
+ gender?: string;
443
+ google_category?: string;
444
+ gtin?: string;
445
+ image_url?: string;
446
+ inventory_level?: number;
447
+ list_price?: number;
448
+ name: string;
449
+ parent_category_id: string[];
450
+ price: number;
451
+ price_currency_code: string;
452
+ product_id: string;
453
+ rating_value?: number;
454
+ review_count?: number;
455
+ skus: PushedProductSKU[];
456
+ source_updated?: Date;
457
+ supplier_cost?: number;
458
+ tags1: string[];
459
+ tags2: string[];
460
+ tags3: string[];
461
+ thumb_url?: string;
462
+ unit_pricing_base_measure?: number;
463
+ unit_pricing_measure?: number;
464
+ unit_pricing_unit?: string;
465
+ update_received?: Date;
466
+ url: string;
467
+ variation_id?: string;
468
+ variations: {
469
+ [index: string]: PushedVariation;
470
+ };
471
+ }
472
+
473
+ declare interface PushedProductSKU extends NostoSku {
474
+ }
475
+
476
+ declare interface PushedVariation extends NostoVariant {
477
+ }
478
+
712
479
  /**
713
480
  * @group Types
714
481
  */
715
482
  export declare interface Recommendation {
716
483
  result_id: string;
717
- products: Product[];
484
+ products: PushedProduct[];
718
485
  result_type: string;
719
486
  title: string;
720
487
  div_id: string;
@@ -722,15 +489,9 @@ export declare interface Recommendation {
722
489
  params: unknown;
723
490
  }
724
491
 
725
- /**
726
- * @group Types
727
- */
728
- declare interface RecommendationRequestFlags {
729
- skipPageViews?: boolean;
730
- trackEvents?: boolean;
731
- skipEvents?: boolean;
732
- reloadCart?: boolean;
733
- }
492
+ declare type RecommendationComponent = ReactElement<{
493
+ nostoRecommendation: Recommendation;
494
+ }>;
734
495
 
735
496
  /**
736
497
  * @group Types
@@ -740,442 +501,29 @@ declare type RenderMode = "HTML" | "SIMPLE" | "JSON_170x170" | "JSON_100_X_100"
740
501
  /**
741
502
  * @group Types
742
503
  */
743
- declare interface Session {
744
- /**
745
- * Sets the information about the user's current shopping cart. It the user
746
- * does not have any items in his shopping cart, you can pass <code>null<code>.
747
- * Passing <code>null<code> will nullify the user's shopping cart on Nosto's
748
- * end. You must also pass in the shopping cart content in it's entirety as
749
- * partial content are not supported.
750
- *
751
- * @example
752
- * nostojs(api => api
753
- * .defaultSession()
754
- * .setCart({
755
- * items: [
756
- * product_id: "101",
757
- * sku_id: "101-S",
758
- * name: "Shoe",
759
- * unit_price: 34.99
760
- * price_currency_code: "EUR"
761
- * ]
762
- * })
763
- * .viewCart()
764
- * .setPlacements(["free-shipper"])
765
- * .update()
766
- * .then(data => console.log(data)))
767
- *
768
- * @public
769
- * @param {Cart|undefined} cart the details of the user's shopping cart contents
770
- * @returns {Session} the current session
771
- */
772
- setCart(cart: Cart | undefined): Session;
504
+ export declare type ScriptLoadOptions = {
773
505
  /**
774
- * Sets the information about the currently logged in customer. If the current
775
- * customer is not provided, you will not be able to leverage features such as
776
- * triggered emails. While it is recommended to always provide the details of
777
- * the currently logged in customer, it may be omitted if there are concerns
778
- * about privacy or compliance.
779
- *
780
- * @example
781
- * nostojs(api => api
782
- * .defaultSession()
783
- * .setCustomer({
784
- * first_name: "Mridang",
785
- * last_name: "Agarwalla",
786
- * email: "mridang@nosto.com",
787
- * newsletter: false,
788
- * customer_reference: "5e3d4a9c-cf58-11ea-87d0-0242ac130003"
789
- * })
790
- * .viewCart()
791
- * .setPlacements(["free-shipper"])
792
- * .load()
793
- * .then(data => console.log(data)))
794
- *
795
- * @public
796
- * @param {Customer} customer the details of the currently logged in customer
797
- * @returns {Session} the current session
506
+ * Indicates the position of the script, default is "body"
798
507
  */
799
- setCustomer(customer: Customer | undefined): Session;
508
+ position?: "head" | "body";
800
509
  /**
801
- * Sets the current variation identifier for the session. A variation identifier
802
- * identifies the current currency (or the current customer group). If your site
803
- * uses multi-currency, you must provide the ISO code current currency being viewed.
804
- *
805
- * @example
806
- * nostojs(api => api
807
- * .defaultSession()
808
- * .setVariation("GBP")
809
- * .viewCart()
810
- * .setPlacements(["free-shipper"])
811
- * .load()
812
- * .then(data => console.log(data)))
813
- *
814
- * @public
815
- * @param {String} variation the case-sensitive identifier of the current variation
816
- * @returns {Session} the current session
510
+ * Indicates the attributes of the script element
817
511
  */
818
- setVariation(variation: string): Session;
819
- /**
820
- * Sets the restore link for the current session. Restore links can be leveraged
821
- * in email campaigns. Restore links allow the the user to restore the cart
822
- * contents in a single click.
823
- * <br/><br/>
824
- * Read more about
825
- * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link}
826
- *
827
- * @example
828
- * nostojs(api => api
829
- * .defaultSession()
830
- * .setRestoreLink("https://jeans.com/session/restore?sid=6bdb69d5-ed15-4d92")
831
- * .viewCart()
832
- * .setPlacements(["free-shipper"])
833
- * .load()
834
- * .then(data => console.log(data)))
835
- *
836
- * @public
837
- * @param {String} restoreLink the secure URL to restore the user's current session
838
- * @returns {Session} the current session
839
- */
840
- setRestoreLink(restoreLink: string): Session;
841
- /**
842
- * Sets the response type to HTML or JSON_ORIGINAL. This denotes the preferred
843
- * response type of the recommendation result.
844
- * If you would like to access the raw recommendation data in <code>JSON</code> form, specify
845
- * <code>JSON</code>. When you specify JSON, you will need to template the result yourself.
846
- * If you require a more simplified approach, specify <code>HTML</code>. When you specify
847
- * <code>HTML</code>, you get back HTML blobs, that you may simply inject into
848
- * you placements.
849
- *
850
- * @example
851
- * nostojs(api => api
852
- * .defaultSession()
853
- * .setResponseMode("HTML")
854
- * .viewCart()
855
- * .setPlacements(["free-shipper"])
856
- * .load()
857
- * .then(data => console.log(data)))
858
- *
859
- * @public
860
- * @param {String} mode the response mode for the recommendation data
861
- * @returns {Session} the current session
862
- */
863
- setResponseMode(mode: RenderMode): Session;
864
- /**
865
- * Create a new action for a front page. This should be used when the user
866
- * visits the home page.
867
- * <br/><br/>
868
- * You must invoke [the load method]{@link Action#load} on the resultant
869
- * action in order for the request to be made.
870
- * <br/><br/>
871
- * You do not need to specify the page-type explicitly as it is inferred
872
- * from the action.
873
- *
874
- * @example
875
- * nostojs(api => api
876
- * .defaultSession()
877
- * .viewFrontPage()
878
- * .setPlacements(["best-seller"])
879
- * .load()
880
- * .then(data => console.log(data)))
881
- *
882
- *
883
- * @public
884
- * @returns {Action} the action instance to load content or track events.
885
- */
886
- viewFrontPage(): Action;
887
- /**
888
- * Create a new action for a cart page. This should be used on all cart and
889
- * checkout pages. If your site has a multi-step checkout, it is recommended
890
- * that you send this event on each checkout page.
891
- * <br/><br/>
892
- * You must invoke [the load method]{@link Action#load} on the resultant
893
- * action in order for the request to be made.
894
- * <br/><br/>
895
- * You do not need to specify the page-type explicitly as it is inferred
896
- * from the action.
897
- *
898
- * @example
899
- * nostojs(api => api
900
- * .defaultSession()
901
- * .viewCart()
902
- * .setPlacements(["free-shipper"])
903
- * .load()
904
- * .then(data => console.log(data)))
905
- *
906
- * @public
907
- * @returns {Action} the action instance to load content or track events.
908
- */
909
- viewCart(): Action;
910
- /**
911
- * Create a new action for a not found page. This should be used only on 404
912
- * pages.
913
- * <br/><br/>
914
- * You must invoke [the load method]{@link Action#load} on the resultant
915
- * action in order for the request to be made.
916
- * <br/><br/>
917
- * You do not need to specify the page-type explicitly as it is inferred
918
- * from the action.
919
- *
920
- * @example
921
- * nostojs(api => api
922
- * .defaultSession()
923
- * .viewNotFound()
924
- * .setPlacements(["best-seller"])
925
- * .load()
926
- * .then(data => console.log(data)))
927
- *
928
- * @public
929
- * @returns {Action} the action instance to load content or track events.
930
- */
931
- viewNotFound(): Action;
932
- /**
933
- * Create a new action for a product page. This must be used only when a
934
- * product is being viewed. In case a specific SKU of the product is being viewed, use viewProductSku instead.
935
- * <br/><br/>
936
- * You must invoke [the load method]{@link Action#load} on the resultant
937
- * action in order for the request to be made.
938
- * <br/><br/>
939
- * You do not need to specify the page-type explicitly as it is inferred
940
- * from the action.
941
- *
942
- * @example
943
- * nostojs(api => api
944
- * .defaultSession()
945
- * .viewProduct("101")
946
- * .setCategories(["/men/trousers"])
947
- * .setRef("123", "example_reco_id")
948
- * .setPlacements(["cross-seller"])
949
- * .load()
950
- * .then(data => console.log(data)))
951
- *
952
- * @public
953
- * @param product
954
- * @returns {Action} the action instance to load content or track events.
955
- */
956
- viewProduct(product: string | Product): Action;
957
- /**
958
- * Create a new action for a product page when a specific SKU has been chosen. This must be used only when a
959
- * product and specific SKU is being viewed.
960
- * <br/><br/>
961
- * You must invoke [the load method]{@link Action#load} on the resultant
962
- * action in order for the request to be made.
963
- * <br/><br/>
964
- * You do not need to specify the page-type explicitly as it is inferred
965
- * from the action.
966
- *
967
- * @example
968
- * nostojs(api => api
969
- * .defaultSession()
970
- * .viewProductSku("101", "101-sku-1")
971
- * .setCategories(["/men/trousers"])
972
- * .setRef("123", "example_reco_id")
973
- * .setPlacements(["cross-seller"])
974
- * .load()
975
- * .then(data => console.log(data)))
976
- *
977
- * @public
978
- * @param productId
979
- * @param skuId
980
- * @returns {Action} the action instance to load content or track events.
981
- */
982
- viewProductSku(productId: string, skuId: string): Action;
983
- /**
984
- * Create a new action for a category page. This should be used on all
985
- * category, collection of brand pages.
986
- * <br/><br/>
987
- * You must invoke [the load method]{@link Action#load} on the resultant
988
- * action in order for the request to be made.
989
- * <br/><br/>
990
- * You do not need to specify the page-type explicitly as it is inferred
991
- * from the action.
992
- *
993
- * @example
994
- * nostojs(api => api
995
- * .defaultSession()
996
- * .viewCategory("/men/shoes")
997
- * .setPlacements(["category123"])
998
- * .load()
999
- * .then(data => console.log(data)))
1000
- *
1001
- * @public
1002
- * @param {Array<String>} categories
1003
- * @returns {Action} the action instance to load content or track events.
1004
- */
1005
- viewCategory(...categories: string[]): Action;
1006
- /**
1007
- * Create a new action for a tag page. This should be used only on tag pages.
1008
- * <br/><br/>
1009
- * You must invoke [the load method]{@link Action#load} on the resultant
1010
- * action in order for the request to be made.
1011
- * <br/><br/>
1012
- * You do not need to specify the page-type explicitly as it is inferred
1013
- * from the action.
1014
- * Note: tags are not case-sensitive.
1015
- *
1016
- * @example
1017
- * nostojs(api => api
1018
- * .defaultSession()
1019
- * .viewTag("colourful")
1020
- * .load()
1021
- * .then(data => console.log(data)))
1022
- *
1023
- * @public
1024
- * @deprecated as this is an advanced action with a limited a use case
1025
- * @param {Array<String>} tags the set of the tags being viewed.
1026
- * @returns {Action} the action instance to load content or track events.
1027
- */
1028
- viewTag(...tags: string[]): Action;
1029
- /**
1030
- * Create a new action with custom fields.
1031
- * <br/><br/>
1032
- * You must invoke [the load method]{@link Action#load} on the resultant
1033
- * action in order for the request to be made.
1034
- * <br/><br/>
1035
- * You do not need to specify the page-type explicitly as it is inferred
1036
- * from the action.
1037
- * Note: tags are not case-sensitive.
1038
- *
1039
- * @example
1040
- * nostojs(api => api
1041
- * .defaultSession()
1042
- * .viewCustomField({material: "cotton"})
1043
- * .load()
1044
- * .then(data => console.log(data)))
1045
- *
1046
- * @public
1047
- * @deprecated as this is an advanced action with a limited a use case
1048
- * @param {Object} customFields custom fields being viewed.
1049
- * @returns {Action} the action instance to load content or track events.
1050
- */
1051
- viewCustomField(customFields: Record<string, string[]>): Action;
1052
- /**
1053
- * Create a new action for a search page. This should be used only
1054
- * on search pages. A search page action requires you to pass the search
1055
- * term. For example, if the user search for "black shoes", you must pass
1056
- * in "black shoes" and not an encoded version such as "black+shoes".
1057
- * <br/><br/>
1058
- * You must invoke [the load method]{@link Action#load} on the resultant
1059
- * action in order for the request to be made.
1060
- * <br/><br/>
1061
- * You do not need to specify the page-type explicitly as it is inferred
1062
- * from the action.
1063
- * Search terms are not case-sensitive.
1064
- *
1065
- * @example
1066
- * nostojs(api => api
1067
- * .defaultSession()
1068
- * .viewSearch("black shoes")
1069
- * .load()
1070
- * .then(data => console.log(data)))
1071
- *
1072
- * @public
1073
- * @param {Array.<String>} searchTerms the non-encoded search terms
1074
- * @returns {Action} the action instance to load content or track events.
1075
- */
1076
- viewSearch(...searchTerms: string[]): Action;
1077
- /**
1078
- * Create a new action for a general page. This should be used only on
1079
- * pages that don't have a corresponding action. For example, if the user
1080
- * is viewing a page such as a "Contact Us" page, you should use the viewOther
1081
- * action.
1082
- * <br/><br/>
1083
- * You must invoke [the load method]{@link Action#load} on the resultant
1084
- * action in order for the request to be made.
1085
- * <br/><br/>
1086
- * You do not need to specify the page-type explicitly as it is inferred
1087
- * from the action.
1088
- *
1089
- * @example
1090
- * nostojs(api => api
1091
- * .defaultSession()
1092
- * .viewOther()
1093
- * .load()
1094
- * .then(data => console.log(data)))
1095
- *
1096
- * @public
1097
- * @returns {Action} the action instance to load content or track events.
1098
- */
1099
- viewOther(): Action;
1100
- /**
1101
- * Create a new action for an order page. This should only be used on order
1102
- * confirmation / thank you pages.
1103
- * <br/><br/>
1104
- * You do not need to specify the page-type explicitly as it is inferred
1105
- * from the action.
1106
- * <br/><br/>
1107
- * You must invoke [the load method]{@link Action#load} on the resultant
1108
- * action in order for the request to be made.
1109
- *
1110
- * @example
1111
- * nostojs(api => {
1112
- * api.defaultSession()
1113
- * .addOrder({
1114
- * external_order_ref: "145000006",
1115
- * info: {
1116
- * order_number: "195",
1117
- * email: "mridang@nosto.com",
1118
- * first_name: "Mridang",
1119
- * last_name: "Agarwalla",
1120
- * type: "order",
1121
- * newsletter: true
1122
- * },
1123
- * items: [{
1124
- * product_id: "406",
1125
- * sku_id: "243",
1126
- * name: "Linen Blazer (White, S)",
1127
- * quantity: 1,
1128
- * unit_price: 455,
1129
- * price_currency_code: "EUR"
1130
- * }]
1131
- * })
1132
- * .setPlacements(["order-related"])
1133
- * .load()
1134
- * .then(data => {
1135
- * console.log(data.recommendations)
1136
- * })
1137
- * })
1138
- * @public
1139
- * @param {Order} order the information about the order that was placed
1140
- * @returns {Action} the action instance to load content or track events.
1141
- */
1142
- addOrder(order: Order): Action;
1143
- /**
1144
- * Creates an action to report that product was added to the shopping cart,
1145
- * e.g. from the recommendation slot with "Add to cart" button.
1146
- * <p>
1147
- * You must invoke [the load method]{@link Action#load} on the resultant
1148
- * action in order for the request to be made.
1149
- *
1150
- *
1151
- * @example
1152
- * nostojs(api => api
1153
- * .defaultSession()
1154
- * .reportAddToCart("123", "reco-slot-1")
1155
- * .load()
1156
- * .then(data => console.log(data)))
1157
- *
1158
- * @public
1159
- * @param product
1160
- * @param element
1161
- * @returns {Action} the action instance to load content or track events.
1162
- */
1163
- reportAddToCart(product: string, element: string): Action;
1164
- /**
1165
- * @example
1166
- * nostojs(api => api
1167
- * .defaultSession()
1168
- * .recordAttribution("vp", "12345678", "123456")
1169
- * .done()
1170
- * .then(data => console.log(data))
1171
- * @param { EventType } type
1172
- * @param { String } target
1173
- * @param { String | undefined } [ref]
1174
- * @param { String | undefined } [refSrc]
1175
- * @return { Object }
1176
- *
1177
- */
1178
- recordAttribution(type: EventType, target: string, ref: string, refSrc: string): object;
512
+ attributes?: Record<string, string>;
513
+ };
514
+
515
+ declare interface Sku {
516
+ availability: string;
517
+ custom_fields: {
518
+ [index: string]: string;
519
+ };
520
+ gtin?: string;
521
+ id: string;
522
+ image_url?: string;
523
+ list_price?: number;
524
+ name: string;
525
+ price: number;
526
+ url?: string;
1179
527
  }
1180
528
 
1181
529
  /**