Skip to content

Commit

Permalink
test(fix test): fix test for usetransport
Browse files Browse the repository at this point in the history
  • Loading branch information
rileylnapier committed May 23, 2024
1 parent 5a2db2c commit 00141d1
Show file tree
Hide file tree
Showing 56 changed files with 318 additions and 418 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Want to use packages with other frameworks/libraries like _angular_ or _vue_? Ch

We've cleaned up a bunch of stale code that isn't being used anymore. We no longer export "Messages" from client-graphql and only support "Inbox" as a datasource.

Typings have also been fixed for client-graphql and useCourier hooks
- Typings have also been fixed for client-graphql and useCourier hooks
- Transport moved to a new package @trycourier/transport
- New package @trycourier/core to hold common types and lib functions

Styled Components is now a peer dependency

Expand Down
3 changes: 1 addition & 2 deletions packages/client-graphql/src/inbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import * as messages from "./messages";
import { MarkAllRead, markAllRead } from "./mark-all-read";
import { TrackEvent, trackEvent } from "./track-event";

export { IInboxMessage } from "./message";
export { IInboxMessagePreview, IGetInboxMessagesParams } from "./messages";
export { IGetInboxMessagesParams } from "./messages";

export default (
params:
Expand Down
7 changes: 2 additions & 5 deletions packages/client-graphql/src/inbox/message-lists.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
IGetInboxMessagesParams,
IInboxMessagePreview,
messagesProps,
} from "./messages";
import { IInboxMessagePreview } from "@trycourier/core";
import { IGetInboxMessagesParams, messagesProps } from "./messages";
import { Client } from "urql";

export type GetInboxMessageLists = (
Expand Down
22 changes: 1 addition & 21 deletions packages/client-graphql/src/inbox/message.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IInboxMessage } from "@trycourier/core";
import { Client } from "urql";

