Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move files to v0.0.1, jest config in ts and validateMessage function call before sending a message #29

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jest.config.js → jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import type { Config } from "@jest/types";

const config: Config.InitialOptions = {
preset: "ts-jest",
testEnvironment: "node",
collectCoverage: true,
Expand All @@ -15,3 +17,4 @@ module.exports = {
modulePaths: ["<rootDir>"],
moduleDirectories: ["node_modules"]
};
export default config;
133 changes: 128 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
"lint:fix": "npm run lint -- --fix",
"prettier": "prettier --write .",
"test": "npm run test:all",
"test:all": "jest --detectOpenHandles --forceExit",
"test:unit": "jest '/tests/unit/' --coverage=false",
"test:integration": "jest '/tests/integration/' --coverage=false --detectOpenHandles --forceExit",
Expand All @@ -32,7 +33,9 @@
},
"dependencies": {
"@xmtp/xmtp-js": "^5.4.0",
"ethers": "^5.6.9"
"ethers": "^5.6.9",
"valid-data-url": "^4.0.1",
"yup": "^0.32.11"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
MessageType,
SupportedFileMimeTypes,
ThreadObject
} from "../util/definitions";
} from "../util/v0.0.1/definitions";

// This is just a playground for development of the SDK
async function main() {
Expand Down
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import {
MessageObject,
ThreadId,
ThreadObject
} from "./util/definitions";
} from "./util/v0.0.1/definitions";
import {
getAuthorityId,
isValidJsonString,
isValidMessageType,
matchThreadIds
} from "./util/functions";
} from "./util/v0.0.1/functions";
import { validateMessage } from "./util/validators";

export class BosonXmtpClient extends XmtpClient {
/**
Expand Down Expand Up @@ -144,6 +145,13 @@ export class BosonXmtpClient extends XmtpClient {
recipient: string,
fallBackDeepLink?: string
): Promise<MessageData> {
if (
!(await validateMessage(messageObject, {
throwError: true
}))
) {
return;
}
const jsonString: string = JSON.stringify(messageObject);
const message: Message = await this.sendMessage(
messageObject.contentType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const version = "0.0.1";
export interface ThreadObject {
threadId: ThreadId;
counterparty: string;
Expand All @@ -21,7 +22,7 @@ export interface MessageData {
export interface MessageObject {
threadId: ThreadId;
contentType: MessageType;
version: string;
version: typeof version;
content: StringContent | FileContent | ProposalContent;
}

Expand Down
13 changes: 3 additions & 10 deletions src/util/functions.ts → src/util/v0.0.1/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ export function isValidJsonString(data: string): boolean {
* @returns boolean
*/
export function isValidMessageType(messageType: MessageType): boolean {
if (Object.values(MessageType).includes(messageType)) {
return true;
}
return false;
return Object.values(MessageType).includes(messageType);
}

/**
Expand All @@ -47,17 +44,13 @@ export function matchThreadIds(
threadId1: ThreadId,
threadId2: ThreadId
): boolean {
if (
return (
isValidThreadId(threadId1) &&
isValidThreadId(threadId2) &&
threadId1.exchangeId === threadId2.exchangeId &&
threadId1.buyerId === threadId2.buyerId &&
threadId1.sellerId === threadId2.sellerId
) {
return true;
}

return false;
);
}

/**
Expand Down
Loading