@nosto/nosto-react 0.4.1 → 0.5.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.
Files changed (33) hide show
  1. package/README.md +5 -2
  2. package/dist/index.d.ts +519 -0
  3. package/dist/index.es.js +1117 -0
  4. package/dist/index.umd.js +25 -0
  5. package/package.json +20 -13
  6. package/src/components/Nosto404.tsx +47 -0
  7. package/src/components/{Category/index.client.tsx → NostoCategory.tsx} +18 -39
  8. package/src/components/NostoCheckout.tsx +47 -0
  9. package/src/components/{Home/index.client.tsx → NostoHome.tsx} +17 -36
  10. package/src/components/NostoOrder.tsx +55 -0
  11. package/src/components/NostoOther.tsx +46 -0
  12. package/src/components/{Placement/index.client.tsx → NostoPlacement.tsx} +5 -8
  13. package/src/components/{Product/index.client.tsx → NostoProduct.tsx} +37 -81
  14. package/src/components/NostoProvider.tsx +220 -0
  15. package/src/components/{Search/index.client.tsx → NostoSearch.tsx} +18 -39
  16. package/src/components/{Session/index.client.tsx → NostoSession.tsx} +14 -17
  17. package/src/components/context.ts +55 -0
  18. package/src/components/index.ts +14 -0
  19. package/src/index.ts +3 -0
  20. package/src/types.ts +112 -97
  21. package/src/utils/compare.ts +9 -9
  22. package/src/utils/hooks.ts +28 -8
  23. package/src/utils/object.ts +10 -11
  24. package/src/utils/snakeize.ts +11 -11
  25. package/dist/index.es.client.js +0 -660
  26. package/dist/index.umd.client.js +0 -9
  27. package/src/components/Checkout/index.client.tsx +0 -66
  28. package/src/components/Fohofo/index.client.tsx +0 -66
  29. package/src/components/Order/index.client.tsx +0 -72
  30. package/src/components/Other/index.client.tsx +0 -64
  31. package/src/components/Provider/context.client.ts +0 -45
  32. package/src/components/Provider/index.client.tsx +0 -222
  33. package/src/index.client.ts +0 -33
package/README.md CHANGED
@@ -42,8 +42,8 @@ _\*\*Note: The search feature is available when implemented via our code editor.
42
42
 
43
43
  #### Required versions
44
44
 
45
- - npm: 8.5.5
46
- - node: v16.15.0
45
+ - npm: 9.8.1
46
+ - node: v18.18.0
47
47
 
48
48
  ### Installation
49
49
 
