From c2dddc44c41cb6c7349c1e9954f845179e24c77a Mon Sep 17 00:00:00 2001 From: Maija Lintunokka Date: Mon, 20 Jan 2025 14:16:03 +0200 Subject: [PATCH 1/2] fix: bump nosto dts --- src/client/nosto.d.ts | 2826 +++++++++++++++++++++-------------------- 1 file changed, 1415 insertions(+), 1411 deletions(-) diff --git a/src/client/nosto.d.ts b/src/client/nosto.d.ts index f9b77c7..b203dbd 100644 --- a/src/client/nosto.d.ts +++ b/src/client/nosto.d.ts @@ -1,1247 +1,149 @@ /** @module client */ // @ts-nocheck -interface Coupon { - campaign?: string; - code?: string; - used?: boolean; -} -interface Order { - items: CartItem[]; +import domReadyCreator from 'domready'; + +/** + * @group Core + */ +type EventType = +/** view product */ +"vp" +/** like product */ + | "lp" +/** dislike product */ + | "dp" +/** remove product */ + | "rp" +/** bought product */ + | "bp" +/** view category */ + | "vc" +/** order */ + | "or" +/** internal search */ + | "is" +/** add to cart */ + | "cp" +/** external campaign */ + | "ec" +/** external search */ + | "es" +/** give coupon */ + | "gc" +/** source */ + | "src" +/** cart popup recommendations */ + | "cpr" +/** page load */ + | "pl" +/** custom campaign */ + | "cc" +/** content campaign */ + | "con"; +/** + * @group Core + */ +type EventRefType = +/** triggered mail */ +"email" +/** email widgets */ + | "imgrec" +/** onsite recommendations */ + | "rec" +/** api recommendations */ + | "api" +/** onsite campaigns */ + | "oc" +/** category merchandising */ + | "cmp" +/** onsite search */ + | "os"; +/** + * @group Core + */ +type EventTuple = [ + type: EventType, + target?: string, + ref?: string, + refSrc?: string, + targetFragment?: string, + refType?: EventRefType +]; +/** + * @group Core + */ +interface Event { + type: EventType; + target?: string; + ref?: string; + refSrc?: string; + targetFragment?: string; + refType?: EventRefType; } -interface PluginMetadata { - mainModule?: string; - cmpModule?: string; - msiModule?: string; +interface AbTestDraftPreviewSettingsDTO extends AbTestPreviewSettingsBase { + variations: AbTestVariationDTO[]; } -type Product = Partial & { +interface AbTestPreviewSettingsBase { + id: TestId; + method: Method; + name: string; + segment: string; + variations: T[]; +} +interface AbTestPreviewSettingsDTO extends AbTestPreviewSettingsBase { + variations: AbTestVariationDTO[]; +} +interface AbTestVariation { + base: boolean; + id: string; + name: string; +} +interface AbTestVariationDTO extends AbTestVariation { +} +interface AbstractFacebookPixelEvent { + d: D; + n: string; +} +interface AbstractGid { +} +interface AbstractStacklaPixelEvent { + d: D; + n: string; +} +interface ActiveVisitDTO { + customer: CustomerDTO; + visit: VisitDTO; +} +interface AnalyticEvent { + properties?: AnalyticEventProperties; +} +interface AnalyticEventProperties { + abTestAttribution?: { + [index: string]: string; + }; +} +interface BigcommerceCustomerInfo { + customer_reference: string; + email: string; + first_name?: string; + group_id?: string; + last_name?: string; + marketing_permission?: boolean; +} +interface CartItem { + name: string; + price_currency_code: string; product_id: string; - valid_until?: string; - selected_sku_id?: string; -}; -interface Cart { - hcid?: string; - items: CartItem[]; + quantity: number; + sku_id?: string; + unit_price: number; } -interface TaggingData { - cart: Cart | undefined; - customer: PushedCustomer | undefined; - variation: string | undefined; - restoreLink: string | undefined; - products: Product[]; - order: WebsiteOrder | undefined; - searchTerms: string[] | undefined; - categories: string[] | undefined; - categoryIds: string[] | undefined; - parentCategoryIds: string[] | undefined; - tags: string[] | undefined; - customFields: Record | undefined; - elements: string[] | undefined; - pageType: PageType | undefined; - affinitySignals: Record | undefined; - sortOrder: string | undefined; - pluginVersion: PluginMetadata | undefined; +interface CategoryClick extends CategoryEvent { + productId: string; } - -interface RecommendationRequestFlags { - skipPageViews?: boolean; - trackEvents?: boolean; - skipEvents?: boolean; - reloadCart?: boolean; -} -/** - * RequestBuilder is a low level API to interact with the Nosto API. It's primary purpose is to fetch recommendations - * and send events to the Nosto API. It is not recommended to use this API directly, but rather use the the higher level - * Tagging and Session APIs. - * - * @group Core - */ -interface RequestBuilder { - /** - * Sets the given list of forced segment identifiers to the current request. This - * method allows you explicitly associate the current customer with a segment. - * - * @private - * @param {String[]} segments the list of force segment identifiers - */ - setForcedSegments(segments: string[]): RequestBuilder; - /** - * Sets the given list of manual segment identifiers to the current request. This - * method allows you explicitly associate the current customer with a segment. - * - * @param {String[]} segments the list of force segment identifiers - */ - setSegmentCodes(segments: string[]): RequestBuilder; - /** - * Sets the identifier of the current page type to the current request. The different - * page types are product, front, search, cart, order, category, notfound and other. - * - * @param {String} pageType the current page type - */ - setPageType(pageType: PageType | undefined): RequestBuilder; - /** - * Sets the identifier of the current sort order to the current request. - * - * @private - * @param {String} sortOrder the current sort order - */ - setSortOrder(sortOrder: string): RequestBuilder; - /** - * Adds affinity signals to the current request. - * - * @param signals signals to set - */ - setAffinitySignals(signals: Record): RequestBuilder; - /** - * Adds the given event to the current set of events. When viewing a product, - * it is required that you specify the "vp" as event and the product id as - * the target. - * - * Also supports legacy signature - * addEvent(type: string, target?: string, ref?: string, targetFragment?: string) { - * } - * - * @private - * @param {Event} event { type, target, ref, refSrc, targetFragment, refType } - */ - addEvent(event: Event): RequestBuilder; - /** - * Sets the information about the currently logged in customer. If the current - * customer is not provided, you will not be able to leverage features such as - * triggered emails. While it is recommended to always provide the details of - * the currently logged in customer, it may be omitted if there are concerns - * about privacy or compliance. - *

