mailchimp-buddy
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -16,6 +16,6 @@ import { AxiosResponse } from 'axios'; | ||
}>>; | ||
get(email: string): Promise<AxiosResponse<Member>>; | ||
get(emailOrMd5: string): Promise<AxiosResponse<Member>>; | ||
setStatus(email: string, status: Status): Promise<AxiosResponse<any>>; | ||
setStatusIfNew(email: string, status: Status): Promise<AxiosResponse<any>>; | ||
remove(email: string): Promise<AxiosResponse<any>>; | ||
remove(emailOrMd5: string): Promise<AxiosResponse<any>>; | ||
}; |
@@ -24,5 +24,5 @@ "use strict"; | ||
}, | ||
get(email) { | ||
get(emailOrMd5) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield axios_1.default.get(`${baseUrl}/${md5(email)}`, { headers }); | ||
return yield axios_1.default.get(`${baseUrl}/${ensureMd5(emailOrMd5)}`, { headers }); | ||
}); | ||
@@ -38,9 +38,9 @@ }, | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const data = { email_address: email, status_if_new: status }; | ||
const data = { email_address: email.toLowerCase(), status_if_new: status }; | ||
return yield axios_1.default.put(`${baseUrl}/${md5(email)}`, data, { headers }); | ||
}); | ||
}, | ||
remove(email) { | ||
remove(emailOrMd5) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield axios_1.default.delete(`${baseUrl}/${md5(email)}`, { headers }); | ||
return yield axios_1.default.delete(`${baseUrl}/${ensureMd5(emailOrMd5)}`, { headers }); | ||
}); | ||
@@ -51,4 +51,11 @@ }, | ||
exports.default = default_1; | ||
function ensureMd5(emailOrMd5) { | ||
return isEmail(emailOrMd5) ? md5(emailOrMd5) : emailOrMd5; | ||
} | ||
function isEmail(emailOrMd5) { | ||
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
return re.test(String(emailOrMd5).toLowerCase()); | ||
} | ||
function md5(email) { | ||
return crypto.createHash('md5').update(email.toLowerCase()).digest('hex'); | ||
} |
{ | ||
"name": "mailchimp-buddy", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
@@ -28,4 +28,4 @@ import * as crypto from 'crypto'; | ||
async get(email: string): Promise<AxiosResponse<Member>> { | ||
return await axios.get<Member>(`${baseUrl}/${md5(email)}`, { headers }); | ||
async get(emailOrMd5: string): Promise<AxiosResponse<Member>> { | ||
return await axios.get<Member>(`${baseUrl}/${ensureMd5(emailOrMd5)}`, { headers }); | ||
}, | ||
@@ -39,8 +39,8 @@ | ||
async setStatusIfNew(email: string, status: Status) { | ||
const data = { email_address: email, status_if_new: status }; | ||
const data = { email_address: email.toLowerCase(), status_if_new: status }; | ||
return await axios.put(`${baseUrl}/${md5(email)}`, data, { headers }); | ||
}, | ||
async remove(email: string) { | ||
return await axios.delete(`${baseUrl}/${md5(email)}`, { headers }); | ||
async remove(emailOrMd5: string) { | ||
return await axios.delete(`${baseUrl}/${ensureMd5(emailOrMd5)}`, { headers }); | ||
}, | ||
@@ -50,4 +50,13 @@ } | ||
function ensureMd5(emailOrMd5: string): string { | ||
return isEmail(emailOrMd5) ? md5(emailOrMd5) : emailOrMd5; | ||
} | ||
function isEmail(emailOrMd5: string): boolean { | ||
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
return re.test(String(emailOrMd5).toLowerCase()); | ||
} | ||
function md5(email: string) { | ||
return crypto.createHash('md5').update(email.toLowerCase()).digest('hex'); | ||
} |
6489
137