@@ -269,6 +269,9 @@ import {
269
269
  </div>;
270
270
  ```
271
271
 
272
+ ### Detailed technical documentation
273
+ Find our latest technical specs and documentation hosted [here](https://nosto.github.io/nosto-react).
274
+
272
275
  ### Feedback
273
276
 
274
277
  If you've found a feature missing or you would like to report an issue, simply [open up an issue](https://github.com/nosto/nosto-react/issues/new) and let us know.
@@ -0,0 +1,519 @@
1
+ import { Context } from 'react';
2
+ import { default as default_2 } from 'react';
3
+ import { JSX as JSX_2 } from 'react/jsx-runtime';
4
+
5
+ /**
6
+ * @group Types
7
+ */
8
+ declare interface Affinity {
9
+ name: string;
10
+ score: number;
11
+ }
12
+
13
+ declare type AnyFunction = (...args: unknown[]) => unknown;
14
+
15
+ /**
16
+ * @group Types
17
+ */
18
+ export declare interface Buyer {
19
+ first_name: string;
20
+ last_name: string;
21
+ email: string;
22
+ type: string;
23
+ newsletter: boolean;
24
+ }
25
+
26
+ /**
27
+ * @group Types
28
+ */
29
+ export declare interface Cart {
30
+ items: Item[];
31
+ }
32
+
33
+ /**
34
+ * @group Types
35
+ */
36
+ export declare interface Customer {
37
+ customer_reference: string;
38
+ email: string;
39
+ first_name: string;
40
+ last_name: string;
41
+ newsletter: boolean;
42
+ }
43
+
44
+ /**
45
+ * @group Types
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;
54
+ }
55
+
56
+ /**
57
+ * You can personalise your cart and checkout pages by using the `Nosto404` component.
58
+ * The component does not require any props.
59
+ *
60
+ * By default, your account, when created, has three 404-page placements named `notfound-nosto-1`, `notfound-nosto-2` and `notfound-nosto-3`.
61
+ * You may omit these and use any identifier you need.
62
+ * The identifiers used here are simply provided to illustrate the example.
63
+ *
64
+ * @example
65
+ * ```
66
+ * <div className="notfound-page">
67
+ * <NostoPlacement id="notfound-nosto-1" />
68
+ * <NostoPlacement id="notfound-nosto-2" />
69
+ * <NostoPlacement id="notfound-nosto-3" />
70
+ * <Nosto404 />
71
+ * </div>
72
+ * ```
73
+ *
74
+ * @group Components
75
+ */
76
+ export declare function Nosto404(props: {
77
+ placements?: string[];
78
+ }): JSX_2.Element;
79
+
80
+ /**
81
+ * You can personalise your category and collection pages by using the NostoCategory component.
82
+ * The component requires that you provide it the the slash-delimited slug representation of the current category.
83
+ *
84
+ * By default, your account, when created, has two category placements named `categorypage-nosto-1` and `categorypage-nosto-2`.
85
+ * You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
86
+ *
87
+ * @example
88
+ * ```
89
+ * <div className="category-page">
90
+ * <NostoPlacement id="categorypage-nosto-1" />
91
+ * <NostoPlacement id="categorypage-nosto-2" />
92
+ * <NostoCategory category={category.name} />
93
+ * </div>
94
+ * ```
95
+ *
96
+ * **Note:** Be sure to pass in the correct category representation.
97
+ * If the category being viewed is `Mens >> Jackets`, you must provide the name as `/Mens/Jackets`.
98
+ * You must ensure that the category path provided here matches that of the categories tagged in your products.
99
+ *
100
+ * @group Components
101
+ */
102
+ export declare function NostoCategory(props: {
103
+ category: string;
104
+ placements?: string[];
105
+ }): JSX_2.Element;
106
+
107
+ /**
108
+ * You can personalise your cart and checkout pages by using the NostoCheckout component.
109
+ * The component does not require any props.
110
+ *
111
+ * By default, your account, when created, has two cart-page placements named `categorypage-nosto-1` and `categorypage-nosto-2`.
112
+ * You may omit these and use any identifier you need.
113
+ * The identifiers used here are simply provided to illustrate the example.
114
+ *
115
+ * @example
116
+ * ```
117
+ * <div className="checkout-page">
118
+ * <NostoPlacement id="checkout-nosto-1" />
119
+ * <NostoPlacement id="checkout-nosto-2" />
120
+ * <NostoCheckout />
121
+ * </div>
122
+ * ```
123
+ *
124
+ * @group Components
125
+ */
126
+ export declare function NostoCheckout(props: {
127
+ placements?: string[];
128
+ }): JSX_2.Element;
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
+ }
161
+
162
+ /**
163
+ * @group Essential Functions
164
+ */
165
+ export declare const NostoContext: Context<NostoContextType>;
166
+
167
+ /**
168
+ * @group Types
169
+ */
170
+ export declare interface NostoContextType {
171
+ account: string;
172
+ clientScriptLoaded: boolean;
173
+ currentVariation?: string;
174
+ renderFunction?: AnyFunction;
175
+ responseMode: string;
176
+ recommendationComponent?: React.ReactElement<{
177
+ nostoRecommendation: Recommendation;
178
+ }>;
179
+ useRenderCampaigns(type: string): {
180
+ renderCampaigns(data: unknown, api: NostoClient): void;
181
+ pageTypeUpdated: boolean;
182
+ };
183
+ pageType: string;
184
+ }
185
+
186
+ /**
187
+ * The `NostoHome` component must be used to personalise the home page. The component does not require any props.
188
+ *
189
+ * By default, your account, when created, has four front-page placements named `frontpage-nosto-1`, `frontpage-nosto-2`, `frontpage-nosto-3` and `frontpage-nosto-4`.
190
+ * You may omit these and use any identifier you need.
191
+ * The identifiers used here are simply provided to illustrate the example.
192
+ *
193
+ * The `<NostoHome \>` component needs to be added after the placements.
194
+ * Content and recommendations will be rendered through this component.
195
+ *
196
+ * @example
197
+ * ```
198
+ * <div className="front-page">
199
+ * <NostoPlacement id="frontpage-nosto-1" />
200
+ * <NostoPlacement id="frontpage-nosto-2" />
201
+ * <NostoPlacement id="frontpage-nosto-3" />
202
+ * <NostoPlacement id="frontpage-nosto-4" />
203
+ * <NostoHome />
204
+ * </div>
205
+ * ```
206
+ *
207
+ * @group Components
208
+ */
209
+ export declare function NostoHome(props: {
210
+ placements?: string[];
211
+ }): JSX_2.Element;
212
+
213
+ /**
214
+ * You can personalise your order-confirmation/thank-you page by using the `NostoOrder` component.
215
+ * The component requires that you provide it with the details of the order.
216
+ *
217
+ * By default, your account, when created, has one other-page placement named `thankyou-nosto-1`.
218
+ * You may omit this and use any identifier you need. The identifier used here is simply provided to illustrate the example.
219
+ *
220
+ * The order prop requires a value that adheres to the type `Purchase`.
221
+ *
222
+ * @example
223
+ * ```
224
+ * <div className="thankyou-page">
225
+ * <NostoPlacement id="thankyou-nosto-1" />
226
+ * <NostoOrder order={{ purchase: toOrder(order) }} />
227
+ * </div>
228
+ * ```
229
+ *
230
+ * @group Components
231
+ */
232
+ export declare function NostoOrder(props: {
233
+ order: {
234
+ purchase: Purchase;
235
+ };
236
+ placements?: string[];
237
+ }): JSX_2.Element;
238
+
239
+ /**
240
+ * You can personalise your miscellaneous pages by using the NostoOther component.
241
+ * The component does not require any props.
242
+ *
243
+ * By default, your account, when created, has two other-page placements named `other-nosto-1` and `other-nosto-2`.
244
+ * You may omit these and use any identifier you need.
245
+ * The identifiers used here are simply provided to illustrate the example.
246
+ *
247
+ * @example
248
+ * ```
249
+ * <div className="other-page">
250
+ * <NostoPlacement id="other-nosto-1" />
251
+ * <NostoPlacement id="other-nosto-2" />
252
+ * <NostoOther />
253
+ * </div>;
254
+ * ```
255
+ *
256
+ * @group Components
257
+ */
258
+ export declare function NostoOther(props: {
259
+ placements?: string[];
260
+ }): JSX_2.Element;
261
+
262
+ /**
263
+ * Nosto React has a special component called NostoPlacement.
264
+ * The component is a simply a hidden `<div>` placeholder into which Nosto injects recommendations or personalises the content between the tags.
265
+ *
266
+ * We recommend adding as many placements across your views as needed as these are hidden and only populated when a corresponding campaign (targeting that placement) is configured.
267
+ *
268
+ * @example
269
+ * ```
270
+ * <NostoPlacement id="frontpage-nosto-1" />
271
+ * ```
272
+ *
273
+ * @group Components
274
+ */
275
+ export declare function NostoPlacement(props: {
276
+ id: string;
277
+ pageType?: string;
278
+ }): JSX_2.Element;
279
+
280
+ /**
281
+ * The NostoProduct component must be used to personalise the product page.
282
+ * The component requires that you provide it the identifier of the current product being viewed.
283
+ *
284
+ * By default, your account, when created, has three product-page placements named `productpage-nosto-1`, `productpage-nosto-2` and `productpage-nosto-3`.
285
+ * You may omit these and use any identifier you need.
286
+ * The identifiers used here are simply provided to illustrate the example.
287
+ *
288
+ * The `<NostoProduct \>` component needs to be added after the placements.
289
+ * Content and recommendations will be rendered through this component.
290
+ * Pass in the product ID via the product prop to pass this information back to Nosto.
291
+ *
292
+ * @example
293
+ * ```
294
+ * <div className="product-page">
295
+ * <NostoPlacement id="productpage-nosto-1" />
296
+ * <NostoPlacement id="productpage-nosto-2" />
297
+ * <NostoPlacement id="productpage-nosto-3" />
298
+ * <NostoProduct product={product.id} />
299
+ * </div>
300
+ * ```
301
+ *
302
+ * @group Components
303
+ */
304
+ export declare function NostoProduct(props: {
305
+ product: string;
306
+ tagging?: Product;
307
+ placements?: string[];
308
+ }): JSX_2.Element;
309
+
310
+ /**
311
+ * This widget is what we call the Nosto root widget, which is responsible for adding the actual Nosto script and the JS API stub.
312
+ * This widget wraps all other React Nosto widgets.
313
+ *
314
+ * ```
315
+ * <NostoProvider account="your-nosto-account-id" recommendationComponent={<NostoSlot />}>
316
+ * <App />
317
+ * </NostoProvider>
318
+ * ```
319
+ *
320
+ * **Note:** the component also accepts a prop to configure the host `host="connect.nosto.com"`.
321
+ * In advanced use-cases, the need to configure the host may surface.
322
+ *
323
+ * In order to implement client-side rendering, the requires a designated component to render the recommendations provided by Nosto.
324
+ * This component should be capable of processing the JSON response received from our backend.
325
+ * Notice the `recommendationComponent` prop passed to `<NostoProvider>` above.
326
+ *
327
+ * Learn more [here](https://github.com/Nosto/shopify-hydrogen/blob/main/README.md#client-side-rendering-for-recommendations) and see a [live example](https://github.com/Nosto/shopify-hydrogen-demo) on our demo store.
328
+ *
329
+ * @group Components
330
+ */
331
+ export declare function NostoProvider(props: NostoProviderProps): JSX_2.Element;
332
+
333
+ /**
334
+ * @group Components
335
+ */
336
+ declare interface NostoProviderProps {
337
+ /**
338
+ * Indicates merchant id
339
+ */
340
+ account: string;
341
+ /**
342
+ * Indicates currency
343
+ */
344
+ currentVariation?: string;
345
+ /**
346
+ * Indicates an url of a server
347
+ */
348
+ host?: string;
349
+ children: default_2.ReactElement;
350
+ /**
351
+ * Indicates if merchant uses multiple currencies
352
+ */
353
+ multiCurrency?: boolean;
354
+ /**
355
+ * Recommendation component which holds nostoRecommendation object
356
+ */
357
+ recommendationComponent?: default_2.ReactElement<{
358
+ nostoRecommendation: Recommendation;
359
+ }>;
360
+ /**
361
+ * Enables Shopify markets with language and market id
362
+ */
363
+ shopifyMarkets?: {
364
+ language?: string;
365
+ marketId?: string | number;
366
+ };
367
+ }
368
+
369
+ /**
370
+ * You can personalise your search pages by using the NostoSearch component.
371
+ * The component requires that you provide it the current search term.
372
+ *
373
+ * By default, your account, when created, has two search-page placements named `searchpage-nosto-1` and `searchpage-nosto-2`.
374
+ * You may omit these and use any identifier you need. The identifiers used here are simply provided to illustrate the example.
375
+ *
376
+ * @example
377
+ * ```
378
+ * <div className="search-page">
379
+ * <NostoPlacement id="searchpage-nosto-1" />
380
+ * <NostoPlacement id="searchpage-nosto-2" />
381
+ * <NostoSearch query={"black shoes"} />
382
+ * </div>
383
+ * ```
384
+ *
385
+ * **Note:** Do not encode the search term in any way.
386
+ * It should be provided an unencoded string.
387
+ * A query for `black shoes` must be provided as-is and not as `black+shoes`.
388
+ * Doing so will lead to invalid results.
389
+ *
390
+ * @group Components
391
+ */
392
+ export declare function NostoSearch(props: {
393
+ query: string;
394
+ placements?: string[];
395
+ }): JSX_2.Element;
396
+
397
+ /**
398
+ * 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.
399
+ * This makes it easier to add attribution.
400
+ *
401
+ * The `NostoSession` component makes it very easy to keep the session up to date so long as the cart and the customer are provided.
402
+ *
403
+ * 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`.
404
+ *
405
+ * @group Essential Functions
406
+ */
407
+ export declare function NostoSession(props: {
408
+ cart: Cart;
409
+ customer: Customer;
410
+ }): JSX_2.Element;
411
+
412
+ /**
413
+ * @group Types
414
+ */
415
+ export declare interface Product {
416
+ alternateImageUrls?: URL[];
417
+ availability: "InStock" | "OutOfStock";
418
+ brand?: string;
419
+ category: string[];
420
+ categoryIds?: string[];
421
+ description: string;
422
+ googleCategory?: string;
423
+ condition?: string;
424
+ gender?: string;
425
+ ageGroup?: string;
426
+ gtin?: string;
427
+ imageUrl: URL;
428
+ listPrice?: number;
429
+ name: string;
430
+ price: number;
431
+ ratingValue?: number;
432
+ reviewCount?: number;
433
+ priceCurrencyCode: string;
434
+ productId: string;
435
+ tags1?: string[];
436
+ tags2?: string[];
437
+ tags3?: string[];
438
+ thumbUrl?: URL;
439
+ url: URL;
440
+ customFields?: {
441
+ [key: string]: string;
442
+ };
443
+ variationId?: string;
444
+ skus?: SKU[];
445
+ }
446
+
447
+ /**
448
+ * @group Types
449
+ */
450
+ export declare interface Purchase {
451
+ number: string;
452
+ info: Buyer;
453
+ items: Item[];
454
+ }
455
+
456
+ /**
457
+ * @group Types
458
+ */
459
+ export declare interface Recommendation {
460
+ result_id: string;
461
+ products: Product[];
462
+ result_type: string;
463
+ title: string;
464
+ div_id: string;
465
+ source_product_ids: string[];
466
+ params: unknown;
467
+ }
468
+
469
+ /**
470
+ * @group Types
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
+ }
481
+
482
+ /**
483
+ * @group Types
484
+ */
485
+ export declare interface SKU {
486
+ id: string;
487
+ name: string;
488
+ price: number;
489
+ listPrice?: number;
490
+ url: URL;
491
+ imageUrl: URL;
492
+ gtin?: string;
493
+ availability: "InStock" | "OutOfStock";
494
+ customFields?: {
495
+ [key: string]: string;
496
+ };
497
+ }
498
+
499
+ /**
500
+ * A hook that allows you to access the NostoContext and retrieve Nosto-related data from it in React components.
501
+ *
502
+ * @group Essential Functions
503
+ */
504
+ export declare function useNostoContext(): NostoContextType;
505
+
506
+ export { }
507
+
508
+ declare global {
509
+ interface Window {
510
+ nosto?: {
511
+ reload(settings: unknown): void;
512
+ };
513
+ nostojs: {
514
+ (callback: (api: NostoClient) => void): void;
515
+ q?: unknown[];
516
+ };
517
+ }
518
+ }
519
+