5.1.2 • Published 3 days ago

@trycourier/react-provider v5.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
3 days ago

Version 5.X CSP Migration

We've released new subdomains to power Inbox and Toast. This migration only applies to Inbox and Toast users who applied our old URLs to their Content Security Policy.

BeforeAfterUsage
https://api.courier.comhttps://api.courier.comBrands and User Preferences
wss://1x60p1o3h8.execute-api.us-east-1.amazonaws.comwss://realtime.courier.comWebsockets
https://fxw3r7gdm9.execute-api.us-east-1.amazonaws.comhttps://inbox.courier.comInbox Messages

Props

interface ICourierProvider {
  /**
   * Token from the Courier auth/issue-token endpoint. Should have
   * user_id scope (user_id:<user-id-here>) and inbox:read:messages at a
   * minimum.
   */
  authorization?: string;
  brand?: Brand;
  brandId?: string;

  /** Allows the browser to modify or react to a received message before the message is displayed to the user */
  onMessage?: (
    message?: IInboxMessagePrpeview
  ) => IInboxMessagePrpeview | undefined;

  /** Courier client key. Along with userId and userSignature this can be used as an alternative to the authorization field / token. */
  clientKey?: string;
  /** Required if using client key and signature */
  userId?: string;
  /** User id signed by courier api key (hmac) */
  userSignature?: string;

  wsOptions?: WSOptions;
}

interface WSOptions {
  url?: string;
  onError?: (error: { message: string; error: Error }) => void;
  onClose?: () => void;
  connectionTimeout?: number;
}

interface Brand {
  inapp?: {
    disableCourierFooter?: boolean;
    borderRadius?: string;
    disableMessageIcon?: boolean;
    placement?: "top" | "bottom" | "left" | "right";
    emptyState?: {
      textColor?: string;
      text?: string;
    };
    icons?: {
      bell?: string;
      message?: string;
    };
    toast?: {
      borderRadius?: string;
      timerAutoClose?: number;
    };
  };
  colors?: {
    primary?: string;
    secondary?: string;
    tertiary?: string;
  };
}

Listening to Messsages

There are a few ways to listen for messages and being able react.

  1. Via Props
import { CourierProvider } from "@trycourier/react-provider";

const MyApp = ({ children }) => {
  const handleOnMessage = (messsage: IInboxMessagePreview) => {
    console.log(message);
    return message;
  };

  return (
    <CourierProvider onMessage={handleOnMessage}>{children}</CourierProvider>
  );
};
  1. Via Transport

You can create a Transport and pass it into CourierProvider.

import { useEffect } from "react";
import { CourierProvider, CourierTransport } from "@trycourier/react-provider";

const courierTransport = new CourierTransport({
  clientKey: CLIENT_KEY,
});

const MyApp = ({ children }) => {
  useEffect(() => {
    courierTransport.intercept((message) => {
      console.log(message);
      return message;
    });
  });

  return (
    <CourierProvider transport={courierTransport}>{children}</CourierProvider>
  );
};
  1. Via useCourier hook

If you don't pass in a transport, we will automatically create one. You can then access the transport via the CourierContext exposed through useCourier.

import { useEffect } from "react";
import { CourierProvider, useCourier } from "@trycourier/react-provider";

const courierTransport = new CourierTransport({
  clientKey: CLIENT_KEY,
});

const MyComponent = () => {
  const courier = useCourier();

  useEffect(() => {
    courier.transport.intercept((message) => {
      console.log(message);
      return message;
    });
  });

  return <div>Hello World</div>;
};

const MyApp = ({ children }) => {
  return (
    <CourierProvider>
      <MyComponent />
    </CourierProvider>
  );
};

Dark Mode / Theme Variables

Dark mode is supported by passing "theme.colorMode" to the CourierProvider

import { CourierProvider } from "@trycourier/react-provider";

const MyApp = ({ children }) => {
  return (
    <CourierProvider thene={{ colorMode: "dark" }}>{children}</CourierProvider>
  );
};

You can customize darkmode by passing in variables to the root level theme:

export interface ThemeVariables {
  background?: string;
  textColor?: string;
  titleColor?: string;
  structure?: string;
  icon?: string;
}```

```tsx
import { CourierProvider } from "@trycourier/react-provider";

const MyApp = ({ children }) => {
  return (
    <CourierProvider thene={{variables: {
        background: "red",
        textColor: "blue",
        titleColor: "green",
        structure: "pink",
        icon: "orange"
    }}}>{children}</CourierProvider>
  );
};
5.1.2

3 days ago

5.1.1

21 days ago

5.1.0

1 month ago

5.0.0

2 months ago

4.11.0

3 months ago

4.11.2

3 months ago

4.10.2

3 months ago

4.10.1

3 months ago

