Class TecsafeWidgetManager

The main entry point for the TECSAFE Widget SDK

Hierarchy (view full)

Constructors

  • The main entry point for the TECSAFE Widget SDK. This class should only be instantiated after the user has consented to the terms, conditions, and privacy policy!

    Parameters

    • customerTokenCallback: ((oldToken?: string) => Promise<string>)

      A function that returns the customer token as a string inside a promise. It is expected that you implement a route in your backend, using your own auth method, and request a token from our backend, forwarding the oldToken if provided to ensure proper session upgrading.

        • (oldToken?): Promise<string>
        • Parameters

          • OptionaloldToken: string

          Returns Promise<string>

    • addToCartCallback: AddToCartHandler

      A function that adds a product to the cart, given the product details, returning a success status.

    • widgetManagerConfig: WidgetManagerConfig

      The configuration for the SDK.

    Returns TecsafeWidgetManager

    An error if the configuration is invalid.

Properties

listeners: Map<string, MessageEventHandler<any>[]> = ...

Methods

  • Destroys all widgets, and resets the SDK to its initial state

    Returns Promise<void>

  • Emits a message to all widgets

    Type Parameters

    • P

    Parameters

    Returns this

    this

  • Gets the full screen data. It is not recommended to use this method directly.

    Returns any

    The full screen data

  • Gets the token, refreshing it if necessary. Utilizes a cache to prevent multiple requests, and only refreshes the token if it is expired (or refresh is true).

    Parameters

    • refresh: boolean = false

    Returns Promise<string>

    The token as a string inside a promise

  • Gets the timestamp (in milliseconds) when the token will expire

    Returns number

    The timestamp when the token will expire

  • Opens the AppWidget in full screen mode on the provided url

    Parameters

    • url: string

      The url to open in full screen

    Returns void

    An error if the url is not in the allowedOrigins list

    AppWidget

  • Refreshes the token and sends it to all widgets

    Parameters

    • Optionaltoken: string

      If provided, the token to use instead of fetching a new one with the tokenFN

    Returns Promise<void>

  • Sets the full screen data. It is not recommended to use this method directly.

    Parameters

    • data: any

      The full screen data

    Returns void

  • Triggers all listeners for a given message type

    Parameters

    • type: string

      The message type

    • envelope: MessageEnvelope<any>

      The message envelope containing the payload

    • sdk: ISDK

      The SDK instance

    • widget: IWidget

      The widget instance

    Returns void