- * It is not recommended to pass the current customer details to the request - * builder but rather use the customer tagging. - * - * @param {Customer} customer the details of the currently logged in customer - */ - setCustomer(customer: PushedCustomer): RequestBuilder; - setCoupon(coupon: Coupon): RequestBuilder; - /** - * Adds the given elements (or placements) to the request. Any identifiers - * specified here are simply added to the elements already in the request. - * - * @param {String[]} elements the array of placements - * - * @example - * To load data for a single placement - * nostojs(api => api - * .createRecommendationRequest() - * .addElements(['bestseller-home']) - * .loadRecommendations()); - */ - addElements(elements: string[]): RequestBuilder; - /** - * Sets the given elements (or placements) to the request. Any identifiers - * specified here override all elements already in the request. - * - * @param {String[]} elements the array of placements - * - * @example - * To load data for a single placement - * nostojs(api => api - * .createRecommendationRequest() - * .setElements(['bestseller-home']) - * .loadRecommendations()); - */ - setElements(elements: string[] | undefined): RequestBuilder; - /** - * Adds the cart object to the current request. This should be preferably - * on every page load so as to keep the cart state as fresh as possible. - * - * @param {PushedCart} cart the details of the current shopping basket - */ - setCartContent(cart: Cart | undefined): RequestBuilder; - /** - * Sets the restore link for the current session. Restore links can be leveraged - * in email campaigns. Restore links allow the the user to restore the cart - * contents in a single click. - *

- * Read more about - * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link} - *

- * It is not recommended to pass the current restore link to the request - * builder but rather use the tagging approach. - * - * @param restoreLink - */ - setRestoreLink(restoreLink: string | undefined): RequestBuilder; - /** - * Adds the given identifiers of the products in the customer's shopping cart - * to the request. - * - * @deprecated since this only transported partial information about the cart - * @private - */ - addCartItems(): RequestBuilder; - /** - * Sets the hash of the current cart cookie for ensure that the cart tagging - * isn't cached. In most cases, simply reading the customer's 2c.cid cookie - * and generating a SHA256 checksum will suffice. - * - * @deprecated - * @param {String} hcid the 32 character unique hash - */ - addCartCookieHash(hash: string): RequestBuilder; - /** - * Sets the total value of the customer's shopping cart. This should be the - * numerical value of what the customer sees in the mini-cart element of the - * store. - * - * @deprecated since this only transported partial information about the cart - * @private - */ - addCartTotal(): RequestBuilder; - /** - * Sets the total value of the customer's shopping cart. This should be the - * numerical value of what the customer sees in the mini-cart element of the - * store. - * - * @deprecated since this only transported partial information about the cart - * @private - */ - addCartSize(): RequestBuilder; - /** - * @param {Array.} products - * @param {String} [ref] the placement id that resulted in the product views - */ - setProducts(products: Product[], ref?: string): RequestBuilder; - /** - * Adds the given category names to the request. Any category name specified here - * are simply added to the request as personalisation filtering hints. - * - * @param {String[]} categories the array of category ids - */ - addCurrentCategories(categories: string[]): RequestBuilder; - /** - * Sets the given category names to the request. Any category names specified here - * override the category names in the request. - * - * @param {String[]} categories the array of category ids - */ - setCurrentCategories(categories: string[]): RequestBuilder; - /** - * Adds the given category ids to the request. Any category ids specified here - * are simply added to the request as personalisation filtering hints. - * - * @param {String[]} categoryIds the array of category ids - */ - addCurrentCategoryIds(categoryIds: string[]): RequestBuilder; - /** - * Adds the given parent category ids to the request. Any parent category ids specified here - * are simply added to the request as personalisation filtering hints. - */ - addCurrentParentCategoryIds(parentCategoryIds: string[]): RequestBuilder; - /** - * Adds the given current tags to the request. Any tags (tags1, tags12, or - * tags13) specified here are simply added to the request as personalisation - * filtering hints. - * - * @param {String[]} tags the array of tags - */ - addCurrentTags(tags: string[]): RequestBuilder; - /** - * Sets the given current tags to the request. Any tags (tags1, tags12, or - * tags13) specified here are simply set to the request as personalisation - * filtering hints. - * - * @param {String[]} tags the array of tags - */ - setCurrentTags(tags: string[]): RequestBuilder; - /** - * Adds the given current custom fields to the request. Any custom fields - * specified here are simply added to the request as personalisation filtering hints. - * - * @param { Object } fields custom field key-value pairs - */ - addCurrentCustomFields(fields: Record): RequestBuilder; - /** - * Sets the current lower price range to the request. Faceting needs to be - * enabled for the slot in order for this to function. Any lower value - * specified here are simply added to the request as personalisation filtering hints. - * - * @param {Number} value the lower range of the price - */ - setCurrentPriceFrom(value: number): RequestBuilder; - /** - * Sets the current upper price range to the request. Faceting needs to be - * enabled for the slot in order for this to function. Any upper value - * specified here are simply added to the request as personalisation filtering hints. - * - * @param {Number} value the upper range of the price - */ - setCurrentPriceTo(value: number): RequestBuilder; - /** - * Sets the current variation identifier for the session. A variation identifier - * identifies the current currency (or the current customer group). If your site - * uses multi-currency, you must provide the ISO code current currency being viewed. - *

- * It is not recommended to pass the variation identifier to an request builder but - * instead leverage the tagging. - * - * @param {String} variation the case-sensitive identifier of the current variation - */ - addCurrentVariation(variation: string): RequestBuilder; - /** - * Sets the information about the currently logged in customer. If the current - * customer is not provided, you will not be able to leverage features such as - * triggered emails. While it is recommended to always provide the details of - * the currently logged in customer, it may be omitted if there are concerns - * about privacy or compliance. - *

- * It is not recommended to pass the current customer details to the request - * builder but rather use the customer tagging. - * - * @param {Customer} customer - */ - addCustomer(customer: PushedCustomer): RequestBuilder; - /** - * Sets the response mode for the current request. The response mode can be - * used to switch between HTML and JSON. Here is an exhaustive list of the - * response modes. - * - * | Modes | Description | - * | -------------------- |:----------------------------------------------:| - * | HTML | HTML (SSR) | - * | JSON_170x170 | Raw JSON with 170x170px original aspect images | - * | JSON_100_X_100 | Raw JSON with 100x100px original aspect images | - * | JSON_90x70 | Raw JSON with 90x70px original aspect images | - * | JSON_50x50 | Raw JSON with 50x50px original aspect images | - * | JSON_30x30 | Raw JSON with 30x30px original aspect images | - * | JSON_100x140 | Raw JSON with 100x140px original aspect images | - * | JSON_200x200 | Raw JSON with 200x200px original aspect images | - * | JSON_400x400 | Raw JSON with 400x400px original aspect images | - * | JSON_750x750 | Raw JSON with 750x750px original aspect images | - * | JSON_10_MAX_SQUARE | Raw JSON with 100x100px center squared images | - * | JSON_200x200_SQUARE | Raw JSON with 200x200px center squared images | - * | JSON_400x400_SQUARE | Raw JSON with 400x400px center squared images | - * | JSON_750x750_SQUARE | Raw JSON with 750x750px center squared images | - * | JSON_ORIGINAL | Raw JSON with the original untouched images | - * - * @param {String} mode the response mode to be used - */ - setResponseMode(mode: RenderMode): RequestBuilder; - setExperiments(experiments: Experiment[]): RequestBuilder; - disableCampaignInjection(): RequestBuilder; - /** - * Enables the preview mode for the current request. The preview mode is - * automatically gathered from the current context's preview mode. If the - * debug toolbar is showing and preview mode is enabled, there is no need - * to invoke this function. - */ - enablePreview(): RequestBuilder; - /** - * Adds the order object to the current request. This should be invoked only - * on the order confirmation page. - * - * @param {Order} order the details of the order that was placed - */ - addOrderData(order: Order): RequestBuilder; - setMailRef(refMail: string, recRef: string): RequestBuilder; - populateFrom(params: { - data: TaggingData; - forcedSegments: string[]; - }, unwrappedReference?: string): RequestBuilder; - setRecommendationRef(recRef: string, recRefSrc?: string): RequestBuilder; - /** - * Builds the request and makes a request to Nosto. - * - * @deprecated since there is already a load method that does the same - * @private - * @param {RecommendationRequestFlags} flags - * @return {Promise} - * - * @example - * To load data for a single placement - * nostojs(api => api - * .createRecommendationRequest() - * .send({metadata: true})) - * .then((response) => console.log(response)); - */ - send(flags: RecommendationRequestFlags): Promise; - /** - * Builds the request and makes a request to Nosto. - * - * @param {RecommendationRequestFlags} flags an object containing additional flags - * @return {Promise} the response returned by Nosto - * - * @example - * To load data for a single placement - * nostojs(api => api - * .createRecommendationRequest() - * .addElements('bestseller-home') - * .load()) - * .then((response) => console.log(response)); - */ - load(flags?: RecommendationRequestFlags): Promise; - /** - * Builds the request and invokes it via JSONP to load the cart popup - * recommendations - * - * @deprecated since this method should de decoupled from the request - * @private - * @return {Promise} - */ - loadCartPopupRecommendations(alwaysShow: boolean): Promise; - /** - * Legacy method used to reloading the recommendations. This method is a - * simple wrapper around the other load method. - * - * @deprecated since the method name isn't aligned with it's behaviour - * @private - * @see {load} - * @param {RecommendationRequestFlags} flags an object containing additional flags - * @return {Promise} - * - * @example - * To load data for a single placement - * nostojs(api => api - * .createRecommendationRequest() - * .addElements('bestseller-home') - * .loadRecommendations()) - * .then((response) => console.log(response)); - */ - loadRecommendations(flags?: RecommendationRequestFlags): Promise; - /** - * Adds attribution for the given product id to reference mappings - * - * @param refs - * @returns - */ - setRefs(refs: Record): RequestBuilder; - getEvents(): Event[]; - getData(): EventRequestMessageV1; -} - -interface Attribution { - recordAttribution: (event: Event) => Attribution; - dumpData: () => EventTuple[]; - done: () => Promise; -} - -/** - * The Session API provides a programmatic way to interact with the Nosto API that is - * optimized for usage in SPA style web applications. The Session object maintains the session level - * data such as the user's shopping cart, the currently logged in customer, the current variation - * and provides function to execute actions such as viewing a product, category, cart, order etc. - * - * @group Core - */ -interface Session { - /** - * Sets the information about the user's current shopping cart. It the user - * does not have any items in his shopping cart, you can pass null. - * Passing null will nullify the user's shopping cart on Nosto's - * end. You must also pass in the shopping cart content in it's entirety as - * partial content are not supported. - * - * @param {Cart|undefined} cart the details of the user's shopping cart contents - * @returns {Session} the current session - * - * @example - * nostojs(api => api - * .defaultSession() - * .setCart({ - * items: [ - * product_id: "101", - * sku_id: "101-S", - * name: "Shoe", - * unit_price: 34.99 - * price_currency_code: "EUR" - * ] - * }) - * .viewCart() - * .setPlacements(["free-shipper"]) - * .update() - * .then(data => console.log(data))) - */ - setCart(cart: Cart | undefined): Session; - /** - * Sets the information about the currently logged in customer. If the current - * customer is not provided, you will not be able to leverage features such as - * triggered emails. While it is recommended to always provide the details of - * the currently logged in customer, it may be omitted if there are concerns - * about privacy or compliance. - * - * @param {Customer} customer the details of the currently logged in customer - * @returns {Session} the current session - * - * @example - * nostojs(api => api - * .defaultSession() - * .setCustomer({ - * first_name: "Mridang", - * last_name: "Agarwalla", - * email: "mridang@nosto.com", - * newsletter: false, - * customer_reference: "5e3d4a9c-cf58-11ea-87d0-0242ac130003" - * }) - * .viewCart() - * .setPlacements(["free-shipper"]) - * .load() - * .then(data => console.log(data))) - */ - setCustomer(customer: PushedCustomer | undefined): Session; - /** - * Sets the current variation identifier for the session. A variation identifier - * identifies the current currency (or the current customer group). If your site - * uses multi-currency, you must provide the ISO code current currency being viewed. - * - * @param {String} variation the case-sensitive identifier of the current variation - * @returns {Session} the current session - * - * @example - * nostojs(api => api - * .defaultSession() - * .setVariation("GBP") - * .viewCart() - * .setPlacements(["free-shipper"]) - * .load() - * .then(data => console.log(data))) - */ - setVariation(variation: string | undefined): Session; - /** - * Sets the restore link for the current session. Restore links can be leveraged - * in email campaigns. Restore links allow the the user to restore the cart - * contents in a single click. - *

- * Read more about - * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link} - * - * @param {String} restoreLink the secure URL to restore the user's current session - * @returns {Session} the current session - * - * @example - * nostojs(api => api - * .defaultSession() - * .setRestoreLink("https://jeans.com/session/restore?sid=6bdb69d5-ed15-4d92") - * .viewCart() - * .setPlacements(["free-shipper"]) - * .load() - * .then(data => console.log(data))) - */ - setRestoreLink(restoreLink: string): Session; - /** - * Sets the response type to HTML or JSON_ORIGINAL. This denotes the preferred - * response type of the recommendation result. - * If you would like to access the raw recommendation data in JSON form, specify - * JSON. When you specify JSON, you will need to template the result yourself. - * If you require a more simplified approach, specify HTML. When you specify - * HTML, you get back HTML blobs, that you may simply inject into - * you placements. - * - * @param {String} mode the response mode for the recommendation data - * @returns {Session} the current session - * - * @example - * nostojs(api => api - * .defaultSession() - * .setResponseMode("HTML") - * .viewCart() - * .setPlacements(["free-shipper"]) - * .load() - * .then(data => console.log(data))) - */ - setResponseMode(mode: RenderMode): Session; - /** - * Create a new action for a front page. This should be used when the user - * visits the home page. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewFrontPage() - * .setPlacements(["best-seller"]) - * .load() - * .then(data => console.log(data))) - */ - viewFrontPage(): Action; - /** - * Create a new action for a cart page. This should be used on all cart and - * checkout pages. If your site has a multi-step checkout, it is recommended - * that you send this event on each checkout page. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewCart() - * .setPlacements(["free-shipper"]) - * .load() - * .then(data => console.log(data))) - */ - viewCart(): Action; - /** - * Create a new action for a not found page. This should be used only on 404 - * pages. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewNotFound() - * .setPlacements(["best-seller"]) - * .load() - * .then(data => console.log(data))) - */ - viewNotFound(): Action; - /** - * Create a new action for a product page. This must be used only when a - * product is being viewed. In case a specific SKU of the product is being viewed, use viewProductSku instead. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * - * @param product - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewProduct("101") - * .setCategories(["/men/trousers"]) - * .setRef("123", "example_reco_id") - * .setPlacements(["cross-seller"]) - * .load() - * .then(data => console.log(data))) - */ - viewProduct(product: string | Product): Action; - /** - * Create a new action for a product page when a specific SKU has been chosen. This must be used only when a - * product and specific SKU is being viewed. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * - * @param productId - * @param skuId - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewProductSku("101", "101-sku-1") - * .setCategories(["/men/trousers"]) - * .setRef("123", "example_reco_id") - * .setPlacements(["cross-seller"]) - * .load() - * .then(data => console.log(data))) - */ - viewProductSku(productId: string, skuId: string): Action; - /** - * Create a new action for a category page. This should be used on all - * category, collection of brand pages. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * - * @param {Array} categories - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewCategory("/men/shoes") - * .setPlacements(["category123"]) - * .load() - * .then(data => console.log(data))) - */ - viewCategory(...categories: string[]): Action; - /** - * Create a new action for a tag page. This should be used only on tag pages. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * Note: tags are not case-sensitive. - * - * @deprecated as this is an advanced action with a limited a use case - * @param {Array} tags the set of the tags being viewed. - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewTag("colourful") - * .load() - * .then(data => console.log(data))) - */ - viewTag(...tags: string[]): Action; - /** - * Create a new action with custom fields. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * Note: tags are not case-sensitive. - * - * @deprecated as this is an advanced action with a limited a use case - * @param {Object} customFields custom fields being viewed. - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewCustomField({material: "cotton"}) - * .load() - * .then(data => console.log(data))) - */ - viewCustomField(customFields: Record): Action; - /** - * Create a new action for a search page. This should be used only - * on search pages. A search page action requires you to pass the search - * term. For example, if the user search for "black shoes", you must pass - * in "black shoes" and not an encoded version such as "black+shoes". - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * Search terms are not case-sensitive. - * - * @param {Array.} searchTerms the non-encoded search terms - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewSearch("black shoes") - * .load() - * .then(data => console.log(data))) - */ - viewSearch(...searchTerms: string[]): Action; - /** - * Create a new action for a general page. This should be used only on - * pages that don't have a corresponding action. For example, if the user - * is viewing a page such as a "Contact Us" page, you should use the viewOther - * action. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - * - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .viewOther() - * .load() - * .then(data => console.log(data))) - */ - viewOther(): Action; - /** - * Create a new action for an order page. This should only be used on order - * confirmation / thank you pages. - *

- * You do not need to specify the page-type explicitly as it is inferred - * from the action. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param {Order} order the information about the order that was placed - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => { - * api.defaultSession() - * .addOrder({ - * external_order_ref: "145000006", - * info: { - * order_number: "195", - * email: "mridang@nosto.com", - * first_name: "Mridang", - * last_name: "Agarwalla", - * type: "order", - * newsletter: true - * }, - * items: [{ - * product_id: "406", - * sku_id: "243", - * name: "Linen Blazer (White, S)", - * quantity: 1, - * unit_price: 455, - * price_currency_code: "EUR" - * }] - * }) - * .setPlacements(["order-related"]) - * .load() - * .then(data => { - * console.log(data.recommendations); - * }) - * }) - */ - addOrder(order: WebsiteOrder): Action; - /** - * Creates an action to report that product was added to the shopping cart, - * e.g. from the recommendation slot with "Add to cart" button. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param product - * @param element - * @returns {Action} the action instance to load content or track events. - * - * @example - * nostojs(api => api - * .defaultSession() - * .reportAddToCart("123", "reco-slot-1") - * .load() - * .then(data => console.log(data))) - */ - reportAddToCart(product: string, element: string): Action; - /** - * @param { EventType } type - * @param { String } target - * @param { String | undefined } [ref] - * @param { String | undefined } [refSrc] - * @return { Object } - * - * @example - * nostojs(api => api - * .defaultSession() - * .recordAttribution("vp", "12345678", "123456") - * .done() - * .then(data => console.log(data)) - */ - recordAttribution(type: EventType, target: string, ref: string, refSrc: string): Attribution; -} -/** - * Action in the Session API context means fetching recommendations for a specific view. For example when - * a visitor navigates from the front page to a product view you would most likely fetch recommendations - * related to a product. This would be considered as an Action. Setting the cart contents however would - * not be considered as action. - * - * @group Core - */ -interface Action { - /** - * Handles click attribution for product recommendations. - * This can be called when reporting a product view - * to signal that the view is a result of a click on a recommendation. - * - * @param {String} productId currently viewed product's product id - * @param {String} reference value of result_id from the recommendation response that was clicked - * @return {Action} - */ - setRef(productId: string, reference: string): Action; - /** - * Allows you to provide an additional recommender hint that a product is being - * viewed. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param {String} product the identifier of the product being viewed - * @return {Action} the instance of the action - */ - setProduct(product: string | Product): Action; - /** - * @deprecated - * @param {Array} products - * @return {Action} - */ - setProducts(products: (string | Product)[]): Action; - /** - * Sets the information about the user's current shopping cart. It the user - * does not have any items in his shopping cart, you can pass null. - * Passing null will nullify the user's shopping cart on Nosto's - * end. You must also pass in the shopping cart content in it's entirety as - * partial content are not supported. - *

- * It is not recommended to pass the current cart contents to an action but - * instead use the the session - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @see {@link Session#setCart} - * @return {Action} - */ - setCart(cart: Cart | undefined): Action; - /** - * Sets the information about the currently logged in customer. If the current - * customer is not provided, you will not be able to leverage features such as - * triggered emails. While it is recommended to always provide the details of - * the currently logged in customer, it may be omitted if there are concerns - * about privacy or compliance. - *

- * It is not recommended to pass the current customer details to an action but - * instead use the the session - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @see {@link Session#setCustomer} - * @param {Customer} customer the details of the currently logged in customer - * @return {Action} - */ - setCustomer(customer: PushedCustomer | undefined): Action; - /** - * @param {Order} order - * @return {Action} - */ - setOrder(order: WebsiteOrder): Action; - /** - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param searchTerms - * @return {Action} - */ - setSearchTerms(searchTerms: string[]): Action; - /** - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param {Array} categories - * @return {Action} - */ - setCategories(categories: string[]): Action; - /** - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param {Array} categoryIds - * @return {Action} - */ - setCategoryIds(categoryIds: string[]): Action; - /** - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param {Array} parentCategoryIds - * @return {Action} - */ - setParentCategoryIds(parentCategoryIds: string[]): Action; - /** - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param tags - * @return {Action} - */ - setTags(tags: string[]): Action; - /** - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param customFields - * @return {Action} - */ - setCustomFields(customFields: Record): Action; - /** - * Sets the current variation identifier for the session. A variation identifier - * identifies the current currency (or the current customer group). If your site - * uses multi-currency, you must provide the ISO code current currency being viewed. - *

- * It is not recommended to pass the variation identifier to an action but - * instead use the the session. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @see {@link Session#setVariation} - * @param {String} variation the case-sensitive identifier of the current variation - * @return {Action} - */ - setVariation(variation: string | undefined): Action; - /** - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @param {Array.} placements - * @return {Action} - */ - setPlacements(placements: string[]): Action; - /** - * Sets the restore link for the current session. Restore links can be leveraged - * in email campaigns. Restore links allow the the user to restore the cart - * contents in a single click. - *

- * Read more about - * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link} - *

- * It is not recommended to pass the restore link to an action but instead use the the - * session. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @see {@link Session#setRestoreLink} - * @param {String} restoreLink the secure URL to restore the user's current session - * @return {Action} - */ - setRestoreLink(restoreLink: string): Action; - /** - * Sets the identifier of the current page type to the current request. The different - * page types are product, front, search, cart, order, category, notfound and other. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - *

- * It is not recommended to pass the page type to an action but instead use the the - * session. - *

- * You must invoke [the load method]{@link Action#load} on the resultant - * action in order for the request to be made. - * - * @see {@link Session#viewFrontPage} for when a front or home page is being viewed - * @see {@link Session#viewCart} for when a cart or checkout page is being viewed - * @see {@link Session#viewNotFound} for when a not-found or 404 page is being viewed - * @see {@link Session#viewProduct} for when a product page is being viewed - * @see {@link Session#viewCategory} for when a category, collection or brand page is being viewed - * @see {@link Session#viewTag} for when a tag page is being viewed - * @see {@link Session#viewSearch} for when a search page is being viewed - * @see {@link Session#viewOther} for when a miscellaneous page is being viewed - */ - setPageType(pageType: PageType): Action; - /** - * Sets the affinity signals for the current action. - * Subsequent invocations will be merged with the previous ones. - * - * @param affinity - * @param options - */ - addAffinity(affinity: Record | undefined, options?: AffinityOptions): Action; - /** - * @return {Object} - * @hidden - */ - dumpData(): TaggingData; - update(): unknown; - /** - * Execute the action and fetch the recommendations for the current action. - * - * @param flags - */ - load(flags?: RecommendationRequestFlags): Promise; -} -interface AffinityOptions { - /** - * If set to true, the current affinity signals will be cleared before setting the new ones. - * Otherwise, the new signals will be appended to the existing ones, overriding the keys with the same name. - * - * @default false - */ - clear?: boolean; -} -/** - * Result object for an action that contains the recommendations and content that was requested for the current action. - * - * @group Core - */ -interface ActionResponse { - /** Recommendations that were requested for the current action. */ - recommendations: Record; - /** Recommendations and content that was requested for the current action. */ - campaigns?: { - recommendations: Record; - content: Record; - }; - /** Page view count */ - page_views: number; - /** Geo location metadarta */ - geo_location: string[]; - /** Affinity metadata */ - affinities: CustomerAffinityResponse; - /** Category Merchandising result id */ - cmpid: string; -} - -type Maybe = NonNullable | undefined; - -/** - * @group Core - */ -type EventType = -/** view product */ -"vp" -/** like product */ - | "lp" -/** dislike product */ - | "dp" -/** remove product */ - | "rp" -/** bought product */ - | "bp" -/** view category */ - | "vc" -/** order */ - | "or" -/** internal search */ - | "is" -/** add to cart */ - | "cp" -/** external campaign */ - | "ec" -/** external search */ - | "es" -/** give coupon */ - | "gc" -/** source */ - | "src" -/** cart popup recommendations */ - | "cpr" -/** page load */ - | "pl" -/** custom campaign */ - | "cc" -/** content campaign */ - | "con"; -/** - * @group Core - */ -type EventRefType = -/** triggered mail */ -"email" -/** email widgets */ - | "imgrec" -/** onsite recommendations */ - | "rec" -/** api recommendations */ - | "api" -/** onsite campaigns */ - | "oc" -/** category merchandising */ - | "cmp" -/** onsite search */ - | "os"; -/** - * @group Core - */ -type EventTuple = [ - type: EventType, - target?: string, - ref?: string, - refSrc?: string, - targetFragment?: string, - refType?: EventRefType -]; -/** - * @group Core - */ -interface Event { - type: EventType; - target?: string; - ref?: string; - refSrc?: string; - targetFragment?: string; - refType?: EventRefType; -} - -interface AbTestDraftPreviewSettingsDTO extends AbTestPreviewSettingsBase { - variations: AbTestVariationDTO[]; -} -interface AbTestPreviewSettingsBase { - id: TestId; - method: Method; - name: string; - segment: string; - variations: T[]; -} -interface AbTestPreviewSettingsDTO extends AbTestPreviewSettingsBase { - variations: AbTestVariationDTO[]; -} -interface AbTestVariation { - base: boolean; - id: string; - name: string; -} -interface AbTestVariationDTO extends AbTestVariation { -} -interface AbstractFacebookPixelEvent { - d: D; - n: string; -} -interface AbstractGid { -} -interface AbstractStacklaPixelEvent { - d: D; - n: string; -} -interface ActiveVisitDTO { - customer: CustomerDTO; - visit: VisitDTO; -} -interface AnalyticEvent { - properties?: AnalyticEventProperties; -} -interface AnalyticEventProperties { - abTestAttribution?: { - [index: string]: string; - }; -} -interface BigcommerceCustomerInfo { - customer_reference: string; - email: string; - first_name?: string; - group_id?: string; - last_name?: string; - marketing_permission?: boolean; -} -interface CartItem { - name: string; - price_currency_code: string; - product_id: string; - quantity: number; - sku_id?: string; - unit_price: number; -} -interface CategoryClick extends CategoryEvent { - productId: string; -} -interface CategoryEvent extends AnalyticEvent { - metadata: CategoryEventMetadata; +interface CategoryEvent extends AnalyticEvent { + metadata: CategoryEventMetadata; } interface CategoryEventMetadata { category: string; @@ -1850,58 +752,1173 @@ interface TestPreviewsDTO { interface UnsavedDraftPreviewSettingsDTO extends AbTestPreviewSettingsBase { variations: VariationWithRulesDTO[]; } -interface ValidationError { - key: string; - message: string; +interface ValidationError { + key: string; + message: string; +} +interface VariantGid extends AbstractGid { +} +interface VariationWithRulesDTO extends AbTestVariationDTO { + rules: TestPlacementRuleDTO[]; +} +interface VisitDTO { + cart_items: CartItem[]; + customer_id: string; + email: string; + events: Events; + id: string; +} +interface WebsiteOrder { + created_at?: Date; + external_order_ref?: string; + info?: OrderCustomer; + items: ConversionItem[]; + order_status?: string; + order_status_label?: string; + payment_provider?: string; +} +interface WidgetPlacement { + enabled: boolean; + id?: string; + name: string; + rules?: WidgetPlacementRule[]; +} +interface WidgetPlacementRule { + feature?: OnsiteFeature; + segment: string; + to?: string; +} +type ContentId = CampaignId<"ContentId">; +type FilterOperator = "INCLUDES" | "IS" | "CONTAINS" | "MATCHES_REGEXP_PATTERN" | "LT" | "GT" | "GTE" | "LTE" | "BETWEEN" | "AND" | "OR"; +type InsertMode = "REPLACE" | "APPEND" | "PREPEND" | "INSERT_INTO" | "INSERT_AFTER_BEGIN"; +type Method = "SPLIT_TEST" | "MVT"; +type OnsiteFeature = "RECOMMENDATION" | "CONTENT_DELIVERY" | "POPUP" | "SPLIT_TESTING" | "SCHEDULING" | "STACKLA_WIDGET"; +type PageType = "front" | "category" | "product" | "cart" | "search" | "notfound" | "order" | "other" | "checkout"; +type RecommendationId = CampaignId<"RecommendationId">; +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"; +type StacklaWidgetEmbedId = CampaignId<"StacklaWidgetEmbedId">; +type StacklaWidgetFilterType = "LATEST" | "CATEGORY_OR_BRAND" | "PRODUCT"; +type TargetType = "RECOMMENDATION" | "ONSITE_CONTENT" | "AB_TEST" | "HIDE_CONTENT" | "STACKLA_WIDGET"; +type TestId = CampaignId<"TestId">; +type WrapMode = "SIMPLE" | "PRESERVE_CLASS" | "CLONED" | "UNWRAPPED"; +type CampaignId = string & { + __kind: T; +}; + +interface Coupon { + campaign?: string; + code?: string; + used?: boolean; +} +interface Order { + items: CartItem[]; +} + +interface PluginMetadata { + mainModule?: string; + cmpModule?: string; + msiModule?: string; +} +type Product = Partial & { + product_id: string; + valid_until?: string; + selected_sku_id?: string; +}; +interface Cart { + hcid?: string; + items: CartItem[]; +} +interface TaggingData { + cart: Cart | undefined; + customer: PushedCustomer | undefined; + variation: string | undefined; + restoreLink: string | undefined; + products: Product[]; + order: WebsiteOrder | undefined; + searchTerms: string[] | undefined; + categories: string[] | undefined; + categoryIds: string[] | undefined; + parentCategoryIds: string[] | undefined; + tags: string[] | undefined; + customFields: Record | undefined; + elements: string[] | undefined; + pageType: PageType | undefined; + affinitySignals: Record | undefined; + sortOrder: string | undefined; + pluginVersion: PluginMetadata | undefined; +} + +interface RecommendationRequestFlags { + skipPageViews?: boolean; + trackEvents?: boolean; + skipEvents?: boolean; + reloadCart?: boolean; +} +/** + * RequestBuilder is a low level API to interact with the Nosto API. It's primary purpose is to fetch recommendations + * and send events to the Nosto API. It is not recommended to use this API directly, but rather use the the higher level + * Tagging and Session APIs. + * + * @group Core + */ +interface RequestBuilder { + /** + * Sets the given list of forced segment identifiers to the current request. This + * method allows you explicitly associate the current customer with a segment. + * + * @private + * @param {String[]} segments the list of force segment identifiers + */ + setForcedSegments(segments: string[]): RequestBuilder; + /** + * Sets the given list of manual segment identifiers to the current request. This + * method allows you explicitly associate the current customer with a segment. + * + * @param {String[]} segments the list of force segment identifiers + */ + setSegmentCodes(segments: string[]): RequestBuilder; + /** + * Sets the identifier of the current page type to the current request. The different + * page types are product, front, search, cart, order, category, notfound and other. + * + * @param {String} pageType the current page type + */ + setPageType(pageType: PageType | undefined): RequestBuilder; + /** + * Sets the identifier of the current sort order to the current request. + * + * @private + * @param {String} sortOrder the current sort order + */ + setSortOrder(sortOrder: string): RequestBuilder; + /** + * Adds affinity signals to the current request. + * + * @param signals signals to set + */ + setAffinitySignals(signals: Record): RequestBuilder; + /** + * Adds the given event to the current set of events. When viewing a product, + * it is required that you specify the "vp" as event and the product id as + * the target. + * + * Also supports legacy signature + * addEvent(type: string, target?: string, ref?: string, targetFragment?: string) { + * } + * + * @private + * @param {Event} event { type, target, ref, refSrc, targetFragment, refType } + */ + addEvent(event: Event): RequestBuilder; + /** + * Sets the information about the currently logged in customer. If the current + * customer is not provided, you will not be able to leverage features such as + * triggered emails. While it is recommended to always provide the details of + * the currently logged in customer, it may be omitted if there are concerns + * about privacy or compliance. + *

+ * It is not recommended to pass the current customer details to the request + * builder but rather use the customer tagging. + * + * @param {Customer} customer the details of the currently logged in customer + */ + setCustomer(customer: PushedCustomer): RequestBuilder; + setCoupon(coupon: Coupon): RequestBuilder; + /** + * Adds the given elements (or placements) to the request. Any identifiers + * specified here are simply added to the elements already in the request. + * + * @param {String[]} elements the array of placements + * + * @example + * To load data for a single placement + * nostojs(api => api + * .createRecommendationRequest() + * .addElements(['bestseller-home']) + * .loadRecommendations()); + */ + addElements(elements: string[]): RequestBuilder; + /** + * Sets the given elements (or placements) to the request. Any identifiers + * specified here override all elements already in the request. + * + * @param {String[]} elements the array of placements + * + * @example + * To load data for a single placement + * nostojs(api => api + * .createRecommendationRequest() + * .setElements(['bestseller-home']) + * .loadRecommendations()); + */ + setElements(elements: string[] | undefined): RequestBuilder; + /** + * Adds the cart object to the current request. This should be preferably + * on every page load so as to keep the cart state as fresh as possible. + * + * @param {PushedCart} cart the details of the current shopping basket + */ + setCartContent(cart: Cart | undefined): RequestBuilder; + /** + * Sets the restore link for the current session. Restore links can be leveraged + * in email campaigns. Restore links allow the the user to restore the cart + * contents in a single click. + *

+ * Read more about + * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link} + *

+ * It is not recommended to pass the current restore link to the request + * builder but rather use the tagging approach. + * + * @param restoreLink + */ + setRestoreLink(restoreLink: string | undefined): RequestBuilder; + /** + * Adds the given identifiers of the products in the customer's shopping cart + * to the request. + * + * @deprecated since this only transported partial information about the cart + * @private + */ + addCartItems(): RequestBuilder; + /** + * Sets the hash of the current cart cookie for ensure that the cart tagging + * isn't cached. In most cases, simply reading the customer's 2c.cid cookie + * and generating a SHA256 checksum will suffice. + * + * @deprecated + * @param {String} hcid the 32 character unique hash + */ + addCartCookieHash(hash: string): RequestBuilder; + /** + * Sets the total value of the customer's shopping cart. This should be the + * numerical value of what the customer sees in the mini-cart element of the + * store. + * + * @deprecated since this only transported partial information about the cart + * @private + */ + addCartTotal(): RequestBuilder; + /** + * Sets the total value of the customer's shopping cart. This should be the + * numerical value of what the customer sees in the mini-cart element of the + * store. + * + * @deprecated since this only transported partial information about the cart + * @private + */ + addCartSize(): RequestBuilder; + /** + * @param {Array.} products + * @param {String} [ref] the placement id that resulted in the product views + */ + setProducts(products: Product[], ref?: string): RequestBuilder; + /** + * Adds the given category names to the request. Any category name specified here + * are simply added to the request as personalisation filtering hints. + * + * @param {String[]} categories the array of category ids + */ + addCurrentCategories(categories: string[]): RequestBuilder; + /** + * Sets the given category names to the request. Any category names specified here + * override the category names in the request. + * + * @param {String[]} categories the array of category ids + */ + setCurrentCategories(categories: string[]): RequestBuilder; + /** + * Adds the given category ids to the request. Any category ids specified here + * are simply added to the request as personalisation filtering hints. + * + * @param {String[]} categoryIds the array of category ids + */ + addCurrentCategoryIds(categoryIds: string[]): RequestBuilder; + /** + * Adds the given parent category ids to the request. Any parent category ids specified here + * are simply added to the request as personalisation filtering hints. + */ + addCurrentParentCategoryIds(parentCategoryIds: string[]): RequestBuilder; + /** + * Adds the given current tags to the request. Any tags (tags1, tags12, or + * tags13) specified here are simply added to the request as personalisation + * filtering hints. + * + * @param {String[]} tags the array of tags + */ + addCurrentTags(tags: string[]): RequestBuilder; + /** + * Sets the given current tags to the request. Any tags (tags1, tags12, or + * tags13) specified here are simply set to the request as personalisation + * filtering hints. + * + * @param {String[]} tags the array of tags + */ + setCurrentTags(tags: string[]): RequestBuilder; + /** + * Adds the given current custom fields to the request. Any custom fields + * specified here are simply added to the request as personalisation filtering hints. + * + * @param { Object } fields custom field key-value pairs + */ + addCurrentCustomFields(fields: Record): RequestBuilder; + /** + * Sets the current lower price range to the request. Faceting needs to be + * enabled for the slot in order for this to function. Any lower value + * specified here are simply added to the request as personalisation filtering hints. + * + * @param {Number} value the lower range of the price + */ + setCurrentPriceFrom(value: number): RequestBuilder; + /** + * Sets the current upper price range to the request. Faceting needs to be + * enabled for the slot in order for this to function. Any upper value + * specified here are simply added to the request as personalisation filtering hints. + * + * @param {Number} value the upper range of the price + */ + setCurrentPriceTo(value: number): RequestBuilder; + /** + * Sets the current variation identifier for the session. A variation identifier + * identifies the current currency (or the current customer group). If your site + * uses multi-currency, you must provide the ISO code current currency being viewed. + *

+ * It is not recommended to pass the variation identifier to an request builder but + * instead leverage the tagging. + * + * @param {String} variation the case-sensitive identifier of the current variation + */ + addCurrentVariation(variation: string): RequestBuilder; + /** + * Sets the information about the currently logged in customer. If the current + * customer is not provided, you will not be able to leverage features such as + * triggered emails. While it is recommended to always provide the details of + * the currently logged in customer, it may be omitted if there are concerns + * about privacy or compliance. + *

+ * It is not recommended to pass the current customer details to the request + * builder but rather use the customer tagging. + * + * @param {Customer} customer + */ + addCustomer(customer: PushedCustomer): RequestBuilder; + /** + * Sets the response mode for the current request. The response mode can be + * used to switch between HTML and JSON. Here is an exhaustive list of the + * response modes. + * + * | Modes | Description | + * | -------------------- |:----------------------------------------------:| + * | HTML | HTML (SSR) | + * | JSON_170x170 | Raw JSON with 170x170px original aspect images | + * | JSON_100_X_100 | Raw JSON with 100x100px original aspect images | + * | JSON_90x70 | Raw JSON with 90x70px original aspect images | + * | JSON_50x50 | Raw JSON with 50x50px original aspect images | + * | JSON_30x30 | Raw JSON with 30x30px original aspect images | + * | JSON_100x140 | Raw JSON with 100x140px original aspect images | + * | JSON_200x200 | Raw JSON with 200x200px original aspect images | + * | JSON_400x400 | Raw JSON with 400x400px original aspect images | + * | JSON_750x750 | Raw JSON with 750x750px original aspect images | + * | JSON_10_MAX_SQUARE | Raw JSON with 100x100px center squared images | + * | JSON_200x200_SQUARE | Raw JSON with 200x200px center squared images | + * | JSON_400x400_SQUARE | Raw JSON with 400x400px center squared images | + * | JSON_750x750_SQUARE | Raw JSON with 750x750px center squared images | + * | JSON_ORIGINAL | Raw JSON with the original untouched images | + * + * @param {String} mode the response mode to be used + */ + setResponseMode(mode: RenderMode): RequestBuilder; + setExperiments(experiments: Experiment[]): RequestBuilder; + disableCampaignInjection(): RequestBuilder; + /** + * Enables the preview mode for the current request. The preview mode is + * automatically gathered from the current context's preview mode. If the + * debug toolbar is showing and preview mode is enabled, there is no need + * to invoke this function. + */ + enablePreview(): RequestBuilder; + /** + * Adds the order object to the current request. This should be invoked only + * on the order confirmation page. + * + * @param {Order} order the details of the order that was placed + */ + addOrderData(order: Order): RequestBuilder; + setMailRef(refMail: string, recRef: string): RequestBuilder; + populateFrom(params: { + data: TaggingData; + forcedSegments: string[]; + }, unwrappedReference?: string): RequestBuilder; + setRecommendationRef(recRef: string, recRefSrc?: string): RequestBuilder; + /** + * Builds the request and makes a request to Nosto. + * + * @deprecated since there is already a load method that does the same + * @private + * @param {RecommendationRequestFlags} flags + * @return {Promise} + * + * @example + * To load data for a single placement + * nostojs(api => api + * .createRecommendationRequest() + * .send({metadata: true})) + * .then((response) => console.log(response)); + */ + send(flags: RecommendationRequestFlags): Promise; + /** + * Builds the request and makes a request to Nosto. + * + * @param {RecommendationRequestFlags} flags an object containing additional flags + * @return {Promise} the response returned by Nosto + * + * @example + * To load data for a single placement + * nostojs(api => api + * .createRecommendationRequest() + * .addElements('bestseller-home') + * .load()) + * .then((response) => console.log(response)); + */ + load(flags?: RecommendationRequestFlags): Promise; + /** + * Builds the request and invokes it via JSONP to load the cart popup + * recommendations + * + * @deprecated since this method should de decoupled from the request + * @private + * @return {Promise} + */ + loadCartPopupRecommendations(alwaysShow: boolean): Promise; + /** + * Legacy method used to reloading the recommendations. This method is a + * simple wrapper around the other load method. + * + * @deprecated since the method name isn't aligned with it's behaviour + * @private + * @see {load} + * @param {RecommendationRequestFlags} flags an object containing additional flags + * @return {Promise} + * + * @example + * To load data for a single placement + * nostojs(api => api + * .createRecommendationRequest() + * .addElements('bestseller-home') + * .loadRecommendations()) + * .then((response) => console.log(response)); + */ + loadRecommendations(flags?: RecommendationRequestFlags): Promise; + /** + * Adds attribution for the given product id to reference mappings + * + * @param refs + * @returns + */ + setRefs(refs: Record): RequestBuilder; + getEvents(): Event[]; + getData(): EventRequestMessageV1; +} + +interface Attribution { + recordAttribution: (event: Event) => Attribution; + dumpData: () => EventTuple[]; + done: () => Promise; } -interface VariantGid extends AbstractGid { + +/** + * The Session API provides a programmatic way to interact with the Nosto API that is + * optimized for usage in SPA style web applications. The Session object maintains the session level + * data such as the user's shopping cart, the currently logged in customer, the current variation + * and provides function to execute actions such as viewing a product, category, cart, order etc. + * + * @group Core + */ +interface Session { + /** + * Sets the information about the user's current shopping cart. It the user + * does not have any items in his shopping cart, you can pass null. + * Passing null will nullify the user's shopping cart on Nosto's + * end. You must also pass in the shopping cart content in it's entirety as + * partial content are not supported. + * + * @param {Cart|undefined} cart the details of the user's shopping cart contents + * @returns {Session} the current session + * + * @example + * nostojs(api => api + * .defaultSession() + * .setCart({ + * items: [ + * product_id: "101", + * sku_id: "101-S", + * name: "Shoe", + * unit_price: 34.99 + * price_currency_code: "EUR" + * ] + * }) + * .viewCart() + * .setPlacements(["free-shipper"]) + * .update() + * .then(data => console.log(data))) + */ + setCart(cart: Cart | undefined): Session; + /** + * Sets the information about the currently logged in customer. If the current + * customer is not provided, you will not be able to leverage features such as + * triggered emails. While it is recommended to always provide the details of + * the currently logged in customer, it may be omitted if there are concerns + * about privacy or compliance. + * + * @param {Customer} customer the details of the currently logged in customer + * @returns {Session} the current session + * + * @example + * nostojs(api => api + * .defaultSession() + * .setCustomer({ + * first_name: "Mridang", + * last_name: "Agarwalla", + * email: "mridang@nosto.com", + * newsletter: false, + * customer_reference: "5e3d4a9c-cf58-11ea-87d0-0242ac130003" + * }) + * .viewCart() + * .setPlacements(["free-shipper"]) + * .load() + * .then(data => console.log(data))) + */ + setCustomer(customer: PushedCustomer | undefined): Session; + /** + * Sets the current variation identifier for the session. A variation identifier + * identifies the current currency (or the current customer group). If your site + * uses multi-currency, you must provide the ISO code current currency being viewed. + * + * @param {String} variation the case-sensitive identifier of the current variation + * @returns {Session} the current session + * + * @example + * nostojs(api => api + * .defaultSession() + * .setVariation("GBP") + * .viewCart() + * .setPlacements(["free-shipper"]) + * .load() + * .then(data => console.log(data))) + */ + setVariation(variation: string | undefined): Session; + /** + * Sets the restore link for the current session. Restore links can be leveraged + * in email campaigns. Restore links allow the the user to restore the cart + * contents in a single click. + *

+ * Read more about + * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link} + * + * @param {String} restoreLink the secure URL to restore the user's current session + * @returns {Session} the current session + * + * @example + * nostojs(api => api + * .defaultSession() + * .setRestoreLink("https://jeans.com/session/restore?sid=6bdb69d5-ed15-4d92") + * .viewCart() + * .setPlacements(["free-shipper"]) + * .load() + * .then(data => console.log(data))) + */ + setRestoreLink(restoreLink: string): Session; + /** + * Sets the response type to HTML or JSON_ORIGINAL. This denotes the preferred + * response type of the recommendation result. + * If you would like to access the raw recommendation data in JSON form, specify + * JSON. When you specify JSON, you will need to template the result yourself. + * If you require a more simplified approach, specify HTML. When you specify + * HTML, you get back HTML blobs, that you may simply inject into + * you placements. + * + * @param {String} mode the response mode for the recommendation data + * @returns {Session} the current session + * + * @example + * nostojs(api => api + * .defaultSession() + * .setResponseMode("HTML") + * .viewCart() + * .setPlacements(["free-shipper"]) + * .load() + * .then(data => console.log(data))) + */ + setResponseMode(mode: RenderMode): Session; + /** + * Create a new action for a front page. This should be used when the user + * visits the home page. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewFrontPage() + * .setPlacements(["best-seller"]) + * .load() + * .then(data => console.log(data))) + */ + viewFrontPage(): Action; + /** + * Create a new action for a cart page. This should be used on all cart and + * checkout pages. If your site has a multi-step checkout, it is recommended + * that you send this event on each checkout page. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewCart() + * .setPlacements(["free-shipper"]) + * .load() + * .then(data => console.log(data))) + */ + viewCart(): Action; + /** + * Create a new action for a not found page. This should be used only on 404 + * pages. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewNotFound() + * .setPlacements(["best-seller"]) + * .load() + * .then(data => console.log(data))) + */ + viewNotFound(): Action; + /** + * Create a new action for a product page. This must be used only when a + * product is being viewed. In case a specific SKU of the product is being viewed, use viewProductSku instead. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * + * @param product + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewProduct("101") + * .setCategories(["/men/trousers"]) + * .setRef("123", "example_reco_id") + * .setPlacements(["cross-seller"]) + * .load() + * .then(data => console.log(data))) + */ + viewProduct(product: string | Product): Action; + /** + * Create a new action for a product page when a specific SKU has been chosen. This must be used only when a + * product and specific SKU is being viewed. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * + * @param productId + * @param skuId + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewProductSku("101", "101-sku-1") + * .setCategories(["/men/trousers"]) + * .setRef("123", "example_reco_id") + * .setPlacements(["cross-seller"]) + * .load() + * .then(data => console.log(data))) + */ + viewProductSku(productId: string, skuId: string): Action; + /** + * Create a new action for a category page. This should be used on all + * category, collection of brand pages. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * + * @param {Array} categories + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewCategory("/men/shoes") + * .setPlacements(["category123"]) + * .load() + * .then(data => console.log(data))) + */ + viewCategory(...categories: string[]): Action; + /** + * Create a new action for a tag page. This should be used only on tag pages. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * Note: tags are not case-sensitive. + * + * @deprecated as this is an advanced action with a limited a use case + * @param {Array} tags the set of the tags being viewed. + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewTag("colourful") + * .load() + * .then(data => console.log(data))) + */ + viewTag(...tags: string[]): Action; + /** + * Create a new action with custom fields. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * Note: tags are not case-sensitive. + * + * @deprecated as this is an advanced action with a limited a use case + * @param {Object} customFields custom fields being viewed. + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewCustomField({material: "cotton"}) + * .load() + * .then(data => console.log(data))) + */ + viewCustomField(customFields: Record): Action; + /** + * Create a new action for a search page. This should be used only + * on search pages. A search page action requires you to pass the search + * term. For example, if the user search for "black shoes", you must pass + * in "black shoes" and not an encoded version such as "black+shoes". + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * Search terms are not case-sensitive. + * + * @param {Array.} searchTerms the non-encoded search terms + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewSearch("black shoes") + * .load() + * .then(data => console.log(data))) + */ + viewSearch(...searchTerms: string[]): Action; + /** + * Create a new action for a general page. This should be used only on + * pages that don't have a corresponding action. For example, if the user + * is viewing a page such as a "Contact Us" page, you should use the viewOther + * action. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + * + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .viewOther() + * .load() + * .then(data => console.log(data))) + */ + viewOther(): Action; + /** + * Create a new action for an order page. This should only be used on order + * confirmation / thank you pages. + *

+ * You do not need to specify the page-type explicitly as it is inferred + * from the action. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param {Order} order the information about the order that was placed + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => { + * api.defaultSession() + * .addOrder({ + * external_order_ref: "145000006", + * info: { + * order_number: "195", + * email: "mridang@nosto.com", + * first_name: "Mridang", + * last_name: "Agarwalla", + * type: "order", + * newsletter: true + * }, + * items: [{ + * product_id: "406", + * sku_id: "243", + * name: "Linen Blazer (White, S)", + * quantity: 1, + * unit_price: 455, + * price_currency_code: "EUR" + * }] + * }) + * .setPlacements(["order-related"]) + * .load() + * .then(data => { + * console.log(data.recommendations); + * }) + * }) + */ + addOrder(order: WebsiteOrder): Action; + /** + * Creates an action to report that product was added to the shopping cart, + * e.g. from the recommendation slot with "Add to cart" button. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param product + * @param element + * @returns {Action} the action instance to load content or track events. + * + * @example + * nostojs(api => api + * .defaultSession() + * .reportAddToCart("123", "reco-slot-1") + * .load() + * .then(data => console.log(data))) + */ + reportAddToCart(product: string, element: string): Action; + /** + * @param { EventType } type + * @param { String } target + * @param { String | undefined } [ref] + * @param { String | undefined } [refSrc] + * @return { Object } + * + * @example + * nostojs(api => api + * .defaultSession() + * .recordAttribution("vp", "12345678", "123456") + * .done() + * .then(data => console.log(data)) + */ + recordAttribution(type: EventType, target: string, ref: string, refSrc: string): Attribution; } -interface VariationWithRulesDTO extends AbTestVariationDTO { - rules: TestPlacementRuleDTO[]; +/** + * Action in the Session API context means fetching recommendations for a specific view. For example when + * a visitor navigates from the front page to a product view you would most likely fetch recommendations + * related to a product. This would be considered as an Action. Setting the cart contents however would + * not be considered as action. + * + * @group Core + */ +interface Action { + /** + * Handles click attribution for product recommendations. + * This can be called when reporting a product view + * to signal that the view is a result of a click on a recommendation. + * + * @param {String} productId currently viewed product's product id + * @param {String} reference value of result_id from the recommendation response that was clicked + * @return {Action} + */ + setRef(productId: string, reference: string): Action; + /** + * Allows you to provide an additional recommender hint that a product is being + * viewed. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param {String} product the identifier of the product being viewed + * @return {Action} the instance of the action + */ + setProduct(product: string | Product): Action; + /** + * @deprecated + * @param {Array} products + * @return {Action} + */ + setProducts(products: (string | Product)[]): Action; + /** + * Sets the information about the user's current shopping cart. It the user + * does not have any items in his shopping cart, you can pass null. + * Passing null will nullify the user's shopping cart on Nosto's + * end. You must also pass in the shopping cart content in it's entirety as + * partial content are not supported. + *

+ * It is not recommended to pass the current cart contents to an action but + * instead use the the session + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @see {@link Session#setCart} + * @return {Action} + */ + setCart(cart: Cart | undefined): Action; + /** + * Sets the information about the currently logged in customer. If the current + * customer is not provided, you will not be able to leverage features such as + * triggered emails. While it is recommended to always provide the details of + * the currently logged in customer, it may be omitted if there are concerns + * about privacy or compliance. + *

+ * It is not recommended to pass the current customer details to an action but + * instead use the the session + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @see {@link Session#setCustomer} + * @param {Customer} customer the details of the currently logged in customer + * @return {Action} + */ + setCustomer(customer: PushedCustomer | undefined): Action; + /** + * @param {Order} order + * @return {Action} + */ + setOrder(order: WebsiteOrder): Action; + /** + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param searchTerms + * @return {Action} + */ + setSearchTerms(searchTerms: string[]): Action; + /** + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param {Array} categories + * @return {Action} + */ + setCategories(categories: string[]): Action; + /** + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param {Array} categoryIds + * @return {Action} + */ + setCategoryIds(categoryIds: string[]): Action; + /** + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param {Array} parentCategoryIds + * @return {Action} + */ + setParentCategoryIds(parentCategoryIds: string[]): Action; + /** + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param tags + * @return {Action} + */ + setTags(tags: string[]): Action; + /** + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param customFields + * @return {Action} + */ + setCustomFields(customFields: Record): Action; + /** + * Sets the current variation identifier for the session. A variation identifier + * identifies the current currency (or the current customer group). If your site + * uses multi-currency, you must provide the ISO code current currency being viewed. + *

+ * It is not recommended to pass the variation identifier to an action but + * instead use the the session. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @see {@link Session#setVariation} + * @param {String} variation the case-sensitive identifier of the current variation + * @return {Action} + */ + setVariation(variation: string | undefined): Action; + /** + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @param {Array.} placements + * @return {Action} + */ + setPlacements(placements: string[]): Action; + /** + * Sets the restore link for the current session. Restore links can be leveraged + * in email campaigns. Restore links allow the the user to restore the cart + * contents in a single click. + *

+ * Read more about + * {@link https://help.nosto.com/en/articles/664692|how to leverage the restore cart link} + *

+ * It is not recommended to pass the restore link to an action but instead use the the + * session. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @see {@link Session#setRestoreLink} + * @param {String} restoreLink the secure URL to restore the user's current session + * @return {Action} + */ + setRestoreLink(restoreLink: string): Action; + /** + * Sets the identifier of the current page type to the current request. The different + * page types are product, front, search, cart, order, category, notfound and other. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + *

+ * It is not recommended to pass the page type to an action but instead use the the + * session. + *

+ * You must invoke [the load method]{@link Action#load} on the resultant + * action in order for the request to be made. + * + * @see {@link Session#viewFrontPage} for when a front or home page is being viewed + * @see {@link Session#viewCart} for when a cart or checkout page is being viewed + * @see {@link Session#viewNotFound} for when a not-found or 404 page is being viewed + * @see {@link Session#viewProduct} for when a product page is being viewed + * @see {@link Session#viewCategory} for when a category, collection or brand page is being viewed + * @see {@link Session#viewTag} for when a tag page is being viewed + * @see {@link Session#viewSearch} for when a search page is being viewed + * @see {@link Session#viewOther} for when a miscellaneous page is being viewed + */ + setPageType(pageType: PageType): Action; + /** + * Sets the affinity signals for the current action. + * Subsequent invocations will be merged with the previous ones. + * + * @param affinity + * @param options + */ + addAffinity(affinity: Record | undefined, options?: AffinityOptions): Action; + /** + * @return {Object} + * @hidden + */ + dumpData(): TaggingData; + update(): unknown; + /** + * Execute the action and fetch the recommendations for the current action. + * + * @param flags + */ + load(flags?: RecommendationRequestFlags): Promise; } -interface VisitDTO { - cart_items: CartItem[]; - customer_id: string; - email: string; - events: Events; - id: string; +interface AffinityOptions { + /** + * If set to true, the current affinity signals will be cleared before setting the new ones. + * Otherwise, the new signals will be appended to the existing ones, overriding the keys with the same name. + * + * @default false + */ + clear?: boolean; } -interface WebsiteOrder { - created_at?: Date; - external_order_ref?: string; - info?: OrderCustomer; - items: ConversionItem[]; - order_status?: string; - order_status_label?: string; - payment_provider?: string; +/** + * Result object for an action that contains the recommendations and content that was requested for the current action. + * + * @group Core + */ +interface ActionResponse { + /** Recommendations that were requested for the current action. */ + recommendations: Record; + /** Recommendations and content that was requested for the current action. */ + campaigns?: { + recommendations: Record; + content: Record; + }; + /** Page view count */ + page_views: number; + /** Geo location metadarta */ + geo_location: string[]; + /** Affinity metadata */ + affinities: CustomerAffinityResponse; + /** Category Merchandising result id */ + cmpid: string; } -interface WidgetPlacement { - enabled: boolean; - id?: string; - name: string; - rules?: WidgetPlacementRule[]; + +type Maybe = NonNullable | undefined; + +interface Store { + getCustomerId(): Maybe; + setCustomerId(id: string): void; } -interface WidgetPlacementRule { - feature?: OnsiteFeature; - segment: string; - to?: string; + +interface Visits { + getCustomerId(): Maybe; + getStore(): Store; + isDoNotTrack(): boolean; + setCustomerId(id: string | undefined): void; + setCustomerIdentifierService(s: Store): Store; + setDoNotTrack(dnt: boolean): boolean; + setStore(s: Store): Store; } -type ContentId = CampaignId<"ContentId">; -type FilterOperator = "INCLUDES" | "IS" | "CONTAINS" | "MATCHES_REGEXP_PATTERN" | "LT" | "GT" | "GTE" | "LTE" | "BETWEEN" | "AND" | "OR"; -type InsertMode = "REPLACE" | "APPEND" | "PREPEND" | "INSERT_INTO" | "INSERT_AFTER_BEGIN"; -type Method = "SPLIT_TEST" | "MVT"; -type OnsiteFeature = "RECOMMENDATION" | "CONTENT_DELIVERY" | "POPUP" | "SPLIT_TESTING" | "SCHEDULING" | "STACKLA_WIDGET"; -type PageType = "front" | "category" | "product" | "cart" | "search" | "notfound" | "order" | "other" | "checkout"; -type RecommendationId = CampaignId<"RecommendationId">; -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"; -type StacklaWidgetEmbedId = CampaignId<"StacklaWidgetEmbedId">; -type StacklaWidgetFilterType = "LATEST" | "CATEGORY_OR_BRAND" | "PRODUCT"; -type TargetType = "RECOMMENDATION" | "ONSITE_CONTENT" | "AB_TEST" | "HIDE_CONTENT" | "STACKLA_WIDGET"; -type TestId = CampaignId<"TestId">; -type WrapMode = "SIMPLE" | "PRESERVE_CLASS" | "CLONED" | "UNWRAPPED"; -type CampaignId = string & { - __kind: T; -}; type PerLinkAttributions = Record>; @@ -1924,15 +1941,6 @@ interface Placements { reset(): void; } -interface AxiosResponse { - data: T; - status: number; - statusText: string; - headers: Record; - config: unknown; - request?: unknown; -} - type ParseUriResult = Pick; declare function clear(): void; @@ -1989,16 +1997,6 @@ type nostojs = { o?: InitOptions; }; -declare function windowTools(win: Window, scriptLoaderWindow: Window): { - window: Window; - loadScript: (url: string, callbackFn?: () => void, options?: { - module?: boolean; - }) => Promise; - loadOnce: (url: string, callbackFn: () => void) => void; - xdr: (url: string, data: EventRequestMessageV1) => Promise; - domReady: (fn: () => void) => void; -}; -type WindowTools = ReturnType; /** * @hidden */ @@ -2012,13 +2010,8 @@ interface Context { updateSiteUrl: () => void; siteUrl: ParseUriResult; siteUrlCleaned: string; - requests: { - sent: unknown[]; - received: unknown[]; - }; referer?: ParseUriResult; - site: WindowTools; - nosto: WindowTools; + domReady: ReturnType; debugToken: string; mode: Mode; popupShown: boolean; @@ -2176,12 +2169,23 @@ interface Settings extends ClientScriptSettingsDTO { } declare function modifySettings(updates: Partial): void; -declare function recommendedProductAddedToCart(productId: string, recoId: string): Promise; +type ProductIdentifier = string | { + productId: string; + skuId?: string; +}; +/** + * Sends an event to Nosto when a recommended product is added to the cart. + * @param product - The product identifier. + * @param recoId - The recommendation identifier. + */ +declare function reportAddToCart(product: ProductIdentifier, recoId: string): Promise; declare function reportCouponGiven(campaignId: string, couponCode: string, couponUsed: boolean): Promise; declare function addSegment(segment: string): Promise; +declare function addAffinitySignals(signals: Record): Promise; + declare function findProducts(): Product[]; declare function findCustomer(): PushedCustomer | undefined; @@ -3483,6 +3487,7 @@ interface Scripterror { */ interface Addtocart { productId: string; + skuId?: string; placementId: string; } /** @@ -3587,6 +3592,89 @@ declare function isAutoLoad(): boolean; declare function setExperiments(experiments: Experiment[]): Promise; +type PopupCampaign = PopupTriggerSettingsDTO & { + type?: PopupTrigger; +}; +declare function createOverlay(): { + sortedCampaignsWithType: () => PopupCampaign[]; + activate: () => void; + campaignList: () => PopupCampaign[]; + openPopup: (popupId: string, opts?: { + preview?: boolean; + effects?: Record; + }) => string | undefined; + enablePopup: (popupId: string) => void; + disablePopup: (popupId: string) => void; + setTriggers: (responseData: EventResponseMessage) => void; + discountPopup: { + instance: { + internal: { + showPopup(showPopupOptions: { + campaignId?: string; + popupId?: string; + effect: Partial; + trigger: PopupTrigger; + preview?: boolean; + cart?: PopupCart; + }): void; + close(): void; + }; + preview: (popupId: string, campaignId: string, effect?: PopupEffect) => void; + previewById: (popupId: string, effect: PopupEffect) => void; + open: (popupId: string, response: ResponseData | null, effect: PopupEffect, trigger: PopupTrigger) => void; + okToOpen: (popupId: string, condition: Condition, responseData?: ResponseData) => boolean; + openCheck: (popupId: string, condition?: Condition, responseData?: ResponseData) => string | null; + stampOnCheckoutPage: () => void; + openMinimized: () => void; + done: (popupId: string) => void; + writePopupAttribute: typeof writePopupAttribute; + readPopupAttributes: typeof readPopupAttributes; + } | null; + preview(popupId: string, campaignId: string, effect?: PopupEffect): { + internal: { + showPopup(showPopupOptions: { + campaignId?: string; + popupId?: string; + effect: Partial; + trigger: PopupTrigger; + preview?: boolean; + cart?: PopupCart; + }): void; + close(): void; + }; + preview: (popupId: string, campaignId: string, effect?: PopupEffect) => void; + previewById: (popupId: string, effect: PopupEffect) => void; + open: (popupId: string, response: ResponseData | null, effect: PopupEffect, trigger: PopupTrigger) => void; + okToOpen: (popupId: string, condition: Condition, responseData?: ResponseData) => boolean; + openCheck: (popupId: string, condition?: Condition, responseData?: ResponseData) => string | null; + stampOnCheckoutPage: () => void; + openMinimized: () => void; + done: (popupId: string) => void; + writePopupAttribute: typeof writePopupAttribute; + readPopupAttributes: typeof readPopupAttributes; + }; + }; +} | { + activate(): void; + campaignList(): (PopupTriggerSettingsDTO & { + type?: PopupTrigger; + })[]; + openPopup(): void; + enablePopup(): void; + disablePopup(): void; + setTriggers(): void; + discountPopup: { + instance: {}; + preview(): void; + }; + sortedCampaignsWithType?: undefined; +}; + +/** + * @hidden + */ +type Overlay = ReturnType; + declare function captureError(error: unknown, reporter: string, level?: Level): void; declare function customer(customer: PushedCustomer): Promise; type Install = { @@ -3607,6 +3695,7 @@ declare function showPlacementPreviews(placement: { declare function defaultSession(): Session; declare function createRecommendationRequest(flags?: { includeTagging?: boolean; + state?: EventRequestMessageV1; }): RequestBuilder; declare function setRecommendationsEnabled(flag: boolean): void; declare function listen(phase: T, callback: (...args: EventMapping[T]) => void): void; @@ -3779,19 +3868,20 @@ declare const api: { /** @hidden */ loadCartPopupRecommendations: typeof loadCartPopupRecommendations; /** - * @param cartItemId + * Sends an event to Nosto when a recommended product is added to the cart. + * + * @param productId * @param nostoElementId * @return {Promise} */ - reportAddToCart: typeof recommendedProductAddedToCart; + reportAddToCart: typeof reportAddToCart; /** @hidden */ captureError: typeof captureError; /** - * @param {String} productId - * @param {String} nostoElementId - * @return {Promise} + * @hidden + * @deprecated */ - recommendedProductAddedToCart: typeof recommendedProductAddedToCart; + recommendedProductAddedToCart: typeof reportAddToCart; /** * API method to force the current session to be a part of the given experiment. * @@ -3940,6 +4030,18 @@ declare const api: { * nostojs(api => api.addSegmentCodeToVisit('discount code user')) */ addSegmentCodeToVisit: typeof addSegment; + /** + * Manually specify user affinity signals. + * This is useful for features like user quizzes or surveys where they would specify their preferences. + *

+ * Explicit affinity signals contribute to the final affinities in a weighted system, and + * they are weighted lower than buying an item, but higher than adding it to cart. + * + * @example + * to add affinity to specific brands + * nostojs(api => api.addAffinitySignals({ brand: ['nike', 'adidas'] })) + */ + addAffinitySignals: typeof addAffinitySignals; /** * Removes injected content from the supplied divIds * If campaign was injected statically, then static placement just clears its contents. @@ -4023,102 +4125,4 @@ declare const api: { * */ type API = typeof api; -type PopupCampaign = PopupTriggerSettingsDTO & { - type?: PopupTrigger; -}; -declare function createOverlay(): { - sortedCampaignsWithType: () => PopupCampaign[]; - activate: () => void; - campaignList: () => PopupCampaign[]; - openPopup: (popupId: string, opts?: { - preview?: boolean; - effects?: Record; - }) => string | undefined; - enablePopup: (popupId: string) => void; - disablePopup: (popupId: string) => void; - setTriggers: (responseData: EventResponseMessage) => void; - discountPopup: { - instance: { - internal: { - showPopup(showPopupOptions: { - campaignId?: string; - popupId?: string; - effect: Partial; - trigger: PopupTrigger; - preview?: boolean; - cart?: PopupCart; - }): void; - close(): void; - }; - preview: (popupId: string, campaignId: string, effect?: PopupEffect) => void; - previewById: (popupId: string, effect: PopupEffect) => void; - open: (popupId: string, response: ResponseData | null, effect: PopupEffect, trigger: PopupTrigger) => void; - okToOpen: (popupId: string, condition: Condition, responseData?: ResponseData) => boolean; - openCheck: (popupId: string, condition?: Condition, responseData?: ResponseData) => string | null; - stampOnCheckoutPage: () => void; - openMinimized: () => void; - done: (popupId: string) => void; - writePopupAttribute: typeof writePopupAttribute; - readPopupAttributes: typeof readPopupAttributes; - } | null; - preview(popupId: string, campaignId: string, effect?: PopupEffect): { - internal: { - showPopup(showPopupOptions: { - campaignId?: string; - popupId?: string; - effect: Partial; - trigger: PopupTrigger; - preview?: boolean; - cart?: PopupCart; - }): void; - close(): void; - }; - preview: (popupId: string, campaignId: string, effect?: PopupEffect) => void; - previewById: (popupId: string, effect: PopupEffect) => void; - open: (popupId: string, response: ResponseData | null, effect: PopupEffect, trigger: PopupTrigger) => void; - okToOpen: (popupId: string, condition: Condition, responseData?: ResponseData) => boolean; - openCheck: (popupId: string, condition?: Condition, responseData?: ResponseData) => string | null; - stampOnCheckoutPage: () => void; - openMinimized: () => void; - done: (popupId: string) => void; - writePopupAttribute: typeof writePopupAttribute; - readPopupAttributes: typeof readPopupAttributes; - }; - }; -} | { - activate(): void; - campaignList(): (PopupTriggerSettingsDTO & { - type?: PopupTrigger; - })[]; - openPopup(): void; - enablePopup(): void; - disablePopup(): void; - setTriggers(): void; - discountPopup: { - instance: {}; - preview(): void; - }; - sortedCampaignsWithType?: undefined; -}; - -/** - * @hidden - */ -type Overlay = ReturnType; - -interface Store { - getCustomerId(): Maybe; - setCustomerId(id: string): void; -} - -interface Visits { - getCustomerId(): Maybe; - getStore(): Store; - isDoNotTrack(): boolean; - setCustomerId(id: string | undefined): void; - setCustomerIdentifierService(s: Store): Store; - setDoNotTrack(dnt: boolean): boolean; - setStore(s: Store): Store; -} - export type { ABTest, API, AbTestDraftPreviewSettingsDTO, AbTestPreviewSettingsBase, AbTestPreviewSettingsDTO, AbTestVariation, AbTestVariationDTO, AbstractFacebookPixelEvent, AbstractGid, AbstractStacklaPixelEvent, Action, ActionResponse, ActiveVisitDTO, Addtocart, AnalyticEvent, AnalyticEventProperties, AnalyticsType, BigcommerceCustomerInfo, Callback, CampaignId, Cart, CartItem, Carttaggingresent, CategoryClick, CategoryEvent, CategoryEventMetadata, CategoryImpression, ClientScriptSettingsDTO, ConditionDTO, ContentDebugDTO, ContentId, Context, ConversionItem, Coupon, Coupongiven, CrawlResponse, CurrencySettingsDTO, CustomerAffinityResponse, CustomerAffinityResponseItem, CustomerDTO, CustomerToken, DebugRequestParamsDTO, DebugToolbarDataDTO, DynamicPlacementDTO, Effect, Endpoint, Event, EventAttributionMetadata, EventAttributionParams, EventFields, EventMapping, EventRefType, EventRequestMessageV1, EventResponseMessage, EventTuple, EventType, Events, Experiment, FacebookData, FilterOperator, FilterRule, ForcedTestDTO, GoogleAnalyticsData, InputSearchABTest, InputSearchABTestVariation, InputSearchBoost, InputSearchFacetConfig, InputSearchFilter, InputSearchHighlight, InputSearchKeywords, InputSearchPin, InputSearchProducts, InputSearchQuery, InputSearchRangeFilter, InputSearchRule, InputSearchRuleMatch, InputSearchSchedule, InputSearchSort, InputSearchTopLevelFilter, InsertMode, Method, NostoSku, NostoVariant, NostojsCallback, OnsiteFeature, Order, OrderCustomer, OrderInfo, OverlapCampaignDTO, Overlay, PageType, PersonalizationBoost, PlacementDebugDTO, PlacementRuleDTO, Placements, Popup, PopupCampaignPreviewSettingsDTO, PopupCouponGiven, PopupEmailCollected, PopupEvent, PopupTriggerSettingsDTO, PopupTriggered, Popupopened, PostPurchaseImage, PostPurchaseOffer, PostPurchaseOptionValue, PostPurchaseProductOption, PostPurchaseRecommendation, PostPurchaseSelectedOption, PostPurchaseTranslation, PostPurchaseVariantNode, Postrender, Prerender, Product, ProductOptionValueGid, ProductPushResponse, PushedCustomer, PushedProduct, PushedProductSKU, PushedVariation, Query, QuerySearchArgs, RecommendationDebugDTO, RecommendationId, RecommendationRequestFlags, RenderMode, RequestBuilder, ScheduleTime, Scripterror, SearchAnalyticsOptions, SearchAutocorrect, SearchClick, SearchEvent, SearchEventMetadata, SearchExclusionBehaviour, SearchExplain, SearchExplainRule, SearchFacet, SearchFacetOrder, SearchFacetTerm, SearchFacetType, SearchFailureEventDTO, SearchHighlight, SearchHit, SearchImpression, SearchKeyword, SearchKeywords, SearchOptions, SearchOutOfStockBehaviour, SearchPageType, SearchParamComparisonFunction, SearchProduct, SearchProductAffinities, SearchProductAiDetected, SearchProductCustomField, SearchProductExtra, SearchProductKeyedVariation, SearchProductSku, SearchProductStats, SearchProducts, SearchQuery, SearchQueryField, SearchResult, SearchRuleScheduleType, SearchRuleScheduleWeekday, SearchSessionParams, SearchSortOrder, SearchStatsFacet, SearchSuccessEventDTO, SearchTermsFacet, SearchTrackOptions, SearchVariationValue, SegmentDebugDTO, SegmentInfoBean, SegmentRuleDebugDTO, Segments, SegmentsResponseBean, Session, Setexperiments, Settings, Sku, StacklaTrackingData, StacklaWidgetDebugDTO, StacklaWidgetEmbedId, StacklaWidgetFilterType, TaggingData, TargetType, TestDebugDTO, TestId, TestPlacementRuleDTO, TestPreviewsDTO, UnsavedDraftPreviewSettingsDTO, ValidationError, VariantGid, VariationWithRulesDTO, VisitDTO, Visits, WebsiteOrder, WidgetPlacement, WidgetPlacementRule, WrapMode, nostojs }; From 4313841a1c079c57e537bd51bba01f85abc53914 Mon Sep 17 00:00:00 2001 From: Maija Lintunokka Date: Mon, 20 Jan 2025 14:22:17 +0200 Subject: [PATCH 2/2] fix: clean up nosto dts and fix testing blind spot --- package.json | 11 ++++++----- src/client/nosto.d.ts | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 9cf1ab9..6b29fb2 100644 --- a/package.json +++ b/package.json @@ -18,17 +18,17 @@ "author": "Nosto", "exports": { ".": { + "types": "./dist/index.d.ts", "import": "./dist/index.es.js", - "require": "./dist/index.cjs.js", - "types": "./dist/index.d.ts" + "require": "./dist/index.cjs.js" }, "./client": { "types": "./dist/client/nosto.d.ts" }, "./testing": { + "types": "./dist/testing/testing.d.ts", "import": "./dist/testing.es.js", - "require": "./dist/testing.cjs.js", - "types": "./dist/testing/testing.d.ts" + "require": "./dist/testing.cjs.js" } }, "scripts": { @@ -36,7 +36,8 @@ "build": "tsc && vite build && npm run build-dts && npm run typedoc", "build-dts": "tsc --noEmit false --emitDeclarationOnly && npm run copy-nosto-dts", "copy-nosto-dts": "copyfiles -u 1 \"src/client/*.d.ts\" dist", - "test": "vitest --run", + "test": "vite build && npm run build-dts && vitest --run", + "test-only": "vitest --run", "lint": "eslint '{src,test}/**/*.ts'", "preview": "vite preview", "typedoc": "typedoc src/index.ts src/client/nosto.d.ts src/testing/testing.ts" diff --git a/src/client/nosto.d.ts b/src/client/nosto.d.ts index b203dbd..3d7714c 100644 --- a/src/client/nosto.d.ts +++ b/src/client/nosto.d.ts @@ -1,6 +1,5 @@ /** @module client */ // @ts-nocheck -import domReadyCreator from 'domready'; /** * @group Core