4.10.0

3 months ago

4.9.1

3 months ago

4.9.0

3 months ago

4.8.0

5 months ago

4.7.0

5 months ago

4.6.0

5 months ago

4.0.0

9 months ago

4.4.0

6 months ago

4.3.2

7 months ago

4.3.0

8 months ago

3.15.0

9 months ago

4.2.3

9 months ago

4.2.2

9 months ago

4.2.5

8 months ago

4.2.4

8 months ago

4.2.1

9 months ago

4.2.0

9 months ago

3.16.0

9 months ago

4.1.0

9 months ago

3.12.0

10 months ago

3.14.1

10 months ago

3.14.0

10 months ago

3.10.0

11 months ago

3.11.0

10 months ago

3.11.1

10 months ago

4.5.0

6 months ago

3.9.1

11 months ago

3.8.0

11 months ago

3.7.1

11 months ago

3.7.0

11 months ago

3.6.2

12 months ago

3.6.0

1 year ago

3.6.4

12 months ago

3.6.3

12 months ago

3.5.2

1 year ago

3.5.1

1 year ago

3.5.0

1 year ago

3.4.2

1 year ago

3.4.0

1 year ago

3.4.1

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.0.3

1 year ago

1.63.0

1 year ago

1.63.1

1 year ago

1.63.2

1 year ago

1.62.2

1 year ago

2.0.1

1 year ago

1.61.0

1 year ago

1.60.0

1 year ago

1.60.2

1 year ago

1.60.1

1 year ago

1.54.2

1 year ago

1.55.2

1 year ago

1.55.1

1 year ago

1.56.1

1 year ago

1.56.0

1 year ago

1.56.2

1 year ago

1.55.0

1 year ago

1.57.0

1 year ago

1.58.1

1 year ago

1.58.2

1 year ago

1.59.1

1 year ago

1.46.2

2 years ago

1.47.3

2 years ago

1.47.2

2 years ago

1.47.5

2 years ago

1.47.4

2 years ago

1.50.0

2 years ago

1.48.1

2 years ago

1.48.5

2 years ago

1.49.1

2 years ago

1.52.2

2 years ago

1.53.1

1 year ago

1.54.1

1 year ago

1.45.1

2 years ago

1.45.0

2 years ago

1.45.3

2 years ago

1.45.2

2 years ago

1.36.1

2 years ago

1.36.2

2 years ago

1.37.0

2 years ago

1.38.1

2 years ago

1.42.0

2 years ago

1.43.0

2 years ago

1.34.1

2 years ago

1.21.1

2 years ago

1.29.0

2 years ago

1.22.0

2 years ago

1.22.1

2 years ago

1.33.0

2 years ago

1.24.1

2 years ago

1.25.0

2 years ago

1.26.0

2 years ago

1.27.0

2 years ago

1.20.0

2 years ago

1.28.0

2 years ago

1.18.0

2 years ago

1.19.0

2 years ago

1.19.1

2 years ago

1.15.0

2 years ago

1.16.0

2 years ago

1.17.0

2 years ago

1.14.1

2 years ago

1.14.2

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.12.0

2 years ago

1.10.1

2 years ago

1.11.0

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.6.0

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.8.0

2 years ago

1.3.6

2 years ago

1.7.1

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.1

2 years ago

1.2.0

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.13-beta.0

3 years ago

0.1.11-beta.1

3 years ago

0.1.12-beta.0

3 years ago

0.1.10-beta.2

3 years ago

0.1.10-beta.0

3 years ago

0.1.10-beta.1

3 years ago

0.1.10-alpha.25

3 years ago

0.1.10-alpha.26

3 years ago

0.1.10-alpha.23

3 years ago

0.1.10-alpha.24

3 years ago

0.1.10-alpha.22

3 years ago

0.1.10-alpha.27

3 years ago

0.1.10-alpha.28

3 years ago

0.1.10-alpha.21

3 years ago

0.1.10-alpha.19

3 years ago

0.1.10-alpha.18

3 years ago

0.1.10-alpha.16

3 years ago

0.1.10-alpha.17

3 years ago

0.1.10-alpha.14

3 years ago

0.1.10-alpha.15

3 years ago

0.1.10-alpha.12

3 years ago

0.1.10-alpha.13

3 years ago

0.1.10-alpha.11

3 years ago

0.1.10-alpha.10

3 years ago

0.1.10-alpha.9

3 years ago

0.1.10-alpha.8

3 years ago

0.1.10-alpha.7

3 years ago

0.1.10-alpha.6

3 years ago

0.1.10-alpha.5

3 years ago

0.1.10-alpha.4

3 years ago

0.1.10-alpha.2

3 years ago

0.1.10-alpha.1

3 years ago

0.1.10-alpha.0

3 years ago