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

Update Deps #4

Closed
wants to merge 1 commit into from
Closed
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
11,725 changes: 7,183 additions & 4,542 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloudmailin",
"version": "0.0.3",
"version": "0.1.0",
"description": "Official Node.js for the CloudMailin Email API - https://www.cloudmailin.com",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -35,18 +35,18 @@
"homepage": "https://www.cloudmailin.com",
"readme": "https://github.com/cloudmailin/cloudmailin-js#readme",
"dependencies": {
"axios": "^0.21.4"
"axios": "1.6.5"
},
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"eslint": "^7.20.0",
"jest": "^27.2.5",
"openapi-typescript": "^3.0.3",
"ts-jest": "^26.5.3",
"typedoc": "^0.20.27",
"typescript": "^4.1.5"
"@types/jest": "^29.5.11",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"jest": "^29.7.0",
"openapi-typescript": "^6.7.4",
"ts-jest": "^29.1.1",
"typedoc": "^0.25.7",
"typescript": "^5.3.3"
}
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import MessageClient, { MessageClientOptions } from "./messageClient";

import { Errors } from "./models"
import { IncomingMail } from "./models";
import { Message, MessageRaw } from "./models"
import { CloudMailinError } from "./models/errors"
import { IncomingMail } from "./models/IncomingMail";
import { Message, MessageRaw } from "./models/message"

export * as Models from "./models"

export {
MessageClient, MessageClientOptions,
Errors,
CloudMailinError as Errors,
IncomingMail,
Message, MessageRaw
};
15 changes: 3 additions & 12 deletions src/messageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default class MessageClient {
this.version = version;
this.options = options;

this.options.host = this.options.host || "api.cloudmailin.com";
this.options.baseURL = this.options.baseURL || `https://${this.options.host}/api/v0.1`;
this.options.host = this.options.host ?? "api.cloudmailin.com";
this.options.baseURL = this.options.baseURL ?? `https://${this.options.host}/api/v0.1`;
}

public sendMessage(message: Message): Promise<MessageResponse> {
Expand Down Expand Up @@ -53,16 +53,7 @@ export default class MessageClient {
}

private handleError(error: AxiosError) {
const response = error.response;
const status = response?.status;

switch (status) {
case 422:
return new errors.CloudMailinError(error.message, error);

default:
return new errors.CloudMailinError(error.message, error);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is redundant code

return new errors.CloudMailinError(error.message, error);
}

private makeClient() {
Expand Down
34 changes: 17 additions & 17 deletions src/models/cloudmailin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* Do not make direct changes to the file.
*/

export interface paths {
export interface Paths {
"/messages": {
post: operations["sendMessage"];
post: Operations["sendMessage"];
};
}

export interface components {
export interface Components {
schemas: {
MessageCommon: {
id?: string;
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface components {
/** Tags to */
tags?: string[] | string;
};
Message: components["schemas"]["MessageCommon"] & {
Message: Components["schemas"]["MessageCommon"] & {
/**
* The plain text part of the email message.
* Either the plain text or the html parts are required.
Expand All @@ -50,15 +50,15 @@ export interface components {
*/
html?: string;
headers?: { [key: string]: string };
attachments?: components["schemas"]["MessageAttachment"][];
attachments?: Components["schemas"]["MessageAttachment"][];
};
MessageAttachment: {
file_name: string;
content: string;
content_type: string;
content_id?: string;
};
RawMessage: components["schemas"]["MessageCommon"] & {
RawMessage: Components["schemas"]["MessageCommon"] & {
/**
* A full raw email.
* This should consist of both headers and a message body.
Expand Down Expand Up @@ -101,50 +101,50 @@ export interface components {
/** The user is not Authorized */
401: {
content: {
"application/json": components["schemas"]["UnauthorizedError"];
"application/json": Components["schemas"]["UnauthorizedError"];
};
};
/** The user is not Authorized */
403: {
content: {
"application/json": components["schemas"]["ForbiddenError"];
"application/json": Components["schemas"]["ForbiddenError"];
};
};
/** Resource be found or does not belong to this account */
404: {
content: {
"application/json": components["schemas"]["NotFoundError"];
"application/json": Components["schemas"]["NotFoundError"];
};
};
/** Unprocessable Entity, most likely your input does not pass validation */
422: {
content: {
"application/json": components["schemas"]["UnprocessableEntityError"];
"application/json": Components["schemas"]["UnprocessableEntityError"];
};
};
};
parameters: {
accountID: components["schemas"]["accountID"];
accountID: Components["schemas"]["accountID"];
};
}

export interface operations {
export interface Operations {
sendMessage: {
responses: {
/** The message has been accepted */
202: {
content: {
"application/json": components["schemas"]["MessageCommon"];
"application/json": Components["schemas"]["MessageCommon"];
};
};
401: components["responses"]["401"];
422: components["responses"]["422"];
401: Components["responses"]["401"];
422: Components["responses"]["422"];
};
requestBody: {
content: {
"application/json":
| components["schemas"]["Message"]
| components["schemas"]["RawMessage"];
| Components["schemas"]["Message"]
| Components["schemas"]["RawMessage"];
};
};
};
Expand Down
3 changes: 2 additions & 1 deletion src/models/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export class CloudMailinError extends Error {
public details: string;

constructor(message: string, baseError: AxiosError) {
const trueMessage = baseError.response?.data?.error || message;
// @ts-expect-error error is type any. not sure how to fix this one
const trueMessage = baseError.response?.data?.error ?? message;
super(trueMessage);

this.details = trueMessage;
Expand Down
3 changes: 3 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { CloudMailinError as Errors } from './errors';
export { IncomingMail } from './IncomingMail';
export { Message, MessageRaw } from './message';
8 changes: 4 additions & 4 deletions src/models/message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { components } from "./cloudmailin-api";
import { Components } from "./cloudmailin-api";

export type Message = components['schemas']['Message'];
export type MessageRaw = components['schemas']['RawMessage'];
export type MessageResponse = components['schemas']['MessageCommon'];
export type Message = Components['schemas']['Message'];
export type MessageRaw = Components['schemas']['RawMessage'];
export type MessageResponse = Components['schemas']['MessageCommon'];
6 changes: 3 additions & 3 deletions tests/integration/sendMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("sendMessage", () => {
plain: 'test message',
subject: "hello world"
});
}).rejects.toThrowError(cloudmailin.Errors.CloudMailinError);
}).rejects.toThrow(cloudmailin.Errors);
});

test("raises an error containing the remote error", async () => {
Expand All @@ -45,7 +45,7 @@ describe("sendMessage", () => {
to: '[email protected]',
from: '[email protected]',
});
}).rejects.toThrowError(/body not found/i);
}).rejects.toThrow(/body not found/i);
});

test("raises a UnprocessableEntity error", async () => {
Expand All @@ -55,6 +55,6 @@ describe("sendMessage", () => {
to: '[email protected]',
from: '[email protected]',
});
}).rejects.toThrowError(cloudmailin.Errors.CloudMailinError);
}).rejects.toThrow(cloudmailin.Errors);
});
});
16 changes: 8 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
Expand All @@ -27,16 +27,16 @@
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
Expand Down