Skip to content

Commit b81a740

Browse files
committed
Documentation and codes have been updated.
1 parent 8e41b4f commit b81a740

File tree

5 files changed

+39
-38
lines changed

5 files changed

+39
-38
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ yarn add @cemalgnlts/mailjs
3232
const Mailjs = require("@cemalgnlts/mailjs");
3333
const mailjs = new Mailjs();
3434
mailjs.createOneAccount()
35-
.then((account)=>{
36-
console.log(account.data);
35+
.then(account => {
36+
console.log(account.data);
37+
});
3738

38-
mailjs.on("ready" , ()=>console.log("Ready To Listen!"));
39-
mailjs.on("arrive" , (msg)=>console.log(msg));
40-
});
39+
mailjs.on("ready" , () => console.log("Ready To Listen!"));
40+
mailjs.on("arrive" , msg => console.log(msg));
4141
```
4242

4343
- Nodejs (ESM)
@@ -56,7 +56,7 @@ Include these `scripts` in `html` page before using to include the extented poly
5656
<script src="https://cdn.jsdelivr.net/gh/cemalgnlts/Mailjs@latest/eventsource.min.js"></script>
5757

5858
<script>
59-
const mailjs = new Mailjs();
59+
const mailjs = new Mailjs();
6060
</script>
6161

6262
```
@@ -65,15 +65,15 @@ For more reference visit `/examples` directory.
6565

6666
# Documentation
6767

68-
Returns a Promise object after the function is called. If the request is sent correctly, `status` returns true. If it returns incorrect, the `status` will be false and the `message` in the data is also added.
68+
Returns a Promise object after the function is called. If the request is sent correctly, `status` returns true. If it returns incorrect, the `status` will be false and the `message` in the data is also added. If there is no error, `status` always returns `true`.
6969

7070
A successfull response example:
7171

7272
```json
7373
{
7474
"status": true,
7575
"message": "ok",
76-
"data": ...
76+
"data": {}
7777
}
7878
```
7979

@@ -83,7 +83,7 @@ A failed response example:
8383
{
8484
"status": false,
8585
"message": "Invalid credentials.",
86-
"data": ...
86+
"data": {}
8787
}
8888
```
8989

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare class Mailjs {
2727
/** Retrieve a domain by its id. */
2828
getDomain(domainId: string): type.DomainResult;
2929
/** open an eventlistener to messages and error */
30-
on(event: string, callback: type.MessageCallback | type.EmptyCallback | type.ErrorCallback): void;
30+
on(event: "seen" | "delete" | "arrive" | "error" | "open" | "ready", callback: type.MessageCallback | type.EmptyCallback | type.ErrorCallback): void;
3131
/** Clears the events and safely closes eventlistener */
3232
close(): void;
3333
/** Gets all the Message resources of a given page. */

dist/types.d.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
export declare type Methods = "GET" | "POST" | "DELETE" | "PATCH";
2-
export declare type PromiseResult<T> = Promise<IResult<T>>;
3-
export declare type RegisterResult = PromiseResult<IRegisterResult>;
4-
export declare type LoginResult = PromiseResult<ILoginResult>;
5-
export declare type DeleteResult = Promise<IDelete>;
6-
export declare type AccountResult = PromiseResult<IAccountResult>;
7-
export declare type DomainListResult = PromiseResult<IDomainResult[]>;
8-
export declare type DomainResult = PromiseResult<IDomainResult>;
9-
export declare type MessageListResult = PromiseResult<IMessagesResult[]>;
10-
export declare type MessageResult = PromiseResult<IMessageResult>;
11-
export declare type MessageSeenResult = PromiseResult<IMessageSeen>;
12-
export declare type SourceResult = PromiseResult<ISourceResource>;
13-
export declare type MessageCallback = (message: IMessagesResult) => void;
14-
export declare type EmptyCallback = () => void;
15-
export declare type ErrorCallback = (err: any) => void;
1+
export type Methods = "GET" | "POST" | "DELETE" | "PATCH";
2+
export type PromiseResult<T> = Promise<IResult<T>>;
3+
export type RegisterResult = PromiseResult<IRegisterResult>;
4+
export type LoginResult = PromiseResult<ILoginResult>;
5+
export type DeleteResult = Promise<IDelete>;
6+
export type AccountResult = PromiseResult<IAccountResult>;
7+
export type DomainListResult = PromiseResult<IDomainResult[]>;
8+
export type DomainResult = PromiseResult<IDomainResult>;
9+
export type MessageListResult = PromiseResult<IMessagesResult[]>;
10+
export type MessageResult = PromiseResult<IMessageResult>;
11+
export type MessageSeenResult = PromiseResult<IMessageSeen>;
12+
export type SourceResult = PromiseResult<ISourceResource>;
13+
export type MessageCallback = (message: IMessagesResult) => void;
14+
export type EmptyCallback = () => void;
15+
export type ErrorCallback = (err: any) => void;
1616
/** register() */
1717
interface IRegisterResult {
1818
id: string;
@@ -101,7 +101,7 @@ interface ISourceResource {
101101
downloadUrl: string;
102102
data: string;
103103
}
104-
export declare type CreateOneAccountResult = Promise<DomainResult | RegisterResult | LoginResult | {
104+
export type CreateOneAccountResult = Promise<DomainResult | RegisterResult | LoginResult | {
105105
status: boolean;
106106
data: {
107107
username: string;

mailjs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,42 +100,43 @@ class Mailjs {
100100
// Message
101101

102102
/** open an eventlistener to messages and error */
103-
on(event:string , callback: type.MessageCallback | type.EmptyCallback | type.ErrorCallback){
104-
103+
on(event: "seen" | "delete" | "arrive" | "error" | "open" | "ready", callback: type.MessageCallback | type.EmptyCallback | type.ErrorCallback) {
105104
const allowedEvents = ["seen" , "delete" , "arrive" , "error" , "ready"];
105+
106106
// Checking if valid events
107-
if(!allowedEvents.includes(event)){
107+
if(!allowedEvents.includes(event)) {
108108
return;
109109
}
110110

111-
if(!this.listener){
111+
if(!this.listener) {
112112
this.listener = new EventSource(`${this.baseMercure}?topic=/accounts/${this.id}` , {
113-
headers : {
113+
headers: {
114114
"Authorization" : `Bearer ${this.token}`,
115115
}
116116
});
117117

118-
for(let i=0;i<3;i++){
119-
this.events[allowedEvents[i]] = (_data)=>{};
118+
for(let i=0; i<3; i++){
119+
this.events[allowedEvents[i]] = (_data) => {};
120120
}
121+
121122
this.listener.on("message" , this.callback_);
122123
}
123124

124-
if(event==="error" || event==="ready"){
125+
if(event === "error" || event === "ready") {
125126

126-
if(event==="ready"){
127+
if(event === "ready") {
127128
event = "open"
128129
}
129130

130-
this.listener.on(event , callback);
131+
this.listener.on(event, callback);
131132
return;
132133
}
133134

134135
this.events[event] = callback;
135136
}
136137

137138
/** Clears the events and safely closes eventlistener */
138-
close(){
139+
close() {
139140
this.events = {};
140141
this.listener.close();
141142
this.listener = null;

0 commit comments

Comments
 (0)