export const GET_INBOX_MESSAGE = `
Expand Down Expand Up @@ -30,27 +31,6 @@ export const GET_INBOX_MESSAGE = `
}
`;

export interface ITextElemental {
type: "text";
content: string;
}
export interface IActionElemental {
background_color?: string;
content: string;
data?: Record<string, any>;
href: string;
type: "text";
}
export interface IInboxMessage {
messageId: string;
read?: string;
created?: string;
content: {
html?: string;
elemental?: Array<ITextElemental | IActionElemental>;
};
}

export type GetInboxMessage = (messageId: string) => Promise<
| {
message: IInboxMessage;
Expand Down
15 changes: 1 addition & 14 deletions packages/client-graphql/src/inbox/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client } from "urql";
import { IActionElemental } from "./message";
import { IInboxMessagePreview } from "@trycourier/core";

export interface IGetInboxMessagesParams {
tenantId?: string;
Expand Down Expand Up @@ -68,19 +68,6 @@ export const createGetInboxMessagesQuery = (includePinned?: boolean) => `
}
`;

export interface IInboxMessagePreview {
actions?: IActionElemental[];
archived?: string;
created: string;
data?: Record<string, any>;
messageId: string;
opened?: string;
preview?: string;
read?: string;
tags?: string[];
title?: string;
}

export type GetInboxMessages = (
params?: IGetInboxMessagesParams,
after?: string
Expand Down
7 changes: 1 addition & 6 deletions packages/client-graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ export { createCourierClient } from "./client";
export { default as Banner } from "./banner";
export { default as Brands } from "./brands";
export { default as Events } from "./events";
export {
default as Inbox,
IInboxMessagePreview,
IInboxMessage,
IGetInboxMessagesParams,
} from "./inbox";
export { default as Inbox, IGetInboxMessagesParams } from "./inbox";
export {
default as Preferences,
UpdateRecipientPreferencesPayload,
Expand Down
3 changes: 2 additions & 1 deletion packages/components/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import {
} from "@testing-library/react";
import { graphql, rest } from "msw";
import { setupServer } from "msw/node";
import { IInboxMessagePreview } from "@trycourier/client-graphql";
import { IInboxMessagePreview } from "@trycourier/core";

function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

const mockGraphMessage: IInboxMessagePreview = {
type: "message",
messageId: "mockMessageId",
created: new Date().toISOString(),
title: "mockTitle",
Expand Down
16 changes: 16 additions & 0 deletions packages/core/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
sourceType: "unambiguous",
plugins: [
"@babel/transform-runtime",
"transform-inline-environment-variables",
"transform-class-properties",
process.env.NODE_ENV !== "test" && [
"babel-plugin-root-import",
{
rootPathSuffix: "./src",
rootPathPrefix: "~/",
},
],
].filter(Boolean),
presets: ["@babel/preset-typescript", "@babel/preset-env"],
};
5 changes: 5 additions & 0 deletions packages/core/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const jestConfigBase = require("../../jest.config.base");
const babelConfig = require("./babel.config.js");

module.exports = jestConfigBase(babelConfig);
23 changes: 23 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@trycourier/core",
"version": "6.0.0",
"description": "",
"main": "dist/index.js",
"types": "typings/index.d.ts",
"scripts": {
"babel": "babel src -d dist --extensions \".ts\" --ignore \"src/**/__tests__/**\"",
"build:watch": "yarn babel --watch",
"build": "rimraf dist && yarn babel",
"clean": "rimraf dist && rimraf typings",
"type-check": "tsc --noEmit",
"types": "tsc --emitDeclarationOnly"
},
"license": "ISC",
"dependencies": {
"rimraf": "^3.0.2"
},
"files": [
"dist/",
"typings/"
]
}
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./types";
export * from "./lib";
File renamed without changes.
156 changes: 156 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
export interface ICourierEventMessage {
event: "read" | "unread" | "archive" | "mark-all-read" | "opened" | "unpin";
type: "event";
messageId?: string;
error?: string;
}

export interface IInboxMessage {
messageId: string;
read?: string;
created?: string;
content: {
html?: string;
elemental?: Array<ITextElemental | IActionElemental>;
};
}

export interface ITextElemental {
type: "text";
content: string;
}

export interface IActionElemental {
background_color?: string;
type: "action";
content: string;
href: string;
data?: Record<string, any>;
}

export interface IInboxMessagePreview {
type: "message";
archived?: string;
created: string;
messageId: string;
pinned?: {
slotId?: string;
};
actions?: Array<IActionElemental>;
preview?: string;
icon?: string;
opened?: string;
data?: Record<string, any>;
/** ISO 8601 date the message was read */
read?: string;
tags?: string[];
title?: string;
trackingIds?: {
openTrackingId?: string;
archiveTrackingId?: string;
clickTrackingId?: string;
deliverTrackingId?: string;
readTrackingId?: string;
unreadTrackingId?: string;
};
}

export interface ICourierEvent {
type?: "message" | "event";
data?: IInboxMessagePreview | ICourierEventMessage;
}

export type ICourierEventCallback = (event: ICourierEvent) => void;

export type Interceptor = (
message?: ICourierEventMessage | IInboxMessagePreview
) => IInboxMessagePreview | ICourierEventMessage | undefined;

import { ErrorEvent } from "reconnecting-websocket";
export type ErrorEventHandler = (event: ErrorEvent) => void;

export type PreferenceStatus = "OPTED_IN" | "OPTED_OUT" | "REQUIRED";

export type RepeatOn = {
sunday?: boolean;
monday?: boolean;
tuesday?: boolean;
wednesday?: boolean;
thursday?: boolean;
friday?: boolean;
saturday?: boolean;
};

export interface DigestSchedule {
period: string;
repetition: string;
scheduleId: string;
default?: boolean;
start: string;
recurrence: string;
repeat?: {
frequency: number;
interval: "day" | "week" | "month" | "year";
on?: string | RepeatOn;
};
end?: number | string;
}

export interface IPreferenceTemplate {
templateName: string;
templateId: string;
defaultStatus: PreferenceStatus;
digestSchedules?: DigestSchedule[];
}

export type WSOptions = {
url?: string;
onError?: ErrorEventHandler;
onClose?: () => void;
onReconnect?: () => void;
connectionTimeout?: number;
};

export interface PinDetails {
id: string;
label: {
value: string;
color: string;
};
icon: {
value: string;
color: string;
};
}
export interface Brand {
inapp?: {
disableCourierFooter?: boolean;
borderRadius?: string;
disableMessageIcon?: boolean;
placement?: "top" | "bottom" | "left" | "right";
emptyState?: {
textColor?: string;
text?: string;
};
widgetBackground?: {
topColor?: string;
bottomColor?: string;
};
icons?: {
bell?: string;
message?: string;
};
slots?: Array<PinDetails>;
toast?: {
borderRadius?: string;
timerAutoClose?: number;
};
renderActionsAsButtons?: boolean;
};
preferenceTemplates?: Array<IPreferenceTemplate>;
colors?: {
primary?: string;
secondary?: string;
tertiary?: string;
};
}
12 changes: 12 additions & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig-base.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"declarationDir": "./typings",
"paths": {
"~/*": ["./src/*"]
}
},
"include": ["../types/@types/*/index.d.ts", "./src/**/*.ts"]
}
1 change: 1 addition & 0 deletions packages/react-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@trycourier/client-graphql": "^6.0.0",
"@trycourier/core": "^6.0.0",
"deep-extend": "^0.6.0",
"rimraf": "^3.0.2"
},
Expand Down
Loading

0 comments on commit 00141d1

Please sign in to comment.