5htp-core 0.6.0-5 → 0.6.0-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.6.0-
|
|
4
|
+
"version": "0.6.0-6",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
- DEPENDANCES
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
|
-
/* NOTE: On évite d'utiliser les alias ici,
|
|
6
|
-
Afin que l'envoi des rapports de bug fonctionne même en cas d'erreur avec les alias
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
5
|
// Core
|
|
10
6
|
import type { Application } from '@server/app';
|
|
11
7
|
import Service from '@server/app/service';
|
|
@@ -13,7 +9,6 @@ import markdown from '@common/data/markdown';
|
|
|
13
9
|
|
|
14
10
|
// Speciic
|
|
15
11
|
import { jsonToHtml } from './utils';
|
|
16
|
-
import type { Transporter } from './transporter';
|
|
17
12
|
|
|
18
13
|
/*----------------------------------
|
|
19
14
|
- SERVICE CONFIG
|
|
@@ -25,16 +20,12 @@ export type Config = {
|
|
|
25
20
|
debug: boolean,
|
|
26
21
|
simulateWhenLocal: boolean,
|
|
27
22
|
default: {
|
|
28
|
-
transporter: string,
|
|
29
23
|
from: TPerson
|
|
30
24
|
},
|
|
31
25
|
bugReport: {
|
|
32
26
|
from: TPerson,
|
|
33
27
|
to: TPerson
|
|
34
28
|
},
|
|
35
|
-
transporters: {
|
|
36
|
-
[transporterId: string]: Transporter
|
|
37
|
-
}
|
|
38
29
|
}
|
|
39
30
|
|
|
40
31
|
export type Hooks = {
|
|
@@ -49,9 +40,7 @@ export type Services = {
|
|
|
49
40
|
- TYPES: EMAILS
|
|
50
41
|
----------------------------------*/
|
|
51
42
|
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
export type TEmail = THtmlEmail | TMarkdownEmail// | TTemplateEmail;
|
|
43
|
+
export type TEmail = THtmlEmail | TMarkdownEmail;
|
|
55
44
|
|
|
56
45
|
type TPerson = {
|
|
57
46
|
name?: string,
|
|
@@ -74,11 +63,6 @@ export type TMarkdownEmail = TBaseEmail & {
|
|
|
74
63
|
markdown: string,
|
|
75
64
|
}
|
|
76
65
|
|
|
77
|
-
/*export type TTemplateEmail = TBaseEmail & {
|
|
78
|
-
template: keyof typeof templates,
|
|
79
|
-
data?: TObjetDonnees
|
|
80
|
-
}*/
|
|
81
|
-
|
|
82
66
|
export type TCompleteEmail = With<THtmlEmail, {
|
|
83
67
|
to: TPerson[],
|
|
84
68
|
from: TPerson,
|
|
@@ -109,14 +93,15 @@ type TOptions = {
|
|
|
109
93
|
/*----------------------------------
|
|
110
94
|
- FONCTIONS
|
|
111
95
|
----------------------------------*/
|
|
112
|
-
export default class Email extends
|
|
113
|
-
|
|
114
|
-
private transporters = this.config.transporters;
|
|
96
|
+
export default abstract class Email<TConfig extends Config>
|
|
97
|
+
extends Service<TConfig, Hooks, Application> {
|
|
115
98
|
|
|
116
99
|
/*----------------------------------
|
|
117
100
|
- ACTIONS
|
|
118
101
|
----------------------------------*/
|
|
119
102
|
|
|
103
|
+
protected abstract sendNow( emails: TCompleteEmail[] ): Promise<void>;
|
|
104
|
+
|
|
120
105
|
public async send( to: string, subject: string, markdown: string, options?: TOptions );
|
|
121
106
|
public async send( emails: TEmail | TEmail[], options?: TOptions ): Promise<void>;
|
|
122
107
|
public async send( ...args: TEmailSendArgs ): Promise<void> {
|
|
@@ -162,30 +147,7 @@ export default class Email extends Service<Config, Hooks, Application> {
|
|
|
162
147
|
? email.to
|
|
163
148
|
: [email.to];
|
|
164
149
|
|
|
165
|
-
|
|
166
|
-
// TODO: Restore templates feature
|
|
167
|
-
/*if ('template' in email) {
|
|
168
|
-
|
|
169
|
-
const template = templates[email.template];
|
|
170
|
-
|
|
171
|
-
if (template === undefined)
|
|
172
|
-
throw new Error(`Impossible de charger la template email ${email.template} depuis le cache (NotFound).`);
|
|
173
|
-
|
|
174
|
-
const txt = template(email.data || {})
|
|
175
|
-
|
|
176
|
-
const delimTitre = txt.indexOf('\n\n');
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
...email,
|
|
180
|
-
// Vire le "> " au début
|
|
181
|
-
subject: txt.substring(2, delimTitre),
|
|
182
|
-
html: htmlWarning + txt.substring(delimTitre + 2),
|
|
183
|
-
from,
|
|
184
|
-
to,
|
|
185
|
-
cc
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
} else */if ('markdown' in email) {
|
|
150
|
+
if ('markdown' in email) {
|
|
189
151
|
|
|
190
152
|
return {
|
|
191
153
|
...email,
|
|
@@ -209,11 +171,7 @@ export default class Email extends Service<Config, Hooks, Application> {
|
|
|
209
171
|
|
|
210
172
|
});
|
|
211
173
|
|
|
212
|
-
|
|
213
|
-
if (transporterName === undefined)
|
|
214
|
-
throw new Error(`Please define at least one mail transporter.`);
|
|
215
|
-
|
|
216
|
-
console.info(LogPrefix, `Sending ${emailsToSend.length} emails via transporter "${transporterName}"`, emailsToSend[0].subject);
|
|
174
|
+
console.info(LogPrefix, `Sending ${emailsToSend.length} emails via transporter`, emailsToSend[0].subject);
|
|
217
175
|
|
|
218
176
|
// Pas d'envoi d'email quand local
|
|
219
177
|
if (this.app.env.name === 'local' && this.config.simulateWhenLocal === true) {
|
|
@@ -224,8 +182,7 @@ export default class Email extends Service<Config, Hooks, Application> {
|
|
|
224
182
|
return;
|
|
225
183
|
}
|
|
226
184
|
|
|
227
|
-
|
|
228
|
-
await transporter.send(emailsToSend);
|
|
185
|
+
await this.sendNow(emailsToSend);
|
|
229
186
|
|
|
230
187
|
}
|
|
231
188
|
}
|
package/types/icons.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type TIcones = "
|
|
1
|
+
export type TIcones = "solid/spinner-third"|"long-arrow-right"|"search"|"paper-plane"|"bookmark"|"solid/download"|"mouse-pointer"|"thumbs-up"|"dollar-sign"|"times"|"angle-down"|"th-large"|"table"|"traffic-light-stop"|"times-circle"|"info-circle"|"check-circle"|"exclamation-circle"|"heart"|"bell"|"chart-bar"|"power-off"|"seedling"|"palette"|"car"|"plane"|"university"|"briefcase"|"hard-hat"|"graduation-cap"|"bolt"|"cogs"|"film"|"leaf"|"tshirt"|"utensils"|"globe"|"map-marked-alt"|"dumbbell"|"stethoscope"|"concierge-bell"|"book"|"shield-alt"|"gavel"|"industry"|"square-root-alt"|"newspaper"|"pills"|"medal"|"capsules"|"balance-scale"|"home"|"praying-hands"|"shopping-cart"|"flask"|"futbol"|"microchip"|"satellite-dish"|"shipping-fast"|"passport"|"tools"|"chart-line"|"lock"|"eye"|"credit-card"|"at"|"brands/linkedin"|"image"|"key"|"brands/google"|"check"|"bars"|"books"|"box-full"|"planet-ringed"|"brands/twitter"|"brands/facebook"|"database"|"brain"|"download"|"code"|"money-bill"|"rocket"|"user-circle"|"plus-circle"|"solid/heart"|"regular/heart"|"trash"|"arrow-left"|"arrow-right"|"meh-rolling-eyes"|"unlink"|"pen"|"bold"|"italic"|"underline"|"strikethrough"|"subscript"|"superscript"|"link"|"file"|"plus"|"font"|"empty-set"|"horizontal-rule"|"page-break"|"poll"|"columns"|"sticky-note"|"caret-right"|"list-ul"|"check-square"|"h1"|"h2"|"h3"|"h4"|"list-ol"|"paragraph"|"quote-left"|"align-left"|"align-center"|"align-right"|"align-justify"|"indent"|"outdent"
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/*----------------------------------
|
|
2
|
-
- DEPENDANCES
|
|
3
|
-
----------------------------------*/
|
|
4
|
-
|
|
5
|
-
import Handlebars, { TemplateDelegate } from 'handlebars';
|
|
6
|
-
|
|
7
|
-
//import * as templates from '@cache/serveur/emails';
|
|
8
|
-
import templatesDefault from '@root/default/serveur/emails/*.hbs';
|
|
9
|
-
import templatesProjet from '@/*/serveur/emails/*.hbs';
|
|
10
|
-
const templates = { ...templatesDefault, ...templatesProjet }
|
|
11
|
-
import url from '@commun/routeur/url';
|
|
12
|
-
|
|
13
|
-
/*----------------------------------
|
|
14
|
-
- HELPERS
|
|
15
|
-
----------------------------------*/
|
|
16
|
-
|
|
17
|
-
Handlebars.registerHelper('plur', (mot: string, nb: number) =>
|
|
18
|
-
mot + (nb > 1 ? 's' : '')
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
Handlebars.registerHelper('url', (route: string, params?: any, absolu?: boolean) =>
|
|
22
|
-
url(route, params, absolu)
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
/*----------------------------------
|
|
26
|
-
- FONCTIONS
|
|
27
|
-
----------------------------------*/
|
|
28
|
-
const cache: {[nomTemplate: string]: TemplateDelegate} = {}
|
|
29
|
-
|
|
30
|
-
export const compiler = async () => {
|
|
31
|
-
|
|
32
|
-
console.log(`[boot] Précompilation de ${Object.keys(templates).length} templates email`);
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
for (const nomTemplate in templates) {
|
|
36
|
-
|
|
37
|
-
const template = templates[nomTemplate];
|
|
38
|
-
|
|
39
|
-
cache[ nomTemplate ] = Handlebars.compile(template, {
|
|
40
|
-
strict: true, // Erreur quand variable inexistante
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error(`Erreur lors de la précompilation des templates email:`, error);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default cache
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*----------------------------------
|
|
2
|
-
- DEPENDANCES
|
|
3
|
-
----------------------------------*/
|
|
4
|
-
|
|
5
|
-
// Npm
|
|
6
|
-
|
|
7
|
-
// Core
|
|
8
|
-
import type Application from "@server/app";
|
|
9
|
-
import Service from '@server/app/service';
|
|
10
|
-
import type EmailService from '@server/services/email';
|
|
11
|
-
|
|
12
|
-
// Specific
|
|
13
|
-
import type { TCompleteEmail } from ".";
|
|
14
|
-
|
|
15
|
-
/*----------------------------------
|
|
16
|
-
- TYPES
|
|
17
|
-
----------------------------------*/
|
|
18
|
-
|
|
19
|
-
export type TBasicConfig = {
|
|
20
|
-
api: string,
|
|
21
|
-
debug: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/*----------------------------------
|
|
25
|
-
- CLASS
|
|
26
|
-
----------------------------------*/
|
|
27
|
-
export abstract class Transporter<TConfig extends TBasicConfig = TBasicConfig>
|
|
28
|
-
extends Service<TConfig, {}, Application> {
|
|
29
|
-
|
|
30
|
-
public abstract send( emails: TCompleteEmail[] ): Promise<void>;
|
|
31
|
-
}
|