@nosto/nosto-react 2.0.0 → 2.2.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/README.md +13 -0
- package/dist/index.d.ts +172 -27
- package/dist/index.es.js +552 -521
- package/dist/index.umd.js +9 -9
- package/package.json +8 -19
- package/src/components/Nosto404.tsx +17 -3
- package/src/components/NostoCategory.tsx +19 -3
- package/src/components/NostoCheckout.tsx +17 -3
- package/src/components/NostoHome.tsx +17 -3
- package/src/components/NostoOrder.tsx +19 -6
- package/src/components/NostoOther.tsx +17 -3
- package/src/components/NostoPlacement.tsx +5 -3
- package/src/components/NostoProduct.tsx +21 -8
- package/src/components/NostoProvider.tsx +21 -77
- package/src/components/NostoSearch.tsx +19 -3
- package/src/components/NostoSession.tsx +26 -6
- package/src/components/index.ts +11 -11
- package/src/context.ts +2 -2
- package/src/hooks/index.ts +2 -1
- package/src/hooks/scriptLoader.ts +30 -0
- package/src/hooks/useLoadClientScript.ts +84 -0
- package/src/hooks/useNostoApi.ts +2 -2
- package/src/hooks/useNostoContext.ts +1 -7
- package/src/hooks/useRenderCampaigns.tsx +2 -3
- package/src/index.ts +1 -0
- package/src/utils/snakeize.ts +5 -1
- package/src/utils/types.ts +29 -0
package/README.md
CHANGED
|
@@ -264,6 +264,19 @@ import {
|
|
|
264
264
|
</div>;
|
|
265
265
|
```
|
|
266
266
|
|
|
267
|
+
### Hook alternatives
|
|
268
|
+
|
|
269
|
+
For all the page type specific components hooks are also provided with the same props
|
|
270
|
+
|
|
271
|
+
- useNosto404
|
|
272
|
+
- useNostoOther
|
|
273
|
+
- useNostoCheckout
|
|
274
|
+
- useNostoProduct
|
|
275
|
+
- useNostoCategory
|
|
276
|
+
- useNostoSearch
|
|
277
|
+
- useNostOrder
|
|
278
|
+
- useNostoHome
|
|
279
|
+
|
|
267
280
|
### Detailed technical documentation
|
|
268
281
|
Find our latest technical specs and documentation hosted [here](https://nosto.github.io/nosto-react).
|
|
269
282
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +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';
|
|
3
|
+
import { ReactElement } from 'react';
|
|
4
4
|
|
|
5
5
|
declare type AnyFunction = (...args: unknown[]) => unknown;
|
|
6
6
|
|
|
@@ -12,6 +12,8 @@ export declare interface Cart {
|
|
|
12
12
|
items: CartItem[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
declare type Cart_2 = Cart | ToCamelCase<Cart>;
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* @group Types
|
|
17
19
|
*/
|
|
@@ -52,6 +54,8 @@ export declare interface Customer {
|
|
|
52
54
|
type?: string;
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
declare type Customer_2 = Customer | ToCamelCase<Customer>;
|
|
58
|
+
|
|
55
59
|
/**
|
|
56
60
|
* You can personalise your cart and checkout pages by using the `Nosto404` component.
|
|
57
61
|
* The component does not require any props.
|
|
@@ -72,9 +76,14 @@ export declare interface Customer {
|
|
|
72
76
|
*
|
|
73
77
|
* @group Components
|
|
74
78
|
*/
|
|
75
|
-
export declare function Nosto404(props:
|
|
79
|
+
export declare function Nosto404(props: Nosto404Props): null;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @group Components
|
|
83
|
+
*/
|
|
84
|
+
export declare type Nosto404Props = {
|
|
76
85
|
placements?: string[];
|
|
77
|
-
}
|
|
86
|
+
};
|
|
78
87
|
|
|
79
88
|
/**
|
|
80
89
|
* You can personalise your category and collection pages by using the NostoCategory component.
|
|
@@ -98,10 +107,15 @@ export declare function Nosto404(props: {
|
|
|
98
107
|
*
|
|
99
108
|
* @group Components
|
|
100
109
|
*/
|
|
101
|
-
export declare function NostoCategory(props:
|
|
110
|
+
export declare function NostoCategory(props: NostoCategoryProps): null;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @group Components
|
|
114
|
+
*/
|
|
115
|
+
export declare type NostoCategoryProps = {
|
|
102
116
|
category: string;
|
|
103
117
|
placements?: string[];
|
|
104
|
-
}
|
|
118
|
+
};
|
|
105
119
|
|
|
106
120
|
/**
|
|
107
121
|
* You can personalise your cart and checkout pages by using the NostoCheckout component.
|
|
@@ -122,9 +136,14 @@ export declare function NostoCategory(props: {
|
|
|
122
136
|
*
|
|
123
137
|
* @group Components
|
|
124
138
|
*/
|
|
125
|
-
export declare function NostoCheckout(props:
|
|
139
|
+
export declare function NostoCheckout(props: NostoCheckoutProps): null;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @group Components
|
|
143
|
+
*/
|
|
144
|
+
export declare type NostoCheckoutProps = {
|
|
126
145
|
placements?: string[];
|
|
127
|
-
}
|
|
146
|
+
};
|
|
128
147
|
|
|
129
148
|
/**
|
|
130
149
|
* @group Essential Functions
|
|
@@ -166,9 +185,14 @@ export declare interface NostoContextType {
|
|
|
166
185
|
*
|
|
167
186
|
* @group Components
|
|
168
187
|
*/
|
|
169
|
-
export declare function NostoHome(props:
|
|
188
|
+
export declare function NostoHome(props: NostoHomeProps): null;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @group Components
|
|
192
|
+
*/
|
|
193
|
+
export declare type NostoHomeProps = {
|
|
170
194
|
placements?: string[];
|
|
171
|
-
}
|
|
195
|
+
};
|
|
172
196
|
|
|
173
197
|
/**
|
|
174
198
|
* You can personalise your order-confirmation/thank-you page by using the `NostoOrder` component.
|
|
@@ -189,10 +213,15 @@ export declare function NostoHome(props: {
|
|
|
189
213
|
*
|
|
190
214
|
* @group Components
|
|
191
215
|
*/
|
|
192
|
-
export declare function NostoOrder(props:
|
|
216
|
+
export declare function NostoOrder(props: NostoOrderProps): null;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @group Components
|
|
220
|
+
*/
|
|
221
|
+
export declare type NostoOrderProps = {
|
|
193
222
|
order: Order;
|
|
194
223
|
placements?: string[];
|
|
195
|
-
}
|
|
224
|
+
};
|
|
196
225
|
|
|
197
226
|
/**
|
|
198
227
|
* You can personalise your miscellaneous pages by using the NostoOther component.
|
|
@@ -213,9 +242,14 @@ export declare function NostoOrder(props: {
|
|
|
213
242
|
*
|
|
214
243
|
* @group Components
|
|
215
244
|
*/
|
|
216
|
-
export declare function NostoOther(props:
|
|
245
|
+
export declare function NostoOther(props: NostoOtherProps): null;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @group Components
|
|
249
|
+
*/
|
|
250
|
+
export declare type NostoOtherProps = {
|
|
217
251
|
placements?: string[];
|
|
218
|
-
}
|
|
252
|
+
};
|
|
219
253
|
|
|
220
254
|
/**
|
|
221
255
|
* Nosto React has a special component called NostoPlacement.
|
|
@@ -230,10 +264,15 @@ export declare function NostoOther(props: {
|
|
|
230
264
|
*
|
|
231
265
|
* @group Components
|
|
232
266
|
*/
|
|
233
|
-
export declare function NostoPlacement(
|
|
267
|
+
export declare function NostoPlacement({ id, pageType }: NostoPlacementProps): JSX_2.Element;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @group Components
|
|
271
|
+
*/
|
|
272
|
+
export declare type NostoPlacementProps = {
|
|
234
273
|
id: string;
|
|
235
274
|
pageType?: string;
|
|
236
|
-
}
|
|
275
|
+
};
|
|
237
276
|
|
|
238
277
|
/**
|
|
239
278
|
* The NostoProduct component must be used to personalise the product page.
|
|
@@ -259,11 +298,16 @@ export declare function NostoPlacement(props: {
|
|
|
259
298
|
*
|
|
260
299
|
* @group Components
|
|
261
300
|
*/
|
|
262
|
-
export declare function NostoProduct(props:
|
|
301
|
+
export declare function NostoProduct(props: NostoProductProps): null;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* @group Components
|
|
305
|
+
*/
|
|
306
|
+
export declare type NostoProductProps = {
|
|
263
307
|
product: string;
|
|
264
308
|
tagging?: Product;
|
|
265
309
|
placements?: string[];
|
|
266
|
-
}
|
|
310
|
+
};
|
|
267
311
|
|
|
268
312
|
/**
|
|
269
313
|
* This widget is what we call the Nosto root widget, which is responsible for adding the actual Nosto script and the JS API stub.
|
|
@@ -291,7 +335,7 @@ export declare function NostoProvider(props: NostoProviderProps): JSX_2.Element;
|
|
|
291
335
|
/**
|
|
292
336
|
* @group Components
|
|
293
337
|
*/
|
|
294
|
-
declare interface NostoProviderProps {
|
|
338
|
+
export declare interface NostoProviderProps {
|
|
295
339
|
/**
|
|
296
340
|
* Indicates merchant id
|
|
297
341
|
*/
|
|
@@ -307,7 +351,7 @@ declare interface NostoProviderProps {
|
|
|
307
351
|
/**
|
|
308
352
|
* children
|
|
309
353
|
*/
|
|
310
|
-
children:
|
|
354
|
+
children: ReactElement | ReactElement[];
|
|
311
355
|
/**
|
|
312
356
|
* Indicates if merchant uses multiple currencies
|
|
313
357
|
*/
|
|
@@ -323,6 +367,14 @@ declare interface NostoProviderProps {
|
|
|
323
367
|
language?: string;
|
|
324
368
|
marketId?: string | number;
|
|
325
369
|
};
|
|
370
|
+
/**
|
|
371
|
+
* Load nosto script (should be false if loading the script outside of nosto-react)
|
|
372
|
+
*/
|
|
373
|
+
loadScript?: boolean;
|
|
374
|
+
/**
|
|
375
|
+
* Custom script loader
|
|
376
|
+
*/
|
|
377
|
+
scriptLoader?: (scriptSrc: string, options?: ScriptLoadOptions) => Promise<void>;
|
|
326
378
|
}
|
|
327
379
|
|
|
328
380
|
/**
|
|
@@ -348,10 +400,15 @@ declare interface NostoProviderProps {
|
|
|
348
400
|
*
|
|
349
401
|
* @group Components
|
|
350
402
|
*/
|
|
351
|
-
export declare function NostoSearch(props:
|
|
403
|
+
export declare function NostoSearch(props: NostoSearchProps): null;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @group Components
|
|
407
|
+
*/
|
|
408
|
+
export declare type NostoSearchProps = {
|
|
352
409
|
query: string;
|
|
353
410
|
placements?: string[];
|
|
354
|
-
}
|
|
411
|
+
};
|
|
355
412
|
|
|
356
413
|
/**
|
|
357
414
|
* Nosto React requires that you pass it the details of current cart contents and the details of the currently logged-in customer, if any, on every route change.
|
|
@@ -361,12 +418,17 @@ export declare function NostoSearch(props: {
|
|
|
361
418
|
*
|
|
362
419
|
* The cart prop requires a value that adheres to the type `Cart`, while the customer prop requires a value that adheres to the type `Customer`.
|
|
363
420
|
*
|
|
364
|
-
* @group
|
|
421
|
+
* @group Components
|
|
365
422
|
*/
|
|
366
|
-
export declare function NostoSession(props?:
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
423
|
+
export declare function NostoSession(props?: NostoSessionProps): null;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* @group Components
|
|
427
|
+
*/
|
|
428
|
+
export declare type NostoSessionProps = {
|
|
429
|
+
cart?: Cart_2;
|
|
430
|
+
customer?: Customer_2;
|
|
431
|
+
};
|
|
370
432
|
|
|
371
433
|
declare interface NostoSku extends Sku {
|
|
372
434
|
inventory_level?: number;
|
|
@@ -481,7 +543,7 @@ export declare interface Recommendation {
|
|
|
481
543
|
params: unknown;
|
|
482
544
|
}
|
|
483
545
|
|
|
484
|
-
declare type RecommendationComponent =
|
|
546
|
+
declare type RecommendationComponent = ReactElement<{
|
|
485
547
|
nostoRecommendation: Recommendation;
|
|
486
548
|
}>;
|
|
487
549
|
|
|
@@ -490,6 +552,20 @@ declare type RecommendationComponent = React.ReactElement<{
|
|
|
490
552
|
*/
|
|
491
553
|
declare 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";
|
|
492
554
|
|
|
555
|
+
/**
|
|
556
|
+
* @group Types
|
|
557
|
+
*/
|
|
558
|
+
export declare type ScriptLoadOptions = {
|
|
559
|
+
/**
|
|
560
|
+
* Indicates the position of the script, default is "body"
|
|
561
|
+
*/
|
|
562
|
+
position?: "head" | "body";
|
|
563
|
+
/**
|
|
564
|
+
* Indicates the attributes of the script element
|
|
565
|
+
*/
|
|
566
|
+
attributes?: Record<string, string>;
|
|
567
|
+
};
|
|
568
|
+
|
|
493
569
|
declare interface Sku {
|
|
494
570
|
availability: string;
|
|
495
571
|
custom_fields: {
|
|
@@ -504,6 +580,33 @@ declare interface Sku {
|
|
|
504
580
|
url?: string;
|
|
505
581
|
}
|
|
506
582
|
|
|
583
|
+
declare type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
|
|
584
|
+
|
|
585
|
+
declare type ToCamelCase<T> = T extends (infer U)[] ? ToCamelCase<U>[] : T extends Date ? T : T extends object ? {
|
|
586
|
+
[K in keyof T as SnakeToCamelCase<K & string>]: ToCamelCase<T[K]>;
|
|
587
|
+
} : T;
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* You can personalise your cart and checkout pages by using the `useNosto404` hook.
|
|
591
|
+
*
|
|
592
|
+
* @group Hooks
|
|
593
|
+
*/
|
|
594
|
+
export declare function useNosto404(props?: Nosto404Props): void;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* You can personalise your category and collection pages by using the useNostoCategory hook.
|
|
598
|
+
*
|
|
599
|
+
* @group Hooks
|
|
600
|
+
*/
|
|
601
|
+
export declare function useNostoCategory({ category, placements }: NostoCategoryProps): void;
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* You can personalise your cart and checkout pages by using the useNostoCheckout hook.
|
|
605
|
+
*
|
|
606
|
+
* @group Hooks
|
|
607
|
+
*/
|
|
608
|
+
export declare function useNostoCheckout(props?: NostoCheckoutProps): void;
|
|
609
|
+
|
|
507
610
|
/**
|
|
508
611
|
* A hook that allows you to access the NostoContext and retrieve Nosto-related data from it in React components.
|
|
509
612
|
*
|
|
@@ -511,6 +614,48 @@ declare interface Sku {
|
|
|
511
614
|
*/
|
|
512
615
|
export declare function useNostoContext(): NostoContextType;
|
|
513
616
|
|
|
617
|
+
/**
|
|
618
|
+
* You can personalise your home page by using the useNostoHome hook.
|
|
619
|
+
*
|
|
620
|
+
* @group Hooks
|
|
621
|
+
*/
|
|
622
|
+
export declare function useNostoHome(props?: NostoHomeProps): void;
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* You can personalise your order-confirmation/thank-you page by using the `useNostoOrder` hook.
|
|
626
|
+
*
|
|
627
|
+
* @group Hooks
|
|
628
|
+
*/
|
|
629
|
+
export declare function useNostoOrder({ order, placements }: NostoOrderProps): void;
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* You can personalise your miscellaneous pages by using the useNostoOther hook.
|
|
633
|
+
*
|
|
634
|
+
* @group Hooks
|
|
635
|
+
*/
|
|
636
|
+
export declare function useNostoOther(props?: NostoOtherProps): void;
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* You can personalise your product pages by using the useNostoProduct hook.
|
|
640
|
+
*
|
|
641
|
+
* @group Hooks
|
|
642
|
+
*/
|
|
643
|
+
export declare function useNostoProduct({ product, tagging, placements }: NostoProductProps): void;
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* You can personalise your search pages by using the useNostoSearch hook.
|
|
647
|
+
*
|
|
648
|
+
* @group Hooks
|
|
649
|
+
*/
|
|
650
|
+
export declare function useNostoSearch({ query, placements }: NostoSearchProps): void;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Nosto React requires that you pass it the details of current cart contents and the details of the currently logged-in customer, if any, on every route change.
|
|
654
|
+
*
|
|
655
|
+
* @group Hooks
|
|
656
|
+
*/
|
|
657
|
+
export declare function useNostoSession({ cart, customer }?: NostoSessionProps): void;
|
|
658
|
+
|
|
514
659
|
export { }
|
|
515
660
|
|
|
516
661
|
declare global {
|