@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/README.md +1 -6
- package/dist/index.d.ts +145 -137
- package/dist/index.es.js +540 -761
- package/dist/index.umd.js +9 -9
- package/package.json +3 -1
- package/src/components/Nosto404.tsx +5 -17
- package/src/components/NostoCategory.tsx +5 -18
- package/src/components/NostoCheckout.tsx +5 -18
- package/src/components/NostoHome.tsx +5 -16
- package/src/components/NostoOrder.tsx +8 -20
- package/src/components/NostoOther.tsx +5 -17
- package/src/components/NostoProduct.tsx +6 -102
- package/src/components/NostoProvider.tsx +12 -68
- package/src/components/NostoSearch.tsx +5 -18
- package/src/components/NostoSession.tsx +3 -4
- package/src/components/helpers.ts +3 -0
- package/src/components/index.ts +0 -3
- package/src/context.ts +31 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useDeepCompareEffect.ts +21 -0
- package/src/hooks/useNostoApi.ts +22 -0
- package/src/hooks/useNostoContext.ts +18 -0
- package/src/hooks/useRenderCampaigns.tsx +60 -0
- package/src/index.ts +3 -2
- package/src/types.ts +863 -100
- package/src/components/context.ts +0 -55
- package/src/utils/hooks.ts +0 -41
package/README.md
CHANGED
|
@@ -251,21 +251,16 @@ You can personalise your order-confirmation/thank-you page by using the `NostoOr
|
|
|
251
251
|
|
|
252
252
|
By default, your account, when created, has one other-page placement named `thankyou-nosto-1`. You may omit this and use any identifier you need. The identifier used here is simply provided to illustrate the example.
|
|
253
253
|
|
|
254
|
-
The `order` prop requires a value that adheres to the type `Purchase`.
|
|
255
|
-
|
|
256
254
|
```jsx
|
|
257
255
|
import {
|
|
258
|
-
Buyer,
|
|
259
|
-
Item,
|
|
260
256
|
NostoOrder,
|
|
261
257
|
NostoPlacement,
|
|
262
|
-
Purchase,
|
|
263
258
|
} from "@nosto/nosto-react";
|
|
264
259
|
|
|
265
260
|
<div className="thankyou-page">
|
|
266
261
|
... ... ...
|
|
267
262
|
<NostoPlacement id="thankyou-nosto-1" />
|
|
268
|
-
<NostoOrder order={
|
|
263
|
+
<NostoOrder order={ order } />
|
|
269
264
|
</div>;
|
|
270
265
|
```
|
|
271
266
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,55 +2,54 @@ import { Context } from 'react';
|
|
|
2
2
|
import { default as default_2 } from 'react';
|
|
3
3
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
|
+
declare type AnyFunction = (...args: unknown[]) => unknown;
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* @group Types
|
|
7
9
|
*/
|
|
8
|
-
declare interface
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export declare interface Cart {
|
|
11
|
+
hcid?: string;
|
|
12
|
+
items: CartItem[];
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
declare type AnyFunction = (...args: unknown[]) => unknown;
|
|
14
|
-
|
|
15
15
|
/**
|
|
16
16
|
* @group Types
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
declare interface CartItem {
|
|
19
|
+
name: string;
|
|
20
|
+
price_currency_code: string;
|
|
21
|
+
product_id: string;
|
|
22
|
+
quantity: number;
|
|
23
|
+
sku_id?: string;
|
|
24
|
+
unit_price: number;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* @group Types
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
declare interface ConversionItem {
|
|
31
|
+
name: string;
|
|
32
|
+
price_currency_code: string;
|
|
33
|
+
product_id: string;
|
|
34
|
+
quantity?: number;
|
|
35
|
+
sku_id?: string;
|
|
36
|
+
unit_price?: number;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
/**
|
|
34
40
|
* @group Types
|
|
35
41
|
*/
|
|
36
42
|
export declare interface Customer {
|
|
37
|
-
customer_reference
|
|
43
|
+
customer_reference?: string;
|
|
38
44
|
email: string;
|
|
39
45
|
first_name: string;
|
|
46
|
+
hcid?: string;
|
|
40
47
|
last_name: string;
|
|
41
|
-
newsletter
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*/
|
|
47
|
-
export declare interface Item {
|
|
48
|
-
name: string;
|
|
49
|
-
price_currency_code: string;
|
|
50
|
-
product_id: string;
|
|
51
|
-
quantity: number;
|
|
52
|
-
sku_id: string;
|
|
53
|
-
unit_price: number;
|
|
48
|
+
newsletter?: boolean;
|
|
49
|
+
order_number?: string;
|
|
50
|
+
source?: string;
|
|
51
|
+
source_id?: string;
|
|
52
|
+
type?: string;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
/**
|
|
@@ -75,7 +74,7 @@ export declare interface Item {
|
|
|
75
74
|
*/
|
|
76
75
|
export declare function Nosto404(props: {
|
|
77
76
|
placements?: string[];
|
|
78
|
-
}):
|
|
77
|
+
}): null;
|
|
79
78
|
|
|
80
79
|
/**
|
|
81
80
|
* You can personalise your category and collection pages by using the NostoCategory component.
|
|
@@ -102,7 +101,7 @@ export declare function Nosto404(props: {
|
|
|
102
101
|
export declare function NostoCategory(props: {
|
|
103
102
|
category: string;
|
|
104
103
|
placements?: string[];
|
|
105
|
-
}):
|
|
104
|
+
}): null;
|
|
106
105
|
|
|
107
106
|
/**
|
|
108
107
|
* You can personalise your cart and checkout pages by using the NostoCheckout component.
|
|
@@ -125,39 +124,7 @@ export declare function NostoCategory(props: {
|
|
|
125
124
|
*/
|
|
126
125
|
export declare function NostoCheckout(props: {
|
|
127
126
|
placements?: string[];
|
|
128
|
-
}):
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @group Types
|
|
132
|
-
*/
|
|
133
|
-
declare interface NostoClient {
|
|
134
|
-
setAutoLoad(autoload: boolean): NostoClient;
|
|
135
|
-
defaultSession(): NostoClientSession;
|
|
136
|
-
placements: {
|
|
137
|
-
getPlacements(): string[];
|
|
138
|
-
injectCampaigns(recommendations: Record<string, Recommendation>): void;
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @group Types
|
|
144
|
-
*/
|
|
145
|
-
declare interface NostoClientSession {
|
|
146
|
-
setCart(cart?: Cart): NostoClientSession;
|
|
147
|
-
setCustomer(customer?: Customer): NostoClientSession;
|
|
148
|
-
setResponseMode(mode: string): NostoClientSession;
|
|
149
|
-
setVariation(variation?: string): NostoClientSession;
|
|
150
|
-
addOrder(order: {
|
|
151
|
-
purchase: Purchase;
|
|
152
|
-
}): SessionAction;
|
|
153
|
-
viewCategory(category: string): SessionAction;
|
|
154
|
-
viewProduct(product: string): SessionAction;
|
|
155
|
-
viewFrontPage(): SessionAction;
|
|
156
|
-
viewNotFound(): SessionAction;
|
|
157
|
-
viewOther(): SessionAction;
|
|
158
|
-
viewSearch(query: string): SessionAction;
|
|
159
|
-
viewCart(): SessionAction;
|
|
160
|
-
}
|
|
127
|
+
}): null;
|
|
161
128
|
|
|
162
129
|
/**
|
|
163
130
|
* @group Essential Functions
|
|
@@ -172,15 +139,8 @@ export declare interface NostoContextType {
|
|
|
172
139
|
clientScriptLoaded: boolean;
|
|
173
140
|
currentVariation?: string;
|
|
174
141
|
renderFunction?: AnyFunction;
|
|
175
|
-
responseMode:
|
|
176
|
-
recommendationComponent?:
|
|
177
|
-
nostoRecommendation: Recommendation;
|
|
178
|
-
}>;
|
|
179
|
-
useRenderCampaigns(type: string): {
|
|
180
|
-
renderCampaigns(data: unknown, api: NostoClient): void;
|
|
181
|
-
pageTypeUpdated: boolean;
|
|
182
|
-
};
|
|
183
|
-
pageType: string;
|
|
142
|
+
responseMode: RenderMode;
|
|
143
|
+
recommendationComponent?: RecommendationComponent;
|
|
184
144
|
}
|
|
185
145
|
|
|
186
146
|
/**
|
|
@@ -208,7 +168,7 @@ export declare interface NostoContextType {
|
|
|
208
168
|
*/
|
|
209
169
|
export declare function NostoHome(props: {
|
|
210
170
|
placements?: string[];
|
|
211
|
-
}):
|
|
171
|
+
}): null;
|
|
212
172
|
|
|
213
173
|
/**
|
|
214
174
|
* You can personalise your order-confirmation/thank-you page by using the `NostoOrder` component.
|
|
@@ -230,11 +190,9 @@ export declare function NostoHome(props: {
|
|
|
230
190
|
* @group Components
|
|
231
191
|
*/
|
|
232
192
|
export declare function NostoOrder(props: {
|
|
233
|
-
order:
|
|
234
|
-
purchase: Purchase;
|
|
235
|
-
};
|
|
193
|
+
order: Order;
|
|
236
194
|
placements?: string[];
|
|
237
|
-
}):
|
|
195
|
+
}): null;
|
|
238
196
|
|
|
239
197
|
/**
|
|
240
198
|
* You can personalise your miscellaneous pages by using the NostoOther component.
|
|
@@ -257,7 +215,7 @@ export declare function NostoOrder(props: {
|
|
|
257
215
|
*/
|
|
258
216
|
export declare function NostoOther(props: {
|
|
259
217
|
placements?: string[];
|
|
260
|
-
}):
|
|
218
|
+
}): null;
|
|
261
219
|
|
|
262
220
|
/**
|
|
263
221
|
* Nosto React has a special component called NostoPlacement.
|
|
@@ -305,7 +263,7 @@ export declare function NostoProduct(props: {
|
|
|
305
263
|
product: string;
|
|
306
264
|
tagging?: Product;
|
|
307
265
|
placements?: string[];
|
|
308
|
-
}):
|
|
266
|
+
}): null;
|
|
309
267
|
|
|
310
268
|
/**
|
|
311
269
|
* This widget is what we call the Nosto root widget, which is responsible for adding the actual Nosto script and the JS API stub.
|
|
@@ -346,7 +304,10 @@ declare interface NostoProviderProps {
|
|
|
346
304
|
* Indicates an url of a server
|
|
347
305
|
*/
|
|
348
306
|
host?: string;
|
|
349
|
-
|
|
307
|
+
/**
|
|
308
|
+
* children
|
|
309
|
+
*/
|
|
310
|
+
children: default_2.ReactElement | default_2.ReactElement[];
|
|
350
311
|
/**
|
|
351
312
|
* Indicates if merchant uses multiple currencies
|
|
352
313
|
*/
|
|
@@ -354,9 +315,7 @@ declare interface NostoProviderProps {
|
|
|
354
315
|
/**
|
|
355
316
|
* Recommendation component which holds nostoRecommendation object
|
|
356
317
|
*/
|
|
357
|
-
recommendationComponent?:
|
|
358
|
-
nostoRecommendation: Recommendation;
|
|
359
|
-
}>;
|
|
318
|
+
recommendationComponent?: RecommendationComponent;
|
|
360
319
|
/**
|
|
361
320
|
* Enables Shopify markets with language and market id
|
|
362
321
|
*/
|
|
@@ -392,7 +351,7 @@ declare interface NostoProviderProps {
|
|
|
392
351
|
export declare function NostoSearch(props: {
|
|
393
352
|
query: string;
|
|
394
353
|
placements?: string[];
|
|
395
|
-
}):
|
|
354
|
+
}): null;
|
|
396
355
|
|
|
397
356
|
/**
|
|
398
357
|
* 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.
|
|
@@ -404,53 +363,109 @@ export declare function NostoSearch(props: {
|
|
|
404
363
|
*
|
|
405
364
|
* @group Essential Functions
|
|
406
365
|
*/
|
|
407
|
-
export declare function NostoSession(props
|
|
408
|
-
cart
|
|
409
|
-
customer
|
|
366
|
+
export declare function NostoSession(props?: {
|
|
367
|
+
cart?: Cart;
|
|
368
|
+
customer?: Customer;
|
|
410
369
|
}): JSX_2.Element;
|
|
411
370
|
|
|
371
|
+
declare interface NostoSku extends Sku {
|
|
372
|
+
inventory_level?: number;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
declare interface NostoVariant {
|
|
376
|
+
availability: string;
|
|
377
|
+
available: boolean;
|
|
378
|
+
discounted: boolean;
|
|
379
|
+
list_price?: number;
|
|
380
|
+
price: number;
|
|
381
|
+
price_currency_code: string;
|
|
382
|
+
price_text?: string;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @group Types
|
|
387
|
+
*/
|
|
388
|
+
export declare interface Order {
|
|
389
|
+
created_at?: Date;
|
|
390
|
+
external_order_ref: string;
|
|
391
|
+
info?: OrderCustomer;
|
|
392
|
+
items: ConversionItem[];
|
|
393
|
+
order_status?: string;
|
|
394
|
+
order_status_label?: string;
|
|
395
|
+
payment_provider: string;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @group Types
|
|
400
|
+
*/
|
|
401
|
+
declare interface OrderCustomer {
|
|
402
|
+
country: string;
|
|
403
|
+
email?: string;
|
|
404
|
+
first_name?: string;
|
|
405
|
+
last_name?: string;
|
|
406
|
+
newsletter: string;
|
|
407
|
+
order_number: string;
|
|
408
|
+
phone: string;
|
|
409
|
+
post_code: string;
|
|
410
|
+
type: string;
|
|
411
|
+
}
|
|
412
|
+
|
|
412
413
|
/**
|
|
413
414
|
* @group Types
|
|
414
415
|
*/
|
|
415
|
-
export declare
|
|
416
|
-
|
|
417
|
-
|
|
416
|
+
export declare type Product = {
|
|
417
|
+
product_id: string;
|
|
418
|
+
selected_sku_id?: string;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
declare interface PushedProduct {
|
|
422
|
+
age_group?: string;
|
|
423
|
+
alternate_image_urls: string[];
|
|
424
|
+
availability: string;
|
|
418
425
|
brand?: string;
|
|
419
426
|
category: string[];
|
|
420
|
-
|
|
421
|
-
description: string;
|
|
422
|
-
googleCategory?: string;
|
|
427
|
+
category_id: string[];
|
|
423
428
|
condition?: string;
|
|
429
|
+
custom_fields: {
|
|
430
|
+
[index: string]: string;
|
|
431
|
+
};
|
|
432
|
+
date_published?: Date;
|
|
433
|
+
description?: string;
|
|
424
434
|
gender?: string;
|
|
425
|
-
|
|
435
|
+
google_category?: string;
|
|
426
436
|
gtin?: string;
|
|
427
|
-
|
|
428
|
-
|
|
437
|
+
image_url?: string;
|
|
438
|
+
inventory_level?: number;
|
|
439
|
+
list_price?: number;
|
|
429
440
|
name: string;
|
|
441
|
+
parent_category_id: string[];
|
|
430
442
|
price: number;
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
443
|
+
price_currency_code: string;
|
|
444
|
+
product_id: string;
|
|
445
|
+
rating_value?: number;
|
|
446
|
+
review_count?: number;
|
|
447
|
+
skus: PushedProductSKU[];
|
|
448
|
+
source_updated?: Date;
|
|
449
|
+
supplier_cost?: number;
|
|
450
|
+
tags1: string[];
|
|
451
|
+
tags2: string[];
|
|
452
|
+
tags3: string[];
|
|
453
|
+
thumb_url?: string;
|
|
454
|
+
unit_pricing_base_measure?: number;
|
|
455
|
+
unit_pricing_measure?: number;
|
|
456
|
+
unit_pricing_unit?: string;
|
|
457
|
+
update_received?: Date;
|
|
458
|
+
url: string;
|
|
459
|
+
variation_id?: string;
|
|
460
|
+
variations: {
|
|
461
|
+
[index: string]: PushedVariation;
|
|
442
462
|
};
|
|
443
|
-
variationId?: string;
|
|
444
|
-
skus?: SKU[];
|
|
445
463
|
}
|
|
446
464
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
number: string;
|
|
452
|
-
info: Buyer;
|
|
453
|
-
items: Item[];
|
|
465
|
+
declare interface PushedProductSKU extends NostoSku {
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
declare interface PushedVariation extends NostoVariant {
|
|
454
469
|
}
|
|
455
470
|
|
|
456
471
|
/**
|
|
@@ -458,7 +473,7 @@ export declare interface Purchase {
|
|
|
458
473
|
*/
|
|
459
474
|
export declare interface Recommendation {
|
|
460
475
|
result_id: string;
|
|
461
|
-
products:
|
|
476
|
+
products: PushedProduct[];
|
|
462
477
|
result_type: string;
|
|
463
478
|
title: string;
|
|
464
479
|
div_id: string;
|
|
@@ -466,34 +481,27 @@ export declare interface Recommendation {
|
|
|
466
481
|
params: unknown;
|
|
467
482
|
}
|
|
468
483
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
declare interface SessionAction {
|
|
473
|
-
setPlacements(placements: string[]): SessionAction;
|
|
474
|
-
load(): Promise<{
|
|
475
|
-
affinities: Record<string, Affinity[]>;
|
|
476
|
-
geo_location?: string[];
|
|
477
|
-
page_views: number;
|
|
478
|
-
recommendations: Recommendation[];
|
|
479
|
-
}>;
|
|
480
|
-
}
|
|
484
|
+
declare type RecommendationComponent = React.ReactElement<{
|
|
485
|
+
nostoRecommendation: Recommendation;
|
|
486
|
+
}>;
|
|
481
487
|
|
|
482
488
|
/**
|
|
483
489
|
* @group Types
|
|
484
490
|
*/
|
|
485
|
-
|
|
491
|
+
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
|
+
|
|
493
|
+
declare interface Sku {
|
|
494
|
+
availability: string;
|
|
495
|
+
custom_fields: {
|
|
496
|
+
[index: string]: string;
|
|
497
|
+
};
|
|
498
|
+
gtin?: string;
|
|
486
499
|
id: string;
|
|
500
|
+
image_url?: string;
|
|
501
|
+
list_price?: number;
|
|
487
502
|
name: string;
|
|
488
503
|
price: number;
|
|
489
|
-
|
|
490
|
-
url: URL;
|
|
491
|
-
imageUrl: URL;
|
|
492
|
-
gtin?: string;
|
|
493
|
-
availability: "InStock" | "OutOfStock";
|
|
494
|
-
customFields?: {
|
|
495
|
-
[key: string]: string;
|
|
496
|
-
};
|
|
504
|
+
url?: string;
|
|
497
505
|
}
|
|
498
506
|
|
|
499
507
|
/**
|